:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7c;
  --line: #dde2e8;
  --accent: #8a5a12;
  --accent-soft: #f5ead9;
  --link: #1f5fa8;
  --vh: #1e7b45;
  --hi: #4f9a3a;
  --mo: #b98a14;
  --lo: #c4652b;
  --vl: #9aa3ad;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --panel: #1b2129; --text: #e5e9ee; --muted: #9aa6b4; --line: #2c3540;
    --accent: #e0a64a; --accent-soft: #33281a; --link: #7db3ef; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --panel: #1b2129; --text: #e5e9ee; --muted: #9aa6b4; --line: #2c3540;
  --accent: #e0a64a; --accent-soft: #33281a; --link: #7db3ef; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.pad { padding: 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem;
  align-items: center; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); text-decoration: none; }
nav { display: flex; flex-wrap: wrap; gap: .25rem; }
nav a { padding: .45rem .7rem; border-radius: 6px; text-decoration: none; color: var(--text); white-space: nowrap; }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1400px; margin: 0 auto; padding: 1rem; }
main:focus { outline: none; }
.foot { max-width: 1400px; margin: 0 auto; padding: 1rem; font-size: .85rem; }
#alerts .alert { max-width: 1400px; margin: .75rem auto 0; padding: .6rem 1rem; border-radius: var(--radius); background: var(--accent-soft); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.card .num { font-size: 1.6rem; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: .85rem; }
a.card { text-decoration: none; color: inherit; }
a.card:hover { border-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.panel h2:first-child, .panel h3:first-child { margin-top: 0; }

.bars { display: grid; gap: .3rem; }
.bar { display: grid; grid-template-columns: minmax(110px, 40%) 1fr 3rem; gap: .5rem; align-items: center; font-size: .88rem; }
.bar .track { background: var(--bg); border-radius: 4px; height: 12px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; }
.bar .val { text-align: right; font-variant-numeric: tabular-nums; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.filters label { display: grid; gap: .15rem; font-size: .8rem; color: var(--muted); }
input, select, button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: .45rem .55rem; min-height: 40px;
}
button { cursor: pointer; }
.search { width: 100%; margin-bottom: .5rem; }
details.filter-box { margin-bottom: .75rem; }
details.filter-box summary { cursor: pointer; padding: .4rem 0; font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: .5rem; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); white-space: nowrap; font-size: .8rem; color: var(--muted); }
th button { all: unset; cursor: pointer; }
th button:focus-visible { outline: 2px solid var(--link); }
th[aria-sort="ascending"] button::after { content: " ▲"; }
th[aria-sort="descending"] button::after { content: " ▼"; }
tr:hover td { background: var(--bg); }
td.contact a { display: inline-block; padding: .15rem 0; overflow-wrap: anywhere; }
td.contact a[href^="tel:"] { white-space: nowrap; }
.name-btn { all: unset; cursor: pointer; color: var(--link); font-weight: 600; }
.name-btn:focus-visible { outline: 2px solid var(--link); }
.sub { font-size: .78rem; color: var(--muted); }

.score { display: inline-block; min-width: 2.4rem; text-align: center; padding: .1rem .35rem; border-radius: 5px; color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
.b-vh { background: var(--vh); } .b-hi { background: var(--hi); } .b-mo { background: var(--mo); }
.b-lo { background: var(--lo); } .b-vl { background: var(--vl); }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .4rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin: 0 .2rem .2rem 0; }

dialog { width: min(860px, 100vw - 1rem); max-height: 92vh; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: start; gap: 1rem; padding: .8rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.close { font-size: 1.4rem; line-height: 1; min-width: 40px; }
#detail-body { padding: 0 1rem 1rem; }
dl.kv { display: grid; grid-template-columns: 200px 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85rem; }
dl.kv dd { margin: 0; word-break: break-word; }
.sources li { margin-bottom: .3rem; word-break: break-all; }

@media (max-width: 760px) {
  main { padding: .75rem 16px; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dd { margin-bottom: .4rem; }
  .table-wrap { background: none; border: 0; overflow: visible; }
  table.cardify thead { display: none; }
  table.cardify, table.cardify tbody, table.cardify tr, table.cardify td { display: block; width: 100%; }
  table.cardify tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; padding: .4rem .2rem; }
  table.cardify td { border: 0; padding: .25rem .6rem; display: grid; grid-template-columns: 6.5rem 1fr; gap: .5rem; }
  table.cardify td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  table.cardify td:empty { display: none; }
  table.cardify td.contact a { padding: .35rem 0; }
  tr:hover td { background: none; }
}
