/* =====================================================================
   CRM – Interface (clair / sombre, responsive). Aucune dépendance externe.
   ===================================================================== */

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-hover: #f3f4f6;
  --border: #e6e7eb;
  --border-strong: #d4d6dc;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-text: #ffffff;
  --ring: rgba(79, 70, 229, .25);

  --green: #059669; --green-soft: #ecfdf5;
  --amber: #b45309; --amber-soft: #fffbeb;
  --red: #dc2626;   --red-soft: #fef2f2;
  --blue: #2563eb;  --blue-soft: #eff6ff;
  --violet: #7c3aed; --violet-soft: #f5f3ff;
  --cyan: #0e7490;  --cyan-soft: #ecfeff;
  --gray: #4b5563;  --gray-soft: #f3f4f6;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .08);
  --sidebar-w: 256px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #161a22;
  --surface-hover: #1c212b;
  --border: #242a35;
  --border-strong: #313846;
  --text: #ecedf0;
  --text-2: #b4b9c4;
  --muted: #8a91a0;
  --primary: #7c7aff;
  --primary-hover: #918fff;
  --primary-soft: rgba(124, 122, 255, .14);
  --primary-text: #0b0d12;
  --ring: rgba(124, 122, 255, .35);
  --green: #34d399; --green-soft: rgba(52, 211, 153, .12);
  --amber: #fbbf24; --amber-soft: rgba(251, 191, 36, .12);
  --red: #f87171;   --red-soft: rgba(248, 113, 113, .12);
  --blue: #60a5fa;  --blue-soft: rgba(96, 165, 250, .12);
  --violet: #a78bfa; --violet-soft: rgba(167, 139, 250, .12);
  --cyan: #22d3ee;  --cyan-soft: rgba(34, 211, 238, .12);
  --gray: #a3aab8;  --gray-soft: rgba(163, 170, 184, .12);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0b0d12; --surface: #12151c; --surface-2: #161a22; --surface-hover: #1c212b;
    --border: #242a35; --border-strong: #313846; --text: #ecedf0; --text-2: #b4b9c4; --muted: #8a91a0;
    --primary: #7c7aff; --primary-hover: #918fff; --primary-soft: rgba(124, 122, 255, .14); --primary-text: #0b0d12; --ring: rgba(124, 122, 255, .35);
    --green: #34d399; --green-soft: rgba(52, 211, 153, .12); --amber: #fbbf24; --amber-soft: rgba(251, 191, 36, .12);
    --red: #f87171; --red-soft: rgba(248, 113, 113, .12); --blue: #60a5fa; --blue-soft: rgba(96, 165, 250, .12);
    --violet: #a78bfa; --violet-soft: rgba(167, 139, 250, .12); --cyan: #22d3ee; --cyan-soft: rgba(34, 211, 238, .12);
    --gray: #a3aab8; --gray-soft: rgba(163, 170, 184, .12);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4); --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6);
    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: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-hover); padding: 1px 6px; border-radius: 5px; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
.h2 { font-size: 22px; font-weight: 650; }
.h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 .8em; }
.icon { flex-shrink: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.success-text { color: var(--green); }
.danger-text { color: var(--red); }
.warning-text { color: var(--amber); }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border);
  transition: transform .25s var(--ease);
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); padding: 0 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 15px; min-width: 0; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-logo { height: 30px; width: auto; max-width: 140px; object-fit: contain; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.brand-mark.lg { width: 48px; height: 48px; border-radius: 12px; font-size: 16px; margin: 0 auto 14px; }
.sidebar-close { display: none; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link span:first-of-type { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: 11px; font-weight: 600; background: var(--surface-hover); color: var(--text-2); border-radius: 999px; padding: 0 7px; line-height: 18px; }
.nav-link.active .nav-count { background: var(--primary); color: var(--primary-text); }
.sidebar-footer { border-top: 1px solid var(--border); padding: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius-sm); color: var(--text); }
.user-chip:hover { background: var(--surface-hover); color: var(--text); }
.user-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-chip-text strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-text small { color: var(--muted); font-size: 11.5px; }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary); font-weight: 650; font-size: 12px;
}
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.sidebar-backdrop { display: none; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; flex: 1; }

