/* ════════════════════════════════════════════════════════════════
   MOTIFICATEUR — Design System
   Modern, accessible, responsive. Dark/light themes.
   ════════════════════════════════════════════════════════════════ */

/* ─── Tokens ─── */
:root {
  /* Brand */
  --brand-50:  #eef4ff;
  --brand-100: #dbe6ff;
  --brand-200: #b6cdff;
  --brand-300: #8aaaff;
  --brand-400: #5b85ff;
  --brand-500: #3a64f5;
  --brand-600: #2549db;
  --brand-700: #1d3aaa;
  --brand-800: #1a3186;
  --brand-900: #1a2c6b;

  /* Neutrals (light) */
  --bg:           #f6f7fb;
  --bg-soft:      #eef0f6;
  --surface:      #ffffff;
  --surface-2:    #fafbfd;
  --header-bg:    #1e293b;   /* en-têtes des tableaux croisés */
  --border:       #e5e8f0;
  --border-strong:#d1d6e0;
  --fg:           #0f172a;
  --fg-muted:     #475569;
  --fg-soft:      #94a3b8;

  /* Semantic */
  --success:      #10b981;
  --success-bg:   #d1fae5;
  --success-fg:   #065f46;
  --danger:       #ef4444;
  --danger-bg:    #fee2e2;
  --danger-fg:    #991b1b;
  --warning:      #f59e0b;
  --warning-bg:   #fef3c7;
  --warning-fg:   #92400e;
  --info:         #0ea5e9;
  --info-bg:      #e0f2fe;
  --info-fg:      #075985;
  --accent:       #8b5cf6;
  --accent-bg:    #ede9fe;
  --accent-fg:    #5b21b6;

  /* Effects */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, .12), 0 8px 16px rgba(15,23,42,.06);
  --ring:      0 0 0 3px rgba(58, 100, 245, .25);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h:  64px;
  --statusbar-h: 36px;

  /* Motion */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

/* ─── Dark theme ─── */
[data-theme="dark"] {
  --bg:           #0b1020;
  --bg-soft:      #0f152b;
  --surface:      #141b34;
  --surface-2:    #182241;
  --header-bg:    #0b1226;
  --border:       #232b48;
  --border-strong:#2d3863;
  --fg:           #e6e9f4;
  --fg-muted:     #a5adcb;
  --fg-soft:      #6b7595;
  --success-bg:   #0e3a2c;
  --success-fg:   #6ee7b7;
  --danger-bg:    #3b1414;
  --danger-fg:    #fca5a5;
  --warning-bg:   #3b2c0e;
  --warning-fg:   #fcd34d;
  --info-bg:      #0a2c44;
  --info-fg:      #7dd3fc;
  --accent-bg:    #2a1a4d;
  --accent-fg:    #c4b5fd;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0,0,0,.25);
  --shadow:    0 6px 18px rgba(0, 0, 0, .45), 0 2px 6px rgba(0,0,0,.3);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, .55);
  --ring:      0 0 0 3px rgba(91, 133, 255, .35);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea, button { font: inherit; color: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }

/* ─── App shell ─── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.main {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  min-width: 0;
  min-height: 0;
}

/* ─── Sidebar ─── */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  gap: 4px;
  overflow-y: auto;
  transition: transform .25s var(--ease);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(58, 100, 245, .35);
}
.brand-mark i { width: 20px; height: 20px; }
.brand-name { font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
.brand-sub  { font-size: 11px; color: var(--fg-soft); font-weight: 600; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--fg-muted);
  position: relative;
  transition: background .15s, color .15s;
}
.nav-item i { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item span { flex: 1; }
.nav-item:hover { background: var(--bg-soft); color: var(--fg); }
.nav-item.active {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 600;
}
[data-theme="dark"] .nav-item.active {
  background: rgba(58, 100, 245, .15);
  color: var(--brand-300);
}
.nav-item .badge {
  background: var(--bg-soft);
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}
.nav-item.active .badge {
  background: var(--brand-100);
  color: var(--brand-700);
}
[data-theme="dark"] .nav-item.active .badge {
  background: rgba(58, 100, 245, .2);
  color: var(--brand-300);
}

.sidebar-foot { padding-top: 8px; border-top: 1px solid var(--border); }
.theme-toggle {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex; align-items: center; gap: 8px;
  color: var(--fg-muted);
  transition: all .15s;
}
.theme-toggle:hover { background: var(--bg-soft); color: var(--fg); }
.theme-toggle i { width: 16px; height: 16px; }

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
  min-width: 0;
}
.client-picker {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-soft);
  padding: 4px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.client-picker label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--fg-muted);
  padding: 0 6px;
}
.client-picker label i { width: 14px; height: 14px; }
.client-picker .select {
  border: none; background: transparent;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  min-width: 140px;
}
.client-picker .select:focus { outline: 2px solid var(--brand-300); }

