:root {
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #1b2640;
  --border: #26334f;
  --text: #e6ebf5;
  --muted: #94a3c0;
  --accent: #5b9dff;
  --accent-ink: #0b1120;
  --ok: #3ccf8e;
  --bad: #ff6b6b;
  --sev1: #5c6780;
  --sev2: #7c8aa5;
  --sev3: #f2c94c;
  --sev4: #ff9f43;
  --sev5: #ff5c5c;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5fa; --surface: #ffffff; --surface-2: #eef1f7; --border: #d8deea;
    --text: #131a2a; --muted: #5a6680; --accent: #2563eb; --accent-ink: #ffffff;
    --sev3: #b7860b; --sev4: #d9660b; --sev5: #d62f2f; --sev2: #64708a; --sev1: #8a94a8;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 650; letter-spacing: .01em; }
.run-status { font-size: .8rem; color: var(--muted); }
.icon-btn { background: none; border: 0; padding: 6px; margin-left: -6px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:active { background: var(--surface-2); }

main { padding: 12px 14px 24px; max-width: 760px; margin: 0 auto; outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 550;
}
.tabbar a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; line-height: 18px; text-align: center;
}
.badge.warn { background: var(--bad); color: #fff; }

/* chips & filters */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 999px; font-size: .88rem; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip .count { opacity: .75; margin-left: 4px; }
.filter-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.search {
  flex: 1 1 180px; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
.search:focus, input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); }
select.compact { padding: 9px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }

/* alert cards */
.card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px 12px 16px; margin-bottom: 10px; color: inherit; text-decoration: none; position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--sevc, var(--sev2)); }
.card.unread .title { font-weight: 650; }
.card.read { opacity: .78; }
.card-meta { display: flex; gap: 8px; align-items: center; font-size: .78rem; color: var(--muted); margin-bottom: 4px; flex-wrap: wrap; }
.card .title { font-size: 1rem; line-height: 1.35; margin: 0 0 4px; font-weight: 500; }
.card .brief { color: var(--muted); font-size: .9rem; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.sev {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-weight: 700;
  font-size: .72rem; color: var(--sevc); border: 1px solid currentColor; letter-spacing: .02em;
}
.sev-1 { --sevc: var(--sev1); } .sev-2 { --sevc: var(--sev2); } .sev-3 { --sevc: var(--sev3); }
.sev-4 { --sevc: var(--sev4); } .sev-5 { --sevc: var(--sev5); }
.pushed { font-size: .72rem; color: var(--muted); }

/* detail */
.detail h2 { font-size: 1.25rem; line-height: 1.3; margin: 8px 0 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.panel p { margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border);
  background: var(--surface-2); padding: 11px 16px; border-radius: 12px; font-weight: 600; text-decoration: none; color: var(--text);
  min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--border)); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.btn-row .btn { flex: 1 1 140px; }

/* lists (sources, health, settings) */
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 18px 4px 8px; font-weight: 650; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border);
  color: inherit; text-decoration: none; min-height: 56px;
}
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { width: 10px; height: 10px; border-radius: 50%; background: var(--sev1); flex: none; }
.status.ok { background: var(--ok); } .status.bad { background: var(--bad); } .status.off { background: transparent; border: 2px solid var(--sev1); }
.chev { color: var(--muted); flex: none; }

/* switch */
.switch { position: relative; width: 50px; height: 30px; 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; background: var(--border); border-radius: 15px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.field input[type=text], .field input[type=url], .field input[type=number], .field input[type=time], .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.field textarea { min-height: 80px; resize: vertical; }
.hint { font-size: .8rem; color: var(--muted); margin: 6px 2px 0; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-left: 1px solid var(--border); background: var(--surface-2); padding: 9px 0; font-weight: 650; min-height: 42px; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border-top: 1px solid var(--border); }
.setting-row:first-child { border-top: 0; }
.setting-row .label { flex: 1; }
.setting-row .label small { display: block; color: var(--muted); font-size: .8rem; }
.setting-row select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.setting-block { padding: 12px 14px; border-top: 1px solid var(--border); }
.setting-block:first-child { border-top: 0; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: .88rem; }
.tag button { border: 0; background: none; color: var(--muted); width: 26px; height: 26px; border-radius: 50%; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.tag button:active { background: var(--border); }
.add-inline { display: flex; gap: 8px; }
.add-inline input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); outline: none; }

.preview { margin-top: 10px; }
.preview li { margin-bottom: 8px; font-size: .9rem; }
.preview ol { padding-left: 20px; margin: 6px 0 0; }
.error-box { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--border)); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: .9rem; margin: 10px 0; overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: .85rem; margin: 6px 2px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 6px; }
.more { display: block; margin: 8px auto 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 550; z-index: 20;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.35); font-size: .92rem;
}
.skeleton { height: 84px; border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .switch span, .switch span::after { transition: none; } }