/* ---------- Recherche globale ---------- */
.global-search { position: relative; flex: 1; max-width: 520px; }
.global-search input {
  width: 100%; height: 36px; padding: 0 36px 0 34px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.global-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.search-icon { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.search-kbd { position: absolute; right: 9px; top: 8px; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; background: var(--surface-2); }
.search-results, .picker-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px;
}
.search-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px 4px; }
.search-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); cursor: pointer; }
.search-item:hover, .search-item.active { background: var(--surface-hover); color: var(--text); }
.search-item small { color: var(--muted); display: block; font-size: 12px; }
.search-empty { padding: 14px; text-align: center; color: var(--muted); }
.picker { position: relative; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-hover); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-text); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--red); color: #fff; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); background: var(--green); color: #fff; }
.btn-whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1ebe5a; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 44px; font-size: 15px; }
.btn-block { width: 100%; }
.btn.loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; animation: spin .7s linear infinite;
}
.btn-primary.loading::after, .btn-danger.loading::after { border-color: #fff transparent #fff transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 0;
  background: transparent; color: var(--text-2); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; font-size: 12.5px; padding: 0; }
.avatar-btn { background: none; border: 0; padding: 2px; cursor: pointer; border-radius: 50%; }
.notif-dot {
  position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center; border: 2px solid var(--bg);
}
[data-theme="light"] .theme-icon-light, [data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="auto"] .theme-icon-dark { display: none; }
@media (prefers-color-scheme: dark) { [data-theme="auto"] .theme-icon-dark { display: inline; } [data-theme="auto"] .theme-icon-light { display: none; } }

/* ---------- En-têtes ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 680; margin: 0; letter-spacing: -.02em; }
.page-subtitle { color: var(--muted); margin: 4px 0 0; }
.page-actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions.center { justify-content: center; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.back-link:hover { color: var(--text); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
.section-title h2, .section-title h3 { font-size: 15px; font-weight: 620; margin: 0; }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-header h2, .card-header h3 { font-size: 14.5px; font-weight: 620; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card + .card, .card + .grid, .grid + .card, .grid + .grid, .alert + .card { margin-top: 16px; }
.grid > .card, .stack > .card { margin-top: 0; }
.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)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.stat-card { padding: 16px 18px; position: relative; overflow: hidden; }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
.stat-icon { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); }
.stat-icon.green { background: var(--green-soft); color: var(--green); }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }
.stat-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stat-icon.violet { background: var(--violet-soft); color: var(--violet); }
.stat-icon.cyan { background: var(--cyan-soft); color: var(--cyan); }
.stat-value { font-size: 26px; font-weight: 680; letter-spacing: -.02em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
a.stat-card { color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.stat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); color: inherit; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 560; white-space: nowrap; background: var(--gray-soft); color: var(--gray);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-cyan { background: var(--cyan-soft); color: var(--cyan); }
.badge-plain::before { display: none; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px; background: var(--surface-hover); color: var(--text-2); border: 1px solid var(--border); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: none;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table th:first-child { border-top-left-radius: var(--radius-lg); }
.table th:last-child { border-top-right-radius: var(--radius-lg); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table a.row-link { color: var(--text); font-weight: 560; }
.table a.row-link:hover { color: var(--primary); }
.cell-sub { display: block; font-size: 12px; color: var(--muted); }
.card > .table-wrap .table th:first-child, .card > .table-wrap .table th:last-child { border-radius: 0; }
.card > .table-wrap:first-child .table th:first-child { border-top-left-radius: var(--radius-lg); }
.card > .table-wrap:first-child .table th:last-child { border-top-right-radius: var(--radius-lg); }

/* ---------- Filtres ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); }
.filters .input, .filters .select { height: 34px; width: auto; min-width: 150px; }
.filters .search-field { flex: 1; min-width: 200px; position: relative; }
.filters .search-field .input { width: 100%; padding-left: 32px; }
.filters .search-field .icon { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.segmented { display: inline-flex; background: var(--surface-hover); border-radius: var(--radius-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented a, .segmented button { padding: 5px 11px; border-radius: 6px; color: var(--text-2); font-size: 13px; font-weight: 550; border: 0; background: none; cursor: pointer; }
.segmented a.active, .segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 560; color: var(--text); }
.label .req { color: var(--red); }
.hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--red); }
.field-error { color: var(--red); font-size: 12.5px; margin: 0; }
.input-group { display: flex; position: relative; }
.input-group .input { padding-right: 42px; }
.input-addon { position: absolute; right: 2px; top: 1px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 6px; flex-wrap: wrap; }
.form-section { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); grid-column: 1 / -1; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
fieldset { border: 0; padding: 0; margin: 0; }

/* ---------- Alertes ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 14px; }
.alert-danger, .alert-error { background: var(--red-soft); border-color: transparent; color: var(--red); }
.alert-success { background: var(--green-soft); border-color: transparent; color: var(--green); }
.alert-warning { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.alert-info { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.alert p { margin: 0; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; font: inherit; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab .count { font-size: 11px; background: var(--surface-hover); border-radius: 999px; padding: 0 6px; }
.tab-panel { display: none; animation: fade .2s var(--ease); }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- Listes de détails ---------- */
.dl { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 10px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 560; color: var(--text); }
.list-item-sub { font-size: 12.5px; color: var(--muted); }