.search {
  position: relative;
  flex: 1;
  max-width: 520px;
  display: flex; align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px 0 12px;
  height: 38px;
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--brand-500); background: var(--surface); box-shadow: var(--ring); }
.search i { width: 16px; height: 16px; color: var(--fg-soft); }
.search input {
  flex: 1; border: none; background: transparent;
  padding: 0 10px; outline: none;
  font-size: 14px;
}
.search kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--fg-soft);
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: all .15s var(--ease);
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--bg-soft); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn i { width: 16px; height: 16px; }

.btn.primary {
  background: var(--brand-600);
  color: #fff;
  box-shadow: 0 2px 6px rgba(58, 100, 245, .3);
}
.btn.primary:hover:not(:disabled) { background: var(--brand-700); }

.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--bg-soft); }

.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn.success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 6px rgba(16, 185, 129, .3);
}
.btn.success:hover:not(:disabled) { background: #059669; }

.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.lg { padding: 11px 18px; font-size: 14px; }
.btn.block { display: flex; width: 100%; justify-content: center; }
.btn.outline { background: transparent; border-color: var(--border-strong); }
.btn.outline:hover:not(:disabled) { background: var(--bg-soft); }

.icon-btn {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-muted);
  border-radius: var(--radius-sm);
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--fg); }
.icon-btn:active { transform: scale(.96); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn i { width: 16px; height: 16px; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }
.icon-btn.close { width: 30px; height: 30px; }

.only-mobile { display: none; }

/* ─── Form controls ─── */
.input, .select, textarea.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--fg);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--ring);
}
.input::placeholder { color: var(--fg-soft); }

textarea.input { min-height: 80px; resize: vertical; font-family: var(--font-mono); font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.field .hint { font-size: 11px; color: var(--fg-soft); }

select.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  padding-right: 32px;
}

/* ─── View container ─── */
.view {
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}
.view > * + * { margin-top: 16px; }

.view-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.view-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.view-sub { color: var(--fg-muted); font-size: 13px; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-head {
  padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-title { font-size: 14px; font-weight: 700; }
.card-body { padding: 16px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ─── KPI grid ─── */
.kpi-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 6px;
  overflow: hidden;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--c, var(--brand-500));
}
.kpi-head { display: flex; align-items: center; gap: 8px; }
.kpi-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--c-bg, var(--brand-50));
  color: var(--c, var(--brand-600));
}
.kpi-icon i { width: 18px; height: 18px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12px; color: var(--fg-soft); display: flex; align-items: center; gap: 4px; }
.kpi.success { --c: var(--success); --c-bg: var(--success-bg); }
.kpi.danger  { --c: var(--danger);  --c-bg: var(--danger-bg); }
.kpi.warning { --c: var(--warning); --c-bg: var(--warning-bg); }
.kpi.info    { --c: var(--info);    --c-bg: var(--info-bg); }
.kpi.accent  { --c: var(--accent);  --c-bg: var(--accent-bg); }

