/* ============================================================
   app.css — design system iOS pour le dashboard Nacre
   ============================================================
   Écrit à la main plutôt que via Tailwind CDN, pour trois raisons :
     1. fidélité — matériaux, ressorts, listes groupées et
        interrupteurs ne se font pas en classes utilitaires ;
     2. hors-ligne — le dashboard sert à diagnostiquer les pannes,
        il ne peut pas dépendre d'un CDN pour s'afficher ;
     3. htmx injecte des fragments : avec le JIT navigateur de
        Tailwind, les classes arrivant par swap posent un risque
        qui disparaît complètement ici.

   Police : celle du système. SF Pro sur macOS, Segoe UI Variable
   sur Windows 11 — donc rendu natif et zéro téléchargement.
   ============================================================ */

/* ─── Tokens ───────────────────────────────────────────────── */

:root {
    /* Couleurs système iOS — mode clair */
    --blue:        #007AFF;
    --green:       #34C759;
    --red:         #FF3B30;
    --orange:      #FF9500;
    --yellow:      #FFCC00;
    --purple:      #AF52DE;
    --indigo:      #5856D6;
    --teal:        #30B0C7;
    --pink:        #FF2D55;

    /* Fonds : iOS empile « grouped background » puis les surfaces */
    --bg:          #F2F2F7;
    --surface:     #FFFFFF;
    --surface-2:   #FFFFFF;
    --surface-3:   rgba(120,120,128,.12);

    /* Texte — les niveaux d'emphase d'iOS */
    --label:       #000000;
    --label-2:     rgba(60,60,67,.60);
    --label-3:     rgba(60,60,67,.30);
    --separator:   rgba(60,60,67,.29);

    /* Matériaux translucides */
    --material:    rgba(255,255,255,.72);
    --material-2:  rgba(242,242,247,.80);

    --shadow-1:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-2:    0 4px 16px rgba(0,0,0,.08);
    --shadow-3:    0 12px 40px rgba(0,0,0,.16);

    /* Rayons */
    --r-sm: 8px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;

    /* La courbe d'animation d'iOS : départ franc, arrivée douce */
    --ease: cubic-bezier(.32,.72,0,1);

    --sidebar-w: 248px;

    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text',
            'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
    --mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
}

/* Mode sombre : suit le système, sauf choix explicite de l'utilisateur.
   Les gris iOS sombres ne sont pas des gris neutres — ils sont
   légèrement froids et partent du noir pur. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --blue:      #0A84FF;
        --green:     #30D158;
        --red:       #FF453A;
        --orange:    #FF9F0A;
        --yellow:    #FFD60A;
        --purple:    #BF5AF2;
        --indigo:    #5E5CE6;
        --teal:      #40C8E0;
        --pink:      #FF375F;

        --bg:        #000000;
        --surface:   #1C1C1E;
        --surface-2: #2C2C2E;
        --surface-3: rgba(120,120,128,.24);

        --label:     #FFFFFF;
        --label-2:   rgba(235,235,245,.60);
        --label-3:   rgba(235,235,245,.30);
        --separator: rgba(84,84,88,.65);

        --material:  rgba(28,28,30,.72);
        --material-2:rgba(0,0,0,.80);

        --shadow-1:  0 1px 3px rgba(0,0,0,.4);
        --shadow-2:  0 4px 16px rgba(0,0,0,.5);
        --shadow-3:  0 12px 40px rgba(0,0,0,.6);
    }
}

/* Le sélecteur manuel doit gagner dans les deux sens */
:root[data-theme="dark"] {
    --blue:#0A84FF; --green:#30D158; --red:#FF453A; --orange:#FF9F0A;
    --yellow:#FFD60A; --purple:#BF5AF2; --indigo:#5E5CE6; --teal:#40C8E0; --pink:#FF375F;
    --bg:#000000; --surface:#1C1C1E; --surface-2:#2C2C2E; --surface-3:rgba(120,120,128,.24);
    --label:#FFFFFF; --label-2:rgba(235,235,245,.60); --label-3:rgba(235,235,245,.30);
    --separator:rgba(84,84,88,.65);
    --material:rgba(28,28,30,.72); --material-2:rgba(0,0,0,.80);
    --shadow-1:0 1px 3px rgba(0,0,0,.4); --shadow-2:0 4px 16px rgba(0,0,0,.5); --shadow-3:0 12px 40px rgba(0,0,0,.6);
}

