/* TeNosKi Dashboard - palette et regles de couleur suivent la methode du
   skill dataviz (references/palette.md) : ramps validees, jamais de
   couleur choisie a l'oeil. Statut (online/offline) utilise la palette de
   statut fixe (jamais reutilisee pour autre chose), toujours icone + texte,
   jamais la couleur seule.

   Mode sombre : "les deux" (suit prefers-color-scheme par defaut, avec un
   bouton qui pose data-theme="light|dark" sur <html> pour forcer un choix
   qui gagne dans les deux sens). Meme structure a trois blocs que
   palette.md : :root (clair, valeurs par defaut) -> @media prefers-color-scheme
   (sombre auto, sauf si data-theme="light" force le clair) -> :root[data-theme="dark"]
   (sombre force, gagne toujours). */

:root {
    color-scheme: light;
    --page-plane: #f9f9f7;
    --surface: #ffffff;
    --surface-hover: #f4f3f1;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --border: #e1e0d9;
    --border-strong: rgba(11, 11, 11, 0.10);

    --accent: #2a78d6;
    --accent-hover: #184f95;
    --accent-soft: #cde2fb;
    --accent-soft-text: #104281;
    --accent-focus-ring: rgba(42, 120, 214, 0.25);

    --good: #0ca30c;
    --good-soft: #e3f6e3;
    --good-text: #0a5c0a;
    --good-halo: rgba(12, 163, 12, 0.16);

    --critical: #d03b3b;
    --critical-soft: #fbe8e8;
    --critical-text: #8f2222;
    --critical-halo: rgba(208, 59, 59, 0.16);

    --warning: #fab219;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 1px rgba(11, 11, 11, 0.03);
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --page-plane: #0d0d0d;
        --surface: #1a1a19;
        --surface-hover: #232322;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --border: #2c2c2a;
        --border-strong: rgba(255, 255, 255, 0.10);

        --accent: #3987e5;
        --accent-hover: #5598e7;
        --accent-soft: rgba(57, 135, 229, 0.18);
        --accent-soft-text: #86b6ef;
        --accent-focus-ring: rgba(57, 135, 229, 0.35);

        --good: #0ca30c;
        --good-soft: rgba(12, 163, 12, 0.16);
        --good-text: #8fe08f;
        --good-halo: rgba(12, 163, 12, 0.25);

        --critical: #e66767;
        --critical-soft: rgba(208, 59, 59, 0.18);
        --critical-text: #f3a8a8;
        --critical-halo: rgba(208, 59, 59, 0.28);

        --warning: #fab219;

        --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page-plane: #0d0d0d;
    --surface: #1a1a19;
    --surface-hover: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: #2c2c2a;
    --border-strong: rgba(255, 255, 255, 0.10);

    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --accent-soft-text: #86b6ef;
    --accent-focus-ring: rgba(57, 135, 229, 0.35);

    --good: #0ca30c;
    --good-soft: rgba(12, 163, 12, 0.16);
    --good-text: #8fe08f;
    --good-halo: rgba(12, 163, 12, 0.25);

    --critical: #e66767;
    --critical-soft: rgba(208, 59, 59, 0.18);
    --critical-text: #f3a8a8;
    --critical-halo: rgba(208, 59, 59, 0.28);

    --warning: #fab219;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--page-plane);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    transition: background 0.15s ease, color 0.15s ease;
}

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-lg { width: 32px; height: 32px; }

/* ---------------------------------------------------------------------- */
/* Bouton de theme clair/sombre                                           */
/* ---------------------------------------------------------------------- */

.theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
}

.theme-toggle:hover { background: var(--surface-hover); color: var(--text-primary); }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline-flex; }

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .theme-toggle .icon-sun { display: inline-flex; }
    :root:where(:not([data-theme="light"])) .theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline-flex; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline-flex; }

/* ---------------------------------------------------------------------- */
/* Structure                                                               */
/* ---------------------------------------------------------------------- */

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

.app-shell.no-sidebar {
    display: block;
}

.sidebar {
    width: 236px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 22px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.brand-mark-lg { width: 48px; height: 48px; font-size: 22px; border-radius: var(--radius-md); }

.brand-name { font-weight: 700; font-size: 15px; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

.nav-link:hover { background: var(--surface-hover); color: var(--text-primary); }

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent-soft-text);
}

.nav-link.active .icon { color: var(--accent); }

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--border);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.user-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    flex-shrink: 0;
}

