:root {
  --color-primary: #0f766e;
  --color-primary-dark: #0b5852;
  --color-primary-light: #e6f4f3;
  --color-accent: #f59e0b;
  --color-accent-dark: #b45309;
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;

  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #e2e8e7;
  --text-primary: #10201f;
  --text-secondary: #4b5f5d;
  --text-muted: #8a9c9a;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 31, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 32, 31, 0.08);
  --sidebar-width: 240px;
}

:root[data-theme="dark"] {
  --bg: #0f1a19;
  --surface: #16221f;
  --surface-raised: #1c2b28;
  --border: #24413c;
  --text-primary: #eef7f5;
  --text-secondary: #a9c2be;
  --text-muted: #6f8d89;
  --color-primary-light: #163632;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a19;
    --surface: #16221f;
    --surface-raised: #1c2b28;
    --border: #24413c;
    --text-primary: #eef7f5;
    --text-secondary: #a9c2be;
    --text-muted: #6f8d89;
    --color-primary-light: #163632;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 700; }
p { margin: 0 0 8px; color: var(--text-secondary); }

/* Titres (h2/h3) et sous-titres (h4) de chaque menu/page accessible depuis la barre laterale :
   fond vert clair de la marque, comme les entetes de tableau (cf. plus bas). Scope a #page-content
   pour ne pas affecter l'ecran de connexion, qui a sa propre identite visuelle. */
#page-content h2,
#page-content h3,
#page-content h4 {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

#page-content table.data-table th {
  background: var(--color-primary-light);
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
}

input, select {
  font-family: inherit;
  font-size: 1rem;
}

/* ---------- Layout ---------- */

#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 4px;
  flex-shrink: 0;
  overflow-y: auto;
}

#sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--color-primary);
}

#sidebar .brand .logo-badge {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  text-align: left;
  width: 100%;
  font-size: 0.98rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item .nav-icon { font-size: 1.15rem; }

.nav-item:hover { background: var(--color-primary-light); color: var(--color-primary); }

.nav-item.active {
  background: var(--color-primary);
  color: white;
}

#sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

#main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

#page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
}

#offline-banner {
  display: none;
  background: var(--color-warning);
  color: #3a2a02;
  text-align: center;
  padding: 8px;
  font-weight: 700;
  font-size: 0.9rem;
}

#offline-banner.visible { display: block; }

/* ---------- Cards / KPI tiles ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Modale generique ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-card--large {
  max-width: 640px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 { margin: 0; }

.modal-fermer {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
}

.modal-erreur {
  color: var(--color-danger, #c0392b);
  font-size: 0.9rem;
  margin-top: 10px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-tile .kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.kpi-tile .kpi-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.kpi-tile .kpi-label { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.menu-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  font-weight: 700;
  color: var(--text-primary);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  min-height: 120px;
  justify-content: center;
}

.menu-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.menu-tile .menu-icon { font-size: 2rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  min-height: 44px;
  transition: filter 0.12s ease, transform 0.05s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--color-accent); color: #402700; }
.btn-primary:hover { filter: brightness(1.05); }

.btn-secondary { background: var(--color-primary-light); color: var(--color-primary-dark); }
.btn-secondary:hover { filter: brightness(0.97); }

.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text-primary); }

.btn-danger { background: var(--color-danger-light); color: var(--color-danger); }

.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.1rem; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; font-size: 0.88rem; margin-bottom: 6px; color: var(--text-secondary); }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  min-height: 44px;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-row { display: flex; gap: 16px; }
.form-row .field { flex: 1; }
.form-row .field.field-wide { flex: 2.2; }
.form-row .field.field-narrow { flex: 0.6; }

/* ---------- Table ---------- */

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}
table.data-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
table.data-table tr:hover td { background: var(--color-primary-light); }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-muted { background: var(--border); color: var(--text-secondary); }

/* ---------- Notifications ---------- */

