/* admind — mobile first.
 *
 * Designed for a phone held one-handed: primary navigation sits at the bottom within
 * thumb reach, tap targets are never below 44px, and the layout only grows into a
 * sidebar past 900px. Light and dark are both first-class, driven by the system setting.
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14161a;
  --muted: #5b6270;
  --border: #d9dde5;
  --accent: #1f5fd0;
  --accent-text: #ffffff;
  --ok: #157347;
  --warn: #9a6700;
  --critical: #b02a2a;
  --radius: 12px;
  --gap: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1f242d;
    --text: #e7eaef;
    --muted: #99a1b0;
    --border: #2b313b;
    --accent: #5a9bff;
    --accent-text: #0b0e13;
    --ok: #4ec27f;
    --warn: #e0b341;
    --critical: #ff6b6b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  /* Stops iOS Safari inflating text in landscape, which breaks the tab bar layout. */
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.15rem; font-weight: 600; }
h2 { font-size: 1rem; font-weight: 600; }
h3 { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 0.875rem; }
.error { color: var(--critical); font-size: 0.875rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 0.8125rem; }

/* ── Auth ─────────────────────────────────────────────────────────────────────────── */

.auth {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(32px + var(--safe-top)) 16px 32px;
}
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
.auth-head p { margin: 0; }
.auth-foot { margin-top: 20px; text-align: center; }
.switcher { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }

/* ── Cards and forms ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  margin: 12px 0 4px;
}

input, select, textarea {
  width: 100%;
  /* 16px exactly: anything smaller makes iOS Safari zoom the viewport on focus. */
  font-size: 16px;
  font-family: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  min-height: 44px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  min-height: 44px;
  padding: 11px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button.primary {
  width: 100%;
  margin-top: 16px;
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}
button.primary.small { width: auto; margin: 0; min-height: 36px; padding: 6px 12px; }
button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 8px 0;
  text-align: left;
  min-height: 36px;
}
button[disabled] { opacity: 0.55; cursor: default; }

