:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #dfe3eb;
  --text: #1b2230;
  --muted: #687386;
  --accent: #326ce5;
  --accent-soft: #e6eefc;
  --ok: #1f9d55;
  --warn: #c88a04;
  --error: #d64545;
  --ok-soft: #e3f5ea;
  --warn-soft: #fdf3dc;
  --error-soft: #fbe7e7;
  --track: #e7eaf0;
  --sidebar: #141a26;
  --sidebar-text: #c6cede;
  --sidebar-muted: #7d889d;
  --sidebar-active: #222c40;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131c;
    --surface: #161d2a;
    --surface-2: #1c2433;
    --border: #283244;
    --text: #e3e8f1;
    --muted: #8b96aa;
    --accent: #5b8def;
    --accent-soft: #1d2b47;
    --ok: #3cc47c;
    --warn: #e5ac2c;
    --error: #ef6b6b;
    --ok-soft: #15301f;
    --warn-soft: #33290f;
    --error-soft: #3a1b1d;
    --track: #252f40;
    --sidebar: #0a0e15;
    --sidebar-active: #1a2234;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- Boutons & formulaires ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-error { color: var(--error); margin: 0; }
.form-ok { color: var(--ok); margin: 0; }
.switch { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }

/* ---------- Connexion ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-card p { margin: -8px 0 6px; }

/* ---------- Structure ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-lg { font-size: 20px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: #326ce5; color: #fff; font-size: 18px;
}
.shell { display: flex; min-height: 100%; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { color: #fff; padding: 0 8px; }
.cluster-pill {
  display: flex; align-items: center; gap: 8px; margin: 0 4px; padding: 6px 10px;
  background: var(--sidebar-active); border-radius: 8px; font-size: 12px; font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted);
  padding: 14px 10px 6px;
}
.menu a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none; cursor: pointer;
}
.menu a:hover { background: var(--sidebar-active); }
.menu a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #5b8def; }
.menu a.disabled { opacity: .5; cursor: default; }
.menu a.disabled:hover { background: transparent; }
.menu .ico { width: 18px; text-align: center; font-family: var(--mono); font-size: 13px; }
.soon {
  margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 6px;
  background: var(--sidebar-active); color: var(--sidebar-muted);
}
.sidebar-foot { margin-top: auto; font-size: 11px; padding: 0 8px; color: var(--sidebar-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.user-chip {
  padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px;
}
.menu-toggle { display: none; font-size: 18px; }
.banner { padding: 10px 24px; font-size: 13px; }
.banner-warn { background: var(--warn-soft); color: var(--text); border-bottom: 1px solid var(--border); }
.page { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 14px; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.count { color: var(--muted); font-weight: 400; font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.narrow { max-width: 460px; }
.card h2 { margin-bottom: 4px; }

/* ---------- Indicateurs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 24px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-sub b.bad { color: var(--error); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-error { background: var(--error); }

/* ---------- Nœuds ---------- */
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.node { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s; }
.node:hover, .node.selected { border-color: var(--accent); }
.node-head { display: flex; align-items: flex-start; gap: 10px; }
.node-name { font-family: var(--mono); font-size: 12.5px; font-weight: 600; word-break: break-all; }
.node-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.tag {
  font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2);
  color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: auto; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-error { background: var(--error-soft); color: var(--error); }

.meter { display: grid; grid-template-columns: 70px 1fr; gap: 3px 10px; align-items: center; }
.meter-label { font-size: 12px; color: var(--muted); }
.meter-bar { position: relative; height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--ok); }
.meter-fill.lvl-warn { background: var(--warn); }
.meter-fill.lvl-error { background: var(--error); }
.meter-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .55; }
.meter-text { grid-column: 2; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; gap: 8px; }
.meter-text b { color: var(--text); font-weight: 600; }

.node-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; font-size: 12px; }
.node-facts div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dashed var(--border); padding: 2px 0; }
.node-facts span:first-child { color: var(--muted); }
.node-facts span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conds { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- Pools ---------- */
.pools { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.pool .nodes { grid-template-columns: 1fr; gap: 12px; }
.pool { display: flex; flex-direction: column; gap: 14px; background: var(--surface-2); padding: 14px; }
.pool .node { background: var(--surface); }
.pool-head { display: flex; flex-direction: column; gap: 12px; cursor: pointer; border-radius: 8px; padding: 2px; }
.pool-head.selected .pool-title h3 { color: var(--accent); }
.pool-head:hover .pool-title h3 { text-decoration: underline; }
.pool-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pool-title h3 { margin: 0 4px 0 0; font-size: 15px; font-family: var(--mono); }
.pool-title .badge { margin-left: 0; }
.pool-meters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.pool-meters .meter { grid-template-columns: 58px 1fr; }

/* ---------- Tableau des pods ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.filters input { width: 230px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; background: var(--surface-2);
}
.table th.sorted::after { content: " ▾"; }
.table th.sorted.asc::after { content: " ▴"; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.pod-name { font-family: var(--mono); font-size: 12px; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.table td.node-cell { font-family: var(--mono); font-size: 11.5px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; }
.restarts-hot { color: var(--error); font-weight: 600; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---------- Ressources par pod ---------- */
.res { min-width: 150px; }
.res-top { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.res-flag { font-size: 10.5px; font-weight: 600; padding: 0 6px; border-radius: 6px; white-space: nowrap; }
.res-flag-warn { background: var(--warn-soft); color: var(--warn); }
.res-flag-error { background: var(--error-soft); color: var(--error); }
.res-bar { position: relative; height: 5px; background: var(--track); border-radius: 3px; margin: 4px 0 3px; }
.res-fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--ok); }
.res-fill.lvl-warn { background: var(--warn); }
.res-fill.lvl-error { background: var(--error); }
.res-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .6; }
.res-sub { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.table tr.row-warn td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.table tr.row-error td:first-child { box-shadow: inset 3px 0 0 var(--error); }
.table tr.row-warn { background: color-mix(in srgb, var(--warn-soft) 45%, transparent); }
.table tr.row-error { background: color-mix(in srgb, var(--error-soft) 55%, transparent); }
.table th .muted { font-weight: 400; font-size: 10.5px; }
.res-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.chip { font: inherit; font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 4px 12px; cursor: pointer; border: 1px solid transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.chip-error { background: var(--error-soft); color: var(--error); border-color: color-mix(in srgb, var(--error) 35%, transparent); }
.chip:hover { filter: brightness(.97); }

/* ---------- Événements ---------- */
.events { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.event { display: grid; grid-template-columns: 90px 160px 1fr; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.event:last-child { border-bottom: 0; }
.event-reason { font-weight: 600; color: var(--warn); }
.event-obj { font-family: var(--mono); font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.event-msg { overflow-wrap: anywhere; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-toggle { display: inline-block; }
  .topbar { padding: 10px 16px; gap: 6px; }
  .topbar h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right { flex-wrap: nowrap; gap: 2px; }
  .topbar .btn { padding: 6px 8px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 20px; }
  .topbar-right .small, #auto-refresh-wrap { display: none; }
  .page { padding: 16px; }
  .banner { padding: 10px 16px; }
  .nodes { grid-template-columns: 1fr; }
  .pools { grid-template-columns: 1fr; }
  .pool-meters { grid-template-columns: 1fr; }
  .filters { margin-left: 0; width: 100%; }
  .filters input, .filters select { flex: 1 1 140px; width: auto; }
  .event { grid-template-columns: 1fr; gap: 2px; }
  .node-facts { grid-template-columns: 1fr; }
}