/* ---------- Fiche client ---------- */
.profile-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 18px; }
.profile-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 4px; }
.profile-meta span { display: inline-flex; align-items: center; gap: 5px; }
.secret { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); background: var(--surface-hover); padding: 3px 8px; border-radius: 6px; font-size: 13px; }
.secret.revealed { background: var(--amber-soft); color: var(--text); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0 20px; }
.timeline li { position: relative; padding: 12px 0 12px 26px; border-left: 1px solid var(--border); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 17px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline-title { font-weight: 560; }
.timeline-meta { font-size: 12px; color: var(--muted); }
.message { padding: 14px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 10px; white-space: pre-wrap; word-break: break-word; }
.message.internal { background: var(--amber-soft); border-color: transparent; }
.message-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; white-space: normal; }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; z-index: 60; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; animation: pop .14s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.dropdown-menu-right { left: auto; right: 0; }
.dropdown-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.dropdown-item:hover { background: var(--surface-hover); color: var(--text); }
.dropdown-item.danger { color: var(--red); }
.dropdown-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-footer { display: block; text-align: center; padding: 8px; font-size: 13px; border-top: 1px solid var(--border); margin-top: 4px; }
.notif-menu { width: 360px; max-width: calc(100vw - 24px); }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: block; padding: 10px; border-radius: 6px; color: var(--text); }
.notif-item:hover { background: var(--surface-hover); color: var(--text); }
.notif-item.unread { background: var(--primary-soft); }
.notif-item strong { display: block; font-size: 13px; font-weight: 580; }
.notif-item small { color: var(--muted); }
.notif-empty { padding: 20px; text-align: center; color: var(--muted); }