/* ─── Base ─────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.47;
    color: var(--label);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Les chiffres alignés verticalement : indispensable dès qu'on
   empile des montants, des compteurs ou des durées. */
table, .tabular, .stat-value, .mono, code, time { font-variant-numeric: tabular-nums; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono { font-family: var(--mono); font-size: .92em; }

:focus-visible {
    outline: 2.5px solid var(--blue);
    outline-offset: 2px;
    border-radius: 4px;
}

::selection { background: color-mix(in srgb, var(--blue) 25%, transparent); }

/* ─── Typographie (échelle iOS) ────────────────────────────── */

.title-lg   { font-size: 34px; font-weight: 700; letter-spacing: -.4px; line-height: 1.15; margin: 0; }
.title      { font-size: 22px; font-weight: 700; letter-spacing: -.3px; margin: 0; }
.headline   { font-size: 17px; font-weight: 600; letter-spacing: -.2px; margin: 0; }
.body       { font-size: 15px; }
.subhead    { font-size: 14px; color: var(--label-2); }
.footnote   { font-size: 13px; color: var(--label-2); }
.caption    { font-size: 12px; color: var(--label-3); }

/* En-tête de section, façon Réglages : petites capitales grises */
.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--label-2);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin: 28px 0 8px;
    padding-inline: 4px;
}

.muted { color: var(--label-2); }
.dim   { color: var(--label-3); }

/* ─── Matériaux ────────────────────────────────────────────── */

.material {
    background: var(--material);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    backdrop-filter: blur(30px) saturate(180%);
}

/* Sans backdrop-filter, la translucidité rendrait le texte illisible
   par-dessus le contenu qui défile : on repasse en opaque. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .material { background: var(--surface); }
}

/* ─── Mise en page ─────────────────────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    border-right: 1px solid var(--separator);
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 18px;
}
.brand-mark {
    width: 30px; height: 30px; border-radius: var(--r-sm);
    background: linear-gradient(135deg, var(--blue), var(--indigo));
    display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 15px;
    box-shadow: var(--shadow-1);
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -.2px; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    color: var(--label);
    font-size: 15px;
    min-height: 36px;
    transition: background .15s var(--ease);
}
.nav-item:hover { background: var(--surface-3); text-decoration: none; }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item.active .nav-icon { background: rgba(255,255,255,.22); color: #fff; }
.nav-item.active .nav-badge { background: rgba(255,255,255,.25); color: #fff; }

/* Icône en carré arrondi coloré — la signature visuelle d'iOS */
.nav-icon {
    width: 26px; height: 26px; flex: 0 0 26px;
    border-radius: 7px;
    display: grid; place-items: center;
    font-size: 14px;
    background: var(--surface-3);
}

.nav-badge {
    margin-left: auto;
    min-width: 20px; height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--red); color: #fff;
    font-size: 12px; font-weight: 600;
    display: grid; place-items: center;
}