/* ─── Table ─── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.t {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.t thead th {
  background: var(--surface-2);
  color: var(--fg-muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
  cursor: pointer;
  user-select: none;
}
.t thead th:hover { color: var(--fg); }
.t thead th .sort-i { opacity: .35; margin-left: 4px; }
.t thead th.sorted .sort-i { opacity: 1; color: var(--brand-500); }
.t tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.t tbody tr { transition: background .12s; }
.t tbody tr:hover { background: var(--bg-soft); }
.t tbody tr.selected { background: var(--brand-50) !important; }
[data-theme="dark"] .t tbody tr.selected { background: rgba(58, 100, 245, .12) !important; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t .amount-credit { color: var(--success); font-weight: 700; }
.t .amount-debit  { color: var(--danger); font-weight: 700; }
.t .amount-cat    { color: var(--warning-fg); font-style: italic; }
.t tbody tr.credit { background: rgba(16, 185, 129, .04); }
.t tbody tr.debit  { background: rgba(239, 68, 68, .04); }
.t tbody tr.uncat  { background: rgba(245, 158, 11, .06); }

.t .row-check { width: 16px; height: 16px; cursor: pointer; }

/* ─── Toolbar ─── */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 140px; }
.toolbar .group {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.toolbar .group label { font-size: 11px; font-weight: 700; color: var(--fg-muted); text-transform: uppercase; }
.toolbar .spacer { flex: 1; }

/* ─── Chips / tags ─── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--fg-muted);
  white-space: nowrap;
}
.chip.success { background: var(--success-bg); color: var(--success-fg); }
.chip.danger  { background: var(--danger-bg);  color: var(--danger-fg); }
.chip.warning { background: var(--warning-bg); color: var(--warning-fg); }
.chip.info    { background: var(--info-bg);    color: var(--info-fg); }
.chip.accent  { background: var(--accent-bg);  color: var(--accent-fg); }
.chip.outline { background: transparent; border: 1px solid var(--border-strong); }
.chip .x { width: 12px; height: 12px; cursor: pointer; opacity: .6; }
.chip .x:hover { opacity: 1; }

/* ─── Inline edit input in cell ─── */
.cell-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
  width: 100%;
  min-width: 80px;
  font-family: inherit;
  color: inherit;
}
.cell-input:hover { border-color: var(--border); background: var(--surface); }
.cell-input:focus { outline: none; border-color: var(--brand-500); background: var(--surface); box-shadow: var(--ring); }

/* ─── Status bar ─── */
.statusbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: var(--statusbar-h);
}
.statusbar .spacer { flex: 1; }

/* ─── Toast ─── */
.toast-container {
  position: fixed; bottom: 60px; right: 20px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  min-width: 280px;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slide-in .3s var(--ease-out);
  font-size: 13px;
  font-weight: 500;
}
.toast i { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success { border-left-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.danger  { border-left-color: var(--danger); }
.toast.danger  i { color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.warning i { color: var(--warning); }
.toast.info    { border-left-color: var(--info); }
.toast.info    i { color: var(--info); }
.toast.leaving { animation: slide-out .25s var(--ease) forwards; }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slide-out {
  to { opacity: 0; transform: translateX(40px); }
}

/* ─── Modal ─── */
.modal-root[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(6px);
  z-index: 999;
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop .25s var(--ease-out);
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal.lg { max-width: 760px; }
.modal.xl { max-width: 960px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── Drop zone ─── */
.dropzone-overlay[hidden] { display: none; }
.dropzone-overlay {
  position: fixed; inset: 0;
  z-index: 998;
  background: rgba(58, 100, 245, .12);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  pointer-events: none;
}
.dropzone-card {
  background: var(--surface);
  border: 2px dashed var(--brand-500);
  border-radius: var(--radius-lg);
  padding: 40px 60px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.dropzone-card i { width: 48px; height: 48px; color: var(--brand-500); }
.dropzone-card h3 { margin-top: 12px; font-size: 18px; }
.dropzone-card p { color: var(--fg-muted); font-size: 13px; margin-top: 4px; }

/* ─── Charts ─── */
.chart-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column;
  min-height: 320px;
}
.chart-box h3 { font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.chart-box .chart-canvas-wrap { flex: 1; position: relative; min-height: 240px; }

/* ─── Empty state ─── */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-muted);
}
.empty i { width: 48px; height: 48px; opacity: .35; margin-bottom: 12px; }
.empty h3 { font-size: 16px; color: var(--fg); margin-bottom: 4px; }
.empty p { font-size: 13px; max-width: 360px; margin: 0 auto 16px; }

/* ─── Loading / spinner ─── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block { text-align: center; padding: 40px; }
.loading-block .spinner { width: 32px; height: 32px; border-width: 3px; }

/* ─── Tabs ─── */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 16px;
  border: none; background: transparent;
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--brand-600); border-bottom-color: var(--brand-600); }

/* ─── Grids ─── */
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, 1fr); }
.grid-auto { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ─── Stat row inside a card ─── */
.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-row .k { color: var(--fg-muted); font-size: 13px; }
.stat-row .v { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ─── TCD (Tableau Croisé Dynamique) ─── */
.t.tcd {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0;
}
.t.tcd th,
.t.tcd td {
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.t.tcd thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header-bg);
  color: white;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  padding: 8px;
}
.t.tcd thead tr:nth-child(2) th {
  top: 32px;
  z-index: 1;
}
.t.tcd tbody tr:hover {
  background: var(--bg-soft);
}
.t.tcd tbody td:first-child,
.t.tcd tfoot td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
  border-right: 2px solid var(--border-strong);
}
.t.tcd tfoot td {
  background: var(--surface-2);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}