/* ---------- Modales ---------- */
.modal { border: 0; padding: 0; background: transparent; max-width: min(520px, calc(100vw - 24px)); width: 100%; color: var(--text); }
.modal::backdrop { background: rgba(15, 18, 25, .55); backdrop-filter: blur(2px); }
.modal[open] { animation: pop .18s var(--ease); }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-lg { max-width: min(720px, calc(100vw - 24px)); }
.modal-title { font-size: 17px; font-weight: 640; margin: 0; }
.modal-text { color: var(--text-2); margin: 0; }
.modal-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); }
.modal-icon.warning { background: var(--red-soft); color: var(--red); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(400px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--text); color: var(--surface);
  box-shadow: var(--shadow-lg); animation: toast-in .25s var(--ease); font-weight: 500;
}
.toast.success .icon { color: #34d399; }
.toast.error .icon, .toast.danger .icon { color: #f87171; }
.toast.warning .icon { color: #fbbf24; }
.toast.hide { animation: toast-out .2s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; }
.pager-btn { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px; border-radius: 7px; color: var(--text-2); border: 1px solid var(--border); background: var(--surface); font-size: 13px; }
.pager-btn:hover { background: var(--surface-hover); color: var(--text); }
.pager-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.pager-btn.disabled { opacity: .45; pointer-events: none; }
.pager-gap { padding: 0 4px; color: var(--muted); align-self: center; }

/* ---------- État vide ---------- */
.empty-state { text-align: center; padding: 44px 20px; }
.empty-icon { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--surface-hover); color: var(--muted); margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; font-weight: 600; }
.empty-state p { max-width: 420px; margin: 0 auto 14px; }

/* ---------- Graphiques ---------- */
.chart { width: 100%; min-height: 240px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); box-shadow: var(--shadow-lg); z-index: 5; }
.chart-empty { display: grid; place-items: center; min-height: 200px; color: var(--muted); font-size: 13px; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* ---------- Calendrier ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-head { font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; text-align: center; background: var(--surface-2); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 110px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-width: 0; }
.cal-day.other { background: var(--surface-2); color: var(--muted); }
.cal-day.today .cal-num { background: var(--primary); color: var(--primary-text); }
.cal-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.cal-event { display: block; font-size: 11.5px; padding: 2px 6px; border-radius: 5px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--blue-soft); color: var(--blue); }
.cal-event.amber { background: var(--amber-soft); color: var(--amber); }
.cal-event.red { background: var(--red-soft); color: var(--red); }
.cal-event.green { background: var(--green-soft); color: var(--green); }
.cal-event.violet { background: var(--violet-soft); color: var(--violet); }
.cal-week .cal-day { min-height: 320px; }

/* ---------- Auth / pages isolées ---------- */
.blank-body { min-height: 100vh; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-bg { background: radial-gradient(1200px 600px at 50% -10%, var(--primary-soft), transparent 70%); }
.auth-card { width: 100%; max-width: 420px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-logo { max-height: 56px; margin-bottom: 12px; }
.auth-foot { text-align: center; margin: 18px 0 0; display: flex; gap: 6px; justify-content: center; align-items: center; }
.error-code { font-size: 64px; font-weight: 750; letter-spacing: -.04em; color: var(--primary); line-height: 1; margin-bottom: 8px; }
.steps { display: flex; gap: 6px; margin-bottom: 20px; }
.steps span { flex: 1; height: 4px; border-radius: 99px; background: var(--surface-hover); }
.steps span.done { background: var(--primary); }
.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- Divers ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.big-number { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.pre { white-space: pre-wrap; word-break: break-word; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.var-chip { font-family: var(--mono); font-size: 12px; background: var(--surface-hover); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; cursor: pointer; color: var(--text-2); }
.var-chip:hover { border-color: var(--primary); color: var(--primary); }
.invoice-lines td { padding: 6px 8px; }
.invoice-lines .input { height: 34px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 18px; }
.mobile-only { display: none; }

/* ---------- Bas de page mobile ---------- */
.bottom-nav { display: none; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 35; }
  .sidebar-close { display: inline-grid; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
  body { font-size: 15px; }
  .content { padding: 16px 14px 96px; }
  .topbar { padding: 0 10px; gap: 6px; }
  .search-kbd { display: none; }
  .grid-2, .grid-4, .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title { font-size: 21px; }
  .page-header { align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .btn { height: 42px; }
  .btn-sm { height: 34px; }
  .input, .select { height: 44px; font-size: 16px; }
  .textarea { font-size: 16px; }
  .icon-btn { width: 40px; height: 40px; }
  .stat-value { font-size: 22px; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dd { margin-bottom: 10px; }
  .filters .input, .filters .select { flex: 1 1 140px; min-width: 0; }
  .mobile-only { display: initial; }
  .desktop-only { display: none !important; }

  /* Tableaux transformés en cartes */
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.responsive tr:last-child { border-bottom: 0; }
  .table.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; text-align: left; flex-shrink: 0; }
  .table.responsive td.primary-cell { display: block; text-align: left; font-size: 15px; margin-bottom: 4px; }
  .table.responsive td.primary-cell::before { display: none; }
  .table.responsive td.actions { justify-content: flex-end; padding-top: 8px; width: 100%; }
  .table.responsive td.actions::before { display: none; }
  .table.responsive td:empty { display: none; }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-link { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); background: none; border: 0; font-family: inherit; padding: 4px 0; cursor: pointer; }
  .bottom-link.active { color: var(--primary); }
  .toast-container { bottom: 84px; left: 16px; right: 16px; max-width: none; }
  .cal-day { min-height: 70px; padding: 3px; }
  .cal-event { font-size: 10px; padding: 1px 3px; }
  .notif-menu { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
  .sidebar, .topbar, .bottom-nav, .page-actions, .btn, .filters, .pagination { display: none !important; }
  .main { margin: 0; }
  .card { box-shadow: none; }
}
