:root {
  --bg: #14181f;
  --card: #1c232d;
  --card2: #232c38;
  --fg: #d8dee9;
  --muted: #8a97a8;
  --accent: #4fc3f7;
  --ok: #66bb6a;
  --bad: #ef5350;
  --border: #2e3a48;
  --err-bg: #3a2428;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --card: #ffffff; --card2: #eef1f4;
    --fg: #1c232d; --muted: #5c6b7a; --border: #d5dbe2; --err-bg: #fbe4e4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0; display: inline-block; }
a { color: var(--accent); text-decoration: none; }
code { background: var(--card2); padding: .1em .4em; border-radius: 4px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- auth pages ---------- */
body.auth { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.auth-wrap { width: 100%; max-width: 380px; }
.auth-card { padding: 1.6rem; }
.auth-card.wide { max-width: 480px; }
.brand { font-size: 1.4rem; margin: 0 0 1rem; }
.qr { display: block; margin: .8rem auto; border-radius: 8px; }
.secret { font-size: .9rem; word-break: break-all; }

/* ---------- cards / forms ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 1rem 1.2rem; margin: .6rem 0;
}
label { display: block; margin: .5rem 0; font-size: .95rem; }
input, select {
  width: 100%; padding: .55rem .7rem; margin-top: .25rem;
  background: var(--card2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px;
}
input.totp { letter-spacing: .5em; font-size: 1.3rem; text-align: center; }
button {
  padding: .55rem 1.1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card2); color: var(--fg); font-size: .95rem; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #0b1116; font-weight: 600; }
button.secondary { background: transparent; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.linkbtn { background: none; border: none; color: var(--accent); padding: 0; }
button:hover { filter: brightness(1.1); }
.actions { display: flex; gap: .6rem; margin: .7rem 0; flex-wrap: wrap; }
.inline { display: inline; }
.error { color: var(--bad); background: var(--err-bg); border-radius: 8px; padding: .5rem .8rem; }
.hint { color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); font-size: .9rem; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 .8rem; align-items: end;
}
.form-grid .actions { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; }
.check input { width: auto; margin: 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ---------- topbar / portal ---------- */
.topbar {
  display: flex; align-items: center; gap: .8rem;
  padding: .6rem 1rem; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-size: 1.1rem; margin: 0; }
.spacer { flex: 1; }
.user { color: var(--muted); }
.content { max-width: 1050px; margin: 0 auto; padding: 1rem; }
.grid {
  display: grid; gap: .8rem;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.service header { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.service .lat { font-size: .8rem; color: var(--muted); margin-left: auto; }
.dot {
  width: .7rem; height: .7rem; border-radius: 50%; display: inline-block; flex: none;
}
.dot.online { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.offline { background: var(--bad); }
.foot { text-align: center; margin: 1.5rem 0; }

/* ---------- audit table ---------- */
table.audit { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.audit th, table.audit td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); }
table.audit th { color: var(--muted); font-weight: 600; }
td.detail { font-family: ui-monospace, monospace; font-size: .8rem; word-break: break-all; }

/* ---------- web ssh ---------- */
body.ssh { display: flex; flex-direction: column; height: 100dvh; }
.ssh-main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: .5rem; }
.ssh-bar { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.ssh-bar label { margin: 0; display: flex; align-items: center; gap: .4rem; }
.ssh-bar select { width: auto; margin: 0; }
.term {
  flex: 1; min-height: 200px; background: #101418; border: 1px solid var(--border);
  border-radius: 8px; padding: .4rem;
  /* xterm renders its own scroll */
}
.term .xterm { height: 100%; }

/* ---------- mobile (NFR-8) ---------- */
@media (max-width: 600px) {
  .content { padding: .6rem; }
  .grid { grid-template-columns: 1fr; }
  input, select { font-size: 16px; } /* prevent iOS zoom */
  .form-grid { grid-template-columns: 1fr; }
  table.audit { font-size: .8rem; }
  .ssh-bar select { max-width: 55vw; }
}
