/* KlyraCloud — design system « centre de sécurité » (thème sombre). */

:root {
  --bg: #0e0e12;
  --bg-2: #121218;
  --panel: #15151b;
  --panel-2: #1b1b23;
  --border: #2a2a33;
  --border-strong: #3a3a46;
  --text: #eceef2;
  --muted: #9b9fab;
  --accent: #6c63ff;
  --accent-2: #a5a0ff;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --unknown: #64748b;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 248px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-2);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(91, 82, 232, .12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(91, 82, 232, .06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .75em; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 .35em; font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
[hidden] { display: none !important; }
::selection { background: rgba(91, 82, 232, .5); }

/* Focus visibles */
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
a:focus-visible, button:focus-visible, .btn:focus-visible { box-shadow: var(--focus); }

/* Barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.spacer { flex: 1 1 auto; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-danger { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ------------------------------------------------------------------ Layout */
.layout { display: flex; min-height: 100vh; }
.content { flex: 1 1 auto; min-width: 0; padding: 28px 32px 48px; max-width: 1600px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

.grid { display: grid; gap: 16px; grid-template-columns: 1fr; margin-bottom: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > * { min-width: 0; }

/* ------------------------------------------------------------------ Sidebar */
#sidebar {
  position: sticky; top: 0; align-self: flex-start;
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  z-index: 20;
}
.nav-top { display: flex; align-items: center; gap: 8px; padding: 2px 6px 18px; }
.nav-toggle { display: none; margin-left: auto; }
.nav-panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-link:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.nav-link.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(139, 92, 246, .18), rgba(34, 211, 238, .05));
  border-color: rgba(91, 82, 232, .4);
}
.nav-link.active .nav-icon { stroke: var(--accent-2); }
.nav-icon { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.nav-user { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.nav-user-text { display: flex; flex-direction: column; min-width: 0; }
.nav-user-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.nav-user-email { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.burger, .burger::before, .burger::after { display: block; width: 14px; height: 2px; background: currentColor; border-radius: 2px; position: relative; }
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -5px; } .burger::after { top: 5px; }

/* Marque */
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08) inset, 0 6px 18px rgba(91, 82, 232, .4);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px 9px 7px;
  border: 2px solid rgba(14, 14, 18, .9); border-top-width: 3px;
  border-radius: 2px 2px 8px 8px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.brand-lg .brand-mark { width: 40px; height: 40px; flex-basis: 40px; border-radius: 10px; }
.brand-lg .brand-mark::after { inset: 11px 12px 10px; }
.brand-lg .brand-name { font-size: 19px; }
.brand-lg .brand-sub { font-size: 12px; }

/* ------------------------------------------------------------------ Cartes */
.card {
  background: linear-gradient(180deg, var(--panel), rgba(15, 21, 38, .85));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 0; }

/* Statistiques */
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ Tableaux */
.table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-wrap .table { border: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.table tbody tr:hover { background: rgba(139, 92, 246, .06); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #1a2440; border-color: #3a4a70; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6d4ae0); border-color: transparent; color: #fff; }
.btn-primary:hover { background: linear-gradient(135deg, #9b70ff, #7a55f0); border-color: transparent; }
.btn-danger { background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, .25); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--panel); color: var(--text); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------------ Formulaires */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.label { font-size: 12px; font-weight: 500; color: var(--muted); }
.input, .select, textarea.input {
  width: 100%; min-height: 38px; padding: 8px 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 90px; resize: vertical; }
.input::placeholder { color: #5a6684; }
.input:hover, .select:hover { border-color: #3a4a70; }
.input:focus, .select:focus, .input:focus-visible, .select:focus-visible {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 92, 246, .25); border-radius: 8px;
}
.select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.form-error {
  margin: 0 0 14px; padding: 9px 12px; border-radius: 8px;
  background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .4); color: #fca5a5; font-size: 13px;
}

/* ------------------------------------------------------------------ Badges & points */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em; line-height: 18px; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: #4ade80; background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .4); }
.badge.warn { color: #fbbf24; background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .4); }
.badge.danger { color: #f87171; background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .45); }
.badge.unknown { color: #94a3b8; background: rgba(100, 116, 139, .12); border-color: rgba(100, 116, 139, .4); }

.dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--unknown); vertical-align: middle; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } }

/* ------------------------------------------------------------------ États vides / non configurés */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 28px 18px;
  color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: rgba(11, 16, 32, .5);
}
.empty strong, .empty b { color: var(--text); }
.empty code { color: var(--accent-2); }

/* ------------------------------------------------------------------ Graphiques & carte */
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.map-box { position: relative; width: 100%; height: 520px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--bg-2); }

/* ------------------------------------------------------------------ Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast {
  padding: 11px 14px 11px 16px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent-2);
  box-shadow: var(--shadow); font-size: 13px; overflow-wrap: anywhere;
  animation: toast-in .2s ease-out;
  transition: opacity .25s, transform .25s;
}
.toast-ok { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-danger { border-left-color: var(--danger); }
.toast.leaving { opacity: 0; transform: translateX(12px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ Connexion */
.login-page { display: flex; min-height: 100vh; }
.login-wrap { margin: auto; width: 100%; max-width: 420px; padding: 32px 16px; }
.login-card { padding: 30px 28px 22px; box-shadow: var(--shadow); border-color: var(--border-strong); position: relative; overflow: hidden; }
.login-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.login-title { margin-top: 26px; font-size: 20px; }
.login-lead { margin: 4px 0 22px; font-size: 13px; }
.login-form .btn { margin-top: 4px; min-height: 40px; }
.login-foot { display: flex; align-items: center; gap: 8px; margin: 20px 0 0; font-size: 12px; }

/* ------------------------------------------------------------------ Page d'erreur */
.error-page { display: flex; min-height: 100vh; }
.error-box { margin: auto; text-align: center; padding: 32px 16px; max-width: 460px; }
.error-code { font-size: 64px; font-weight: 700; margin: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-box h1 { margin-bottom: 8px; }
.error-box .btn { margin-top: 12px; }

/* ------------------------------------------------------------------ Responsive */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  #sidebar {
    position: sticky; top: 0; width: 100%; flex: 0 0 auto; height: auto;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border);
    background: rgba(11, 16, 32, .96);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  }
  .nav-top { padding: 0; }
  .nav-toggle { display: inline-flex; }
  .nav-panel { display: none; padding-top: 12px; max-height: calc(100vh - 64px); overflow-y: auto; }
  #sidebar.open .nav-panel { display: flex; }
  .content { padding: 20px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .map-box { height: 400px; }
}
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: 1fr; }
  .stat-value { font-size: 22px; }
  .card { padding: 14px; }
  .toolbar > .input, .toolbar > .select { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
