/* ==========================================================================
   ImmoPilot — design system
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --bg-soft: #e9eff3;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #dfe6ed;
  --border-strong: #c9d4de;
  --text: #10202b;
  --text-soft: #33495a;
  --muted: #6b7f8f;
  --faint: #94a3b0;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-ink: #1e3a8a;
  --info: #0284c7;
  --info-soft: #e0f2fe;
  --warning: #b45309;
  --warning-soft: #fdf0d5;
  --danger: #c02626;
  --danger-soft: #fde8e8;
  --success: #15803d;
  --success-soft: #dcfce7;
  --gold: #d4a24c;
  --shadow-sm: 0 1px 2px rgba(16, 32, 43, 0.06);
  --shadow: 0 10px 30px rgba(16, 32, 43, 0.08), 0 2px 6px rgba(16, 32, 43, 0.04);
  --shadow-lg: 0 24px 70px rgba(10, 28, 40, 0.22);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-bg: linear-gradient(180deg, #0b1e3a 0%, #071426 100%);
  --sidebar-text: #dbe7ee;
  --sidebar-muted: #8fa6b5;
  --sidebar-active: rgba(96, 165, 250, 0.16);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SFMono-Regular", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08121a;
  --bg-soft: #0c1a25;
  --surface: #0f1f2b;
  --surface-2: #122635;
  --surface-3: #17303f;
  --border: #1e3a4c;
  --border-strong: #2a4c61;
  --text: #e8f1f6;
  --text-soft: #c2d3de;
  --muted: #8ba3b3;
  --faint: #6d8798;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: #172554;
  --accent-ink: #dbeafe;
  --info: #38bdf8;
  --info-soft: #0c2a45;
  --warning: #fbbf24;
  --warning-soft: #36260c;
  --danger: #f87171;
  --danger-soft: #3a1717;
  --success: #4ade80;
  --success-soft: #10301d;
  --gold: #e2b96d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.55);
  --sidebar-bg: linear-gradient(180deg, #050d1a 0%, #030812 100%);
  --sidebar-text: #d7e5ee;
  --sidebar-muted: #7d96a7;
  --sidebar-active: rgba(96, 165, 250, 0.18);
  --sidebar-border: rgba(255, 255, 255, 0.07);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --bg: #08121a;
    --bg-soft: #0c1a25;
    --surface: #0f1f2b;
    --surface-2: #122635;
    --surface-3: #17303f;
    --border: #1e3a4c;
    --border-strong: #2a4c61;
    --text: #e8f1f6;
    --text-soft: #c2d3de;
    --muted: #8ba3b3;
    --faint: #6d8798;
    --accent: #60a5fa;
    --accent-strong: #93c5fd;
    --accent-soft: #172554;
    --accent-ink: #dbeafe;
    --info: #38bdf8;
    --info-soft: #0c2a45;
    --warning: #fbbf24;
    --warning-soft: #36260c;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --success: #4ade80;
    --success-soft: #10301d;
    --gold: #e2b96d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.55);
    --sidebar-bg: linear-gradient(180deg, #050d1a 0%, #030812 100%);
    --sidebar-text: #d7e5ee;
    --sidebar-muted: #7d96a7;
    --sidebar-active: rgba(96, 165, 250, 0.18);
    --sidebar-border: rgba(255, 255, 255, 0.07);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.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;
}

/* --------------------------------------------------------------------------
   App layout
   -------------------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px 18px;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #3b82f6, #2563eb 60%, #1e3a8a);
  color: #fff; font-weight: 800; letter-spacing: -0.03em; font-size: 15px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 8px 18px rgba(0,0,0,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: 0.01em; color: #fff; }
.brand-text span { font-size: 11px; color: var(--sidebar-muted); letter-spacing: 0.06em; text-transform: uppercase; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px 12px; }
.nav-section { margin-top: 16px; padding: 0 10px 6px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--sidebar-muted); }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 10px 12px; margin: 2px 0;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--sidebar-text); font-size: 13.5px; text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 #60a5fa; }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: 0.9; }
.nav-item .nav-label { flex: 1; }
.nav-item .nav-count {
  min-width: 20px; padding: 1px 6px; border-radius: 999px;
  background: rgba(248, 113, 113, 0.22); color: #fecaca; font-size: 11px; text-align: center;
}
.nav-item .nav-count.muted { background: rgba(255,255,255,.08); color: var(--sidebar-muted); }

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 14px 14px 16px; }
.theme-switch {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--sidebar-border);
  border-radius: 10px; padding: 3px; margin-bottom: 12px;
}
.theme-switch button {
  border: 0; background: transparent; color: var(--sidebar-muted);
  border-radius: 7px; padding: 6px 0; display: grid; place-items: center;
}
.theme-switch button svg { width: 15px; height: 15px; }
.theme-switch button.active { background: rgba(96, 165, 250, 0.22); color: #dbeafe; }
.user-card { display: flex; align-items: center; gap: 10px; width: 100%; background: transparent; border: 0; color: var(--sidebar-text); padding: 6px; border-radius: 10px; text-align: left; }
.user-card:hover { background: rgba(255,255,255,.05); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 34px;
  background: linear-gradient(140deg, #60a5fa, #2563eb);
  color: #06152d; font-weight: 700; font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { display: block; font-size: 11px; color: var(--sidebar-muted); }
.icon-btn {
  border: 0; background: transparent; color: var(--sidebar-muted);
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.icon-btn svg { width: 17px; height: 17px; }

.main { min-width: 0; padding: 20px 30px 70px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.menu-btn { display: none; }
.page-title { margin: 0; font-size: 22px; letter-spacing: -0.02em; font-weight: 700; color: var(--text); }
.page-sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Buttons, inputs, badges
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(140deg, #3b82f6, #1d4ed8); color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3); }
.btn-primary:hover { background: linear-gradient(140deg, #2563eb, #1e40af); }
.btn-soft { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; box-shadow: none; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-soft); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); box-shadow: none; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s; font-size: 13.5px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 86px; resize: vertical; line-height: 1.45; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--text-soft); letter-spacing: 0.01em; }
.hint { font-size: 11.5px; color: var(--muted); }
.error-text { font-size: 12px; color: var(--danger); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--text-soft); border: 1px solid transparent; white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-outline { background: transparent; border-color: var(--border-strong); color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* --------------------------------------------------------------------------
   Cards, grids, tables
   -------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.card-title { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.card-body { padding: 16px 18px 18px; }
.card-tight .card-body { padding: 12px 14px; }
.grid { display: grid; gap: 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)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.text-soft { color: var(--text-soft); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-num); font-size: 12.5px; }
.tiny { font-size: 11px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 26px 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent); opacity: .65;
}
.kpi-label { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi-value { margin-top: 5px; font-size: 21px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-value.small { font-size: 17px; }
.kpi-delta { margin-top: 4px; font-size: 11.5px; font-weight: 600; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.table-wrap { width: 100%; overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; background: var(--surface); }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--text); }
table.data tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.strong { color: var(--text); font-weight: 600; }
table.data td.actions { white-space: nowrap; text-align: right; }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 6px; }

.chart-card .card-body { padding-top: 8px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 10px; font-family: var(--font-sans); }
.chart .bar { fill: var(--accent); transition: opacity .15s; }
.chart .bar:hover { opacity: .8; }
.chart .bar-info { fill: var(--info); }
.chart .bar-warning { fill: var(--warning); }
.chart .bar-danger { fill: var(--danger); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-2 { fill: none; stroke: var(--info); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .point { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .value-label { fill: var(--text-soft); font-size: 10px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 2px 0 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.legend-swatch { width: 9px; height: 9px; border-radius: 3px; background: var(--accent); }

/* --------------------------------------------------------------------------
   Search
   -------------------------------------------------------------------------- */
