/* Server Admin — same palette as the in-game design system (Apple system colours), dark first. */
:root {
  --bg: #000000;
  --surface: #1C1C1E;
  --surface-2: #2C2C2E;
  --line: #38383A;
  --fg: #FFFFFF;
  --secondary: #8E8E93;
  --tertiary: #636366;
  --accent: #0A84FF;
  --success: #30D158;
  --warning: #FF9F0A;
  --error: #FF453A;
  --log-bg: #0B0B0C;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --nav-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #F2F2F7;
    --surface: #FFFFFF;
    --surface-2: #E5E5EA;
    --line: #D1D1D6;
    --fg: #000000;
    --secondary: #6C6C70;
    --tertiary: #8E8E93;
    --accent: #007AFF;
    --success: #248A3D;
    --warning: #C93400;
    --error: #D70015;
    --log-bg: #FFFFFF;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
code { font: 13px var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons, fields ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--fg);
  padding: 9px 16px; border-radius: 10px; font-weight: 500;
  min-height: 38px; white-space: nowrap;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: transparent; color: var(--error); box-shadow: inset 0 0 0 1px var(--line); }
.btn-wide { width: 100%; }
.field {
  width: 100%; min-height: 42px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; outline: none;
}
.field:focus { border-color: var(--accent); }
.link { color: var(--accent); text-decoration: none; font-size: 14px; }
.muted { color: var(--secondary); font-size: 14px; }

/* ---------- sign in ---------- */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left)); }
.gate-card { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.gate-icon { justify-self: center; border-radius: 14px; margin-bottom: 4px; }
.gate-title { font-size: 22px; font-weight: 600; }
.gate-sub { color: var(--secondary); margin-bottom: 8px; }
.gate-msg { color: var(--error); min-height: 1.4em; font-size: 14px; }

/* ---------- shell ---------- */
.app { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.brand img { border-radius: 7px; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  font-size: 13px; font-weight: 500; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--secondary); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { color: var(--success); }
.pill.off { color: var(--secondary); }
.pill.warn { color: var(--warning); }

/* phone: bottom tab bar */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.nav-item {
  display: grid; justify-items: center; gap: 2px; padding: 4px 0;
  color: var(--secondary); text-decoration: none; font-size: 11px; font-weight: 500;
}
.nav-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.active { color: var(--accent); }

.content {
  max-width: 1080px; margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.view { display: grid; gap: 16px; }
.view-title { font-size: 28px; font-weight: 700; letter-spacing: -.01em; }

/* desktop: sidebar */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .nav {
    position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px);
    display: flex; flex-direction: column; gap: 2px; padding: 16px 12px;
    background: transparent; backdrop-filter: none; border: 0; border-right: 1px solid var(--line);
  }
  .nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; font-size: 14px; color: var(--fg); }
  .nav-item svg { width: 20px; height: 20px; color: var(--secondary); }
  .nav-item.active { background: var(--surface-2); color: var(--fg); }
  .nav-item.active svg { color: var(--accent); }
  .content { padding: 28px 32px 40px; width: 100%; }
}

