/* =============================================================================
   Kitsune Admin — design system
   Refonte 2026-08-19. Remplace 536 lignes de CSS sans une seule variable et sans
   media query. Tout est piloté par les tokens ci-dessous : changer une valeur ici
   la change partout, y compris en thème sombre.
   ============================================================================= */

:root {
    /* Neutres — base de l'interface */
    --bg:            #f1f3f7;
    --surface:       #ffffff;
    --surface-2:     #f7f8fa;
    --surface-3:     #eceff4;
    --border:        #dfe3ea;
    --border-strong: #c6ccd8;

    --text:          #1a1f2b;
    --text-muted:    #5c6577;
    --text-faint:    #8b94a6;

    /* Marque — hérité du dégradé violet d'origine, assagi */
    --brand:         #6355d8;
    --brand-hover:   #5445c4;
    --brand-soft:    #eeecfc;
    --brand-text:    #4b3fb0;

    /* Sémantique */
    --ok:            #1f8a55;
    --ok-soft:       #e4f5ec;
    --warn:          #b26a00;
    --warn-soft:     #fdf1dd;
    --danger:        #c8362f;
    --danger-soft:   #fce9e8;
    --info:          #1668b8;
    --info-soft:     #e6f1fb;

    /* Palette graphiques — ordre stable, lisible en clair comme en sombre */
    --c1: #6355d8;  --c2: #1f8a55;  --c3: #d98324;  --c4: #c8362f;
    --c5: #1668b8;  --c6: #8e44ad;  --c7: #00897b;  --c8: #7a8699;

    --radius:    10px;
    --radius-sm: 7px;
    --shadow:    0 1px 2px rgba(16, 22, 38, .06), 0 4px 12px rgba(16, 22, 38, .05);
    --shadow-lg: 0 12px 40px rgba(16, 22, 38, .18);

    --sidebar-w: 236px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
    --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

/* Thème sombre : appliqué au choix explicite, ou par défaut système si aucun choix.
   Seuls les tokens sont redéfinis — aucune règle de composant n'est dupliquée. */
:root[data-theme="dark"],
:root:not([data-theme="light"]) {
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg:            #10141c;
        --surface:       #171d27;
        --surface-2:     #1d2431;
        --surface-3:     #242c3b;
        --border:        #2c3545;
        --border-strong: #3d4859;

        --text:          #e7eaf0;
        --text-muted:    #a0aabd;
        --text-faint:    #6f7b91;

        --brand:         #8b7ef0;
        --brand-hover:   #9d92f4;
        --brand-soft:    #232043;
        --brand-text:    #b3a8f7;

        --ok:      #3ecf8e;  --ok-soft:     #14301f;
        --warn:    #e0a340;  --warn-soft:   #33260f;
        --danger:  #f0665e;  --danger-soft: #341715;
        --info:    #4da3f0;  --info-soft:   #10263a;

        --c1: #8b7ef0;  --c2: #3ecf8e;  --c3: #e0a340;  --c4: #f0665e;
        --c5: #4da3f0;  --c6: #c07fe0;  --c7: #35c2b1;  --c8: #8b97ad;

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

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg:            #10141c;
    --surface:       #171d27;
    --surface-2:     #1d2431;
    --surface-3:     #242c3b;
    --border:        #2c3545;
    --border-strong: #3d4859;

    --text:          #e7eaf0;
    --text-muted:    #a0aabd;
    --text-faint:    #6f7b91;

    --brand:         #8b7ef0;
    --brand-hover:   #9d92f4;
    --brand-soft:    #232043;
    --brand-text:    #b3a8f7;

    --ok:      #3ecf8e;  --ok-soft:     #14301f;
    --warn:    #e0a340;  --warn-soft:   #33260f;
    --danger:  #f0665e;  --danger-soft: #341715;
    --info:    #4da3f0;  --info-soft:   #10263a;

    --c1: #8b7ef0;  --c2: #3ecf8e;  --c3: #e0a340;  --c4: #f0665e;
    --c5: #4da3f0;  --c6: #c07fe0;  --c7: #35c2b1;  --c8: #8b97ad;

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

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

/* ---------------------------------------------------------------- Auth screens */

.auth {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 36px;
    width: 100%;
    max-width: 400px;
}

.auth-box h1 { font-size: 24px; margin-bottom: 6px; }
.auth-box .sub { color: var(--text-muted); margin-bottom: 24px; }
.auth-box .field { margin-bottom: 14px; }
.auth-box label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.auth-logo { font-size: 34px; line-height: 1; margin-bottom: 10px; }

/* ---------------------------------------------------------------- App shell */

.app { display: none; min-height: 100vh; }
.app.active { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 16px 18px;
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo { font-size: 20px; }

.nav { padding: 10px 8px; flex: 1; }
.nav-group-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 14px 10px 5px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    background: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font: inherit;
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-item .ico { width: 17px; text-align: center; flex-shrink: 0; }
.nav-item .badge-count {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 9px;
}

.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); display: grid; gap: 6px; }

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

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar h1 { font-size: 17px; font-weight: 650; }
.topbar .spacer { flex: 1; }

.search-trigger {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-faint);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    min-width: 210px;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger kbd { margin-left: auto; }

kbd {
    font-family: var(--mono);
    font-size: 10.5px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--text-muted);
}

