:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #687080;
  --accent: #2557d6;
  --accent-text: #ffffff;
  --red: #d33a2c;
  --red-bg: #fdecea;
  --yellow: #b7791f;
  --yellow-bg: #fdf5e6;
  --green: #1f8a4c;
  --green-bg: #e8f6ee;
  --info: #2557d6;
  --info-bg: #eaf0fd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --border: #2e333c;
    --text: #e8eaee;
    --muted: #9aa2b1;
    --accent: #5b8cff;
    --accent-text: #0b0d10;
    --red: #ff6b5e;
    --red-bg: #3a1d1a;
    --yellow: #f0b45a;
    --yellow-bg: #3a2e18;
    --green: #4cc982;
    --green-bg: #17331f;
    --info: #7ea4ff;
    --info-bg: #1b2640;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h2 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 30%, transparent 32%), conic-gradient(var(--accent) 0 25%, color-mix(in srgb, var(--accent) 25%, transparent) 0);
}
.tag { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; align-items: center; gap: 12px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 60px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.file input { display: none; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.stat.red .n { color: var(--red); }
.stat.yellow .n { color: var(--yellow); }
.stat.green .n { color: var(--green); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 9px 14px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.check { display: inline-flex; gap: 6px; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); max-width: 760px; }
.card .row { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.card .row input { flex: 1; min-width: 180px; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.firm-name { font-weight: 600; }
.firm-sub { color: var(--muted); font-size: 12px; }
.neg { color: var(--red); }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; background: var(--border); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }
.dot.pending { background: transparent; border: 2px dashed var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.yellow { background: var(--yellow-bg); color: var(--yellow); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.mute { background: var(--surface-2); color: var(--muted); }

.reasons { margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.reasons li.red { color: var(--red); }
.reasons li.yellow { color: var(--yellow); }

.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alert-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
}
.alert-item.red { border-left-color: var(--red); }
.alert-item.yellow { border-left-color: var(--yellow); }
.alert-item.green { border-left-color: var(--green); }
.alert-item.info { border-left-color: var(--info); }
.alert-item.unseen { box-shadow: var(--shadow); }
.alert-item.seen { opacity: .65; }
.alert-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

dialog {
  width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
.d-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.d-head h2 { font-size: 19px; }
.d-body { padding: 18px 22px 24px; display: grid; gap: 20px; }
.d-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; }
.kv div span { display: block; color: var(--muted); font-size: 12px; }
.fin-table { width: 100%; border-collapse: collapse; }
.fin-table th, .fin-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.fin-table th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; }
.fin-table th:first-child, .fin-table td:first-child { text-align: left; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 550; z-index: 50;
}

@media (max-width: 720px) {
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .tag { display: none; }
  main { padding: 16px 16px 48px; }
  .grid th:nth-child(3), .grid td:nth-child(3),
  .grid th:nth-child(5), .grid td:nth-child(5),
  .grid th:nth-child(8), .grid td:nth-child(8) { display: none; }
}