.nav-spacer { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Barre de titre translucide et collante */
.topbar {
    position: sticky; top: 0; z-index: 20;
    border-bottom: 1px solid transparent;
    padding: 14px 28px;
    display: flex; align-items: center; gap: 14px;
    transition: border-color .2s var(--ease);
}
.topbar.scrolled { border-bottom-color: var(--separator); }
.topbar-title { font-size: 17px; font-weight: 600; opacity: 0; transition: opacity .2s var(--ease); }
.topbar.scrolled .topbar-title { opacity: 1; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { padding: 8px 28px 64px; max-width: 1180px; width: 100%; }

.page-header { margin: 8px 0 4px; }
.page-sub { margin: 6px 0 0; }

/* ─── Cartes ───────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    padding: 18px 20px;
}
.card + .card { margin-top: 14px; }

.grid { display: grid; gap: 14px; }
.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)); }

/* Tuile d'indicateur */
.stat {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    padding: 16px 18px;
    display: block;
    color: inherit;
    transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
a.stat:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-2); }
a.stat:active { transform: scale(.985); }
.stat-label { font-size: 13px; color: var(--label-2); font-weight: 500; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -.6px; margin-top: 2px; line-height: 1.1; }
.stat-meta  { font-size: 12px; color: var(--label-3); margin-top: 2px; }
.stat.accent-red    .stat-value { color: var(--red); }
.stat.accent-green  .stat-value { color: var(--green); }
.stat.accent-orange .stat-value { color: var(--orange); }
.stat.accent-blue   .stat-value { color: var(--blue); }

/* ─── Liste groupée encadrée (le motif de l'app Réglages) ──── */

.list {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}

.row {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 16px;
    min-height: 44px;                 /* cible tactile iOS */
    position: relative;
    color: inherit;
}
/* Séparateur décalé à gauche pour s'aligner sous le texte, pas sous
   l'icône — c'est ce décalage qui « fait iOS ». */
.row + .row::before {
    content: '';
    position: absolute; top: 0; left: 16px; right: 0;
    border-top: 1px solid var(--separator);
}
.row.has-icon + .row.has-icon::before { left: 54px; }

a.row, button.row { width: 100%; text-align: left; background: none; border: 0; font: inherit; cursor: pointer; }
a.row:hover, button.row:hover { background-color: var(--surface-3); text-decoration: none; }
a.row:active, button.row:active { background-color: var(--surface-3); }

.row-icon {
    width: 28px; height: 28px; flex: 0 0 28px;
    border-radius: 7px;
    display: grid; place-items: center;
    font-size: 15px; color: #fff;
    background: var(--blue);
}
.row-icon.green { background: var(--green); }
.row-icon.red { background: var(--red); }
.row-icon.orange { background: var(--orange); }
.row-icon.purple { background: var(--purple); }
.row-icon.teal { background: var(--teal); }
.row-icon.gray { background: var(--label-3); }
/* `blue` manquait alors que trois vues l'utilisaient déjà (création de
   client, système, boutique) : leurs icônes sortaient sans couleur. */
.row-icon.blue { background: var(--blue); }
.row-icon.indigo { background: var(--indigo, var(--blue)); }

.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 15px; }
.row-sub { font-size: 13px; color: var(--label-2); margin-top: 1px; }
.row-value { color: var(--label-2); font-size: 15px; text-align: right; white-space: nowrap; }
.row-chevron { color: var(--label-3); font-size: 17px; flex: 0 0 auto; }

/* ─── Interrupteur ─────────────────────────────────────────── */

.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex: 0 0 51px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
    position: absolute; inset: 0;
    background: var(--surface-3);
    border-radius: 31px;
    transition: background .25s var(--ease);
    cursor: pointer;
}
.switch-track::before {
    content: '';
    position: absolute; top: 2px; left: 2px;
    width: 27px; height: 27px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16);
    transition: transform .25s var(--ease);
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2.5px solid var(--blue); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; cursor: not-allowed; }

/* ─── Contrôle segmenté ────────────────────────────────────── */

.segmented {
    display: inline-flex;
    background: var(--surface-3);
    border-radius: 9px;
    padding: 2px;
    gap: 2px;
}
.segmented a, .segmented button {
    padding: 5px 13px;
    border-radius: 7px;
    font-size: 13px; font-weight: 500;
    color: var(--label);
    border: 0; background: none; cursor: pointer;
    font-family: inherit;
    transition: background .2s var(--ease);
    white-space: nowrap;
}
.segmented a:hover, .segmented button:hover { text-decoration: none; }
.segmented .active {
    background: var(--surface);
    box-shadow: var(--shadow-1);
    font-weight: 600;
}