.notif-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.notif-item:hover { background: var(--color-primary-light); }
.notif-item.non-lue { background: var(--color-primary-light); }
.notif-item .notif-titre { font-weight: 700; font-size: 0.92rem; }
.notif-item .notif-message { font-size: 0.85rem; color: var(--text-secondary); margin-top: 2px; }
.notif-item .notif-date { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

/* ---------- Login ---------- */

#login-screen, #change-password-screen, #licence-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

#change-password-screen {
  background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}

#login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

#login-card .brand, #login-form-card .brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
  color: var(--color-primary);
  font-weight: 800;
  font-size: 1.25rem;
}

#login-card .logo-badge, #login-form-card .logo-badge {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

#login-error {
  display: none;
  background: var(--color-danger-light);
  color: var(--color-danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
  font-weight: 600;
}

/* ---------- Login (ecran d'accueil split) ---------- */

#login-box {
  width: 100%;
  max-width: 960px;
  min-height: 560px;
  display: flex;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--surface);
}

#login-visual {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 56px;
  color: #ffffff;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 2px, transparent 2px 22px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.06) 0 2px, transparent 2px 22px),
    linear-gradient(160deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
}

#login-visual h1 { font-size: 2.1rem; margin: 0; color: #ffffff; }
#login-visual p { font-size: 1rem; opacity: 0.92; max-width: 320px; margin: 0; color: #ffffff; }

#login-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
}

#login-form-card {
  width: 100%;
  max-width: 360px;
}

#login-form-card h2 {
  margin: 0 0 20px;
  font-size: 1.3rem;
  text-align: center;
}

#login-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 18px;
}

.login-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.login-input-wrap .login-input-icon {
  position: absolute;
  left: 14px;
  font-size: 1rem;
  opacity: 0.55;
  pointer-events: none;
}

.login-input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  min-height: 44px;
}

.login-input-wrap input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.login-input-toggle {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  padding: 6px;
}
.login-input-toggle:hover { opacity: 0.9; }

@media (min-width: 760px) {
  #login-visual { display: flex; }
}

/* ---------- Caisse (POS) ---------- */

.caisse-layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.caisse-layout .card {
  padding: 12px 16px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.caisse-layout .field { margin-bottom: 8px; }

#panier-tbody {
  max-height: 260px;
  overflow-y: auto;
}

.panier-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.panier-line .panier-desig { flex: 1; font-weight: 600; }
.panier-line .panier-qte { width: 70px; }
.panier-line .panier-montant { width: 90px; text-align: right; font-weight: 700; }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 6px;
}
.numpad button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  min-height: 44px;
}
.numpad button:hover { background: var(--color-primary-light); }

.total-line {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.total-line.grand-total {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  border-top: 2px solid var(--border);
  margin-top: 3px;
  padding-top: 5px;
}

/* ---------- Tableau de bord (sous-titre et libelles des menus raccourcis) ---------- */

.dashboard-vue > p,
.dashboard-vue .kpi-label,
.dashboard-vue .menu-tile span:last-child {
  color: var(--color-primary);
}

/* ---------- Historique des ventes (espacement des titres de section) ---------- */
/* Couleur/fond herites de la regle #page-content h2/h3/h4 plus haut. */

.historique-vue h3,
.historique-vue h4 {
  margin-top: 16px;
  margin-bottom: 10px;
}

/* ---------- Chart (ventes 7 jours) ---------- */

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 160px;
  padding: 8px 4px 0;
}
.chart-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar {
  width: 100%;
  max-width: 36px;
  background: var(--color-primary);
  border-radius: 4px 4px 2px 2px;
  min-height: 3px;
  position: relative;
}
.chart-bar:hover { filter: brightness(1.15); }
.chart-bar-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
  font-weight: 600;
  min-width: 240px;
}
.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }

@media (max-width: 900px) {
  .caisse-layout { grid-template-columns: 1fr; }
  #sidebar { position: fixed; z-index: 50; height: 100vh; transform: translateX(-100%); transition: transform 0.2s ease; }
  #sidebar.open { transform: translateX(0); }
}
