/* Admin panel styles. Dark, dense, terminal-friendly. */
:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #1a2130;
  --border: #263044;
  --text: #d6dbe4;
  --muted: #8a93a6;
  --accent: #6ea8fe;
  --accent-strong: #3d7be0;
  --ok: #8fcf7a;
  --warn: #e8c46a;
  --danger: #f2777a;
  --danger-strong: #c9444a;
  --radius: 8px;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .25rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .4em; border-radius: 4px; }
.muted { color: var(--muted); margin: 0 0 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: .3rem .75rem;
  border-radius: 6px;
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar nav a.active { color: var(--text); background: var(--surface-2); }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: .75rem; color: var(--muted); min-width: 0; }
.topbar .user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- buttons & inputs ------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem .9rem;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-strong); border-color: var(--danger-strong); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem .6rem;
  min-width: 0;
}
input::placeholder { color: #566074; }
select { cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent-strong); }

label { font-size: .8rem; color: var(--muted); }

/* ---- login ------------------------------------------------------------ */
.page-login main { align-items: center; justify-content: center; padding: 1rem; }
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.login-card form { display: flex; flex-direction: column; gap: .35rem; }
.login-card label { margin-top: .5rem; }
.login-card .btn { width: 100%; margin-top: 1rem; }
.login-card .btn-secondary { margin-top: 0; }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; color: var(--muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.form-error {
  margin: 1rem 0 0;
  padding: .6rem .75rem;
  color: var(--danger);
  background: rgba(242, 119, 122, .1);
  border: 1px solid rgba(242, 119, 122, .35);
  border-radius: 6px;
}

/* ---- logs ------------------------------------------------------------- */
.logs-layout { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: .75rem 1rem 0; gap: .75rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem 1rem;
}
.toolbar .field { display: flex; flex-direction: column; gap: .2rem; }
.toolbar .field.grow { flex: 1 1 240px; }
.toolbar .field.checks { flex-direction: row; align-items: center; gap: 1rem; padding-bottom: .5rem; }
.toolbar .field.buttons { flex-direction: row; gap: .5rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); font-size: .85rem; cursor: pointer; }

.terminal-wrap {
  flex: 1;
  min-height: 0;
  background: #0b0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem 0 .5rem .75rem;
  overflow: hidden;
}
#terminal { height: 100%; }
.terminal-wrap .xterm-viewport { background-color: transparent !important; }

.statusbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .1rem .6rem;
  color: var(--muted);
  font-size: .8rem;
}
.statusbar .spacer { flex: 1; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); }
.dot-on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot-warn { background: var(--warn); }
.dot-off { background: var(--muted); }

/* ---- actions ---------------------------------------------------------- */
.page-actions main { overflow: auto; }
.actions-layout { width: 100%; max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.card {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.card .muted { margin-bottom: .75rem; }
.card-danger { border-color: rgba(242, 119, 122, .45); }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline-form input { flex: 1 1 220px; }

.toast { margin-top: 1rem; padding: .7rem .9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.toast-ok { color: var(--ok); border-color: rgba(143, 207, 122, .4); }
.toast-warn { color: var(--warn); border-color: rgba(232, 196, 106, .4); }
.toast-err { color: var(--danger); border-color: rgba(242, 119, 122, .4); }

/* ---- small screens ---------------------------------------------------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
  .topbar .user { margin-left: 0; width: 100%; }
  .toolbar .field.grow { flex-basis: 100%; }
}

/* ---- metrics ---------------------------------------------------------- */
.page-metrics main { overflow: auto; }
.metrics-layout { width: 100%; max-width: 1320px; margin: 0 auto; padding: 1.25rem 1rem 3rem; display: flex; flex-direction: column; gap: 1rem; }
.metrics-layout .card { margin-top: 0; }
.metrics-layout h3 { margin: 0; }

.metrics-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1.25rem; }
.metrics-toolbar .field { display: flex; flex-direction: column; gap: .2rem; }
.inline-note { color: var(--muted); font-size: .8rem; margin: 0; }
.metrics-toolbar .inline-note { margin-left: auto; align-self: center; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; }
.kpi {
  position: relative;
  padding: 1rem 1.1rem .9rem;
  background: linear-gradient(160deg, var(--surface-2), var(--surface) 70%);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); }
.kpi.tone-ok::before { background: var(--ok); }
.kpi.tone-warn::before { background: var(--warn); }
.kpi.tone-bad::before { background: var(--danger); }
.kpi-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 1.9rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi.tone-bad .kpi-value { color: var(--danger); }
.kpi.tone-warn .kpi-value { color: var(--warn); }
.kpi-sub { color: var(--muted); font-size: .78rem; min-height: 1.1em; }

.chart-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1rem; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.chart-card { display: flex; flex-direction: column; min-width: 0; }
.chart-sub { color: var(--muted); font-size: .8rem; margin: 0 0 .75rem; }
.chart-box { position: relative; height: 270px; }
.chart-card .empty {
  flex: 1; display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 270px; margin: 0; padding: 0 1rem; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 8px;
}
.chart-card .empty[hidden] { display: none; }

.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 1rem; }
.gauge-head { display: flex; justify-content: space-between; margin-bottom: .35rem; }
.gauge-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.gauge-track { height: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.gauge-fill { height: 100%; width: 0; border-radius: 999px; transition: width .4s ease; background: var(--ok); }
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.bad { background: var(--danger); }
.gauge-sub { color: var(--muted); font-size: .78rem; margin-top: .3rem; min-height: 1.1em; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem .75rem; margin: 0; }
.fact { padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.fact dt { color: var(--muted); font-size: .75rem; }
.fact dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.table-card { min-width: 0; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th, table.data td { padding: .5rem .65rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; background: var(--surface); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.dim td { opacity: .55; }
table.data .mono, .mono { font-family: var(--mono); font-size: .82em; }
table.data .empty-row { text-align: center; color: var(--muted); padding: 1.25rem; }
.bad { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }

.sub-heading { margin: 1.25rem 0 .5rem !important; font-size: .9rem; color: var(--muted); }
.recent-errors { display: flex; flex-direction: column; gap: .4rem; }
details.err { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
details.err summary { display: flex; flex-wrap: wrap; gap: .25rem 1rem; padding: .5rem .75rem; cursor: pointer; list-style-position: inside; }
details.err .err-time { color: var(--muted); }
details.err .err-type { color: var(--danger); font-weight: 600; }
details.err .err-msg { color: var(--muted); overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 200px; }
details.err pre { margin: 0; padding: .75rem; overflow-x: auto; border-top: 1px solid var(--border); font: .78rem/1.5 var(--mono); color: var(--text); }

@media (max-width: 900px) {
  .span-4, .span-6, .span-8 { grid-column: span 12; }
  .metrics-toolbar .inline-note { margin-left: 0; width: 100%; }
}