/* ─── Boutons ──────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 15px;
    min-height: 34px;
    border-radius: var(--r-md);
    border: 0;
    font-family: inherit; font-size: 15px; font-weight: 500;
    cursor: pointer;
    background: var(--surface-3);
    color: var(--label);
    transition: transform .12s var(--ease), filter .15s var(--ease), opacity .15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--blue); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red);   color: #fff; }
.btn-warning { background: var(--orange); color: #fff; }
.btn-plain   { background: none; color: var(--blue); padding-inline: 6px; }
.btn-sm      { padding: 5px 11px; min-height: 28px; font-size: 13px; }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

/* Pendant une requête htmx, le bouton se met en attente tout seul,
   après 150 ms seulement (comme les squelettes, ui.css) : une réponse
   rapide ne fait rien clignoter. */
.btn.htmx-request { pointer-events: none; }
.btn.htmx-request::after {
    content: '';
    width: 13px; height: 13px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite, apparait 0s linear .15s both;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes apparait { from { opacity: 0; } to { opacity: 1; } }

/* ─── Badges ───────────────────────────────────────────────── */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
    background: var(--surface-3);
    color: var(--label-2);
    white-space: nowrap;
}
.badge-green  { background: color-mix(in srgb, var(--green) 16%, transparent);  color: var(--green); }
.badge-red    { background: color-mix(in srgb, var(--red) 16%, transparent);    color: var(--red); }
.badge-orange { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.badge-blue   { background: color-mix(in srgb, var(--blue) 16%, transparent);   color: var(--blue); }
.badge-purple { background: color-mix(in srgb, var(--purple) 16%, transparent); color: var(--purple); }
.badge-teal   { background: color-mix(in srgb, var(--teal) 16%, transparent);   color: var(--teal); }
.badge-yellow { background: color-mix(in srgb, var(--yellow) 20%, transparent); color: #9a7b00; }
:root[data-theme="dark"] .badge-yellow { color: var(--yellow); }
/* Dans la media query : hors d'elle, ce sélecteur visait aussi le mode
   clair « automatique », et y écrivait du jaune vif sur fond jaune pâle. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .badge-yellow { color: var(--yellow); }
}

/* Pastille d'état, avec halo pulsant quand le bot tourne */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; background: var(--label-3); }
.dot.on  { background: var(--green); box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); animation: pulse 2.2s infinite; }
.dot.off { background: var(--label-3); }
.dot.err { background: var(--red); }
@keyframes pulse {
    70%  { box-shadow: 0 0 0 7px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* ─── Champs ───────────────────────────────────────────────── */

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--label-2); margin-bottom: 5px; }

.input, .select, .textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--separator);
    background: var(--surface);
    color: var(--label);
    font-family: inherit; font-size: 15px;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--blue) 18%, transparent);
}
.input::placeholder { color: var(--label-3); }
.textarea { min-height: 80px; resize: vertical; }

/* Champ de recherche arrondi, façon iOS */
.search {
    display: flex; align-items: center; gap: 7px;
    background: var(--surface-3);
    border-radius: var(--r-md);
    padding: 7px 11px;
}
.search input {
    border: 0; background: none; outline: none;
    font-family: inherit; font-size: 15px; color: var(--label);
    width: 100%;
}

/* ─── Tableaux ─────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
    text-align: left;
    font-size: 12px; font-weight: 600;
    color: var(--label-2);
    text-transform: uppercase; letter-spacing: .4px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--separator);
    white-space: nowrap;
}
table.tbl td {
    padding: 11px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--separator);
}
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: var(--surface-3); }

/* ─── Sheet (dialog natif) ─────────────────────────────────── */

dialog.sheet {
    border: 0; padding: 0;
    background: transparent;
    max-width: 520px; width: calc(100% - 32px);
    margin: auto auto 0;                /* ancré en bas, comme iOS */
    color: var(--label);
}
dialog.sheet::backdrop {
    background: rgba(0,0,0,.4);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}