/* ── App chrome ───────────────────────────────────────────────────────────────────── */

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 8px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; text-align: center; }
.icon-button {
  width: 44px; height: 44px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.25rem;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--warn) 16%, var(--surface));
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.view {
  flex: 1;
  padding: var(--gap);
  /* Clears the fixed tab bar plus the home indicator so nothing is unreachable. */
  padding-bottom: calc(72px + var(--safe-bottom));
}

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.tabbar button {
  flex: 1;
  border: none;
  background: none;
  border-radius: 0;
  padding: 8px 2px;
  font-size: 0.6875rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
}
.tabbar button .glyph { font-size: 1.125rem; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ── Data display ─────────────────────────────────────────────────────────────────── */

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

.stat {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat .value { font-size: 1.375rem; font-weight: 650; letter-spacing: -0.02em; }
.stat .label { font-size: 0.75rem; color: var(--muted); }
/* A metric with no source renders in muted italics with an em dash, never a zero. */
.stat .value.none { color: var(--muted); font-weight: 400; font-style: italic; font-size: 1rem; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
}
.row:last-child { border-bottom: none; }
.row .k { color: var(--muted); font-size: 0.875rem; }
.row .v { text-align: right; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.critical { background: color-mix(in srgb, var(--critical) 18%, transparent); color: var(--critical); }

.list-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 8px;
  min-height: 44px;
}
.list-item .title { font-weight: 600; font-size: 0.9375rem; }
.list-item .sub { color: var(--muted); font-size: 0.8125rem; margin-top: 2px; }

/* Unread is marked the way mail clients actually mark it — a leading dot and a heavier
 * title — rather than by restyling the card, so a list of mostly-unread mail still reads
 * as one uniform list. */
.list-item.unread .title::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  vertical-align: 0.1em;
  border-radius: 50%;
  background: var(--accent);
}
.list-item.unread .title { font-weight: 700; }

/* Wide content scrolls inside its own box; the page body never scrolls sideways. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.8125rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

.log-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.log-line.p3, .log-line.p2, .log-line.p1, .log-line.p0 { color: var(--critical); }
.log-line.p4 { color: var(--warn); }

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

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 0.875rem;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + var(--safe-bottom));
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  z-index: 50;
  max-width: calc(100vw - 32px);
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal-inner { padding: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin: 16px 0 0; padding: 0; }
.modal-actions button { min-width: 96px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--gap); }
.toolbar input, .toolbar select { width: auto; flex: 1 1 140px; }

/* ── Desktop ──────────────────────────────────────────────────────────────────────── */

/* ── Desktop ──────────────────────────────────────────────────────────────────────────
 *
 * Not "the phone layout, wider". A dashboard on a 1440px screen should show more at once,
 * not the same single column stretched — so cards flow into a responsive multi-column
 * grid and the stat tiles tighten up. Anything that needs the full width (a table, a log
 * stream, a mail list) spans every column rather than being squeezed into one.
 */

@media (min-width: 900px) {
  /* Block, not flex-row. `.app` holds the topbar, an optional banner, the view and the
   * tabbar; the first and last are position:fixed and leave the flow, but the banner and
   * the view do not — as flex-row children they would sit side by side, putting the
   * step-up prompt in a column next to the content instead of above it. */
  .app { display: block; }

  .tabbar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 220px;
    flex-direction: column;
    justify-content: flex-start;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 16px 0 0;
  }
  .tabbar button {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 18px;
    font-size: 0.9375rem;
    min-height: 44px;
  }
  .tabbar button .glyph { font-size: 1rem; width: 1.25em; text-align: center; }

  .topbar {
    position: fixed;
    top: 0; left: 220px; right: 0;
    /* Title left, controls right. Centring a title beside a left-hand sidebar reads as a
     * phone header that forgot where it was. */
    grid-template-columns: 1fr 44px 44px;
    padding: 10px 16px;
    height: 60px;
  }
  /* The row is explicit as well as the column. Placing the second child back into
   * column 1 after the first took column 2 makes sparse auto-placement start a new row
   * rather than move backwards, which dropped the title and the account button out of
   * the bar and on top of the content. */
  .topbar > :nth-child(1) { grid-column: 2; grid-row: 1; }
  .topbar > :nth-child(2) { grid-column: 1; grid-row: 1; text-align: left; font-size: 1.25rem; }
  .topbar > :nth-child(3) { grid-column: 3; grid-row: 1; }

  .banner {
    margin-left: 220px;
    /* Clears the fixed topbar exactly, rather than guessing at a gap. */
    padding-top: calc(10px + 60px);
  }

  .view {
    margin-left: 220px;
    padding: 84px 24px 32px;
    max-width: 1600px;

    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 16px;
    /* start, not stretch: a card with one line in it should be one line tall, not as tall
     * as the busiest card in its row. */
    align-items: start;
    align-content: start;
  }

  /* Full width by default — search bars, toolbars, back links, mail rows. Only cards opt
   * into the columns, so a new element added later is legible rather than squeezed. */
  .view > * { grid-column: 1 / -1; }
  .view > .card { grid-column: auto; margin-bottom: 0; }

  /* …except cards carrying inherently wide content, which span everything again. */
  .view > .card:has(table),
  .view > .card:has(.log-line),
  .view > .card:has(.sparkline) { grid-column: 1 / -1; }

  /* Denser tiles: in a 330px card, four stats at the mobile minimum would each get a line
   * of their own and undo the point of the grid. */
  .grid { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 6px; }
  .stat { padding: 8px 10px; }
  .stat .value { font-size: 1.25rem; }
  .stat .value.none { font-size: 0.9375rem; }

  .empty { padding: 18px 12px; }
  .toast { bottom: 24px; left: auto; right: 24px; transform: none; }
}

/* Beyond a certain width the sidebar looks marooned; give the content room to breathe
 * rather than adding a fifth column of 330px cards. */
@media (min-width: 1600px) {
  .view { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Giveaways ─────────────────────────────────────────────────────────────────────── */

/* Minted codes are shown once and never again, so this panel is built to be selected and
   copied rather than read: monospace, no wrapping mid-code, and tall enough that a normal
   batch needs no scrolling. */
.codes {
  width: 100%;
  padding: 0.6rem 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  white-space: pre;
}

.note {
  margin: 0.9rem 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.1rem 0 0.6rem;
}
