/* ==========================================================================
   1. VARIABLES & RESET GLOBAL
   ========================================================================== */

:root {
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --success-color: #2ecc71;
  --error-color: #e74c3c;
  --bg-color: #f4f6f8;
  --card-bg: #ffffff;
  --text-color: #333;
  --border-color: #e0e0e0;
}

* {
  touch-action: manipulation;
  box-sizing: border-box;
}

*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: white url("/static/cashlogo.png") no-repeat center center fixed;
  background-size: 500px auto;
  min-height: 100vh;
  color: var(--text-color);
  margin: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  overflow-y: hidden;
  width: 100vw;
}

/* ==========================================================================
   2. NAVBAR & NAVIGATION
   ========================================================================== */

.navbar {
  width: 100%;
  max-width: 1100px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-center {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-color);
  white-space: nowrap;
}

.nav-badge {
  background: #f1f4f7;
  color: var(--primary-color);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.nav-btn {
  background-color: var(--primary-color);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition:
    background-color 0.3s,
    transform 0.1s;
}

.nav-btn:hover {
  background-color: var(--accent-color);
  transform: translateY(-1px);
}

/* ==========================================================================
   3. BARRE DE SCAN, FOOTER & INPUTS
   ========================================================================== */

.scan-bar {
  position: sticky;
  top: 10px;
  z-index: 100;
  background: var(--card-bg);
  padding: 15px 25px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  max-width: 600px;
  margin-bottom: 30px;
  border: 1px solid var(--border-color);
}

#scanForm {
  display: flex;
  flex: 1;
  gap: 10px;
}

.footer-bar {
  position: sticky;
  bottom: 10px;
  z-index: 100;
  background: var(--card-bg);
  padding: 15px 25px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: center;
  gap: 15px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 30px;
  border: 1px solid var(--border-color);
}

input[type="text"] {
  flex: 1;
  padding: 12px 20px;
  border: 2px solid var(--border-color);
  border-radius: 25px;
  font-size: 16px;
  color: var(--text-color);
  outline: none;
  transition: border-color 0.3s;
}

input[type="text"]:focus {
  border-color: var(--accent-color);
}

button,
a {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 25px;
  border-radius: 10px;
  font-weight: bold;
  cursor: pointer;
  transition:
    background-color 0.3s,
    transform 0.1s;
  text-decoration: none;
  display: inline-block;
}

button:hover,
a:hover {
  background-color: var(--accent-color);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

/* ==========================================================================
   4. DASHBOARD ADMIN (GRILLE & CARTES)
   ========================================================================== */

.admin-grid {
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: 32px;
  width: 100%;
  max-width: 90vw;
  margin: 0 auto 40px auto;
  grid-template-areas:
    "stats stats"
    "logs magasins";
}

.widget-logs {
  grid-area: logs;
}
.widget-magasins {
  grid-area: magasins;
}
.widget-stats {
  grid-area: stats;
}

.admin-card {
  margin: 0;
  background-color: var(--bg-color);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 200px;
  max-height: 40vh;
  border-radius: 10px;
  overflow: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.admin-card-header,
.admin-card-footer {
  background: var(--primary-color);
  text-align: center;
  color: white;
}

.admin-card-header {
  border-radius: 10px 10px 0 0;
}
.admin-card-footer {
  border-radius: 0 0 10px 10px;
  padding: 5px;
}

.admin-card-content {
  display: flex;
  justify-content: center;
  flex: 1;
  overflow: hidden;
  padding: 15px;
}

/* ==========================================================================
   5. TABLEAUX & LISTES
   ========================================================================== */
.stats-card-content {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 0 18px 0;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 28px;
}
.stat-block {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(44, 62, 80, 0.07);
  padding: 18px 22px;
  text-align: center;
  min-width: 120px;
  border: 1px solid var(--border-color);
}
.stat-label {
  font-size: 0.98rem;
  color: #888;
  margin-bottom: 6px;
  font-weight: 500;
}
.stat-value {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--primary-color);
  letter-spacing: 1px;
}
.stat-success {
  color: var(--success-color);
}
.stat-error {
  color: var(--error-color);
}
.stat-rate {
  color: var(--accent-color);
}
.store-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 100%;
  width: 250px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #bdc3c7 #f0f0f0;
}
.store-list::-webkit-scrollbar {
  width: 8px;
}
.store-list::-webkit-scrollbar-thumb {
  background: #bdc3c7;
  border-radius: 4px;
}

