/* Mobile-first. The base rules ARE the phone layout; wider screens only add. */
:root {
  --bg: #f4f7f9; --card: #ffffff; --ink: #0f1d26; --muted: #5b6b78; --line: #dbe3e9;
  --brand: #0e7490; --brand-ink: #ffffff; --brand-soft: #e0f2f7;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --off: #64748b; --off-soft: #e8edf1;
  --shadow: 0 1px 2px rgba(15,29,38,.06), 0 4px 14px rgba(15,29,38,.06);
  --r: 16px; --tap: 52px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1419; --card: #121f27; --ink: #e6eef3; --muted: #93a4b1; --line: #25343e;
    --brand: #22b8d6; --brand-ink: #04222b; --brand-soft: #123642;
    --ok: #4ade80; --ok-soft: #12351f; --warn: #fbbf24; --warn-soft: #3a2e0c;
    --bad: #f87171; --bad-soft: #3d1717; --off: #9fb0bd; --off-soft: #1c2a33;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1419; --card: #121f27; --ink: #e6eef3; --muted: #93a4b1; --line: #25343e;
  --brand: #22b8d6; --brand-ink: #04222b; --brand-soft: #123642;
  --ok: #4ade80; --ok-soft: #12351f; --warn: #fbbf24; --warn-soft: #3a2e0c;
  --bad: #f87171; --bad-soft: #3d1717; --off: #9fb0bd; --off-soft: #1c2a33;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.admin { padding-bottom: 24px; }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; }
.wrap { max-width: 980px; margin: 0 auto; padding: 14px 16px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 0; }
.topbar .in { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.grow { flex: 1; }
.iconbtn { min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); font-size: 1.1rem; cursor: pointer; }

/* nav: bottom tab bar on phones */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; text-align: center; padding: 10px 4px 9px; text-decoration: none; color: var(--muted); font-size: .8rem; min-height: 58px; }
.tabs a b { display: block; font-size: 1.35rem; font-weight: 400; line-height: 1.2; }
.tabs a.on { color: var(--brand); font-weight: 600; }
.admintabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; max-width: 980px; margin: 0 auto; scrollbar-width: none; }
.admintabs a { white-space: nowrap; padding: 9px 14px; border-radius: 999px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); background: var(--card); font-size: .92rem; min-height: 40px; }
.admintabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* cards + devices */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin: 0 0 14px; }
.hello { padding: 6px 2px 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
.dev h3 { margin: 0; font-size: 1.15rem; }
.dev .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chip { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.chip.idle { background: var(--ok-soft); color: var(--ok); }
.chip.running, .chip.starting, .chip.stopping { background: var(--brand-soft); color: var(--brand); }
.chip.offline { background: var(--off-soft); color: var(--off); }
.chip.fault, .chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.info { background: var(--brand-soft); color: var(--brand); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 20px;
  border-radius: 14px; border: 0; font: inherit; font-weight: 650; cursor: pointer; background: var(--brand); color: var(--brand-ink);
  text-decoration: none; touch-action: manipulation; }
.btn.big { width: 100%; min-height: 64px; font-size: 1.2rem; margin-top: 14px; border-radius: 18px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.confirm { background: var(--warn); color: #1a1200; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .9rem; border-radius: 10px; }
.btn[disabled] { background: var(--off-soft); color: var(--muted); border: 1px solid var(--line); cursor: not-allowed; }
.btn:focus-visible, .iconbtn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.meter { height: 8px; border-radius: 99px; background: var(--off-soft); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.meter.low > i { background: var(--warn); } .meter.none > i { background: var(--bad); }
.msg { min-height: 1.3em; margin: 10px 0 0; font-size: .92rem; }
.msg.err { color: var(--bad); } .msg.good { color: var(--ok); }
.flash { padding: 12px 14px; border-radius: 12px; margin: 0 0 14px; font-size: .95rem; }
.flash.ok { background: var(--ok-soft); color: var(--ok); } .flash.err { background: var(--bad-soft); color: var(--bad); }
.stopline { margin-top: 10px; }

/* history list (cards on phones) */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list li:first-child { border-top: 0; }
.list .t { font-weight: 600; } .list .s { color: var(--muted); font-size: .85rem; }

/* forms */
label { display: block; font-size: .9rem; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
input[type=checkbox] { width: 22px; min-height: 22px; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; }
.check input { flex: none; }
.formgrid { display: grid; gap: 0 14px; grid-template-columns: 1fr; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.login { max-width: 400px; margin: 8vh auto 0; }
.login .brandbig { text-align: center; margin-bottom: 18px; }
.login .brandbig img { width: 56px; height: 56px; }

/* admin */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.tile b { display: block; font-size: 1.8rem; line-height: 1.1; } .tile span { color: var(--muted); font-size: .85rem; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tr:last-child td { border-bottom: 0; }
td.wrapcell { white-space: normal; min-width: 220px; }
.alertrow { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.alertrow:first-child { border-top: 0; } .alertrow .grow { min-width: 0; }
.inline { display: inline; } .inline button { margin: 0; }

@media (min-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .formgrid { grid-template-columns: 1fr 1fr; }
  .btn.big { width: auto; min-width: 280px; }
  .dev .btn.big { width: 100%; }
  .tabs { position: static; border: 0; background: transparent; max-width: 980px; margin: 0 auto; padding: 0 16px; gap: 6px; }
  .tabs a { flex: none; min-height: 0; padding: 8px 16px; border-radius: 999px; font-size: .95rem; }
  .tabs a b { display: none; }
  .tabs a.on { background: var(--brand-soft); }
  body { padding-bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.m0 { margin: 0; } .mt0 { margin-top: 0; } .mt14 { margin-top: 14px; } .hint { margin: 4px 0 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.admintabs.flush { padding-left: 0; padding-right: 0; }
code { font-size: .85em; background: var(--off-soft); padding: 1px 5px; border-radius: 6px; word-break: break-all; }
[hidden] { display: none !important; }