.sheet-panel {
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--shadow-3);
    padding: 10px 22px 26px;
    max-height: 88vh; overflow-y: auto;
}
/* La petite barre qu'on « attrape » en haut des feuilles iOS */
.sheet-grabber {
    width: 36px; height: 5px; border-radius: 3px;
    background: var(--label-3);
    margin: 0 auto 14px;
}
.sheet-title { font-size: 19px; font-weight: 700; margin: 0 0 4px; }
.sheet-sub { font-size: 14px; color: var(--label-2); margin: 0 0 18px; }
/* Côte à côte, de même largeur ; l'un sous l'autre quand un libellé ne
   tient pas (téléphone, anglais), au lieu de déborder de la feuille. */
.sheet-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.sheet-actions .btn { flex: 1 1 140px; min-height: 44px; font-size: 16px; font-weight: 600; }

dialog.sheet[open] { animation: sheetIn .4s var(--ease); }
dialog.sheet[open]::backdrop { animation: fadeIn .3s ease; }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 640px) {
    /* Sur large écran iOS centre la feuille au lieu de la coller en bas */
    dialog.sheet { margin: auto; }
    .sheet-panel { border-radius: var(--r-xl); }
}

/* ─── Toasts ───────────────────────────────────────────────── */

.toasts {
    position: fixed; top: 18px; left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex; flex-direction: column; gap: 8px;
    align-items: center;
    pointer-events: none;
}
.toast {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 18px;
    border-radius: 24px;
    background: var(--material);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    backdrop-filter: blur(30px) saturate(180%);
    box-shadow: var(--shadow-3);
    font-size: 14px; font-weight: 500;
    max-width: min(520px, calc(100vw - 32px));
    animation: toastIn .4s var(--ease);
}
.toast.out { animation: toastOut .3s var(--ease) forwards; }
.toast-icon { width: 19px; height: 19px; flex: 0 0 19px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; }
.toast-success .toast-icon { background: var(--green); }
.toast-error   .toast-icon { background: var(--red); }
.toast-info    .toast-icon { background: var(--blue); }
@keyframes toastIn  { from { opacity: 0; transform: translateY(-14px) scale(.94); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-10px) scale(.96); } }

/* ─── État vide ────────────────────────────────────────────── */

.empty { text-align: center; padding: 52px 24px; }
.empty-icon { font-size: 40px; opacity: .35; margin-bottom: 12px; }
.empty-title { font-size: 17px; font-weight: 600; margin-bottom: 5px; }
.empty-sub { font-size: 14px; color: var(--label-2); max-width: 380px; margin: 0 auto 18px; }

/* ─── Console de logs ──────────────────────────────────────── */