.icon-btn:hover { background: var(--surface-hover); color: var(--critical); }

.main-content {
    flex: 1;
    min-width: 0;
    padding: 36px 40px 60px;
    max-width: 1080px;
}

.container-plain {
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ---------------------------------------------------------------------- */
/* Page header                                                             */
/* ---------------------------------------------------------------------- */

.page-header { margin-bottom: 28px; }
.page-header h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { margin: 0; color: var(--text-secondary); font-size: 14px; max-width: 640px; }

h2 { font-size: 15px; font-weight: 600; margin: 0; }

/* ---------------------------------------------------------------------- */
/* Auth screens (login / access denied)                                    */
/* ---------------------------------------------------------------------- */

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

.auth-card {
    max-width: 420px;
    width: 100%;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    padding: 40px 32px;
    border-radius: var(--radius-lg);
}

.auth-brand { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-brand-error { color: var(--critical); }

.auth-card h1 { font-size: 19px; margin: 0 0 10px; }
.auth-text { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin: 0 0 22px; }
.error-text { color: var(--critical); }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-large { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------------- */
/* Stat tiles                                                              */
/* ---------------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-md);
    padding: 18px 20px;
}

.stat-label {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

.stat-value { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.stat-value-md { font-size: 22px; }

.stat-status-row { display: flex; align-items: center; gap: 8px; }

.stat-meta { color: var(--text-muted); font-size: 13px; margin-top: 6px; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-dot-good { background: var(--good); box-shadow: 0 0 0 3px var(--good-halo); }
.status-dot-critical { background: var(--critical); box-shadow: 0 0 0 3px var(--critical-halo); }

/* ---------------------------------------------------------------------- */
/* Cards / tables                                                          */
/* ---------------------------------------------------------------------- */

.cards-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-md);
    padding: 20px;
    flex: 1;
    min-width: 320px;
}

.table-card h2 { margin-bottom: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
td.rank { color: var(--text-muted); font-variant-numeric: tabular-nums; width: 24px; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }

.empty-text { color: var(--text-muted); font-size: 13.5px; }

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */

.settings-form { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-md);
    padding: 20px 22px;
}

.form-card-header { margin-bottom: 16px; }
.form-card-desc { margin: 4px 0 0; color: var(--text-secondary); font-size: 13px; }

.field { margin-top: 16px; }
.field:first-of-type { margin-top: 0; }

.field label {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    margin-bottom: 3px;
}

.field-desc { color: var(--text-muted); font-size: 12.5px; margin: 0 0 8px; }

.input-select,
.input-text {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}

.input-select:focus,
.input-text:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-focus-ring);
}

textarea.input-text { min-height: 76px; resize: vertical; }

/* ---------------------------------------------------------------------- */
/* Toggle switch (habille un <input type="checkbox"> standard)             */
/* ---------------------------------------------------------------------- */

.toggle-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    cursor: pointer;
}

.toggle-title { display: block; font-size: 13.5px; font-weight: 600; }

.toggle { position: relative; flex-shrink: 0; margin-top: 2px; }

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 40px;
    height: 22px;
    margin: 0;
    cursor: pointer;
}

.toggle-track {
    display: block;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: var(--border);
    transition: background 0.15s ease;
}

.toggle-thumb {
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(11, 11, 11, 0.25);
    transition: transform 0.15s ease;
}

.toggle-input:checked ~ .toggle-track { background: var(--accent); }
.toggle-input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }
.toggle-input:focus-visible ~ .toggle-track { box-shadow: 0 0 0 3px var(--accent-focus-ring); }

/* ---------------------------------------------------------------------- */
/* Banners                                                                 */
/* ---------------------------------------------------------------------- */

.banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 13.5px;
    font-weight: 500;
    max-width: 640px;
}

.banner-success { background: var(--good-soft); color: var(--good-text); }
.banner-success .icon { color: var(--good); }
.banner-error { background: var(--critical-soft); color: var(--critical-text); }
.banner-error .icon { color: var(--critical); }

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

@media (max-width: 800px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        padding: 10px 14px;
        gap: 16px;
    }
    .sidebar-brand { padding: 0; }
    .sidebar-nav { flex-direction: row; flex: 1; overflow-x: auto; }
    .nav-link span { display: none; }
    .sidebar-footer { border-top: none; padding: 0; }
    .user-name { display: none; }
    .main-content { padding: 24px 18px 40px; }
    .theme-toggle { top: 10px; right: 10px; }
}
