/* Supervision de parc — feuille de style (thèmes clair/sombre, responsive) */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --critical: #dc2626;
  --critical-soft: #fee2e2;
  --offline: #475569;
  --offline-soft: #e2e8f0;
  --info: #0891b2;
  --info-soft: #cffafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --radius: 10px;
  --sidebar-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #182236;
  --border: #26324a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-soft: #1e3a5f;
  --ok: #4ade80;
  --ok-soft: #14532d;
  --warning: #fbbf24;
  --warning-soft: #4a3510;
  --critical: #f87171;
  --critical-soft: #4c1d1d;
  --offline: #94a3b8;
  --offline-soft: #273246;
  --info: #22d3ee;
  --info-soft: #134e5a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* --- Structure ------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  height: 56px; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 16px;
}
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-muted); font-size: .9rem; }

.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; padding: 1rem .75rem;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar a {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; margin-bottom: 2px;
  border-radius: 8px; color: var(--text); font-weight: 500;
}
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar .icon { width: 1.2rem; text-align: center; }
.sidebar .footer { margin-top: 2rem; padding: 0 .75rem; font-size: .8rem; color: var(--text-muted); }

main { flex: 1; min-width: 0; padding: 1.5rem; max-width: 1400px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.btn.menu-toggle { display: none; }

@media (max-width: 860px) {
  .btn.menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  body.menu-open .sidebar { transform: none; }
  main { padding: 1rem; }
  .topbar .user { display: none; }
}

/* --- Composants ------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 1.25rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; box-shadow: var(--shadow); border-left: 4px solid var(--border);
}
.kpi .value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.kpi .label { color: var(--text-muted); font-size: .9rem; }
.kpi.ok { border-left-color: var(--ok); }
.kpi.warning { border-left-color: var(--warning); }
.kpi.critical { border-left-color: var(--critical); }
.kpi.offline { border-left-color: var(--offline); }
.kpi.primary { border-left-color: var(--primary); }

.site-card { display: block; color: var(--text); border-top: 4px solid var(--border); }
.site-card:hover { text-decoration: none; border-color: var(--primary); }
.site-card.ok { border-top-color: var(--ok); }
.site-card.warning { border-top-color: var(--warning); }
.site-card.critical { border-top-color: var(--critical); }
.site-card.offline { border-top-color: var(--offline); }
.site-card .counts { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9rem; }

/* Pastilles et badges de statut */
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; background: var(--offline); flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.dot.offline { background: #1f2937; box-shadow: 0 0 0 2px var(--offline-soft); }
[data-theme="dark"] .dot.offline { background: #0b0f17; box-shadow: 0 0 0 2px var(--offline); }
.dot.disabled { background: transparent; border: 2px solid var(--offline); }

.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .1rem .55rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--offline-soft); color: var(--text); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.critical { background: var(--critical-soft); color: var(--critical); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.offline, .badge.disabled, .badge.muted { background: var(--offline-soft); color: var(--offline); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

.text-ok { color: var(--ok); }
.text-warning { color: var(--warning); }
.text-critical { color: var(--critical); }

/* Barres de pourcentage */
.bar { position: relative; height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; min-width: 60px; }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--ok); border-radius: 999px; }
.bar.warning > span { background: var(--warning); }
.bar.critical > span { background: var(--critical); }
.bar.muted > span { background: var(--offline); }
.meter { display: flex; align-items: center; gap: .5rem; }
.meter .bar { flex: 1; }
.meter .val { width: 3.2rem; text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th.sorted-asc::after { content: " ▲"; }
th.sorted-desc::after { content: " ▼"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 1.5rem; text-align: center; color: var(--text-muted); }
dl.props { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: .35rem 1rem; margin: 0; }
dl.props dt { color: var(--text-muted); }
dl.props dd { margin: 0; word-break: break-word; }

/* Onglets */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; scrollbar-width: thin; }
.tabs a {
  padding: .6rem .9rem; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { margin-left: .3rem; }

/* Formulaires et boutons */
label { display: block; font-weight: 500; margin-bottom: .3rem; font-size: .9rem; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 120px; font-family: var(--mono); font-size: .9rem; }
.field { margin-bottom: 1rem; }
.field .help { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; align-items: end; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.inline-form { display: inline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .btn.primary { color: #0b1120; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn.danger:hover { background: var(--critical-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); z-index: 1; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .85rem; cursor: pointer;
}
.chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* Messages */
.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.success { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.flash.error { background: var(--critical-soft); border-color: var(--critical); color: var(--text); }
.flash.warning { background: var(--warning-soft); border-color: var(--warning); color: var(--text); }
.flash.info { background: var(--info-soft); border-color: var(--info); color: var(--text); }
.secret-box {
  display: flex; gap: .5rem; align-items: center; padding: .75rem; border-radius: 8px;
  background: var(--surface-2); border: 1px dashed var(--primary); font-family: var(--mono); word-break: break-all;
}
.secret-box code { flex: 1; }
pre.cmd {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .75rem;
  overflow-x: auto; font-size: .82rem; white-space: pre-wrap; word-break: break-all;
}

/* Page de connexion */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; margin-bottom: 1.25rem; font-size: 1.2rem; }

/* Graphiques */
.chart-box { position: relative; height: 260px; }
.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem 1rem; }

.refresh-info { font-size: .8rem; color: var(--text-muted); }
.danger-zone { border-color: var(--critical); }
.danger-zone h2 { color: var(--critical); }
details summary { cursor: pointer; color: var(--primary); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: .45rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.list-plain li:last-child { border-bottom: 0; }
