:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #15181d;
  --muted: #5e6672;
  --line: #dde1e6;
  --accent: #2f6fed;
  --on-accent: #ffffff;
  --ok: #1f9d55;
  --warn: #c98a04;
  --down: #d93636;
  --offline: #6b7280;
  --paused: #3b82f6;
  --danger: #d93636;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #eceef1;
    --muted: #9aa3ae;
    --line: #2c313a;
    --accent: #6c9bff;
    --on-accent: #0b1020;
    --ok: #34c77b;
    --warn: #f0b429;
    --down: #ff5c5c;
    --offline: #8b93a0;
    --paused: #6ea8ff;
    --danger: #ff5c5c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; color: inherit; }
#app { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: 14px 0 10px; }
.top h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
.top .sub { color: var(--muted); font-size: 12px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 11px; cursor: pointer; }
.back { border: 0; background: none; color: var(--accent); padding: 6px 4px; cursor: pointer; font-size: 16px; }

/* summary chips */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 14px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: left; cursor: pointer; box-shadow: var(--shadow); }
.chip b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.chip span { color: var(--muted); font-size: 12px; }
.chip[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: -1px; }
.chip.ok b { color: var(--ok); } .chip.warn b { color: var(--warn); } .chip.down b { color: var(--down); } .chip.offline b { color: var(--offline); }

/* site sections */
.site { margin: 18px 0 8px; display: flex; align-items: baseline; gap: 8px; }
.site h2 { font-size: 14px; margin: 0; color: var(--muted); font-weight: 600; }
.site small { color: var(--muted); font-size: 12px; }
.banner { background: color-mix(in srgb, var(--offline) 14%, var(--surface)); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 0 8px; font-size: 13px; }
.banner.alert { background: color-mix(in srgb, var(--down) 12%, var(--surface)); }

/* device cards */
.list { display: grid; gap: 8px; }
.card { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.card:active { transform: scale(.995); }
.card .name { font-weight: 600; }
.card .reason { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.card .meta { font-size: 12px; color: var(--muted); }
.card .seen { font-size: 12px; color: var(--muted); white-space: nowrap; align-self: start; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--offline); align-self: start; margin-top: 4px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.down { background: var(--down); }
.dot.offline { background: transparent; border: 2px solid var(--offline); } .dot.paused { background: var(--paused); }
.card.down { border-color: color-mix(in srgb, var(--down) 45%, var(--line)); }
.empty { color: var(--muted); text-align: center; padding: 40px 12px; }

/* detail */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; color: #fff; background: var(--offline); }
.pill.ok { background: var(--ok); } .pill.warn { background: var(--warn); color: #1b1300; } .pill.down { background: var(--down); } .pill.paused { background: var(--paused); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; margin: 10px 0; box-shadow: var(--shadow); }
.panel h3 { font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.row { display: grid; grid-template-columns: 12px 92px 1fr; gap: 10px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .label { color: var(--muted); font-size: 13px; }
.row .value { overflow-wrap: anywhere; }
.row .dot { margin-top: 3px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; padding: 8px 0 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.headline { margin: 2px 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.headline h2 { margin: 0; font-size: 22px; }
.reason-big { color: var(--muted); margin: 0 0 6px; overflow-wrap: anywhere; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 6px 0 14px; }
.btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 12px 10px; cursor: pointer; font-weight: 600; min-height: 46px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { grid-column: 1 / -1; }

.shot { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; margin: 6px 0 12px; background: #000; }
.log { list-style: none; margin: 0; padding: 0 0 10px; font-size: 13px; }
.log li { padding: 7px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 74px 1fr; gap: 8px; }
.log li:first-child { border-top: 0; }
.log time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.status-tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); margin-left: 4px; }

/* forms */
.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { font-size: 26px; margin: 0 0 4px; }
.field { display: grid; gap: 4px; margin: 12px 0; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
pre.code { background: var(--surface-2); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); width: min(92vw, 420px); padding: 18px; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 14px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.dialog-actions .btn { min-width: 96px; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw; z-index: 20; }

@media (max-width: 380px) {
  .chips { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 12px 78px 1fr; }
}

.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 12px; }
.push { margin-left: auto; }

.choice-list { display: grid; gap: 8px; margin: 4px 0 6px; }
.choice { display: grid; gap: 2px; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.choice b { font-size: 15px; }
.choice span { font-size: 13px; color: var(--muted); }
.keys { list-style: none; margin: 0 0 6px; padding: 0; }
.keys li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.keys li:first-child { border-top: 0; }
.keys li > span { flex: 1; display: grid; min-width: 0; overflow-wrap: anywhere; }
.keys small { color: var(--muted); font-size: 12px; }