.console {
    background: #0b0b0d;
    color: #e6e6e6;
    border-radius: var(--r-md);
    padding: 13px 15px;
    font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
    height: 380px; overflow-y: auto;
    white-space: pre-wrap; word-break: break-word;
}
.console .err { color: #ff8a80; }

/* ─── Divers ───────────────────────────────────────────────── */

.stack { display: flex; flex-direction: column; gap: 14px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.hstack.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; }

/* ─── Responsive ───────────────────────────────────────────── */

@media (max-width: 860px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 680px) {
    .shell { flex-direction: column; }
    .sidebar {
        width: 100%; flex: none; height: auto; position: static;
        flex-direction: row; overflow-x: auto; gap: 6px;
        border-right: 0; border-bottom: 1px solid var(--separator);
        padding: 10px 12px;
    }
    .brand { padding: 0 8px 0 0; }
    .brand-name, .nav-item span.nav-label { display: none; }
    .nav-spacer { display: none; }
    .nav-item { padding: 7px; }
    .content, .topbar { padding-inline: 16px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .title-lg { font-size: 28px; }
}

/* ─── Mouvement réduit ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* ─── Graphiques SVG ───────────────────────────────────────── */

.chart { width: 100%; height: auto; display: block; }
.chart-empty { text-align: center; padding: 28px 0; }

.chart-line       { stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot        { fill: var(--blue); }
.chart-fill-top    { stop-color: var(--blue); stop-opacity: .22; }
.chart-fill-bottom { stop-color: var(--blue); stop-opacity: 0; }
.chart-bar        { fill: var(--blue); transition: fill .15s var(--ease); }
.chart-bar:hover  { fill: var(--indigo); }
.chart-axis       { fill: var(--label-3); font-size: 10px; font-family: var(--font); }

.chart-ring   { flex: 0 0 auto; }
.ring-track   { stroke: var(--surface-3); }
.ring-value   { stroke: var(--blue); transition: stroke-dasharray .5s var(--ease); }
.ring-label   { fill: var(--label); font-size: 13px; font-weight: 600; font-family: var(--font); }

/* ─── Icônes ───────────────────────────────────────────────── */
/* Les emoji sont proscrits comme icônes structurelles : dépendants de
   la police, incohérents entre systèmes, insensibles aux tokens de
   couleur. Ces SVG héritent de currentColor, donc du thème. */

.icon {
    display: inline-block;
    vertical-align: -0.14em;   /* aligne sur la ligne de base du texte */
    flex: 0 0 auto;
    fill: currentColor;
}

/* Dans un carré arrondi coloré (navigation, lignes de liste), l'icône
   prend la couleur du texte du conteneur. */
.nav-icon .icon,
.row-icon .icon { display: block; }

.btn .icon { margin-inline-end: -1px; }

/* Retourne une icône directionnelle — évite d'embarquer un second tracé
   pour l'orientation opposée. */
.icon.flip { transform: scaleX(-1); }

/* ─── Etat du bot ──────────────────────────────────────────── */
/* Le dashboard delegue au bot tout ce qui touche Discord. Savoir
   s'il repond AVANT de cliquer evite de croire qu'un client a ete
   prevenu alors que rien n est parti. */

.bot-state {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 10px; margin: 0 4px 4px;
    border-radius: var(--r-sm);
    background: color-mix(in srgb, var(--green) 12%, transparent);
}
.bot-state.off { background: color-mix(in srgb, var(--red) 14%, transparent); }
.bot-state .caption { color: var(--green); font-weight: 500; }
.bot-state.off .caption { color: var(--red); }

/* ─── Frise d'historique ──────────────────────────────────────
   Une commande n'est pas une liste d'états, c'est une suite
   d'événements. La liste groupée aurait aplati l'ordre ; la frise
   le rend, avec le dernier mouvement en tête. */
.timeline { position: relative; padding-left: 24px; margin: 2px 0; }
.timeline::before {
    content: ''; position: absolute; left: 5px; top: 10px; bottom: 10px;
    width: 2px; background: var(--separator); border-radius: 1px;
}
.tl-item { position: relative; padding: 9px 0; }
.tl-item + .tl-item { border-top: 1px solid var(--surface-3); }
.tl-dot {
    position: absolute; left: -23px; top: 15px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--separator);
    box-sizing: border-box;
}
.tl-dot.blue   { background: var(--blue);   border-color: var(--blue); }
.tl-dot.green  { background: var(--green);  border-color: var(--green); }
.tl-dot.orange { background: var(--orange); border-color: var(--orange); }
.tl-dot.red    { background: var(--red);    border-color: var(--red); }
.tl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tl-title { font-size: 15px; font-weight: 590; }
.tl-time { font-size: 12px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.tl-note { font-size: 13px; color: var(--label-2); margin-top: 2px; word-break: break-word; }

/* ─── Conversation du ticket ──────────────────────────────────
   Le fil est en lecture seule côté visuel : les bulles ne sont pas
   éditables, seule la zone de saisie du bas écrit. Un message qui ne
   porte qu'un embed ou une image a un contenu vide de façon légitime —
   c'est le cas de la plupart des messages d'un ticket — donc l'absence
   de texte se dit, elle ne se laisse pas deviner. */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow-y: auto; padding: 2px; }
.bubble { display: flex; gap: 9px; align-items: flex-start; }
.bubble-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px;
    background: var(--surface-3); object-fit: cover;
}
.bubble-body {
    background: var(--surface-3); border-radius: var(--r-md);
    padding: 7px 11px; max-width: min(78%, 620px);
}
.bubble.mine { flex-direction: row-reverse; }
.bubble.mine .bubble-body { background: color-mix(in srgb, var(--blue) 16%, transparent); }
.bubble-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.bubble-who { font-size: 12px; font-weight: 590; }
.bubble-when { font-size: 11px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.bubble-text { font-size: 14px; line-height: 1.42; white-space: pre-wrap; word-break: break-word; }
.bubble-aside { font-size: 12px; color: var(--label-2); font-style: italic; }
.bubble-card { border: 1px dashed var(--separator); background: transparent; }

@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .bubble.mine .bubble-body { background: var(--surface-3); }
}

/* ─── Markdown Discord dans le fil ────────────────────────────
   Le texte etait rendu brut : « **important** » se lisait avec ses
   asterisques. On ne relisait donc pas la meme chose que le client. */
.bubble-text strong { font-weight: 640; }
.bubble-text em     { font-style: italic; }
.bubble-text u      { text-decoration: underline; text-underline-offset: 2px; }
.bubble-text s      { opacity: .6; }

.md-code {
    font-family: var(--mono); font-size: .89em;
    background: rgba(120,120,128,.20); border-radius: 5px;
    padding: 1px 5px;
}
.md-pre {
    font-family: var(--mono); font-size: 12.5px; line-height: 1.45;
    background: rgba(120,120,128,.16); border-radius: 8px;
    padding: 9px 11px; margin: 6px 0; overflow-x: auto;
    white-space: pre; tab-size: 2;
}
.md-pre code { background: none; padding: 0; font-size: inherit; }

/* Une mention doit se voir sans crier : le bleu systeme, sur un fond
   tres leger, comme dans Discord. */
.md-mention, .md-channel {
    color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, transparent);
    border-radius: 4px; padding: 0 3px; font-weight: 560;
}
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .md-mention, .md-channel { background: var(--surface-3); }
}

