/* ============================================================
   JustInvent — Design System v5.0
   Police : DM Sans (Google Fonts, chargée dans header)
   Thème   : Bleu professionnel / glassmorphism léger
   ============================================================ */

/* ── Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ─────────────────────────────────────────── */
:root {
  /* Couleurs */
  --bg:       #f0f4fa;
  --bg2:      #e8eef8;
  --panel:    #ffffff;
  --panel2:   #f7f9ff;
  --border:   #dde5f2;
  --border2:  #c8d6ee;
  --text:     #0d1829;
  --text2:    #2d3d55;
  --muted:    #6b7a99;
  --muted2:   #94a3b8;

  /* Brand */
  --blue:     #1a4dc9;
  --blue2:    #2563eb;
  --blue3:    #3b82f6;
  --blue-bg:  #eff5ff;
  --blue-glow:rgba(37,99,235,.18);

  /* Status */
  --green:    #059669; --green-bg: #ecfdf5;
  --red:      #dc2626; --red-bg:   #fef2f2;
  --orange:   #d97706; --orange-bg:#fffbeb;
  --gray:     #6b7280; --gray-bg:  #f9fafb;

  /* Shape */
  --r:        14px;
  --r2:       20px;
  --r3:       10px;
  --shadow:   0 1px 3px rgba(13,24,41,.06), 0 8px 24px rgba(13,24,41,.07);
  --shadow2:  0 1px 2px rgba(13,24,41,.04), 0 4px 12px rgba(13,24,41,.06);
  --shadow-b: 0 4px 20px rgba(37,99,235,.22);

  /* Sidebar */
  --sb-w:     248px;
  --sb-bg:    #0f1e3d;
  --sb-text:  #c8d9f5;
  --sb-hover: rgba(255,255,255,.07);
  --sb-active:rgba(255,255,255,.12);
  --sb-border:rgba(255,255,255,.08);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue2); text-decoration: none; }
a:hover { text-decoration: underline; }
.small, small { font-size: 12px; }
.muted { color: var(--muted); }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Layout ────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sb-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sb-w);
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,.05);
}

/* Brand */
.sb-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
  text-decoration: none !important;
}
.sb-brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--blue2), #1d4ed8);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
  flex-shrink: 0;
}
.sb-brand-text { line-height: 1.2; }
.sb-brand-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}
.sb-brand-sub {
  font-size: 11px;
  color: var(--sb-text);
  opacity: .7;
}

/* Search */
.sb-search {
  padding: 12px 14px 8px;
  flex-shrink: 0;
  position: relative;
}
.sb-search input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--sb-border);
  color: #fff;
  border-radius: var(--r3);
  padding: 8px 10px 8px 34px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: background .15s, border .15s;
}
.sb-search input::placeholder { color: rgba(255,255,255,.35); }
.sb-search input:focus {
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.2);
}
.sb-search-icon {
  position: absolute;
  left: 24px; top: 50%;
  transform: translateY(-50%);
  opacity: .4;
  pointer-events: none;
  margin-top: 2px;
}
.sb-search-results {
  display: none;
  position: absolute;
  left: 14px; right: 14px;
  top: calc(100% - 6px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 16px 40px rgba(13,24,41,.2);
  z-index: 500;
  max-height: 320px;
  overflow-y: auto;
}
.sb-search-results.show { display: block; }
.sr-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--blue-bg); }
.sr-tag { font-weight: 700; }
.sr-sub { font-size: 11px; color: var(--muted); }

/* Nav */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sb-nav::-webkit-scrollbar { width: 4px; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

/* Nav section label */
.sb-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.28);
  padding: 14px 10px 5px;
}
.sb-section:first-child { padding-top: 4px; }

/* Nav link */
.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r3);
  color: var(--sb-text);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .12s, color .12s;
  position: relative;
  text-decoration: none !important;
}
.sb-link:hover {
  background: var(--sb-hover);
  color: #fff;
  text-decoration: none;
}
.sb-link.active {
  background: var(--sb-active);
  color: #fff;
  border-color: rgba(255,255,255,.1);
  font-weight: 600;
}
.sb-link .si {
  width: 17px; height: 17px;
  opacity: .7;
  flex-shrink: 0;
  transition: opacity .12s;
}
.sb-link:hover .si,
.sb-link.active .si { opacity: 1; }
.sb-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

/* Footer */
.sb-footer {
  flex-shrink: 0;
  padding: 10px;
  border-top: 1px solid var(--sb-border);
}
.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r3);
  cursor: pointer;
  transition: background .12s;
  text-decoration: none !important;
}
.sb-user:hover { background: var(--sb-hover); }
.sb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue2), #1d4ed8);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -.01em;
}
.sb-user-info { flex: 1; min-width: 0; line-height: 1.25; }
.sb-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #e2eeff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-user-role {
  font-size: 11px;
  color: rgba(255,255,255,.4);
}
.sb-logout {
  display: flex; align-items: center;
  padding: 8px 10px;
  border-radius: var(--r3);
  color: rgba(255,255,255,.45);
  font-size: 12px;
  gap: 8px;
  margin-top: 2px;
  transition: color .12s, background .12s;
  text-decoration: none !important;
}
.sb-logout:hover { color: #fff; background: rgba(220,38,38,.18); text-decoration: none; }

/* ── Topbar (mobile) ────────────────────────────────────── */
.topbar-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--sb-bg);
  border-bottom: 1px solid var(--sb-border);
  position: sticky;
  top: 0;
  z-index: 200;
}
.topbar-mobile-brand { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -.02em; }
.hamburger {
  background: rgba(255,255,255,.1);
  border: 1px solid var(--sb-border);
  border-radius: 8px;
  padding: 7px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
}