.store-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 18px;
  box-shadow: 0 2px 8px rgba(44, 62, 80, 0.06);
  transition:
    box-shadow 0.2s,
    background 0.2s;
}
.store-item:hover {
  background: #f4f6fa;
  box-shadow: 0 4px 16px rgba(44, 62, 80, 0.1);
}

.store-name {
  font-weight: 500;
  color: var(--primary-color);
  font-size: 1.05rem;
  letter-spacing: 0.4px;
}

.store-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  transition:
    background-color 0.3s,
    transform 0.1s;
}
.store-btn:hover {
  background-color: var(--accent-color);
  transform: translateY(0px);
}

.table-wrapper {
  width: 100%;
  max-width: 1200px;
  width: 100%;
  max-height: 75vh;
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow: auto;
  border: 1px solid var(--border-color);
  scrollbar-width: thin;
  scrollbar-color: #bdc3c7 #f0f0f0;
}

.table-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.table-wrapper::-webkit-scrollbar-track {
  background: #f0f0f0;
}
.table-wrapper::-webkit-scrollbar-thumb {
  background-color: #bdc3c7;
  border-radius: 4px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent-color);
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrapper thead {
  background-color: var(--primary-color);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-wrapper th,
.table-wrapper td {
  padding: 15px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

.table-wrapper th {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.table-wrapper tbody tr {
  transition: background-color 0.3s;
}
.table-wrapper tbody tr:nth-child(even) {
  background-color: #f9fbfd;
}
.table-wrapper tbody tr:hover {
  background-color: #f1f7fc;
}

td[id^="qty-"] {
  font-weight: bold;
  color: var(--primary-color);
  white-space: nowrap;
}

.manual-btn {
  color: white;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation; /* Sécurité supplémentaire */
}

.manual-btn.add {
  background-color: var(--success-color);
}
.manual-btn.remove {
  background-color: var(--error-color);
}

.no-data {
  color: #ccc;
  font-style: italic;
}

.table-wrapper.logs-table {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: #fff;
}
.logs-table table {
  width: 100%;
  min-width: unset;
  table-layout: fixed;
}
.logs-table th:nth-child(1),
.logs-table td:nth-child(1) {
  width: 160px;
}
.logs-table th:nth-child(2),
.logs-table td:nth-child(2) {
  width: 80px;
  text-align: center;
}
.logs-table th:nth-child(3),
.logs-table td:nth-child(3) {
  font-weight: bold;
}
.logs-table td {
  vertical-align: middle;
  font-size: 0.9rem;
  padding: 10px 15px;
  word-wrap: break-word;
}
.logs-table td:nth-child(2) {
  font-weight: bold;
  color: var(--accent-color);
}

/* ==========================================================================
   6. MODALES & POPUPS
   ========================================================================== */

.modal-overlay {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  max-height: 100vh;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background-color: var(--card-bg);
  width: 90%;
  max-width: 100%;
  border-radius: 15px;
  max-height: 100%;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  background-color: var(--primary-color);
  color: white;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}
.close-btn {
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.modal-form {
  padding: 20px;
}
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-color);
}
.form-input {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}
.form-input:focus {
  border-color: var(--accent-color);
}
.file-input {
  padding: 5px;
  background: #f9f9f9;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #eee;
}

.btn-cancel {
  background-color: #95a5a6;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-submit {
  background-color: var(--success-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
}

.btn-submit:hover {
  background-color: #27ae60;
}
.btn-cancel:hover {
  background-color: #7f8c8d;
}

#popup-notification {
  visibility: hidden;
  min-width: 280px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 8px;
  padding: 16px;
  position: fixed;
  z-index: 2000;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  font-size: 1rem;
  font-weight: 500;
  opacity: 0;
  transition:
    opacity 0.3s,
    top 0.3s;
}

#popup-notification.show {
  visibility: visible;
  opacity: 1;
  top: 80px;
}
#popup-notification.success {
  background-color: var(--success-color);
}
#popup-notification.error {
  background-color: var(--error-color);
}

/* ==========================================================================
   7. UTILITAIRES (JSON, ScrollTop, Keypad)
   ========================================================================== */

#scrollTopBtn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  line-height: 1;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background-color: var(--primary-color);
  color: white;
  font-size: 1.5rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s,
    visibility 0.3s,
    background-color 0.3s,
    transform 0.2s;
}

