/* EuroLatam Panel UI ---------------------------------------------------------- */
:root {
  --bg: #0b1017;
  --bg-elev: #121a24;
  --bg-elev-2: #18222f;
  --line: #24313f;
  --line-soft: #1b2632;
  --text: #e6edf4;
  --text-dim: #97a6b6;
  --text-faint: #68798b;
  --accent: #38bdf8;
  --accent-ink: #062330;
  --ok: #34d399;
  --warn: #fbbf24;
  --crit: #f87171;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --shadow: 0 8px 28px rgba(0, 0, 0, .38);
  /* Chart series, validated against --bg-elev #121a24: CVD dE 26.8, contrast >= 3:1 */
  --series-1: #3987e5;
  --series-2: #d95926;
}
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef2f7;
  --line: #d7dfe8;
  --line-soft: #e5ebf1;
  --text: #16202b;
  --text-dim: #566575;
  --text-faint: #83919f;
  --accent: #0b7fb0;
  --accent-ink: #ffffff;
  --ok: #0f9d6e;
  --warn: #b7791f;
  --crit: #d1495b;
  --shadow: 0 6px 20px rgba(16, 32, 48, .1);
  /* Validated against --bg-elev #ffffff: CVD dE 24.7, contrast >= 3:1 */
  --series-1: #2a78d6;
  --series-2: #eb6834;
}

* { box-sizing: border-box; }