/* ── Main content ───────────────────────────────────────── */
.main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.main-inner {
  flex: 1;
  padding: 22px 28px 32px;
  max-width: 1280px;
  width: 100%;
}

/* ── Page header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header .h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1.2;
}
.page-header .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.topbar { /* compat */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: var(--shadow2);
  padding: 18px;
}
.card.soft { background: var(--panel2); }
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
}

/* ── Grid ───────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
  background: linear-gradient(180deg, var(--blue2), #1d4ed8);
  color: #fff;
  box-shadow: var(--shadow-b);
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow2);
}
.btn-secondary:hover { border-color: var(--border2); background: var(--panel2); }
.btn-ghost {
  background: transparent;
  border-color: var(--sb-border);
  color: rgba(255,255,255,.7);
  box-shadow: none;
}
.btn-danger {
  background: linear-gradient(180deg, #dc2626, #b91c1c);
  box-shadow: 0 4px 14px rgba(220,38,38,.3);
}
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: var(--r3); }

/* ── Forms ──────────────────────────────────────────────── */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue3);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
textarea { min-height: 100px; resize: vertical; line-height: 1.6; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field { margin-bottom: 14px; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.green  { background: var(--green-bg);  color: var(--green);  border-color: #a7f3d0; }
.badge.blue   { background: var(--blue-bg);   color: var(--blue);   border-color: #bfdbfe; }
.badge.red    { background: var(--red-bg);    color: var(--red);    border-color: #fecaca; }
.badge.gray   { background: var(--gray-bg);   color: var(--gray);   border-color: #e5e7eb; }
.badge.orange { background: var(--orange-bg); color: var(--orange); border-color: #fde68a; }

/* ── Tables ─────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 12px 10px;
}
.table tbody tr {
  border-radius: var(--r);
  transition: background .1s;
}
.table tbody tr:hover td { background: var(--panel2); }
.table tbody td {
  padding: 11px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:first-child td { border-top: none; }
.table tbody td:first-child { border-radius: var(--r) 0 0 var(--r); }
.table tbody td:last-child { border-radius: 0 var(--r) var(--r) 0; }

/* ── KPI cards ──────────────────────────────────────────── */
.kpi { padding: 18px 20px; }
.kpi-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
}
.kpi-value {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -.04em;
  margin-top: 4px;
  line-height: 1;
}

/* ── KV items (fiche) ───────────────────────────────────── */
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kv-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel2);
}
.kv-item .lbl {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.kv-item .val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-top: 3px;
  word-break: break-word;
}

/* ── Flashes ────────────────────────────────────────────── */
.flash {
  padding: 11px 14px;
  border-radius: var(--r);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.flash.success { background: var(--green-bg); border-color: #a7f3d0; color: #065f46; }
.flash.error   { background: var(--red-bg);   border-color: #fecaca; color: #991b1b; }

/* ── Utilities ──────────────────────────────────────────── */
.row-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--blue-bg);
  border: 1px solid #bfdbfe;
  font-weight: 600;
  font-size: 13px;
  color: var(--blue);
}
.bar {
  height: 8px;
  border-radius: 999px;
  background: #e9effa;
  overflow: hidden;
}
.bar > div { height: 100%; border-radius: 999px; }

/* ── Charts ─────────────────────────────────────────────── */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.legend { display: grid; gap: 7px; }
.legend .item { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 500; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ── Hero (compat) ──────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--blue-bg), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 24px;
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 20px;
  align-items: center;
}
.hero h2 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.hero p { margin-top: 6px; color: var(--muted); }

/* ── Dark mode ──────────────────────────────────────────── */
body.dark {
  --bg: #0b1120;
  --bg2: #111827;
  --panel: #131f35;
  --panel2: #0f1a2e;
  --border: #1e2d47;
  --border2: #253553;
  --text: #e2e8f0;
  --text2: #b0bdd0;
  --muted: #718096;
  --muted2: #4a5568;
  --blue-bg: #0f1f40;
  --green-bg: #052e16;
  --red-bg: #2d0a0a;
  --orange-bg: #1c0f00;
  --gray-bg: #1a2232;
}
body.dark input,
body.dark select,
body.dark textarea {
  background: var(--panel2);
  color: var(--text);
  border-color: var(--border);
}
body.dark .btn-secondary {
  background: var(--panel2);
  color: var(--text);
}
body.dark .table tbody td { background: var(--panel); }
body.dark .table tbody tr:hover td { background: var(--panel2); }

/* ── Dark toggle ────────────────────────────────────────── */
.dark-toggle {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  cursor: pointer;
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  z-index: 900;
  transition: transform .2s, box-shadow .2s;
}
.dark-toggle:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,.2); }

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  padding: 14px 28px;
  text-align: right;
  font-size: 12px;
  color: var(--muted2);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; width: 100%; position: fixed; height: 100vh; }
  .sidebar.mobile-open { display: flex; }
  .topbar-mobile { display: flex; }
  .main-inner { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .actions { justify-content: flex-start; }
}
@media (max-width: 640px) {
  .table thead { display: none; }
  .table tbody td { display: block; border: none; padding: 4px 10px; }
  .table tbody td:first-child { padding-top: 12px; border-radius: var(--r) var(--r) 0 0; }
  .table tbody td:last-child { padding-bottom: 12px; border-radius: 0 0 var(--r) var(--r); border-top: 1px solid var(--border); }
}

/* ── QR (compat) ────────────────────────────────────────── */
.qrbox { display: flex; flex-direction: column; gap: 12px; }
.qrimg {
  width: 200px; height: 200px;
  align-self: center;
  background: #fff;
  padding: 12px;
  border-radius: var(--r2);
  border: 1px dashed var(--border2);
  box-shadow: var(--shadow2);
}