.t.tcd tfoot td:first-child {
  background: var(--surface-2);
}
.t.tcd tfoot tr td {
  position: sticky;
  bottom: 0;
  z-index: 1;
}
/* TCD Motif × Mois : colonnes C/D en alternance.
   Positions : 1 Motif · 2 Total crédit · 3 Total débit · puis C (pair ≥ 4) / D (impair ≥ 5). */
.t.tcd-motif-mois td:nth-child(2),
.t.tcd-motif-mois td:nth-child(2n+4) {
  background: rgba(25, 135, 84, 0.05);
}
.t.tcd-motif-mois td:nth-child(3),
.t.tcd-motif-mois td:nth-child(2n+5) {
  background: rgba(220, 53, 69, 0.05);
}
.t.tcd-motif-mois tfoot td:nth-child(2),
.t.tcd-motif-mois tfoot td:nth-child(2n+4) {
  background: rgba(25, 135, 84, 0.15);
}
.t.tcd-motif-mois tfoot td:nth-child(3),
.t.tcd-motif-mois tfoot td:nth-child(2n+5) {
  background: rgba(220, 53, 69, 0.15);
}
/* en-tête : les mois sur fond sombre uniforme (le vert/rouge est réservé à C/D et aux totaux) */
.t.tcd-motif-mois thead tr:first-child th {
  background: var(--header-bg);
  text-align: center;
}

/* ─── Scrollbar (subtle, modern) ─── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-soft); }

/* ─── Mobile ─── */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 260px;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: grid; }
  .topbar { padding: 0 12px; gap: 8px; }
  .search { display: none; }
  .client-picker { flex: 1; min-width: 0; }
  .client-picker .select { min-width: 0; flex: 1; }
  .topbar-actions .btn span { display: none; }
  .view { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .modal { max-width: 100%; }
  .nav-item span { font-size: 14px; }
}

@media (max-width: 540px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .input, .toolbar .select { width: 100%; }
  .view-title { font-size: 18px; }
  .topbar-actions { gap: 4px; }
}

