:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: #dde3ee;
  --text: #0f172a;
  --muted: #5b6577;
  --accent: #0891b2;
  --accent-soft: #cff3fa;
  --critical: #dc2626;
  --high: #ea580c;
  --medium: #ca8a04;
  --low: #2563eb;
  --info: #64748b;
  --ok: #16a34a;
  --p1-bg: #fee2e2; --p1-fg: #991b1b;
  --p2-bg: #ffedd5; --p2-fg: #9a3412;
  --p3-bg: #fef9c3; --p3-fg: #854d0e;
  --p4-bg: #e2e8f0; --p4-fg: #334155;
  --kev-bg: #7f1d1d; --kev-fg: #fff;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 4px 16px rgb(15 23 42 / .05);
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #121b2d; --surface-2: #19243a; --border: #24314a;
    --text: #e6ebf5; --muted: #93a0b8; --accent: #22d3ee; --accent-soft: #0e3a46;
    --critical: #f87171; --high: #fb923c; --medium: #facc15; --low: #60a5fa; --info: #94a3b8; --ok: #4ade80;
    --p1-bg: #4c1414; --p1-fg: #fecaca; --p2-bg: #4a2410; --p2-fg: #fed7aa; --p3-bg: #3f3510; --p3-fg: #fef08a; --p4-bg: #1f2a40; --p4-fg: #cbd5e1;
    --kev-bg: #dc2626; --kev-fg: #fff;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #121b2d; --surface-2: #19243a; --border: #24314a;
  --text: #e6ebf5; --muted: #93a0b8; --accent: #22d3ee; --accent-soft: #0e3a46;
  --critical: #f87171; --high: #fb923c; --medium: #facc15; --low: #60a5fa; --info: #94a3b8; --ok: #4ade80;
  --p1-bg: #4c1414; --p1-fg: #fecaca; --p2-bg: #4a2410; --p2-fg: #fed7aa; --p3-bg: #3f3510; --p3-fg: #fef08a; --p4-bg: #1f2a40; --p4-fg: #cbd5e1;
  --kev-bg: #dc2626; --kev-fg: #fff;
  --shadow: 0 1px 2px rgb(0 0 0 / .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  overflow-x: hidden;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; flex: none; }
h2, h3 { margin: 0; line-height: 1.25; }

/* ---------- Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.updated { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 12px; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface-2); color: var(--text); }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 12px; font-size: 13px; background: var(--p3-bg); color: var(--p3-fg); }

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

/* ---------- Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 10.5px; font-weight: 500; min-width: 0;
}
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tab-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--critical); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- Generic blocks */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 10px; }
.section-title h2 { font-size: 16px; }
.section-title small { color: var(--muted); font-size: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.digest { padding: 16px; }
.digest .eyebrow { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.digest .eyebrow svg { width: 14px; height: 14px; color: var(--accent); }
.digest h2 { font-size: 20px; margin: 6px 0 8px; letter-spacing: -.01em; }
.digest p { margin: 0; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.kpi { padding: 10px 8px; text-align: center; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.kpi b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); }
.kpi.alert b { color: var(--critical); }

.actions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.action { display: flex; gap: 10px; align-items: flex-start; padding: 12px; cursor: pointer; }
.action:hover { border-color: var(--accent); }
.action p { margin: 0; }

.watch { margin: 0; padding-left: 18px; color: var(--muted); }
.watch li { margin: 4px 0; }

/* ---------- Badges */
.prio { flex: none; display: inline-block; padding: 2px 7px; border-radius: 7px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; }
.prio.P1 { background: var(--p1-bg); color: var(--p1-fg); }
.prio.P2 { background: var(--p2-bg); color: var(--p2-fg); }
.prio.P3 { background: var(--p3-bg); color: var(--p3-fg); }
.prio.P4 { background: var(--p4-bg); color: var(--p4-fg); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 7px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.kev { background: var(--kev-bg); color: var(--kev-fg); }
.badge.ai { background: var(--accent-soft); color: var(--accent); }
.badge.new { background: var(--accent); color: var(--surface); }
.sev { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.sev::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sev.critical { color: var(--critical); } .sev.high { color: var(--high); } .sev.medium { color: var(--medium); } .sev.low { color: var(--low); } .sev.info { color: var(--info); }

/* ---------- Items list */
.list { display: grid; gap: 10px; }
.item { padding: 12px 14px; cursor: pointer; border-left: 4px solid var(--border); }
.item.sev-critical { border-left-color: var(--critical); }
.item.sev-high { border-left-color: var(--high); }
.item.sev-medium { border-left-color: var(--medium); }
.item.sev-low { border-left-color: var(--low); }
.item:hover { border-color: var(--accent); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.item h3 { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.item p { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.item-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { padding: 1px 7px; border-radius: 999px; font-size: 11.5px; background: var(--surface-2); color: var(--text); }

/* ---------- Filters */
.filters { display: grid; gap: 10px; margin-bottom: 12px; }
.search {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; margin: 0 -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.count { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }

/* ---------- Products */
.product { padding: 14px; }
.product-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.product h3 { font-size: 16px; }
.product .cat { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0 8px; }
.stat { text-align: center; padding: 6px 2px; border-radius: 10px; background: var(--surface-2); }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--ok), var(--medium), var(--critical)); }
.risk-note { margin: 10px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--p1-bg); color: var(--p1-fg); font-size: 13px; }
.product-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500;
  text-decoration: none; cursor: pointer;
}
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn:hover { border-color: var(--accent); }

/* ---------- Alternatives */
details.alt-group { padding: 0; overflow: hidden; }
details.alt-group summary { list-style: none; padding: 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
details.alt-group summary::-webkit-details-marker { display: none; }
details.alt-group summary::after { content: "›"; font-size: 22px; color: var(--muted); transition: transform .2s; }
details.alt-group[open] summary::after { transform: rotate(90deg); }
.alt-body { padding: 0 14px 14px; }
.alt-body > p { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.alt { padding: 10px 0; border-top: 1px solid var(--border); }
.alt h4 { margin: 0 0 4px; font-size: 14.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.alt p { margin: 2px 0; font-size: 13px; }
.alt .pro::before { content: "+ "; color: var(--ok); font-weight: 700; }
.alt .con::before { content: "− "; color: var(--critical); font-weight: 700; }
.type { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.flagged { border-color: var(--critical); }
.grid2 { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.tool { padding: 12px 14px; }
.tool h4 { margin: 0 0 2px; font-size: 14.5px; }
.tool .cat { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.tool p { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- Sheet */
.sheet {
  width: 100%; max-width: 760px; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgb(2 6 23 / .55); }
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (min-width: 760px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet-inner { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 16px 16px 8px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 17px; overflow-wrap: anywhere; padding-top: 8px; }
.sheet-body { overflow-y: auto; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.sheet-body p { margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.ai-box { padding: 12px; border-radius: 12px; background: var(--accent-soft); }
.ai-box p:last-child { margin-bottom: 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 16px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.src { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.src .ok { color: var(--ok); } .src .ko { color: var(--critical); }
.small { font-size: 12px; color: var(--muted); }
