/* ==========================================================================
   CLIENTNODE — Design system v1
   Bleu nuit · blanc · gris clair · accents violet et bleu électrique
   Aucune dépendance. Compatible CSP stricte (pas de style en ligne).
   ========================================================================== */

:root {
  --cn-navy-950: #060B22;
  --cn-navy-900: #0B1437;
  --cn-navy-800: #111C47;
  --cn-navy-700: #1B2760;
  --cn-violet: #7C3AED;
  --cn-violet-600: #6D28D9;
  --cn-violet-100: #EDE5FE;
  --cn-electric: #2F6BFF;
  --cn-electric-600: #1F55E0;
  --cn-electric-100: #E3ECFF;
  --cn-gray-50: #F5F7FB;
  --cn-gray-100: #EDF0F7;
  --cn-gray-200: #DEE3EE;
  --cn-gray-400: #9AA3B8;
  --cn-gray-600: #5A647C;
  --cn-success: #0E9F6E;
  --cn-warning: #B7791F;
  --cn-danger: #DC2643;
  --cn-gradient: linear-gradient(135deg, var(--cn-violet) 0%, var(--cn-electric) 100%);

  /* Jetons sémantiques (thème clair) */
  --bg: var(--cn-gray-50);
  --surface: #FFFFFF;
  --surface-2: var(--cn-gray-100);
  --text: var(--cn-navy-900);
  --text-muted: var(--cn-gray-600);
  --border: var(--cn-gray-200);
  --primary: var(--cn-violet);
  --primary-hover: var(--cn-violet-600);
  --primary-soft: var(--cn-violet-100);
  --accent: var(--cn-electric);
  --accent-soft: var(--cn-electric-100);
  --focus: 0 0 0 3px rgba(47, 107, 255, .45);
  --shadow-sm: 0 1px 2px rgba(11, 20, 55, .06);
  --shadow: 0 4px 16px rgba(11, 20, 55, .08);
  --sidebar-bg: var(--cn-navy-900);
  --sidebar-text: #C7CDE4;
  --sidebar-active: rgba(124, 58, 237, .22);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: var(--cn-navy-950);
  --surface: #0E1638;
  --surface-2: #142049;
  --text: #E7EAF6;
  --text-muted: #9AA3C2;
  --border: #22305F;
  --primary: #8B5CF6;
  --primary-hover: #7C3AED;
  --primary-soft: rgba(139, 92, 246, .18);
  --accent: #5B8CFF;
  --accent-soft: rgba(91, 140, 255, .16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 6px 20px rgba(0, 0, 0, .45);
  --sidebar-bg: #050A1E;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: var(--cn-navy-950);
    --surface: #0E1638;
    --surface-2: #142049;
    --text: #E7EAF6;
    --text-muted: #9AA3C2;
    --border: #22305F;
    --primary: #8B5CF6;
    --primary-hover: #7C3AED;
    --primary-soft: rgba(139, 92, 246, .18);
    --accent: #5B8CFF;
    --accent-soft: rgba(91, 140, 255, .16);
    --sidebar-bg: #050A1E;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--space-3); }
code, .mono { font-family: var(--font-mono); font-size: .88em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mt-3 { margin-top: var(--space-3); } .mt-5 { margin-top: var(--space-5); }
.mb-0 { margin-bottom: 0; } .mb-3 { margin-bottom: var(--space-3); } .mb-5 { margin-bottom: var(--space-5); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: var(--space-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ---------- Coque applicative ---------- */
.app-shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: var(--space-4) var(--space-3);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-4);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; letter-spacing: .04em; padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand img { width: 32px; height: 32px; }
.brand small { display: block; font-weight: 500; font-size: .7rem; letter-spacing: .08em; color: var(--cn-gray-400); text-transform: uppercase; }
.company-switch { background: rgba(255,255,255,.06); border-radius: var(--radius); padding: 10px 12px; color: #fff; font-size: .9rem; }
.company-switch span { display: block; font-size: .72rem; color: var(--cn-gray-400); text-transform: uppercase; letter-spacing: .06em; }
.company-switch a { color: #fff; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--cn-gray-400); padding: 12px 10px 4px; }
.nav a, .nav .nav-disabled {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-size: .92rem;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a[aria-current="page"] { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--cn-violet); }
.nav .nav-disabled { opacity: .5; cursor: default; }
.nav .nav-disabled .badge { margin-left: auto; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; font-size: .75rem; color: var(--cn-gray-400); padding: 0 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px var(--space-5); background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .search { flex: 1; max-width: 420px; }
.topbar .search input { background: var(--surface-2); border-color: transparent; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-toggle { display: none; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--cn-gradient); color: #fff; font-weight: 600; font-size: .85rem;
}
.content { padding: var(--space-5); max-width: 1280px; width: 100%; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-header h1 { margin-bottom: 4px; }
.page-header p { margin: 0; color: var(--text-muted); }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-body { padding: var(--space-5); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.card-header h2 { margin: 0; font-size: 1rem; }
.stat-card { padding: var(--space-4) var(--space-5); }
.stat-card .label { color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 1.9rem; font-weight: 700; margin-top: 4px; }
.stat-card .hint { font-size: .82rem; color: var(--text-muted); }
.stat-card.accent { background: var(--cn-gradient); color: #fff; border: 0; }
.stat-card.accent .label, .stat-card.accent .hint { color: rgba(255,255,255,.82); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; text-decoration: none; line-height: 1.2;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--cn-gradient); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--cn-danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { padding: 6px 10px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.inline-form { display: inline; }

/* ---------- Formulaires ---------- */
.form-group { margin-bottom: var(--space-4); }
.form-group label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.form-hint { font-size: .82rem; color: var(--text-muted); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.input[aria-invalid="true"] { border-color: var(--cn-danger); }
.textarea { min-height: 96px; resize: vertical; }
.field-error { color: var(--cn-danger); font-size: .84rem; margin: 6px 0 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--primary); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.form-actions { display: flex; gap: var(--space-3); align-items: center; margin-top: var(--space-5); flex-wrap: wrap; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); margin: 0 0 var(--space-4); }
legend { font-weight: 700; padding: 0 6px; }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 12px var(--space-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: .82rem; color: var(--text-muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.badge-success { background: rgba(14,159,110,.14); color: var(--cn-success); }
.badge-warning { background: rgba(183,121,31,.15); color: var(--cn-warning); }
.badge-danger { background: rgba(220,38,67,.13); color: var(--cn-danger); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .badge-success { color: #34D399; }
[data-theme="dark"] .badge-warning { color: #FBBF24; }
[data-theme="dark"] .badge-danger { color: #FB7185; }

/* ---------- Alertes ---------- */
.alert { padding: 12px var(--space-4); border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin-bottom: var(--space-4); display: flex; gap: 10px; align-items: flex-start; }
.alert-success { border-color: rgba(14,159,110,.35); background: rgba(14,159,110,.08); }
.alert-error { border-color: rgba(220,38,67,.35); background: rgba(220,38,67,.07); }
.alert-warning { border-color: rgba(183,121,31,.4); background: rgba(183,121,31,.08); }
.alert-info { border-color: rgba(47,107,255,.35); background: var(--accent-soft); }
.alert p:last-child { margin-bottom: 0; }

/* ---------- États vides / chargement ---------- */
.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-muted); }
.empty svg { width: 44px; height: 44px; color: var(--cn-gray-400); margin-bottom: var(--space-3); }
.empty h3 { color: var(--text); }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); min-height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Jauges (élément natif <meter>, sans style en ligne) ---------- */
meter { width: 100%; height: 8px; }
meter::-webkit-meter-bar { background: var(--surface-2); border: 0; border-radius: 999px; height: 8px; }
meter::-webkit-meter-optimum-value { background: var(--cn-gradient); border-radius: 999px; }
meter::-webkit-meter-suboptimum-value { background: var(--cn-warning); border-radius: 999px; }
meter::-webkit-meter-even-less-good-value { background: var(--cn-danger); border-radius: 999px; }
meter::-moz-meter-bar { background: var(--cn-violet); border-radius: 999px; }
.quota { display: grid; gap: 4px; }
.quota-head { display: flex; justify-content: space-between; font-size: .85rem; }

/* ---------- Listes, onglets, pagination ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: var(--space-3); }
.list li:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }
.pagination { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding: var(--space-4); font-size: .88rem; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-4); }
.code-box { font-family: var(--font-mono); background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 12px; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: var(--font-mono); }
.qr { background: #fff; display: inline-block; padding: 8px; border-radius: var(--radius); border: 1px solid var(--border); }
.qr svg { display: block; width: 200px; height: 200px; }
.swatch { height: 64px; border-radius: var(--radius); border: 1px solid var(--border); }
.sw-navy { background: var(--cn-navy-900); } .sw-violet { background: var(--cn-violet); } .sw-electric { background: var(--cn-electric); }
.sw-gray { background: var(--cn-gray-100); } .sw-white { background: #fff; } .sw-gradient { background: var(--cn-gradient); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; display: none; z-index: 30; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu .sep { border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown-head { padding: 8px 10px; font-size: .85rem; }

/* ---------- Pages d'authentification ---------- */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-aside { background: var(--cn-navy-900); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; width: 520px; height: 520px; right: -180px; bottom: -200px; background: var(--cn-gradient); filter: blur(90px); opacity: .45; border-radius: 50%; }
.auth-aside h2 { font-size: 1.9rem; max-width: 420px; position: relative; z-index: 1; }
.auth-aside p, .auth-aside ul { color: #C7CDE4; max-width: 420px; position: relative; z-index: 1; }
.auth-aside ul { padding-left: 18px; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-foot { margin-top: var(--space-5); font-size: .9rem; color: var(--text-muted); text-align: center; }
.locale-switch { display: flex; gap: 6px; justify-content: center; margin-top: var(--space-5); }
.locale-switch button { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 10px; color: var(--text-muted); cursor: pointer; font: inherit; font-size: .8rem; }
.locale-switch button[aria-pressed="true"] { border-color: var(--primary); color: var(--primary); }
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.error-page .code { font-size: 4rem; font-weight: 800; background: var(--cn-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-toggle { display: inline-flex; }
  .content { padding: var(--space-4); }
  .topbar { padding: 8px var(--space-4); }
  .topbar .search { display: none; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}
@media (max-width: 600px) {
  .table .hide-sm { display: none; }
  .page-header { flex-direction: column; }
  .codes { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.fieldset-plain { border: 0; padding: 0; margin: 0; min-width: 0; }