/* ─── Print ─── */
@media print {
  .sidebar, .topbar, .statusbar, .toast-container, .modal-root, .toolbar { display: none !important; }
  .app { display: block; }
  .view { padding: 0; overflow: visible; }
  .card { box-shadow: none; border-color: #999; }
}


/* ═══ v9.5 — connexion, comptes et droits ═══ */
.login-screen {
  position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 0%, var(--brand-50, #eff6ff), transparent 60%), var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,.12)); padding: 28px;
}
.login-screen[hidden] { display: none; }
.login-intro { font-size: 13px; color: var(--fg-muted); line-height: 1.55; margin: 0 0 18px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-field { display: flex; flex-direction: column; gap: 4px; }
.login-field > span { font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.login-error { min-height: 18px; font-size: 12px; color: var(--danger); font-weight: 600; }
.login-foot { display: flex; gap: 6px; align-items: flex-start; font-size: 11px; color: var(--fg-soft); margin: 18px 0 0; line-height: 1.5; }
.user-box { padding: 0 6px 8px; }
.user-chip { display: flex; align-items: center; gap: 6px; padding: 8px 8px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; }
.user-chip > i { width: 18px; height: 18px; color: var(--brand-600, var(--brand-500)); flex: none; }
.user-chip .user-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .user-role { color: var(--fg-muted); font-size: 11px; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .icon-btn { width: 26px; height: 26px; padding: 0; flex: none; }
.user-chip .icon-btn i, .user-chip .icon-btn svg { width: 15px; height: 15px; }
.sidebar.collapsed .user-chip div, .sidebar.collapsed .user-chip .icon-btn { display: none; }
#readonlyChip { display: inline-flex; align-items: center; gap: 4px; }
#readonlyChip[hidden], .nav-item[hidden], .icon-btn[hidden] { display: none !important; }
#readonlyChip i { width: 13px; height: 13px; }
body.readonly .view [data-edit], body.readonly .view input[type=file] { pointer-events: none; opacity: .5; }
.rights-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 14px; }
.rights-grid label { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; line-height: 1.4; cursor: pointer; }
.rights-grid input { margin-top: 3px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 9px 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--fg-muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button.active { color: var(--brand-600, var(--brand-500)); border-bottom-color: var(--brand-500); }
.tabs button:hover { color: var(--fg); }
.chip.level-manage { background: var(--accent-bg); color: var(--accent-fg); }
.chip.level-write  { background: var(--success-bg); color: var(--success-fg); }
.chip.level-read   { background: var(--info-bg); color: var(--info-fg); }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11.5px; }

/* tableau croisé : lignes / cellules cliquables (détail des transactions) */
.t.tcd .tcd-click { cursor: pointer; }
.t.tcd .tcd-click:hover, .t.tcd .tcd-click:focus-visible { background: var(--info-bg) !important; color: var(--info-fg); outline: none; box-shadow: inset 0 0 0 1px var(--brand-500); }
.t.tcd td:first-child.tcd-click::after { content: ' ›'; color: var(--fg-soft); font-weight: 400; }

/* v9.6 — indicateur d'enregistrement automatique */
#saveChip { cursor: pointer; user-select: none; }
#saveChip[hidden] { display: none !important; }
#saveChip i { width: 13px; height: 13px; vertical-align: -2px; }
#saveChip i[data-lucide="loader"], #saveChip svg.lucide-loader { animation: mf-spin 1s linear infinite; }
@keyframes mf-spin { to { transform: rotate(360deg); } }
#statusSave { margin-left: 8px; color: var(--fg-muted); }

/* v9.6 — dialogue de déconnexion */
.logout-line { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; margin: 0 0 8px; }
.logout-line i, .logout-line svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.logout-line.warn { color: var(--warning-fg); }
.logout-line.fine { color: var(--success-fg); }
.logout-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }

/* v9.7 — double authentification */
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; letter-spacing: 6px; text-align: center; }
.mfa-alts { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; align-items: flex-start; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand-600); cursor: pointer; font: inherit; font-size: 13px; text-decoration: underline; }
.linklike:hover { color: var(--brand-700); }
.qr { display: flex; justify-content: center; margin: 8px auto 12px; }
.qr svg { width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 6px; box-shadow: var(--shadow-sm); }
.qr-missing { color: var(--warning-fg); font-size: 13px; }
.mfa-secret { font-size: 13px; color: var(--fg-muted); margin-bottom: 12px; }
.mfa-secret summary { cursor: pointer; }
.mfa-secret code { display: block; margin-top: 6px; font-size: 14px; letter-spacing: 1px; user-select: all; }
.backup-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; margin: 8px 0; }
.backup-codes code { font-size: 15px; letter-spacing: 1px; padding: 6px 10px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 6px; text-align: center; user-select: all; }
.mfa-confirm { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 10px 0; cursor: pointer; }
.sec-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.sec-row i, .sec-row svg { width: 22px; height: 22px; flex: none; color: var(--brand-600); }
.sec-block { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.sec-block.accent { border: 1px solid var(--brand-500); border-radius: 8px; padding: 12px; }
.sec-block .muted, .sec-row .muted { font-size: 12px; color: var(--fg-muted); }

.mfa-settings { margin: 0 16px 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.mfa-settings-head { display: flex; gap: 10px; align-items: flex-start; }
.mfa-settings-head i, .mfa-settings-head svg { width: 20px; height: 20px; color: var(--brand-600); flex: none; }
.mfa-settings-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mfa-settings-row .select { max-width: 260px; }
.mfa-settings .muted { font-size: 12px; color: var(--fg-muted); }
.mfa-settings input[hidden] { display: none; }
