:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1f3a5f; --accent2: #2563eb; --up: #e5484d; --down: #3e63dd; --ok: #12a150; --warn: #d97706; --bad: #dc2626;
  --chip: #eef2f7; --tab: rgba(255,255,255,.92);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b111b; --card: #141c28; --text: #e5e9f0; --muted: #8b96a8; --line: #253041;
  --accent: #8fb3e8; --accent2: #60a5fa; --chip: #1d2838; --tab: rgba(16,23,34,.92);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111b; --card: #141c28; --text: #e5e9f0; --muted: #8b96a8; --line: #253041;
    --accent: #8fb3e8; --accent2: #60a5fa; --chip: #1d2838; --tab: rgba(16,23,34,.92);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
body { padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.up { color: var(--up); } .down { color: var(--down); } .ok { color: var(--ok); } .bad { color: var(--bad); }

.topbar { position: sticky; top: env(safe-area-inset-top); z-index: 5; display: flex; justify-content: space-between;
  align-items: center; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.app-title { font-weight: 800; font-size: 20px; color: var(--accent); }
.top-actions { display: flex; gap: 6px; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font-size: 17px; }
.status-bar { margin: 10px 16px 0; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: #fff4e5; color: #7a4100; border: 1px solid #f5c27a; }
:root[data-theme="dark"] .status-bar { background: #2b1d07; color: #fbd38d; border-color: #5c3d0a; }

main { padding: 8px 16px 16px; max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px 0; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.kpi { background: var(--chip); border-radius: 12px; padding: 10px 12px; }
.kpi .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--chip); font-size: 12.5px; margin: 2px 4px 2px 0; }
.chip.a { background: #dcfce7; color: #166534; } .chip.b { background: #e0e7ff; color: #3730a3; }
.chip.off { opacity: .55; } .chip.warn { background: #fee2e2; color: #991b1b; }
.rules { list-style: none; margin: 0; padding: 0; }
.rules li { padding: 11px 2px; border-bottom: 1px solid var(--line); font-size: 16px; display: flex; gap: 10px; }
.rules li:last-child { border-bottom: 0; }
.rules .n { flex: 0 0 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--card);
  font-size: 13px; display: grid; place-items: center; font-weight: 700; }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.chart { width: 100%; border-radius: 10px; border: 1px solid var(--line); margin: 8px 0; background: #fff; }
.commentary { white-space: pre-wrap; font-size: 15px; line-height: 1.65; }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent2); }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.list-item { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.list-item:last-child { border-bottom: 0; }
.list-item a { color: var(--accent2); text-decoration: none; }
.empty { text-align: center; padding: 26px 8px; color: var(--muted); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--tab); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar button { background: none; border: 0; color: var(--muted); font-size: 11px; display: flex; flex-direction: column;
  align-items: center; gap: 1px; padding: 4px 0; }
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); font-weight: 700; }
.tabbar button.active span { filter: none; opacity: 1; }

.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.lock-box { text-align: center; width: 100%; max-width: 320px; }
.lock-logo { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 18px; background: var(--accent); color: var(--card);
  font-size: 34px; font-weight: 800; display: grid; place-items: center; }
.lock h1 { font-size: 20px; margin: 6px 0 2px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 18px 0 22px; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots i.on { background: var(--accent); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.keypad button { height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 24px; font-weight: 600; aspect-ratio: 1; margin: 0 auto; width: 64px; }
.keypad button.txt { font-size: 14px; border: 0; background: none; }
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; }