#scrollTopBtn.show {
  opacity: 1;
  visibility: visible;
}
#scrollTopBtn:hover {
  background-color: var(--accent-color);
  transform: translateY(-3px);
}
#scrollTopBtn:active {
  transform: scale(0.9);
}

.modal-body-json {
  background-color: #282c34;
}
pre {
  margin: 0;
  padding: 20px;
  text-align: left;
  counter-reset: line;
}
code {
  font-family: "Consolas", "Monaco", "Fira Code", monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #abb2bf;
  white-space: pre-wrap;
}
.json-key {
  color: #e06c75;
  font-weight: bold;
}
.json-string {
  color: #98c379;
}
.json-number {
  color: #d19a66;
}
.json-boolean {
  color: #61afef;
  font-weight: bold;
}
.json-null {
  color: #56b6c2;
}
.modal-body::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.modal-body::-webkit-scrollbar-track {
  background: #282c34;
}
.modal-body::-webkit-scrollbar-thumb {
  background: #4b5263;
  border-radius: 5px;
  border: 2px solid #282c34;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: #5c6370;
}

.keypad-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}
.keypad-content {
  background: white;
  padding: 20px;
  border-radius: 10px;
  width: 300px;
}
.keypad-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}
#keypad-display {
  font-size: 1.2rem;
  font-weight: bold;
  border-bottom: 2px solid #333;
  flex-grow: 1;
  margin-right: 10px;
  min-height: 30px;
}
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.keypad-grid button {
  padding: 20px;
  font-size: 1.2rem;
  border: 1px solid #ccc;
  border-radius: 5px;
  cursor: pointer;
}

/* ==========================================================================
   8. MEDIA QUERIES (MOBILE)
   ========================================================================== */

@media (max-width: 768px) {
  body {
    padding: 10px;
    padding-bottom: 80px;
    overflow-y: auto;
  }
  h1 {
    font-size: 1.2rem;
  }

  button,
  a {
    touch-action: manipulation;
    padding: 5px 10px;
    border-radius: 10px;
  }

  .navbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .nav-left,
  .nav-right {
    justify-content: space-between;
  }
  .nav-center {
    justify-content: center;
  }
  .nav-btn {
    width: 100%;
    text-align: center;
  }

  .scan-bar {
    width: 100%;
    padding: 10px;
    gap: 8px;
    border-radius: 15px;
  }
  input[type="text"] {
    font-size: 16px;
    width: 60%;
  }

  .table-wrapper {
    background: transparent;
    box-shadow: none;
    border: none;
    max-height: none;
    overflow: visible;
  }

  .table-wrapper table,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper thead,
  .table-wrapper td,
  .table-wrapper tr {
    display: block;
  }

  .table-wrapper thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  .table-wrapper tbody tr {
    margin-bottom: 20px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
  }

  .table-wrapper tbody tr:hover {
    background-color: var(--card-bg);
  }

  .table-wrapper td {
    border: none;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
    padding: 12px 15px;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .table-wrapper td:last-child {
    border-bottom: none;
  }

  .table-wrapper td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #7f8c8d;
    font-size: 0.85rem;
    text-transform: uppercase;
  }

  .table-wrapper td[data-label="Code"],
  .table-wrapper td[data-label="Nom Fichier"] {
    background-color: var(--primary-color);
    color: white;
    justify-content: center;
    padding: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    letter-spacing: 1px;
  }
  .table-wrapper td[data-label="Code"]::before,
  .table-wrapper td[data-label="Nom Fichier"]::before {
    display: none;
  }

  .table-wrapper td[data-label="Libellé"] {
    display: block;
    text-align: left;
    font-weight: 500;
    color: var(--primary-color);
    padding-top: 15px;
  }
  .table-wrapper td[data-label="Libellé"]::before {
    margin-bottom: 5px;
    display: block;
  }

  .table-wrapper td[data-label="Scanné"] {
    background-color: #fcfcfc;
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .table-wrapper td[data-label="Action"] {
    background-color: var(--primary-color);
    justify-content: center;
  }
  .table-wrapper td[data-label="Action"] a {
    background-color: var(--secondary-color);
    padding: 10px 90px;
    border-radius: 15px;
    color: white;
    text-decoration: none;
    font-weight: bold;
  }
  .table-wrapper td[data-label="Action"]::before {
    display: none;
  }

  .manual-btn {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  }
  #scrollTopBtn {
    bottom: 25px;
    right: 25px;
    width: 55px;
    height: 55px;
    font-size: 1.8rem;
  }
}