.md-link { color: var(--blue); text-decoration: none; }
.md-link:hover { text-decoration: underline; }

.md-quote {
    display: block; border-left: 3px solid var(--separator);
    padding-left: 9px; margin: 2px 0; color: var(--label-2);
}
.md-li { display: block; padding-left: 14px; text-indent: -9px; }
.md-li::before { content: '• '; color: var(--label-2); }

.md-h1 { display: block; font-size: 1.28em; font-weight: 680; margin: 5px 0 2px; }
.md-h2 { display: block; font-size: 1.14em; font-weight: 660; margin: 4px 0 2px; }
.md-h3 { display: block; font-size: 1.04em; font-weight: 640; margin: 3px 0 2px; }

.md-time {
    background: rgba(120,120,128,.18); border-radius: 4px;
    padding: 0 4px; font-variant-numeric: tabular-nums;
}

/* Un spoiler reste masque jusqu au survol : le montrer d office
   trahirait l intention de celui qui l a ecrit. */
.md-spoiler {
    background: var(--label); color: transparent; border-radius: 4px;
    padding: 0 3px; cursor: pointer;
}
.md-spoiler:hover { color: var(--surface); }

/* ─── Non-lu ──────────────────────────────────────────────────
   Un point, pas un compteur : connaitre le nombre exact de messages non
   lus demanderait un appel Discord par ticket. Le point se lit aussi
   vite et se sert du cache. */
.unread-dot {
    width: 9px; height: 9px; flex: 0 0 9px;
    border-radius: 50%; background: var(--blue);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent);
}
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .unread-dot { box-shadow: none; }
}
.row-title.is-unread { font-weight: 640; }
