:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6d7380;
  --line: #e4e6ea;
  --accent: #2d6cff;
  --accent-soft: #e8efff;
  --green: #1f9d55;
  --green-soft: #e3f6ea;
  --red: #e0453a;
  --red-soft: #fde9e7;
  --amber: #c98a00;
  --amber-soft: #fff4d6;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1013;
    --card: #1b1d22;
    --text: #eceef2;
    --muted: #8f95a1;
    --line: #2a2d34;
    --accent: #5b8cff;
    --accent-soft: #1e2a47;
    --green: #3ccf7c;
    --green-soft: #15301f;
    --red: #ff6b60;
    --red-soft: #3a1c1a;
    --amber: #f2b330;
    --amber-soft: #3a2e12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
     color: var(--muted); margin: 22px 4px 8px; }

.loading, .empty { color: var(--muted); text-align: center; padding: 40px 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row .side { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--line); }

.hero {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px;
}
.hero .num { font-size: 44px; font-weight: 700; line-height: 1; }
.hero .label { color: var(--muted); }

.plate {
  display: inline-block;
  font: 600 13px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  border: 1.5px solid var(--text);
  border-radius: 5px;
  padding: 3px 6px;
  letter-spacing: .03em;
  white-space: nowrap;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.dot.off { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.dot.idle { background: var(--muted); }

.badge { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.badge.in { background: var(--green-soft); color: var(--green); }
.badge.out { background: var(--red-soft); color: var(--red); }
.badge.unknown { background: var(--amber-soft); color: var(--amber); }
.badge.gray { background: var(--line); color: var(--muted); }

.thumb {
  width: 64px; height: 44px; border-radius: 8px; object-fit: cover; flex: none;
  background: var(--line);
}

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
.banner.warn { background: var(--amber-soft); color: var(--amber); }
.banner.ok { background: var(--green-soft); color: var(--green); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input { flex: 1; }

.chips { display: flex; gap: 6px; margin: 0 0 12px; overflow-x: auto; }
.chip {
  border: 0; border-radius: 99px; padding: 7px 12px; font: inherit; font-size: 14px;
  background: var(--card); color: var(--text); white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; }

input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.sheet input, .sheet select { background: var(--bg); }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 2px 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }

button.btn {
  font: inherit; font-weight: 600;
  border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--accent); color: #fff; cursor: pointer;
}
button.btn.secondary { background: var(--accent-soft); color: var(--accent); }
button.btn.danger { background: var(--red-soft); color: var(--red); }
button.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
button.btn.wide { width: 100%; margin-top: 10px; }
button.btn:disabled { opacity: .5; }
button.icon {
  border: 0; background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 12px;
  font-size: 22px; line-height: 1; flex: none; cursor: pointer;
}

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px;
  padding: 8px 4px; border-radius: 8px;
}
.seg button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav input { flex: 1; text-align: center; }
.daynav button { flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px;
                 background: var(--card); color: var(--text); font-size: 18px; }

.frame { margin-top: 12px; border-radius: 10px; overflow: hidden; background: var(--bg); }
.frame img { width: 100%; display: block; }
.frame .msg { padding: 14px; font-size: 14px; }
.frame .msg.err { color: var(--red); }

nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav#tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 11px; padding: 8px 0 9px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
nav#tabs button svg { width: 24px; height: 24px; }
nav#tabs button.active { color: var(--accent); }

.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; z-index: 10;
}
.sheet-body {
  background: var(--card); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
.sheet-body h3 { margin: 0 0 4px; font-size: 18px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

.viewer {
  position: fixed; inset: 0; background: #000; z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
.viewer img { max-width: 100%; max-height: 100%; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px;
  z-index: 30; text-align: center; font-size: 14px;
}

.fatal { text-align: center; padding: 60px 16px; }
.fatal .big { font-size: 40px; }
