:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --line: #e8e8ed;
  --accent: #0071e3;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --shadow-hover: 0 2px 6px rgba(0,0,0,.06), 0 16px 40px rgba(0,0,0,.09);
  --risk-low: #34c759;
  --risk-med: #ff9f0a;
  --risk-high: #ff3b30;
  --risk-crit: #d70015;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(245,245,247,.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.brand-sub { font-size: 13px; color: var(--text-3); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.updated { font-size: 13px; color: var(--text-3); }
.btn-refresh {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  padding: 8px 18px;
  border-radius: 980px;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, opacity .2s ease;
}
.btn-refresh:hover { background: #0077ed; }
.btn-refresh:active { transform: scale(.96); }
.btn-refresh.loading { opacity: .6; pointer-events: none; }

.btn-how {
  border: 1px solid var(--line); background: var(--surface); color: var(--accent);
  font-size: 14px; font-weight: 500; font-family: inherit;
  padding: 8px 16px; border-radius: 980px; cursor: pointer;
  transition: background .15s ease, transform .12s ease;
}
.btn-how:hover { background: #f0f6ff; }
.btn-how:active { transform: scale(.96); }

/* ---------- How it works modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.32);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative; background: var(--surface); border-radius: 22px;
  max-width: 540px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 34px 34px 28px; box-shadow: 0 24px 70px rgba(0,0,0,.28);
  animation: pop .22s cubic-bezier(.2,.8,.3,1.1);
}
@keyframes pop { from { transform: scale(.94) translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close {
  position: absolute; top: 16px; right: 18px; border: none; background: transparent;
  font-size: 28px; line-height: 1; color: var(--text-3); cursor: pointer; padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; margin: 0 0 6px; }
.modal-intro { font-size: 15px; color: var(--text-2); line-height: 1.5; margin: 0 0 22px; }
.how-steps { list-style: none; margin: 0 0 24px; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.how-step { display: flex; gap: 14px; align-items: flex-start; }
.how-num {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.how-text { display: flex; flex-direction: column; gap: 2px; }
.how-text b { font-size: 15px; font-weight: 600; }
.how-text span { font-size: 14px; color: var(--text-2); line-height: 1.45; }
.how-flow {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
}
.flow-node { font-size: 13px; font-weight: 500; background: #fff; border: 1px solid var(--line);
  border-radius: 980px; padding: 6px 12px; white-space: nowrap; }
.flow-node.accent { background: rgba(0,113,227,.1); border-color: transparent; color: var(--accent); font-weight: 600; }
.flow-arrow { color: var(--text-3); font-size: 14px; }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }

/* ---------- Filters ---------- */
.filters {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.filter-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.filter-foot { display: flex; align-items: center; gap: 12px; min-height: 8px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.active-filters .chip { background: rgba(0,113,227,.1); color: var(--accent); cursor: default; }
.btn-clear {
  border: none; background: #f0f0f3; color: var(--text-2); font-family: inherit;
  font-size: 13px; font-weight: 500; padding: 6px 14px; border-radius: 980px; cursor: pointer;
}
.btn-clear:hover { background: #e6e6eb; }
.toggle-pill {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  font-family: inherit; font-size: 14px; font-weight: 500; padding: 9px 16px;
  border-radius: 980px; cursor: pointer; transition: all .15s ease; white-space: nowrap;
}
.toggle-pill.active { background: var(--risk-high); border-color: var(--risk-high); color: #fff; }
input[type="date"] {
  appearance: none; -webkit-appearance: none; font-family: inherit; font-size: 14px;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; cursor: pointer;
}
input[type="date"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 150px; }
.field.grow { flex: 1; min-width: 200px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: "⌄"; position: absolute; right: 12px; top: 46%;
  transform: translateY(-50%); color: var(--text-3); pointer-events: none; font-size: 14px;
}
select, input[type="search"] {
  appearance: none; -webkit-appearance: none;
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 32px 9px 12px;
  width: 100%;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="search"] { padding-right: 12px; cursor: text; }
select:focus, input[type="search"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,.15);
}
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; height: 28px; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat-value { font-size: 40px; font-weight: 700; letter-spacing: -0.04em; margin: 6px 0 2px; line-height: 1; }
.stat-foot { font-size: 12px; color: var(--text-3); }
.stat-card.accent-red .stat-value { color: var(--risk-high); }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: 24px; align-items: start; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; background: #ededf0; border-radius: 9px; padding: 2px; }
.segmented button {
  border: none; background: transparent; font-family: inherit;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  padding: 5px 12px; border-radius: 7px; cursor: pointer; transition: all .15s ease;
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Feed ---------- */
.feed { display: flex; flex-direction: column; }
.article {
  display: flex; gap: 16px; padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  transition: background .15s ease;
}
.article:last-child { border-bottom: none; }
.article:hover { background: var(--surface-2); }
.risk-badge {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700; color: #fff;
}
.risk-0,.risk-1,.risk-2,.risk-3 { background: var(--risk-low); }
.risk-4,.risk-5,.risk-6 { background: var(--risk-med); }
.risk-7,.risk-8 { background: var(--risk-high); }
.risk-9,.risk-10 { background: var(--risk-crit); }
.risk-na { background: #c7c7cc; }
.article-body { min-width: 0; flex: 1; }
.article-title { font-size: 15px; font-weight: 600; line-height: 1.35; margin: 0 0 4px; }
.article-title a { color: var(--text); text-decoration: none; }
.article-title a:hover { color: var(--accent); }
.article-summary { font-size: 14px; color: var(--text-2); line-height: 1.45; margin: 0 0 8px; }
.article-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; color: var(--text-3); }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 980px;
  font-size: 11px; font-weight: 600; background: #f0f0f3; color: var(--text-2);
}
.chip.cat { background: rgba(0,113,227,.1); color: var(--accent); }
.chip.trip { background: #efe9fb; color: #6c3fd4; }
.chip.role { background: #eaf7ee; color: #1f8a4c; }
.meta-dot::before { content: "·"; margin: 0 2px; color: var(--line); }

/* ---------- Category bars ---------- */
.catbars { padding: 16px 22px 20px; display: flex; flex-direction: column; gap: 14px; }
.catbar-row { display: flex; flex-direction: column; gap: 5px; }
.catbar-top { display: flex; justify-content: space-between; font-size: 13px; }
.catbar-name { font-weight: 500; }
.catbar-count { color: var(--text-3); }
.catbar-track { height: 7px; background: #ededf0; border-radius: 980px; overflow: hidden; }
.catbar-fill { height: 100%; border-radius: 980px; background: var(--accent); transition: width .4s ease; }

/* ---------- Location list ---------- */
.loclist { padding: 8px 12px 14px; }
.locrow {
  display: flex; align-items: center; gap: 12px; padding: 10px 10px;
  border-radius: 12px; transition: background .15s ease;
}
.locrow:hover { background: var(--surface-2); cursor: pointer; }
.loc-pill {
  flex: 0 0 auto; min-width: 30px; height: 30px; padding: 0 8px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
}
.loc-info { min-width: 0; flex: 1; }
.loc-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-sub { font-size: 12px; color: var(--text-3); }

/* ---------- Misc ---------- */
.empty { padding: 40px 22px; text-align: center; color: var(--text-3); font-size: 14px; }
.hidden { display: none; }
.footer {
  max-width: 1180px; margin: 0 auto; padding: 20px 24px 40px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-3);
}
.autostatus { display: inline-flex; align-items: center; gap: 6px; }
.autostatus::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--risk-low); box-shadow: 0 0 0 0 rgba(52,199,89,.6);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52,199,89,.5); }
  70% { box-shadow: 0 0 0 7px rgba(52,199,89,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,199,89,0); }
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 540px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .brand-sub { display: none; }
  .stat-value { font-size: 32px; }
}
