:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #1d1f23;
  --muted: #676b72;
  --line: #e2e0d9;
  --accent: #1f4e79;
  --accent-soft: #e6eef6;
  --neg: #c8261b;
  --neg-soft: #fdebe7;
  --pos: #2f7a43;
  --gov: #b0000f;
  --warn-bg: #fff6d6;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
h1 { font-size: 26px; line-height: 1.2; margin: 8px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 18px 0 8px; display: flex; align-items: baseline; gap: 8px; }
h2 .more { margin-left: auto; font-size: 13px; font-weight: 400; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.container { max-width: 1240px; margin: 0 auto; padding: 16px 20px 48px; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 54px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 1000; }
.brand { color: #fff; text-decoration: none; font-weight: 650; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 40% 40%, #ffe14d, #ff8c00 55%, #c40000); }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a { color: #c9cbd0; text-decoration: none; padding: 7px 11px; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { color: #fff; background: #2d3036; }
.topbar nav a[aria-current] { color: #fff; background: #383c44; }
.logout { margin-left: auto; display: flex; gap: 10px; align-items: center; color: #9a9da3; font-size: 13px; }
.logout .link { color: #c9cbd0; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 7px; border: 1px solid #cfcdc5; background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #a9a79f; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #183f63; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--neg); }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid #cfcdc5; border-radius: 7px; padding: 7px 10px; min-height: 36px; }
textarea { width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check, label.radio { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #cfcdc5; background: var(--surface); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; color: var(--ink); cursor: pointer; text-decoration: none; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.topic[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.chip small { opacity: 0.7; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.inline { display: inline-flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.stack { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.stack input, .stack textarea { width: 100%; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.warn { background: var(--warn-bg); border: 1px solid #f0dc8a; padding: 10px 14px; border-radius: var(--radius); }
.error { color: var(--neg); }
.ok-msg { background: #e8f4ec; border: 1px solid #bfe0c9; padding: 8px 12px; border-radius: var(--radius); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; }

/* Dashboard */
.dash { padding: 14px 20px 40px; max-width: 1600px; margin: 0 auto; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 12px; }
.custom-range { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.custom-range label { flex-direction: row; align-items: center; }
.selects { display: flex; gap: 8px; flex-wrap: wrap; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; }
.map-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: relative; }
#map .base-tiles { filter: grayscale(1) contrast(0.9) brightness(1.05); }
#map { height: calc(100vh - 190px); min-height: 460px; background: #e9e7e0; }
.legend { position: absolute; left: 12px; bottom: 34px; z-index: 500; background: rgba(255, 255, 255, 0.94); border-radius: 6px; padding: 6px 10px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.legend-bar { width: 120px; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #ffe14d, #ffc21a 35%, #ff8c00 60%, #f24b0f 80%, #c40000); }
.map-note { margin: 0; padding: 7px 12px; font-size: 12px; border-top: 1px solid var(--line); }
.side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow-y: auto; max-height: calc(100vh - 150px); }
.side h2:first-of-type { margin-top: 10px; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; }
.kpi b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.neg b { color: var(--neg); }
.kpi.gov { border-color: #f1b8b3; background: #fff7f6; }
.kpi.gov b { color: var(--gov); }
.period { font-size: 12px; margin: 8px 0 0; }
.bars { display: flex; flex-direction: column; gap: 5px; }
.bar { display: grid; grid-template-columns: 130px 1fr 36px; gap: 8px; align-items: center; background: none; border: 0; padding: 2px 0; font: inherit; font-size: 13px; text-align: left; cursor: pointer; color: var(--ink); }
.bar:hover .bar-label { color: var(--accent); }
.bar-track { position: relative; height: 10px; background: #f0efea; border-radius: 5px; overflow: hidden; }
.bar-track i { position: absolute; left: 0; top: 0; bottom: 0; background: #c9c7bf; border-radius: 5px; }
.bar-track i.neg { background: var(--neg); }
.bar-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.problem-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.problem-list a { text-decoration: none; color: var(--ink); }
.problem-list a:hover { color: var(--accent); }
.problem-list span { display: block; font-size: 12px; }
.gov-text { color: var(--gov); font-weight: 600; }
.queue-card { margin-top: 16px; }

/* Message cards */
.items { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid #c9c7bf; border-radius: var(--radius); padding: 10px 14px; }
.item.s-negative { border-left-color: #ff8c00; }
.item.p2 { border-left-color: var(--neg); }
.item.p3 { border-left-color: var(--gov); background: #fffafa; }
.item header { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
.item .meta { color: var(--muted); }
.item .text { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item .parent { margin: 6px 0 0; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted); font-size: 13px; }
.item footer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; }
.item .addr { color: var(--muted); }
.item.updated { opacity: 0.65; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #efeee9; font-size: 12px; color: var(--ink); text-decoration: none; }
.tag.negative { background: var(--neg-soft); color: var(--neg); }
.tag.positive { background: #e6f3ea; color: var(--pos); }
.tag.gov { background: var(--gov); color: #fff; font-weight: 600; }
.tag.hi { background: #ffe1d6; color: #9d2a00; font-weight: 600; }
.tag.problem { background: var(--accent-soft); color: var(--accent); }
.status-buttons { margin-left: auto; display: inline-flex; gap: 4px; flex-wrap: wrap; }
.status-buttons button { border: 1px solid #d8d6ce; background: var(--surface); border-radius: 6px; padding: 3px 8px; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted); }
.status-buttons button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
dialog { border: 0; border-radius: 10px; padding: 18px 20px; width: min(760px, calc(100vw - 32px)); max-height: 85vh; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(20, 22, 26, 0.45); }
dialog h2 { margin-top: 0; }
dialog .close { position: absolute; right: 12px; top: 8px; background: none; border: 0; font-size: 26px; cursor: pointer; color: var(--muted); }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 10px; border-bottom: 1px solid #efeee9; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table.compact th { width: 40%; }
.table a { text-decoration: none; }
.sources tr.off { opacity: 0.5; }
.pf { display: inline-block; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 4px; margin-right: 4px; color: #fff; vertical-align: 1px; }
.pf-tg { background: #2a9ed8; }
.pf-vk { background: #2c6fd1; }
.status { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #efeee9; }
.st-new { background: #ffe9c2; color: #8a4b00; }
.st-in_work { background: #fff3c4; color: #7a5a00; }
.st-done { background: #e6f3ea; color: var(--pos); }
.st-ignored { color: var(--muted); }
.st-error { background: var(--neg-soft); color: var(--neg); }

/* Reports */
.report-grid { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 20px; align-items: start; }
.builder { display: flex; flex-direction: column; gap: 12px; }
.builder h2 { margin: 0; }
.builder fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.builder legend { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.kind-pick { flex-direction: row !important; flex-wrap: wrap; gap: 14px !important; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
.builder select, .builder input[type="date"] { width: 100%; }
.actions { display: flex; gap: 8px; }
.save { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.save summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.save[open] { gap: 10px; }
.save > * + * { margin-top: 10px; }
.deliveries { list-style: none; padding: 0; margin: 0; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.deliveries .ok b { color: var(--pos); }
.deliveries .fail b { color: var(--neg); }
.report-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.report-screen { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 26px; }
.problem-tools { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 14px; }
.note-form { width: 100%; display: flex; gap: 8px; align-items: flex-end; }
.note-form label { flex: 1; }

/* Report body on screen (the PDF has its own styles) */
.report-screen .r-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.report-screen h1 { margin: 4px 0; }
.report-screen .r-sub, .report-screen .r-period, .report-screen .r-muted, .report-screen .r-note { color: var(--muted); margin: 2px 0; }
.report-screen h2 { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 24px; }
.report-screen .r-governor h2 { color: var(--gov); border-color: #f1b8b3; }
.r-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.r-kpis > div { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.r-kpis b { display: block; font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }
.r-kpis .neg b { color: var(--neg); }
.r-kpis .gov { border-color: #f1b8b3; }
.r-kpis .gov b { color: var(--gov); }
.r-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.r-table th { text-align: left; font-size: 12px; color: var(--muted); padding: 7px 8px; border-bottom: 1px solid var(--ink); }
.r-table td { padding: 7px 8px; border-bottom: 1px solid #efeee9; vertical-align: top; }
.r-facts th { width: 180px; border-bottom: 1px solid #efeee9; }
.q { border-left: 3px solid #d0cfc8; padding: 4px 0 4px 12px; margin: 10px 0; }
.q.s-negative { border-color: #ff6a1a; }
.q.s-positive { border-color: var(--pos); }
.q-meta { font-size: 12px; color: var(--muted); }
.q-text { white-space: pre-wrap; margin: 3px 0; overflow-wrap: anywhere; }
.q-link { font-size: 11px; color: var(--muted); word-break: break-all; }
.tone.negative { color: var(--neg); }
.tone.positive { color: var(--pos); }
.tone-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; font-size: 12px; color: #fff; }
.tone-bar span { padding: 5px 8px; white-space: nowrap; overflow: hidden; }
.tone-bar .negative { background: #d33a17; }
.tone-bar .neutral { background: #8a8d93; }
.tone-bar .positive { background: #3a8a4f; }
.r-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.settings-grid h2 { margin-top: 0; }

@media (max-width: 1000px) {
  .dash-grid, .report-grid { grid-template-columns: 1fr; }
  #map .base-tiles { filter: grayscale(1) contrast(0.9) brightness(1.05); }
#map { height: 60vh; min-height: 360px; }
  .side { max-height: none; }
}
@media (max-width: 640px) {
  .container, .dash { padding: 12px 16px 40px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand { font-size: 0; gap: 0; }
  .logout span { display: none; }
  .r-kpis { grid-template-columns: repeat(2, 1fr); }
  .report-screen { padding: 14px; }
  .table { display: block; overflow-x: auto; }
  .status-buttons { margin-left: 0; }
  .bar { grid-template-columns: 110px 1fr 32px; }
}