.search-hero {
  position: relative; overflow: hidden;
  background: linear-gradient(130deg, #0b1e3a 0%, #12315c 55%, #1e40af 100%);
  border-radius: 18px; padding: 24px; color: #fff; box-shadow: var(--shadow);
}
[data-theme="dark"] .search-hero, [data-theme="system"] .search-hero { background: linear-gradient(130deg, #061225 0%, #0b2447 55%, #14357a 100%); }
.search-hero::before {
  content: ""; position: absolute; width: 340px; height: 340px; right: -90px; top: -160px;
  background: radial-gradient(circle, rgba(96,165,250,.38), transparent 65%); pointer-events: none;
}
.search-hero h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: -0.02em; }
.search-hero p { margin: 0 0 16px; color: #a9c0dc; font-size: 12.5px; }
.search-box { position: relative; display: flex; gap: 10px; align-items: flex-end; }
.search-input-wrap { position: relative; flex: 1; }
.search-box textarea {
  width: 100%; min-height: 54px; max-height: 160px; resize: vertical;
  border-radius: 12px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.98); color: #0f172a; padding: 14px 16px; font-size: 15px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.06);
}
[data-theme="dark"] .search-box textarea, [data-theme="system"] .search-box textarea { background: #f8fafc; }
.search-box textarea:focus { outline: none; border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,.32); }
.search-box .btn { height: 54px; padding: 0 22px; font-size: 14px; }
.search-helper { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; font-size: 11.5px; color: #9db4d1; }
.kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.08); font-family: var(--font-num); font-size: 10.5px; }
.example-chip { border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.07); color: #e0edff; border-radius: 999px; padding: 4px 10px; font-size: 11.5px; }
.example-chip:hover { background: rgba(255,255,255,.14); }

.autocomplete {
  position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 6px);
  max-height: 330px; overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  color: var(--text);
}
.ac-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.ac-item:hover, .ac-item.active { background: var(--surface-2); }
.ac-icon { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); flex: 0 0 26px; }
.ac-icon svg { width: 14px; height: 14px; }
.ac-body { min-width: 0; flex: 1; }
.ac-label { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-detail { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-empty { padding: 12px; text-align: center; color: var(--muted); font-size: 12px; }
.ac-hint { padding: 6px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-soft); font-size: 11.5px; font-weight: 500;
}
.chip.removable button { border: 0; background: transparent; color: var(--faint); width: 16px; height: 16px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.chip.removable button:hover { background: var(--surface-3); color: var(--danger); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.chip-muted { background: var(--surface-2); border-color: transparent; color: var(--muted); }

.interpretation {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.interpretation .icon { color: var(--accent); flex: 0 0 auto; }
.interpretation-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 700; margin-bottom: 4px; }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; text-align: left; width: 100%; color: var(--text-soft);
}
.history-item:hover { background: var(--surface-2); border-color: var(--border); }
.history-item .hq { flex: 1; min-width: 0; }
.history-item .hq strong { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .hq span { font-size: 11px; color: var(--muted); }
.history-actions { display: flex; gap: 2px; }
.history-actions button { border: 0; background: transparent; color: var(--faint); width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; }
.history-actions button:hover { background: var(--surface-3); color: var(--text); }
.history-actions button.pinned { color: var(--gold); }

/* --------------------------------------------------------------------------
   Recherche
   -------------------------------------------------------------------------- */
.search-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; margin-top: 16px; }
.search-layout > .card { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
@media (max-width: 1100px) {
  .search-layout { grid-template-columns: 1fr; }
  .search-layout > .card { position: static; max-height: none; }
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */
.alert-summary { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.alert-stat { padding: 14px 16px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface); }
.alert-stat .n { font-size: 24px; font-weight: 700; line-height: 1.1; }
.alert-stat .l { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 3px; font-weight: 600; }
.alert-stat.critique .n { color: var(--danger); }
.alert-stat.attention .n { color: var(--warning); }
.alert-stat.info .n { color: var(--info); }

.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert-item {
  display: flex; align-items: flex-start; gap: 13px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  border-left: 4px solid var(--faint);
}
.alert-item.critique { border-left-color: var(--danger); }
.alert-item.attention { border-left-color: var(--warning); }
.alert-item.info { border-left-color: var(--info); }
.alert-item.done { opacity: .6; }
.alert-main { flex: 1; min-width: 0; }
.alert-title { font-size: 13.5px; font-weight: 700; color: var(--text); }
.alert-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 7px; font-size: 11.5px; color: var(--faint); align-items: center; }
.alert-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }

/* --------------------------------------------------------------------------
   Modal / drawer / toast
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(4, 16, 24, 0.55); backdrop-filter: blur(3px); padding: 18px;
  animation: fadeIn .12s ease;
}
.modal {
  width: min(720px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); animation: popIn .16s ease;
}
.modal.modal-lg { width: min(1000px, 100%); }
.modal.modal-sm { width: min(440px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.modal-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-body { padding: 16px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 4px 22px 20px; flex-wrap: wrap; }
.modal-close { border: 0; background: var(--surface-3); color: var(--muted); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; }
.modal-close:hover { color: var(--text); }

.drawer-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(4,16,24,.45); backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 91; width: min(680px, 100%);
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  overflow-y: auto; animation: slideIn .18s ease;
}
.drawer-head { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--border); padding: 18px 22px; display: flex; align-items: flex-start; gap: 12px; }
.drawer-body { padding: 18px 22px 40px; }

#toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  color: #fff; border-radius: 11px; box-shadow: var(--shadow-lg); font-size: 13px;
  animation: slideUp .18s ease; background: #16305c;
}
.toast.success { background: #1d4ed8; }
.toast.error { background: #b91c1c; }
.toast.info { background: #1d4ed8; }
.toast.warning { background: #b45309; }
.toast svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.toast button { border: 0; background: transparent; color: rgba(255,255,255,.7); margin-left: auto; }

/* --------------------------------------------------------------------------
   Auth
   -------------------------------------------------------------------------- */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--bg); }
