:root {
  /* graphite gray, sobre — les couleurs ne servent qu'a porter du sens (etat, accent) */
  --bg-app: #101113;
  --bg-sidebar: #0b0c0e;
  --bg-surface: #17181b;
  --bg-surface-2: #1c1e22;
  --bg-surface-hover: #212327;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e9eaed;
  --text-dim: #9a9ea8;
  --text-faint: #6b6f78;

  --accent: #8b6ef2;
  --accent-2: #22d3ee;
  --accent-soft: rgba(139, 110, 242, 0.14);
  --accent-grad: linear-gradient(135deg, #8b6ef2 0%, #6d8df2 100%);

  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.14);
  --gray-soft: rgba(154, 158, 168, 0.14);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 20px -12px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 24px 60px -16px rgba(0, 0, 0, 0.65);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand { font-family: 'Outfit', 'Inter', sans-serif; }
h2 { font-size: 20px; font-weight: 700; margin: 0; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 14px; }
p { margin: 0; }
code, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ============ FORMS ============ */
label { display: block; font-size: 11.5px; color: var(--text-dim); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 8px; text-transform: none; font-size: 13px; color: var(--text); font-weight: 500; letter-spacing: 0; margin: 0; }
label.check input { width: auto; }
.check-row { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

input, select, textarea {
  width: 100%; background: var(--bg-surface-2); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--text-faint); }

button { font-family: inherit; }
button.primary, .btn {
  background: var(--bg-surface-2); border: 1px solid var(--border-strong); color: var(--text); font-weight: 600;
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--bg-surface-hover); }
button.primary { background: var(--accent-grad); border: none; color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }
button.primary.full, .btn.full { width: 100%; justify-content: center; }
.btn.danger { background: var(--red-soft); border-color: rgba(248,113,113,.35); color: var(--red); }
.btn.danger:hover { background: rgba(248,113,113,.22); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; fill: currentColor; flex: none; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-surface-2); color: var(--text-dim); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-surface-hover); color: var(--text); }

.error-msg { color: var(--red); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ============ LOGIN ============ */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 360px; padding: 34px 30px; border-radius: var(--radius-lg);
  background: var(--bg-surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  text-align: center;
}
.login-mark {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 12px; background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-dim); font-size: 12.5px; margin-bottom: 22px; }
.login-card form { text-align: left; }

/* ============ SHELL / SIDEBAR ============ */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; }
.sidebar-brand .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; flex: none;
}
.sidebar-brand .label { font-weight: 700; font-size: 14.5px; letter-spacing: .01em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px;
  background: none; border: none; color: var(--text-dim); font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-align: left; width: 100%; position: relative;
}
.nav-item svg { width: 17px; height: 17px; fill: currentColor; flex: none; opacity: .85; }
.nav-item:hover { background: var(--bg-surface); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #cbb9ff; }
.nav-item.active svg { fill: #cbb9ff; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 20px; padding: 1px 7px; min-width: 18px; text-align: center;
}

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px 12px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--bg-surface-2); border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: var(--accent-2);
  flex: none; text-transform: uppercase;
}
.user-meta { overflow: hidden; }
.user-email { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }

.main { padding: 26px 32px 60px; max-width: 1320px; }

/* ============ PAGE HEAD ============ */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; flex-wrap: wrap; }
.page-sub { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

.nodes-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.node-chip {
  display: flex; align-items: center; gap: 7px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px 6px 8px; font-size: 12px; color: var(--text-dim);
}
.node-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.node-chip b { color: var(--text); font-weight: 600; }

/* ============ KPI CARDS ============ */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi-card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-card);
}
.kpi-card .kpi-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 800; margin-top: 6px; font-family: 'Outfit', sans-serif; }
.kpi-card .kpi-value.accent-red { color: var(--red); }
.kpi-card .kpi-value.accent-amber { color: var(--amber); }
.kpi-card .kpi-value.accent-green { color: var(--green); }

/* ============ TOOLBAR ============ */
.toolbar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box {
  flex: 1; min-width: 220px; display: flex; align-items: center; gap: 8px;
  background: var(--bg-surface-2); border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 12px;
}
.search-box svg { width: 15px; height: 15px; fill: var(--text-faint); flex: none; }
.search-box input { border: none; background: none; padding: 9px 0; }
.search-box input:focus { box-shadow: none; }
.toolbar select { width: auto; min-width: 140px; }

/* ============ SERVER GROUPS / GRID ============ */
.group-block { margin-bottom: 28px; }
.group-title { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin-bottom: 12px; }
.group-title .count { background: var(--bg-surface-2); border-radius: 20px; padding: 1px 8px; font-size: 11px; color: var(--text-dim); }
.empty-note { color: var(--text-faint); font-size: 13px; padding: 18px 0; }

