/* ─── Echo portal ──────────────────────────────────────────────────────────
   One stylesheet, no framework. The CSP forbids inline style and outside
   origins, so everything the UI looks like is here.                        */

:root {
  --bg: #0b0d12;
  --surface: #14171e;
  --surface-2: #1b1f28;
  --surface-3: #232833;
  --line: #2a3040;
  --line-soft: #20242e;
  --text: #e8ebf2;
  --text-dim: #98a1b3;
  --text-faint: #6b7488;
  --accent: #5b8def;
  --accent-dim: #2a3d68;
  --ok: #46c46a;
  --warn: #e0a13a;
  --bad: #f2555a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

h1 { font-size: 1.35rem; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0; font-weight: 620; }
h3 { font-size: .72rem; margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }

p { margin: 0; }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82em; }

[hidden] { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────── */

.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }

.login-card {
  width: min(370px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem 1.8rem;
  box-shadow: var(--shadow);
}

.login-mark { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.login-sub { color: var(--text-dim); font-size: .88rem; margin-bottom: 1.4rem; }
.login-card label { display: block; margin: .9rem 0 .3rem; font-size: .78rem; color: var(--text-dim); }

/* ── Shell ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.6rem;
  padding: 0 1.4rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { color: var(--text); font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: .2rem; flex: 1; }
.nav a {
  color: var(--text-dim);
  padding: .4rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-3); }

.who { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--text-dim); }
.who-name { max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { padding: 1.5rem 1.4rem 4rem; max-width: 1220px; margin: 0 auto; }

/* ── Page furniture ────────────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.page-head .sub { color: var(--text-dim); font-size: .87rem; margin-top: .15rem; }

.crumb {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: var(--text-dim);
  font-size: .82rem;
  margin-bottom: .5rem;
}
.crumb a { color: var(--text-dim); }
.crumb a:hover { color: var(--text); }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.right { justify-content: flex-end; }
.row.center { justify-content: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.grow { flex: 1; }

/* Spacing utilities: the CSP forbids inline style, so these live here. */
.mt-sm { margin-top: .4rem; }
.mt { margin-top: .9rem; }
.mt-lg { margin-top: 1.3rem; }
.mb { margin-bottom: .6rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--line-soft);
}
.card-body { padding: 1.1rem; }
.card-body.tight { padding: .6rem 1.1rem 1rem; }
.card-note { color: var(--text-dim); font-size: .84rem; margin-top: .2rem; }

/* ── Metrics ───────────────────────────────────────────────────────────── */

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }

.metric { padding: 1rem 1.1rem; }
.metric .value { font-size: 1.9rem; font-weight: 640; letter-spacing: -.02em; line-height: 1.15; margin-top: .35rem; }
.metric .value.muted { color: var(--text-faint); }
.metric .split { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

button, input, select, textarea { font: inherit; color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: .42rem .8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 560; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: none; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--bad); border-color: #4a2427; }
.btn.danger:hover { background: #2a1719; }
.btn.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: .28rem .6rem; font-size: .82rem; }
.btn.block { width: 100%; margin-top: 1.3rem; padding: .55rem; }
.btn.icon { padding: .2rem .5rem; font-size: 1.2rem; line-height: 1; }

/* ── Inputs ────────────────────────────────────────────────────────────── */

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .45rem .6rem;
}
input::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input.narrow, select.narrow { width: auto; min-width: 150px; }
select { cursor: pointer; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label { font-size: .78rem; color: var(--text-dim); }
.field .help { font-size: .78rem; color: var(--text-faint); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 1rem; }

/* ── Tabs ──────────────────────────────────────────────────────────────── */

.tabstrip {
  display: flex;
  gap: .15rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
  overflow-x: auto;
}
.tabstrip button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: .55rem .85rem;
  cursor: pointer;
  white-space: nowrap;
}
.tabstrip button:hover { color: var(--text); }
.tabstrip button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabstrip .count { color: var(--text-faint); font-size: .8em; margin-left: .3rem; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem 1.1rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
thead th {
  color: var(--text-faint);
  font-weight: 500;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td .stackline { display: flex; flex-direction: column; }
td .stackline small { color: var(--text-faint); font-size: .78rem; }

/* ── Badges ────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .74rem;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge.ok { color: var(--ok); border-color: #1f4a2c; background: #12241a; }
.badge.warn { color: var(--warn); border-color: #4c3c17; background: #241d10; }
.badge.bad { color: var(--bad); border-color: #4a2427; background: #241417; }

.pill {
  padding: .1rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: .72rem;
  color: var(--text-dim);
}

/* ── Misc blocks ───────────────────────────────────────────────────────── */

.empty { padding: 2rem 1.1rem; text-align: center; color: var(--text-dim); }
.empty strong { display: block; color: var(--text); margin-bottom: .3rem; font-weight: 560; }
.empty .hint { font-size: .85rem; color: var(--text-faint); max-width: 44ch; margin: 0 auto; }

.alert { padding: .6rem .8rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); font-size: .87rem; margin-top: 1rem; }
.alert.bad { border-color: #4a2427; background: #241417; color: #ffb4b7; }
.alert.ok { border-color: #1f4a2c; background: #12241a; color: #b6f0c6; }
.alert.warn { border-color: #4c3c17; background: #241d10; color: #f3d79a; }

.copy {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .1rem .4rem;
  cursor: pointer;
  color: var(--text-dim);
  max-width: 100%;
}
.copy:hover { color: var(--text); border-color: var(--accent); }
.copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .7rem;
  overflow: auto;
  max-height: 300px;
  font-size: .8rem;
  margin: 0;
}

.kv { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; }
.kv > div { padding: .5rem 0; border-bottom: 1px solid var(--line-soft); }
.kv > div:nth-child(-n+2) { border-top: none; }
.kv .k { color: var(--text-dim); font-size: .85rem; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: .6rem; color: var(--text-dim); padding: 2rem 1.1rem; justify-content: center; }

.var-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.var-row label { color: var(--text-dim); font-size: .82rem; }

/* ── Modal ─────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, .72);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 1.2rem;
}
.modal-card {
  width: min(600px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line-soft);
}
.modal-body { padding: 1.1rem; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem 1rem;
  z-index: 50;
  box-shadow: var(--shadow);
  max-width: min(560px, 92vw);
}
.toast.bad { border-color: #4a2427; color: #ffb4b7; }
.toast.ok { border-color: #1f4a2c; color: #b6f0c6; }

/* ── Small screens ─────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .topbar { gap: .8rem; padding: 0 .9rem; height: auto; flex-wrap: wrap; padding-bottom: .5rem; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .who-name { display: none; }
  main { padding: 1rem .9rem 3rem; }
  .kv { grid-template-columns: 1fr; }
  .kv .k { padding-bottom: 0; border-bottom: none; }
  th, td { padding: .55rem .8rem; }
}
