:root {
    color-scheme: light;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-text-subtle: #94a3b8;
    --color-track: #f1f5f9;

    --color-accent: #4f46e5;
    --color-accent-hover: #4338ca;
    --color-accent-contrast: #ffffff;

    --color-danger: #dc2626;
    --color-danger-hover: #991b1b;

    --color-success-bg: #ecfdf5;
    --color-success-text: #047857;
    --color-success-border: #a7f3d0;

    --color-error-bg: #fef2f2;
    --color-error-text: #b91c1c;
    --color-error-border: #fecaca;

    --status-2xx: #059669;
    --status-3xx: #0284c7;
    --status-4xx: #d97706;
    --status-5xx: #dc2626;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --color-bg: #0f172a;
        --color-surface: #1e293b;
        --color-border: #334155;
        --color-text: #f1f5f9;
        --color-text-muted: #94a3b8;
        --color-text-subtle: #64748b;
        --color-track: #334155;

        --color-success-bg: rgba(16, 185, 129, .12);
        --color-success-text: #34d399;
        --color-success-border: rgba(52, 211, 153, .35);

        --color-error-bg: rgba(239, 68, 68, .12);
        --color-error-text: #f87171;
        --color-error-border: rgba(248, 113, 113, .35);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-text-subtle: #64748b;
    --color-track: #334155;

    --color-success-bg: rgba(16, 185, 129, .12);
    --color-success-text: #34d399;
    --color-success-border: rgba(52, 211, 153, .35);

    --color-error-bg: rgba(239, 68, 68, .12);
    --color-error-text: #f87171;
    --color-error-border: rgba(248, 113, 113, .35);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    transition: background-color .15s ease, color .15s ease;
}

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

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1rem;
}

nav.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

nav.topbar .container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding-top: .75rem;
    padding-bottom: .75rem;
}

nav.topbar .brand {
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
}

nav.topbar .links {
    display: flex;
    gap: 1rem;
    align-items: center;
}

nav.topbar .links a {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: .9rem;
}

nav.topbar .links a:hover { color: var(--color-text); }

nav.topbar form { margin: 0; }

nav.topbar button.link {
    background: none;
    border: none;
    color: var(--color-danger);
    cursor: pointer;
    font-size: .9rem;
    padding: 0;
}

main { padding: 2rem 0 4rem; }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1.25rem;
}

.card + .card { margin-top: 1.25rem; }

.grid {
    display: grid;
    gap: 1.25rem;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
}

.kpi .value { font-size: 1.6rem; font-weight: 700; }
.kpi .label { font-size: .8rem; color: var(--color-text-muted); margin-top: .15rem; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.toolbar .group { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

select, input[type=password] {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: .4rem .6rem;
    font-size: .9rem;
}

.tabs { display: flex; gap: .3rem; }

.tabs a {
    text-decoration: none;
    font-size: .85rem;
    padding: .35rem .7rem;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

.tabs a.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-accent-contrast);
}

button.btn, a.btn {
    display: inline-block;
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    border: none;
    border-radius: 6px;
    padding: .55rem 1rem;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
}

button.btn:hover, a.btn:hover { background: var(--color-accent-hover); }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

th, td {
    text-align: left;
    padding: .5rem .6rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

th { color: var(--color-text-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; }

.table-scroll { overflow-x: auto; }

.badge {
    display: inline-block;
    padding: .1rem .45rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.badge.ok { background: var(--color-success-bg); color: var(--color-success-text); }
.badge.redirect { background: rgba(2,132,199,.12); color: var(--status-3xx); }
.badge.client-error { background: rgba(217,119,6,.14); color: var(--status-4xx); }
.badge.server-error { background: var(--color-error-bg); color: var(--color-error-text); }
.badge.unknown { background: var(--color-track); color: var(--color-text-muted); }

.badge.bot { background: var(--color-track); color: var(--color-text-subtle); }

/* Graphiques en barres CSS (pas de JS/SVG externe) */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 120px;
}

.bar-chart .bar {
    flex: 1;
    background: var(--color-accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    position: relative;
}

.bar-chart.trend .bar { background: var(--color-accent); opacity: .85; }

.bar-chart .bar:hover { opacity: 1; }

.bar-labels {
    display: flex;
    gap: 3px;
    margin-top: .4rem;
    font-size: .65rem;
    color: var(--color-text-subtle);
}

.bar-labels span { flex: 1; text-align: center; overflow: hidden; }

.empty { color: var(--color-text-subtle); font-size: .85rem; padding: .5rem 0; }

.flash-error {
    margin-bottom: 1rem;
    font-size: .9rem;
    background: var(--color-error-bg);
    color: var(--color-error-text);
    border: 1px solid var(--color-error-border);
    border-radius: 6px;
    padding: .6rem .8rem;
}

.login-wrap {
    max-width: 380px;
    margin: 4rem auto 0;
}

.login-wrap p.subtitle {
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-wrap label {
    display: block;
    font-size: .85rem;
    margin-bottom: .3rem;
}

.login-wrap input[type=password] { width: 100%; margin-bottom: 1rem; }

.login-wrap button { width: 100%; }

.live-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .78rem;
}

.theme-toggle {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.muted { color: var(--color-text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