.view { padding: 22px; flex: 1; }
.view-head { margin-bottom: 16px; }
.view-head h2 { font-size: 19px; margin-bottom: 3px; }
.view-head p { color: var(--text-muted); font-size: 13px; }

/* ---------------------------------------------------------------- Cards / grid */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.card-head h3 { font-size: 14.5px; font-weight: 650; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

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

/* ---------------------------------------------------------------- KPI */

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 13px 15px;
}
.kpi.ok     { border-left-color: var(--ok); }
.kpi.warn   { border-left-color: var(--warn); }
.kpi.danger { border-left-color: var(--danger); }
.kpi.info   { border-left-color: var(--info); }
.kpi .label {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: 5px;
}
.kpi .value { font-size: 23px; font-weight: 700; line-height: 1.15; }
.kpi .sub { font-size: 12px; color: var(--text-faint); margin-top: 3px; }

/* ---------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn    { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.ghost   { border-color: transparent; background: none; color: var(--text-muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn.block { width: 100%; justify-content: center; }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------------------------------------------------------- Inputs */

input[type=text], input[type=password], input[type=number], input[type=search],
input[type=date], select, textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--brand);
    outline-offset: -1px;
    border-color: var(--brand);
}
textarea { min-height: 92px; resize: vertical; }
label.inline { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
label.inline input { width: auto; }

.field-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field-row > * { flex: 1; min-width: 130px; }
.field-row > .fixed { flex: 0 0 auto; min-width: 0; }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ---------------------------------------------------------------- Segmented */

.segmented {
    display: inline-flex;
    background: var(--surface-3);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}
.segmented button {
    border: 0;
    background: none;
    padding: 4px 11px;
    border-radius: 6px;
    font: inherit;
    font-size: 12.5px;
    color: var(--text-muted);
    cursor: pointer;
}
.segmented button.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- Tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

.table-toolbar {
    display: flex;
    gap: 9px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.table-toolbar .grow { flex: 1; min-width: 160px; }
.table-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12.5px;
}
.table-foot .spacer { flex: 1; }

/* ---------------------------------------------------------------- Badges */

.badge {
    display: inline-block;
    padding: 1.5px 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.badge.ok     { background: var(--ok-soft);     color: var(--ok); }
.badge.warn   { background: var(--warn-soft);   color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info   { background: var(--info-soft);   color: var(--info); }
.badge.brand  { background: var(--brand-soft);  color: var(--brand-text); }
.badge.muted  { background: var(--surface-3);   color: var(--text-muted); }

/* ---------------------------------------------------------------- States */

.empty, .loading-state {
    padding: 34px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty .icon { font-size: 30px; display: block; margin-bottom: 8px; opacity: .6; }

.error-state {
    padding: 16px;
    background: var(--danger-soft);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
}
.error-state .msg { margin-bottom: 10px; font-weight: 500; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
    border-radius: 5px;
    height: 13px;
    margin-bottom: 9px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------------------------------------------------------------- Charts */

.chart-box { position: relative; height: 290px; }
.chart-box.tall { height: 360px; }
.chart-box.short { height: 210px; }

/* ---------------------------------------------------------------- Modal */

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 22, .55);
    z-index: 100;
    padding: 24px;
    overflow-y: auto;
}
.modal-backdrop.open { display: flex; align-items: flex-start; justify-content: center; }
.modal {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 660px;
    margin: auto;
}
.modal.wide { max-width: 940px; }
.modal-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15.5px; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- Command palette */

.palette-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 22, .5);
    z-index: 200;
    padding-top: 12vh;
}
.palette-backdrop.open { display: flex; justify-content: center; align-items: flex-start; }
.palette {
    background: var(--surface);
    border-radius: 13px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    overflow: hidden;
}
.palette input {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 14px 16px;
    font-size: 15px;
}
.palette input:focus { outline: 0; }
.palette-results { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 13.5px;
}
.palette-item.sel { background: var(--brand-soft); color: var(--brand-text); }
.palette-item .grp { margin-left: auto; font-size: 11.5px; color: var(--text-faint); }

/* ---------------------------------------------------------------- Toast */

.toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--ok);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 11px 15px;
    font-size: 13.5px;
    max-width: 380px;
    animation: slide-in .18s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn  { border-left-color: var(--warn); }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------------------------------------------------------------- Misc */

.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.strike { text-decoration: line-through; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.pre {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 340px;
    overflow-y: auto;
}
.dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.dl dt { color: var(--text-muted); }
.dl dd { font-weight: 500; }

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 980px) {
    .app.active { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 50;
        width: var(--sidebar-w);
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: none; }
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
    .search-trigger { min-width: 0; }
    .search-trigger .txt, .search-trigger kbd { display: none; }
}
@media (min-width: 981px) { .menu-toggle { display: none; } }
@media (max-width: 620px) {
    .view { padding: 14px; }
    .grid.cols-4 { grid-template-columns: 1fr; }
    .topbar { padding: 10px 14px; }
}
