:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2230;
  --sunken: #0d1117;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #25d366;
  --accent-dim: #1a9e4b;
  --blue: #4f8cff;
  --orange: #f0a020;
  --red: #f05252;
  --radius: 12px;

  /* Séries (validées CVD sur la surface #161b22) */
  --series-in: #3987e5;
  --series-out: #d95926;
  --grid: #232a35;
  --axis: #3a4352;

  /* Statut (distincts des séries, jamais réutilisés pour une identité) */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* Barre supérieure */
.topbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: linear-gradient(180deg, #161b22, #12171f);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { font-size: 30px; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -0.2px; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.last-update { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.switch { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

.gateway-chip {
  background: rgba(37, 211, 102, 0.12); color: var(--accent);
  border: 1px solid rgba(37, 211, 102, 0.35); border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.gateway-chip.off { background: rgba(240, 160, 32, 0.12); color: var(--orange); border-color: rgba(240, 160, 32, 0.35); }

/* Corps du tableau de bord */
.dashboard { padding: 22px 28px 40px; display: flex; flex-direction: column; gap: 22px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.empty-row { color: var(--muted); text-align: center; padding: 26px; font-size: 13.5px; }
.offline-note { padding: 18px 20px; color: var(--red); font-size: 13.5px; }

/* Chiffres clés */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.stat.ok .stat-value { color: var(--accent); }
.stat.warn .stat-value { color: var(--orange); }
.stat.bad .stat-value { color: var(--red); }

/* Grille deux colonnes (cartes de graphiques) */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; padding: 16px 20px 6px; }
.chart-head h2 { margin: 0; font-size: 15px; }
.chart-sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.chart-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key-in { background: var(--series-in); }
.key-out { background: var(--series-out); }

.chart-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px 16px;
}

.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--sunken); border: 1px solid var(--border); border-radius: 9px; }
.segmented button { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 6px; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

.select-field { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
select {
  background: var(--sunken); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 13.5px; min-width: 200px;
}
select:focus { outline: none; border-color: var(--accent-dim); }

/* Graphique en ligne (volume de messages) */
.chart-wrap { position: relative; padding: 4px 12px 10px; transition: opacity 0.15s; }
.chart-wrap.refetching { opacity: 0.5; }
svg { display: block; overflow: visible; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.hit { fill: transparent; outline: none; }
.hit:focus-visible { stroke: var(--muted); stroke-width: 1; }
.peak-label { fill: #c9d4e0; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty-label { fill: var(--muted); font-size: 13.5px; }

.line { fill: none; stroke-width: 2; }
.line-in { stroke: var(--series-in); }
.line-out { stroke: var(--series-out); stroke-dasharray: 5 4; }
.area-in { fill: var(--series-in); opacity: 0.1; stroke: none; }
.end-dot { stroke: var(--surface); stroke-width: 2; }
.end-dot-in { fill: var(--series-in); }
.end-dot-out { fill: var(--series-out); }
.hover-line { stroke: var(--axis); stroke-width: 1; }

.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 170px;
  background: var(--sunken); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; font-size: 12.5px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.chart-tooltip[hidden] { display: none; }
.tip-title { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.75; }
.tip-row strong { color: var(--text); font-size: 14px; font-weight: 600; min-width: 26px; text-align: right; font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--muted); }
.tip-key { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tip-key.key-in { background: var(--series-in); }
.tip-key.key-out { background: var(--series-out); }

/* Donut de répartition des statuts */
.donut-wrap { display: flex; align-items: center; gap: 20px; padding: 10px 20px 20px; flex-wrap: wrap; }
.donut-track { fill: none; stroke: var(--sunken); }
.donut-center-value { fill: var(--text); font-size: 22px; font-weight: 600; text-anchor: middle; }
.donut-center-label { fill: var(--muted); font-size: 10.5px; text-anchor: middle; }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; flex: 1; min-width: 140px; }
.donut-legend li { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-label { color: var(--muted); }
.legend-value { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Barres horizontales (top hôtels) */
.bars-wrap { display: flex; flex-direction: column; gap: 10px; padding: 10px 20px 18px; }
.bar-row {
  display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 10px;
  background: none; border: none; padding: 4px 0; cursor: pointer; font: inherit; color: inherit; width: 100%; text-align: left;
  border-radius: 6px;
}
.bar-row:hover { background: var(--sunken); }
.bar-row.selected .bar-fill { background: var(--accent); }
.bar-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--sunken); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--series-in); border-radius: 999px; min-width: 3px; transition: width 0.2s; }
.bar-value { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; min-width: 40px; }

/* Disponibilité (jauges) */
.meters-wrap { display: flex; flex-direction: column; gap: 14px; padding: 14px 20px 20px; }
.meter-row { display: grid; grid-template-columns: 150px 1fr 56px; align-items: center; gap: 12px; }
.meter-label { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter-track { background: var(--sunken); border-radius: 999px; height: 9px; overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--good); border-radius: 999px; transition: width 0.3s; }
.meter-fill.meter-warn { background: var(--warning); }
.meter-value { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; }

.badge-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-good { background: var(--good); box-shadow: 0 0 0 2px rgba(12, 163, 12, 0.22); }
.dot-bad { background: var(--critical); box-shadow: 0 0 0 2px rgba(230, 103, 103, 0.22); }

/* Cartes génériques de section */
.panel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-card-head h2 { margin: 0; font-size: 15px; }
.panel-card-hint { color: var(--muted); font-size: 12px; }

/* Table des numéros */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1040px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 600; padding: 12px 20px; border-bottom: 1px solid var(--border); }
td { padding: 14px 20px; border-bottom: 1px solid #1e2531; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #191f29; }

.hotel-name { font-weight: 600; white-space: nowrap; }
.hotel-edit { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 4px; font-family: system-ui, sans-serif; line-height: 1; }
.hotel-edit:hover { color: var(--text); background: #232b38; }
.session-id { color: var(--muted); font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; }
.phone { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.phone-empty { color: var(--muted); font-style: italic; font-family: inherit; }
.server-cell { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.link-btn { background: none; border: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.activity-cell { font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.activity-cell:hover { text-decoration: underline; }
.activity-cell.muted { color: var(--muted); font-style: italic; }

.hook-cell { font-size: 12.5px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hook-on { color: var(--accent); }
.hook-off { color: var(--muted); font-style: italic; }

.data-table { min-width: 480px; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td { padding: 11px 20px; font-size: 13.5px; }

/* Badges de statut */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-working { background: rgba(12, 163, 12, 0.14); color: var(--good); }
.badge-scan { background: rgba(250, 178, 25, 0.16); color: var(--warning); }
.badge-starting { background: rgba(79, 140, 255, 0.14); color: var(--blue); }
.badge-stopped { background: rgba(139, 152, 169, 0.14); color: var(--muted); }
.badge-failed { background: rgba(230, 103, 103, 0.16); color: var(--critical); }

/* Mini-serveurs */
.server-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; padding: 18px 20px; }
.server-card-mini { background: var(--sunken); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.server-card-mini-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.server-card-mini-meta { color: var(--muted); font-size: 12px; }
.server-card-mini-meta code { background: #08090c; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.server-card-mini-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border); }

/* Mises à jour */
.update-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; padding: 18px 20px; }
.update-card { background: var(--sunken); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.update-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.update-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.update-steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; display: grid; gap: 5px; }
.update-progress { background: var(--sunken); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #c9d4e0; }

.backups-block { padding: 4px 20px 20px; border-top: 1px solid var(--border); }
.backups-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 16px; margin-bottom: 4px; }
.backups-head h3 { margin: 0; font-size: 14px; }

/* Boutons */
.btn { border-radius: 8px; border: 1px solid var(--border); padding: 7px 13px; font-size: 13px; font-weight: 500; cursor: pointer; background: var(--surface-2); color: var(--text); transition: background 0.12s, border-color 0.12s; }
.btn:hover { background: #263040; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger:hover { background: rgba(230, 103, 103, 0.16); border-color: var(--critical); color: #ffb4b4; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
a.btn { display: inline-block; text-decoration: none; }
.actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: #232b38; }

/* Modales */
.modal-backdrop { position: fixed; inset: 0; background: rgba(4, 7, 12, 0.72); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; backdrop-filter: blur(2px); }
.modal-backdrop[hidden] { display: none !important; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; box-shadow: 0 22px 60px rgba(0, 0, 0, 0.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-wide { max-width: 680px; }
.modal-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.modal-sub strong { color: var(--text); }
.modal-sub code, .panel code, #updateSummary code { background: var(--sunken); padding: 1px 6px; border-radius: 5px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.qr-body { align-items: center; text-align: center; }
.qr-target { margin: 0; color: var(--muted); font-size: 13px; }
.qr-target strong { color: var(--text); }
.qr-frame { background: #fff; padding: 12px; border-radius: 12px; line-height: 0; width: 256px; height: 256px; display: flex; align-items: center; justify-content: center; }
.qr-frame img { width: 232px; height: 232px; display: block; }
.qr-frame img[hidden] { display: none; }
.qr-frame::after { content: "…"; color: #8b98a9; font-size: 26px; line-height: 1; display: none; }
.qr-frame:has(img[hidden])::after { display: block; }
.qr-steps { text-align: left; color: var(--muted); font-size: 13px; margin: 0; padding-left: 20px; display: grid; gap: 5px; }
.qr-steps strong { color: var(--text); }
.qr-status { margin: 0; font-size: 13px; color: var(--orange); }
.qr-status.done { color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field > span { color: var(--muted); font-weight: 500; }
.field small { color: var(--muted); font-size: 11.5px; }
input[type="text"], input[type="password"], textarea {
  background: var(--sunken); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; color: var(--text); font: inherit; font-size: 14px; width: 100%;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus { outline: none; border-color: var(--accent-dim); }
input[readonly] { color: #c9d4e0; }
textarea { resize: vertical; }
.form-error { color: var(--red); font-size: 13px; margin: 0; }

.panel { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: var(--sunken); display: flex; flex-direction: column; gap: 10px; }
.panel h3 { margin: 0; font-size: 14px; }
.panel-help { margin: 0; color: var(--muted); font-size: 12.5px; }
.panel-help strong { color: var(--text); }
.panel-warn { margin: 0; color: var(--orange); font-size: 12.5px; }

.copy-field { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy-field input { flex: 1; min-width: 200px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

.webhook-form { display: flex; flex-direction: column; gap: 12px; }
.webhook-form .modal-actions { justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 7px 16px; }
.event { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.event input { accent-color: var(--accent); }
.event code { margin-left: auto; color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }

.snippet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.snippet { margin: 0; background: var(--sunken); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 12.5px; line-height: 1.55; overflow-x: auto; color: #c9d4e0; font-family: ui-monospace, Consolas, monospace; white-space: pre; }

/* Écran de connexion */
/* :not([hidden]) — sinon ce display:flex l'emporte sur le [hidden] du HTML et l'écran reste visible après connexion */
.login-screen:not([hidden]) { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 340px; padding: 28px 26px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card .brand-mark { font-size: 34px; }
.login-card h1 { margin: 0; font-size: 17px; }
.login-card .field { text-align: left; }
.login-card .btn { width: 100%; padding: 10px; margin-top: 4px; }

/* Notifications */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 9px; padding: 11px 15px; font-size: 13.5px; max-width: 340px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); animation: slide 0.2s ease; }
.toast.ok { border-left-color: var(--accent); }
.toast.err { border-left-color: var(--red); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }

.footer { padding: 16px 28px 28px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; border-top: 1px solid var(--border); }

@media (max-width: 640px) {
  .topbar, .dashboard, .footer { padding-left: 16px; padding-right: 16px; }
  .bar-row, .meter-row { grid-template-columns: 1fr; gap: 4px; }
  .bar-value, .meter-value { text-align: left; }
}
