/* ============================================================================
   RADPILOT — design system (CSS custom, sans dépendance ni pipeline JS).
   Tokens (variables) + composants : cartes, badges d'état, boutons, tables,
   formulaires, navigation, onglets, dashboard. Thème clair forcé.
   ============================================================================ */

:root {
    color-scheme: light;

    /* Couleurs de base */
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #10202f;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Marque / accents */
    --topbar: #0f1b2d;
    --topbar-text: #e6edf5;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #e8f0fe;

    /* États de santé */
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --neutral: #475569;
    --neutral-bg: #eef2f6;

    /* Formes */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .10);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .10), 0 2px 4px rgba(15, 23, 42, .06);
    --ring: 0 0 0 3px rgba(37, 99, 235, .25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Typographie ---------- */
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; font-weight: 620; margin: 0 0 .75rem; }
h3 { font-size: 1.02rem; font-weight: 600; margin: 1.25rem 0 .5rem; }
h1:focus, h2:focus, h3:focus { outline: none; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
small, .muted { color: var(--muted); }
code, pre { font-family: "Cascadia Mono", ui-monospace, Consolas, monospace; font-size: .86em; }

/* ---------- Layout général ---------- */
main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.page-head .subtitle { color: var(--muted); margin: 0; }

/* ---------- Barre de navigation ---------- */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 1rem 1.5rem;
    padding: 0 1.5rem;
    min-height: 58px;
    flex-wrap: wrap;
    background: var(--topbar);
    color: var(--topbar-text);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-weight: 700;
    letter-spacing: .14em;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: .55rem;
}
.nav-brand::before {
    content: "";
    width: 11px; height: 11px;
    border-radius: 50%;
    background: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .25);
}
.nav-menu nav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
.nav-menu nav a {
    color: #b9c6d6;
    padding: .45rem .8rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background .12s, color .12s;
}
.nav-menu nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-menu nav a.active { background: rgba(56, 189, 248, .16); color: #fff; }
.nav-user { color: #cdd8e6; font-weight: 500; }
.nav-menu > a { color: #b9c6d6; }
.nav-menu > a:hover { color: #fff; }

/* ---------- Cartes ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.35rem;
    margin-bottom: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* ---------- Dashboard : grille de cartes d'état ---------- */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.1rem;
}
.status-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 5px solid var(--neutral);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.05rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: .7rem;
    transition: box-shadow .15s, transform .15s;
}
.status-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.status-card.ok { border-left-color: var(--ok); }
.status-card.warn { border-left-color: var(--warn); }
.status-card.danger { border-left-color: var(--danger); }
.status-card.neutral { border-left-color: var(--neutral); }

.status-card .sc-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.status-card .sc-name { font-weight: 640; font-size: 1.05rem; }
.status-card .sc-meta { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }
.status-card .sc-meta .row { display: flex; justify-content: space-between; gap: 1rem; }
.status-card .sc-meta .row span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }
.status-card .sc-foot { display: flex; gap: .4rem; margin-top: .2rem; flex-wrap: wrap; }

/* ---------- Badges d'état ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .2rem .6rem;
    border-radius: var(--radius-pill);
    font-size: .78rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Boutons ---------- */
button, .btn {
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    padding: .42rem .8rem;
    border-radius: var(--radius-sm);
    transition: background .12s, border-color .12s, box-shadow .12s;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: .55; cursor: not-allowed; }
button + button, .btn + .btn { margin-left: .35rem; }

button.primary, .btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
button.primary:hover, .btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger, .btn-danger { color: var(--danger); border-color: #f2c2c2; background: #fff; }
button.danger:hover, .btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
button[type="submit"] { background: var(--primary); border-color: var(--primary); color: #fff; }
button[type="submit"]:hover { background: var(--primary-hover); }

/* ---------- Formulaires ---------- */
form > div, .form-row { margin-bottom: .9rem; }
label {
    display: block;
    font-weight: 550;
    font-size: .88rem;
    margin-bottom: .3rem;
    color: #334155;
}
input, select, textarea {
    font: inherit;
    width: 100%;
    max-width: 460px;
    padding: .48rem .6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
textarea { resize: vertical; min-height: 4.5rem; font-family: "Cascadia Mono", ui-monospace, Consolas, monospace; }
select { max-width: 460px; }
.valid.modified:not([type=checkbox]) { border-color: var(--ok); }
.invalid { border-color: var(--danger) !important; }
.validation-message { color: var(--danger); font-size: .82rem; }
details > summary { cursor: pointer; color: var(--primary); font-size: .88rem; margin-bottom: .5rem; }

/* ---------- Tables ---------- */
table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    margin: .5rem 0 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
th, td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
    background: var(--surface-2);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .btn, td button { padding: .28rem .55rem; font-size: .82rem; }

/* ---------- Onglets (Administration) ---------- */
.admin-tabs {
    display: flex;
    gap: .3rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}
.admin-tab {
    background: none;
    border: none;
    border-bottom: 2.5px solid transparent;
    border-radius: 0;
    padding: .6rem .9rem;
    color: var(--muted);
    font-weight: 550;
    margin-bottom: -1px;
}
.admin-tab:hover { background: none; color: var(--text); border-color: var(--border-strong); }
.admin-tab.active { color: var(--primary); border-color: var(--primary); font-weight: 650; }

.admin-content { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- Messages ---------- */
.error { color: var(--danger); }
.success { color: var(--ok); }
.alert {
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    margin: .75rem 0;
    font-size: .9rem;
    border: 1px solid transparent;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #f3c9c9; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #bbf0cb; }
.alert-info { background: var(--primary-soft); color: var(--primary-hover); border-color: #cfe0fd; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}
.empty-state strong { color: var(--text); display: block; margin-bottom: .35rem; font-size: 1.05rem; }

/* ---------- Authentification (login / install) ---------- */
.auth-layout { display: flex; justify-content: center; align-items: flex-start; min-height: 100vh; padding: 6vh 1rem; background: linear-gradient(160deg, #0f1b2d 0%, #1e3a5f 100%); }
.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem 1.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.auth-card h2 { text-align: center; letter-spacing: .16em; margin-bottom: 1.25rem; }
.auth-card button[type="submit"] { width: 100%; margin-top: .5rem; padding: .55rem; }

/* ---------- Pages opérationnelles (ADR-0018) ---------- */
.target-picker {
    display: flex; flex-direction: column; gap: .4rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1rem 1.15rem; margin-bottom: 1.25rem; max-width: 560px;
}
.target-picker label { margin-bottom: 0; }
tbody tr.row-clickable { cursor: pointer; }
tbody tr.row-clickable:hover { background: var(--primary-soft); }
tbody tr.row-selected { background: var(--primary-soft); }
.detail-grid { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: .3rem 1rem; font-size: .9rem; }
.detail-grid dt { color: var(--muted); font-weight: 600; }
.detail-grid dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.toolbar { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .35rem; }
.toolbar > div { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 200px; }
.count-note { color: var(--muted); font-size: .82rem; margin: .3rem 0 1rem; }
.placeholder-note { max-width: 640px; }

/* Jauges d'état de santé (CPU / mémoire / disque) */
.metric-row { display: grid; grid-template-columns: 120px 1fr minmax(150px, auto); gap: .75rem; align-items: center; margin: .5rem 0; }
.metric-row .m-label { color: var(--muted); font-weight: 600; font-size: .85rem; word-break: break-word; }
.metric-row .m-val { font-variant-numeric: tabular-nums; font-size: .84rem; white-space: nowrap; text-align: right; }
.meter { height: .55rem; border-radius: var(--radius-pill); background: var(--neutral-bg); overflow: hidden; }
.meter-fill { height: 100%; border-radius: var(--radius-pill); background: var(--ok); transition: width .3s ease; }
.meter-fill.warn { background: var(--warn); }
.meter-fill.danger { background: var(--danger); }
.health-panel .health-foot { color: var(--muted); font-size: .82rem; margin: .75rem 0 0; }

/* ---------- Divers ---------- */
.config-tree { font-family: "Cascadia Mono", ui-monospace, Consolas, monospace; font-size: .85rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---------- Blazor error UI / boundary (conservé) ---------- */
#blazor-error-ui {
    display: none;
    background: #b91c1c;
    color: white;
    padding: .75rem 1rem;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 1000;
}
.blazor-error-boundary { background: #b91c1c; padding: 1rem; color: white; border-radius: var(--radius-sm); }
.blazor-error-boundary::after { content: "Une erreur est survenue."; }