/* ---------- overview ---------- */
.hero {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 20px; border-radius: var(--radius); background: var(--surface);
}
.eyebrow { color: var(--secondary); font-size: 13px; font-weight: 500; }
.hero-title { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.hero-title.on { color: var(--success); }
.hero-sub { color: var(--secondary); margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.job { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; }
.job-head { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.job-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.job.done .job-dot { animation: none; background: var(--success); }
.job.failed .job-dot { animation: none; background: var(--error); }
.job-lines { margin: 0; font: 12.5px/1.5 var(--mono); color: var(--secondary); max-height: 160px; overflow: auto; white-space: pre-wrap; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .job-dot { animation: none; } }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile-label { color: var(--secondary); font-size: 13px; font-weight: 500; }
.tile-value { font-size: 24px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-note { color: var(--tertiary); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.good { color: var(--success); } .warnc { color: var(--warning); } .bad { color: var(--error); }
.meter { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .4s; }

/* ---------- cards & lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 6px 16px 10px; display: grid; gap: 8px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; padding-top: 10px; }
.card-head h3 { font-size: 17px; font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.list li:first-child { border-top: 0; }
.list .empty { color: var(--secondary); justify-content: center; padding: 18px 0; }
.avatar { width: 32px; height: 32px; border-radius: 7px; background: var(--surface-2); flex: none; image-rendering: pixelated; }
.who { min-width: 0; flex: 1; }
.who b { font-weight: 500; display: block; }
.who small { color: var(--secondary); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--secondary); }
.inline-form { display: flex; gap: 8px; padding-top: 4px; }
.stack { display: grid; gap: 10px; padding: 4px 0 8px; }
.rows .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.rows .row:first-child { border-top: 0; }
.hint { color: var(--secondary); font-size: 13px; line-height: 1.7; }

/* ---------- console ---------- */
.view-console { gap: 12px; }
.console-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--secondary); font-size: 14px; cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.log {
  background: var(--log-bg); border: 1px solid var(--line); border-radius: var(--radius);
  font: 12.5px/1.55 var(--mono); padding: 12px 14px; overflow: auto;
  height: calc(100dvh - 330px - env(safe-area-inset-bottom)); min-height: 260px;
  white-space: pre-wrap; word-break: break-word;
}
@media (min-width: 900px) { .log { height: calc(100vh - 290px); } }
.log .l { display: block; }
.log .t { color: var(--tertiary); margin-right: 8px; }
.log .warn { color: var(--warning); }
.log .error { color: var(--error); }
.log .mine { color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; cursor: pointer; flex: none; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); color: var(--secondary); font: 13px var(--mono);
}
.cmd { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 12px; padding: 6px 6px 6px 14px; }
.cmd-prompt { color: var(--tertiary); font-family: var(--mono); }
.cmd-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-family: var(--mono); min-height: 38px; font-size: 16px; }

/* ---------- sheet & toast ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet-card {
  position: relative; width: 100%; max-width: 420px; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 10px; animation: rise .22s ease-out;
}
@media (min-width: 640px) { .sheet { align-items: center; } .sheet-card { border-radius: 18px; } }
.sheet-title { font-size: 17px; font-weight: 600; text-align: center; }
.sheet-text { color: var(--secondary); text-align: center; font-size: 14px; }
.sheet-buttons { display: grid; gap: 8px; margin-top: 4px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  background: var(--surface-2); color: var(--fg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* ---------- map ---------- */
.view-map { gap: 0; }
.map-frame-wrap {
  height: calc(100dvh - 150px - env(safe-area-inset-bottom) - env(safe-area-inset-top));
  min-height: 320px; border-radius: var(--radius); overflow: hidden; background: var(--surface);
  margin: -4px calc(-1 * max(16px, env(safe-area-inset-left)) + 8px) 0;
}
@media (min-width: 900px) { .map-frame-wrap { height: calc(100vh - 120px); margin: 0; } }
.map-frame { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- switch ---------- */
.row-note { display: block; color: var(--tertiary); font-size: 12px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- status ---------- */
.groups { display: grid; gap: 16px; }
.hdot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--tertiary); }
.hdot.ok { background: var(--success); }
.hdot.warn { background: var(--warning); }
.hdot.error { background: var(--error); }
.hdot.info { background: var(--accent); }
.summary { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: inherit; text-decoration: none; }
.summary:hover { background: var(--surface-2); }
.chev { color: var(--tertiary); font-size: 22px; line-height: 1; }
.hero-title.warnc { color: var(--warning); }
.hero-title.bad { color: var(--error); }
.check .who small { white-space: normal; }
.check .state { font-size: 13px; color: var(--secondary); flex: none; }
.check.error .state { color: var(--error); }
.check.warn .state { color: var(--warning); }