/* Author rules beat the user-agent [hidden] rule, so .boot/.gate/.app/.modal
   declaring display:grid would keep them on screen while hidden — and a hidden
   full-screen overlay silently swallows every click. Restore it explicitly. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); font-weight: 600; }
.muted { color: var(--text-dim); }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.error { color: var(--crit); }
.nowrap { white-space: nowrap; }

/* boot + gate ------------------------------------------------------------ */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.spinner { width: 26px; height: 26px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.gate-card label { display: grid; gap: 6px; font-size: 12.5px; color: var(--text-dim); }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -.015em; font-size: 15px; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(140deg, var(--accent), #6366f1); flex: none; }

/* layout ----------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 216px 1fr; height: 100vh; }
.sidebar {
  background: var(--bg-elev); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px; padding: 16px 12px;
  overflow-y: auto;
}
.nav { display: grid; gap: 2px; }
.nav-group { margin-top: 10px; padding: 0 8px 4px; }
.nav button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text-dim); font: inherit;
  padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer;
}
.nav button:hover { background: var(--bg-elev-2); color: var(--text); }
.nav button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 560; }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-faint); }
.nav .dot.ok { background: var(--ok); }
.nav .dot.warn { background: var(--warn); }
.nav .dot.crit { background: var(--crit); }
.nav .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.who { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
}
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view { padding: 20px 22px 40px; overflow-y: auto; flex: 1; }

/* primitives ------------------------------------------------------------- */
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack { display: grid; gap: 10px; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; width: 100%; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; resize: vertical; min-height: 220px; }
label { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-dim); }
.field-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.btn {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 560; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--accent-ink); }
.btn.danger { border-color: var(--crit); color: var(--crit); }
.btn.danger:hover:not(:disabled) { background: var(--crit); color: #fff; }
.btn.ghost { background: none; }
.btn.small { padding: 4px 9px; font-size: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.crit { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.chip.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

/* tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 12px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint); font-weight: 600;
  border-bottom: 1px solid var(--line); background: var(--bg-elev-2); position: sticky; top: 0;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-elev-2); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 5px; }
.clickable { cursor: pointer; }

/* metric tiles ----------------------------------------------------------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; }
.tile .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.tile .v { font-size: 23px; font-weight: 620; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--text-dim); }

.meter { height: 5px; border-radius: 3px; background: var(--bg-elev-2); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s ease; }
.meter > i.warn { background: var(--warn); }
.meter > i.crit { background: var(--crit); }

.spark { display: block; width: 100%; height: 40px; }

/* server cards ----------------------------------------------------------- */
.server-card { display: grid; gap: 10px; cursor: pointer; transition: border-color .15s; }
.server-card:hover { border-color: var(--accent); }
.server-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.server-card .name { font-weight: 600; }
.server-card .mini { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* tabs ------------------------------------------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--text-dim);
  padding: 8px 13px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-current="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 560; }

/* terminal --------------------------------------------------------------- */
.term-host { height: min(62vh, 560px); background: #05080c; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
:root[data-theme="light"] .term-host { background: #10151c; }

/* log / pre -------------------------------------------------------------- */
pre.log {
  margin: 0; background: #05080c; color: #cfe0ef; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; overflow: auto; max-height: 60vh;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
:root[data-theme="light"] pre.log { background: #0e141b; }

/* file manager ----------------------------------------------------------- */
.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; font-family: var(--mono); font-size: 12.5px; }
.crumbs button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 3px; border-radius: 4px; }
.crumbs button:hover { background: var(--bg-elev-2); }
.crumbs span { color: var(--text-faint); }

/* modal + toasts --------------------------------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(5, 9, 14, .62); display: grid; place-items: center; padding: 20px; z-index: 50; backdrop-filter: blur(2px); }
.modal-card { width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; padding: 0; box-shadow: var(--shadow); }
.modal-head, .modal-foot { padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-body { padding: 18px; overflow-y: auto; display: grid; gap: 12px; }
.modal-card.wide { max-width: 940px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(440px, 92vw); }
.toast {
  background: var(--bg-elev); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 13px; box-shadow: var(--shadow); font-size: 13px;
  animation: rise .18s ease-out;
}
.toast.err { border-left-color: var(--crit); }
.toast.ok { border-left-color: var(--ok); }
.toast pre { margin: 6px 0 0; font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; max-height: 180px; overflow: auto; color: var(--text-dim); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.empty { padding: 34px 20px; text-align: center; color: var(--text-dim); border: 1px dashed var(--line); border-radius: var(--radius); }
.warn-banner { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--bg-elev)); padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; }
.crit-banner { border-left: 3px solid var(--crit); background: color-mix(in srgb, var(--crit) 9%, var(--bg-elev)); padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: column; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { overflow: visible; }
  .view { padding: 16px; }
  .topbar { padding: 14px 16px; }
}

/* time-series chart ------------------------------------------------------- */
.ts-chart { position: relative; width: 100%; min-height: 220px; outline: none; border-radius: var(--radius-sm); }
.ts-chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.ts-svg { display: block; overflow: visible; }
.ts-grid { stroke: var(--line-soft); stroke-width: 1; }
.ts-base { stroke: var(--line); stroke-width: 1; }
.ts-tick { fill: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.ts-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ts-area { fill-opacity: .1; stroke: none; }
.ts-dot { stroke: var(--bg-elev); stroke-width: 2; }
.ts-crossline { stroke: var(--text-faint); stroke-width: 1; }
.ts-empty { display: grid; place-items: center; min-height: 220px; color: var(--text-dim); font-size: 13px;
  border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.ts-tip { position: absolute; z-index: 2; width: 170px; pointer-events: none; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 8px 10px;
  display: grid; gap: 4px; font-size: 12.5px; }
.ts-tip-time { color: var(--text-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ts-tip-row { display: flex; align-items: center; gap: 7px; }
.ts-tip-row strong { font-weight: 600; }
.ts-key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; flex: none; }
.ts-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.ts-stat .k { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.ts-stat .v { font-size: 20px; font-weight: 620; margin-top: 2px; letter-spacing: -.01em; }
.ts-table { max-height: 260px; overflow-y: auto; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px; }
.seg button { background: none; border: 0; color: var(--text-dim); padding: 5px 12px; border-radius: 5px; cursor: pointer; font: inherit; font-size: 13px; }
.seg button.on { background: var(--bg-elev-2); color: var(--text); font-weight: 560; }
@media (max-width: 860px) { .ts-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.spinner.tiny-spin { display: inline-block; width: 10px; height: 10px; border-width: 1.5px; vertical-align: -1px; margin-right: 2px; }

/* status gauges */
.gauges { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.gauge { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; justify-items: center; gap: 6px; text-align: center; }
.gauge .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); justify-self: stretch; text-align: left; }
.gauge .s { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.ring-wrap { position: relative; width: 112px; height: 112px; }
.ring { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: var(--bg-elev-2); stroke-width: 9; }
.ring-arc { fill: none; stroke: var(--ok); stroke-width: 9; stroke-linecap: round; transition: stroke-dasharray .4s ease; }
.ring-arc.warn { stroke: var(--warn); }
.ring-arc.crit { stroke: var(--crit); }
.ring-value { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 640; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--text); }
.verdict { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13.5px; color: var(--text); }
.verdict .ico { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--ok); }
.verdict.warn .ico { background: var(--warn); color: #1a1a1a; }
.verdict.crit .ico { background: var(--crit); }
@media (forced-colors: active) { .ring-arc { stroke: CanvasText; } .verdict .ico { border: 1px solid CanvasText; } }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.direct-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; align-items: end; }
.direct-grid .btn { white-space: nowrap; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }
@media (max-width: 560px) { .direct-grid { grid-template-columns: 1fr; } }