.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.server-card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); cursor: pointer; transition: border-color .12s ease, transform .12s ease;
  overflow: hidden;
}
.server-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.server-card .card-top { padding: 14px 16px 10px; }
.server-card .card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-dot.running { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.status-dot.starting, .status-dot.stopping { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.status-dot.unknown { background: var(--text-faint); box-shadow: 0 0 0 3px var(--gray-soft); }

.server-card .name { font-weight: 700; font-size: 14.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-icon { width: 15px; height: 15px; fill: var(--text-faint); flex: none; }
.server-card .node-line { font-size: 11.5px; color: var(--text-faint); margin: 2px 0 10px; }

.badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 3px 8px; border-radius: 20px; white-space: nowrap;
}
.badge.running { background: var(--green-soft); color: var(--green); }
.badge.offline { background: var(--red-soft); color: var(--red); }
.badge.starting, .badge.stopping { background: var(--amber-soft); color: var(--amber); }
.badge.unknown { background: var(--gray-soft); color: var(--text-dim); }
.badge.maintenance { background: var(--accent-soft); color: #cbb9ff; }

.stats-row { display: flex; gap: 0; margin: 0 16px 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.stats-row > div { flex: 1; font-size: 11px; color: var(--text-faint); text-align: center; }
.stats-row b { display: block; color: var(--text); font-size: 13px; font-weight: 700; margin-top: 2px; }

.card-actions { display: flex; gap: 6px; padding: 0 16px 14px; flex-wrap: wrap; }
.card-actions .btn { flex: 1; justify-content: center; }

.unregistered-note { font-size: 12px; color: var(--text-faint); padding: 0 16px 12px; }
.mini-register { display: flex; gap: 6px; padding: 0 16px 14px; }
.mini-register select { flex: 1; }

/* ============ INCIDENTS ============ */
.incident-list { display: flex; flex-direction: column; gap: 8px; }
.incident-row {
  display: flex; align-items: flex-start; gap: 12px; background: var(--bg-surface); border: 1px solid var(--border);
  border-left: 3px solid var(--red); border-radius: var(--radius); padding: 12px 14px;
}
.incident-row.level-warning { border-left-color: var(--amber); }
.incident-row.resolved { opacity: .5; border-left-color: var(--text-faint); }
.incident-row .incident-main { flex: 1; }
.incident-row .incident-msg { font-size: 13.5px; font-weight: 600; }
.incident-row .incident-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.incident-row .incident-meta code { color: var(--text-dim); }

/* ============ TABLES ============ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-card); }
.card.no-pad { padding: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-faint); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--border-strong); font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text-dim); }
td:first-child { color: var(--text); }
tr:hover td { background: rgba(255,255,255,.015); }
.level-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 2px 7px; border-radius: 20px; }
.level-tag.info { background: var(--gray-soft); color: var(--text-dim); }
.level-tag.warning { background: var(--amber-soft); color: var(--amber); }
.level-tag.error { background: var(--red-soft); color: var(--red); }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 5, 6, 0.72); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto;
  background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.modal-title-row { display: flex; align-items: center; gap: 9px; }
.modal-title-row h3 { margin: 0; font-size: 17px; }
.modal-node { font-size: 12px; color: var(--text-faint); margin-top: 3px; margin-left: 17px; }
.modal-body { padding: 20px; }

.modal-section { margin-bottom: 22px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: 10px; }

.resource-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.resource-tile { background: var(--bg-surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.resource-tile .r-label { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; }
.resource-tile .r-value { font-size: 15px; font-weight: 700; margin-top: 3px; }
.bar-track { height: 5px; background: var(--bg-app); border-radius: 6px; margin-top: 7px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent-grad); border-radius: 6px; }

.action-grid { display: flex; gap: 8px; flex-wrap: wrap; }

.history-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.history-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.history-row .h-detail { color: var(--text-faint); }
.history-row .h-when { color: var(--text-faint); white-space: nowrap; }

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }

.toast {
  position: fixed; bottom: 20px; right: 20px; padding: 12px 18px; border-radius: 10px;
  background: var(--bg-surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop);
  font-size: 13px; z-index: 300;
}
.toast.error { border-color: rgba(248,113,113,.4); color: #fecaca; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface-2); border-radius: 6px; border: 2px solid var(--bg-app); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main { padding: 18px; }
  .grid-2 { grid-template-columns: 1fr; }
}