.auth-visual {
  position: relative; overflow: hidden; padding: 48px 52px;
  background: linear-gradient(140deg, #071426 0%, #0c2a52 55%, #1e40af 100%);
  color: #fff; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-visual::before, .auth-visual::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
}
.auth-visual::before { width: 520px; height: 520px; right: -180px; top: -200px; background: radial-gradient(circle, rgba(59,130,246,.36), transparent 62%); }
.auth-visual::after { width: 420px; height: 420px; left: -180px; bottom: -200px; background: radial-gradient(circle, rgba(37,99,235,.25), transparent 65%); }
.auth-brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.auth-brand .brand-mark { width: 44px; height: 44px; }
.auth-brand strong { font-size: 18px; }
.auth-copy { position: relative; z-index: 1; max-width: 460px; }
.auth-copy h1 { font-size: 36px; line-height: 1.12; letter-spacing: -0.035em; margin: 0 0 16px; font-weight: 700; }
.auth-copy p { color: #a9bdd8; font-size: 14px; line-height: 1.6; margin: 0 0 26px; }
.auth-features { display: flex; flex-direction: column; gap: 13px; position: relative; z-index: 1; }
.auth-feature { display: flex; gap: 12px; align-items: flex-start; }
.auth-feature .ficon { width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.12); display: grid; place-items: center; flex: 0 0 32px; color: #93c5fd; }
.auth-feature .ficon svg { width: 16px; height: 16px; }
.auth-feature strong { display: block; font-size: 13px; }
.auth-feature span { display: block; color: #9db4d1; font-size: 12px; margin-top: 1px; }
.auth-foot { position: relative; z-index: 1; color: #7f97b5; font-size: 11.5px; }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 30px 24px; }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand-mobile { display: none; }
.auth-step-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.auth-card h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.025em; }
.auth-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.auth-alert { background: var(--danger-soft); color: var(--danger); border-radius: 9px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; }
.auth-info { background: var(--info-soft); color: var(--info); border-radius: 9px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px; }
.code-input { letter-spacing: .45em; font-family: var(--font-num); font-size: 22px; text-align: center; padding: 13px 10px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px; border: 1px dashed var(--border-strong); border-radius: 12px; background: #fff; margin-bottom: 14px; }
.qr-box img { width: 190px; height: 190px; display: block; }
.secret { font-family: var(--font-num); font-size: 12px; background: var(--surface-3); padding: 7px 10px; border-radius: 7px; word-break: break-all; text-align: center; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.recovery-code { font-family: var(--font-num); font-size: 13.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; text-align: center; letter-spacing: .06em; }
.auth-back { border: 0; background: transparent; color: var(--muted); padding: 0; font-size: 12px; margin-top: 12px; }
.auth-back:hover { color: var(--text); text-decoration: underline; }
.auth-links { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* --------------------------------------------------------------------------
   Dépôt de fichier
   -------------------------------------------------------------------------- */
.upload-zone {
  border: 2px dashed var(--border-strong); border-radius: 15px;
  background: var(--surface-2); padding: 26px 20px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s, transform .1s;
}
.upload-zone:hover { border-color: var(--accent); background: var(--accent-soft); }
.upload-zone.dragover { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.upload-zone .uicon {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 10px;
  display: grid; place-items: center; background: var(--surface);
  border: 1px solid var(--border); color: var(--accent); box-shadow: var(--shadow-sm);
}
.upload-zone .uicon.small { width: 34px; height: 34px; margin: 0; border-radius: 9px; flex: 0 0 34px; }
.upload-title { font-size: 15px; font-weight: 700; color: var(--text); }
.upload-hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.upload-limit { font-size: 11px; color: var(--faint); margin-top: 7px; }
.upload-file {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
  padding: 10px 12px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface-2);
}
.upload-file.hidden { display: none; }
.upload-file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.upload-file-meta strong { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-meta span { font-size: 11.5px; color: var(--muted); }

/* --------------------------------------------------------------------------
   Misc components
   -------------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  border: 0; background: transparent; padding: 9px 13px; font-size: 13px; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; }
.settings-nav { display: flex; flex-direction: column; gap: 3px; }
.settings-nav button { text-align: left; border: 0; background: transparent; color: var(--text-soft); padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.settings-nav button:hover { background: var(--surface-2); }
.settings-nav button.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.section-head { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.section-desc { margin: 0 0 16px; color: var(--muted); font-size: 12.5px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .sr-label { font-size: 13px; font-weight: 600; color: var(--text); }
.switch-row .sr-desc { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 42px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background .18s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

.info-box { display: flex; gap: 10px; padding: 12px 14px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-soft); }
.info-box.warn { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.info-box.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.info-box .i { flex: 0 0 auto; margin-top: 1px; }
.info-box svg { width: 16px; height: 16px; }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .eicon { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 15px; background: var(--surface-2); display: grid; place-items: center; color: var(--faint); }
.empty .eicon svg { width: 24px; height: 24px; }
.empty h3 { margin: 0 0 4px; font-size: 15px; color: var(--text); }
.empty p { margin: 0 auto; max-width: 380px; font-size: 12.5px; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 8px; }
.skeleton-line { height: 12px; margin-bottom: 9px; }
.skeleton-card { height: 128px; border-radius: 14px; }
.loading-block { padding: 30px; text-align: center; color: var(--muted); font-size: 12.5px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }

.kv { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

.auth-loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.auth-loading .brand-mark { margin: 0 auto 12px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alert-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 272px; transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 35; background: rgba(2,10,16,.5); }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px 18px 60px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-card .brand-mobile { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .main { padding: 12px 12px 50px; }
  .page-title { font-size: 19px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 18px; }
  .alert-summary { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .search-hero { padding: 18px; border-radius: 14px; }
  .search-box { flex-direction: column; align-items: stretch; }
  .search-box .btn { height: 44px; }
  .search-box textarea { min-height: 70px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { width: 100%; }
  .modal-body, .modal-head, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .drawer-body { padding: 14px 14px 30px; }
  .kv { grid-template-columns: 120px minmax(0, 1fr); }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .sidebar, .topbar-actions, .menu-btn, .btn { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
