:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14161a;
  --ink-2: #5b6270;
  --ink-3: #8b93a1;
  --line: #e3e6ec;
  --line-2: #eef0f4;
  --accent: #2f5597;
  --accent-soft: #eaf0fb;
  --good: #1a7f4b;
  --good-soft: #e7f6ee;
  --warn: #9a6400;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --radius: 12px;
}
html[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a20;
  --ink: #e9ecf1;
  --ink-2: #a3abba;
  --ink-3: #737b8a;
  --line: #262b34;
  --line-2: #1e222a;
  --accent: #6f9bff;
  --accent-soft: #1b2436;
  --good: #56d39a;
  --good-soft: #14291f;
  --warn: #e0b055;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
.top {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.top-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { font-size: 26px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.brand .sub { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.brand .dot { opacity: .5; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 9px 14px; font-size: 14px; font-weight: 550; cursor: pointer;
  font-family: inherit; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--line-2); filter: none; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  width: 38px; height: 38px; font-size: 16px; cursor: pointer; line-height: 1;
}

/* ---------- hero / search ---------- */
.hero { background: var(--panel); border-bottom: 1px solid var(--line); padding: 20px 0 16px; }
.searchbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 0 8px 0 14px; height: 50px;
  transition: border-color .15s, box-shadow .15s;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.s-icon { font-size: 20px; color: var(--ink-3); }
.searchbar input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 15.5px; color: var(--ink); font-family: inherit; height: 100%;
}
.clear {
  border: 0; background: var(--line); color: var(--ink-2); border-radius: 50%;
  width: 26px; height: 26px; cursor: pointer; font-size: 12px; line-height: 1;
}

.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px; margin-top: 14px; align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.field select, .field input {
  height: 40px; border: 1.5px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); padding: 0 10px;
  font-size: 14.5px; font-family: inherit; outline: none; width: 100%;
}
.field select:focus, .field input:focus { border-color: var(--accent); }
.range { display: flex; gap: 8px; }
.reset { height: 40px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 550;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 13px; padding: 0; line-height: 1; opacity: .7; }
.chip button:hover { opacity: 1; }

/* ---------- results ---------- */
main { padding: 20px 20px 40px; }
.resultbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.count { font-size: 14px; color: var(--ink-2); }
.count b { color: var(--ink); font-weight: 650; }
.spacer { flex: 1; }
.perpage { display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); }
.perpage select {
  height: 34px; border: 1.5px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); padding: 0 8px; font-family: inherit; font-size: 14px;
}

.tablewrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; font-weight: 650; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 14px; background: var(--bg); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0;
}
thead th[data-sort] { cursor: pointer; user-select: none; }
thead th[data-sort]:hover { color: var(--accent); }
thead th.num, td.num { text-align: right; }
tbody tr { border-bottom: 1px solid var(--line-2); cursor: pointer; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child { border-bottom: 0; }
td { padding: 11px 14px; vertical-align: middle; font-size: 14.5px; }
.c-name { max-width: 320px; }
.name-btn { font-weight: 600; color: var(--ink); display: block; text-align: left; background: none; border: 0; padding: 0; font-size: 14.5px; font-family: inherit; cursor: pointer; }
.name-btn:hover { color: var(--accent); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 650; padding: 1px 7px;
  border-radius: 999px; margin-left: 7px; vertical-align: 1px;
}
.badge.own { background: var(--good-soft); color: var(--good); }
.muted { color: var(--ink-3); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }
td.num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }
.empty .big { font-size: 40px; margin: 0 0 6px; }

.pager { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.pager button {
  min-width: 38px; height: 38px; border: 1.5px solid var(--line);
  background: var(--panel); color: var(--ink); border-radius: 9px;
  cursor: pointer; font-size: 14px; font-family: inherit; padding: 0 10px;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 650; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager .gap { align-self: center; color: var(--ink-3); }

/* ---------- drawer ---------- */
/* The `hidden` attribute must win over the display rules below: both `.modal`
   and `.drawer` set `display: flex`, which otherwise beats the UA stylesheet's
   `[hidden] { display: none }` and leaves the overlay permanently on screen. */
.drawer[hidden], .modal[hidden] { display: none; }

.drawer { position: fixed; inset: 0; z-index: 60; background: rgba(10,14,22,.42); display: flex; justify-content: flex-end; }
.drawer-panel {
  background: var(--panel); width: min(560px, 100%); height: 100%;
  overflow-y: auto; padding: 26px 28px 50px; position: relative;
  box-shadow: -8px 0 32px rgba(0,0,0,.18);
  animation: slide .22s ease;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-close {
  position: absolute; top: 16px; right: 16px; width: 34px; height: 34px;
  border-radius: 9px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); cursor: pointer; font-size: 14px; z-index: 2;
}
.d-title { font-size: 21px; font-weight: 680; margin: 4px 40px 6px 0; line-height: 1.25; letter-spacing: -.01em; }
.d-sub { color: var(--ink-2); font-size: 14px; margin-bottom: 18px; }
.d-rev {
  background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; margin-bottom: 20px;
}
.d-rev .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; }
.d-rev .val { font-size: 24px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.d-rev .yr { font-size: 13px; color: var(--ink-2); font-weight: 500; }

.d-fields { display: grid; gap: 2px; }
.d-row { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.d-row .k { font-size: 12.5px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
.d-row .v { font-size: 14.5px; word-break: break-word; }
.d-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 22px; }
.d-actions .btn, .d-actions .btn-ghost { font-size: 14px; }
.copy-ok { color: var(--good); font-size: 13px; margin-left: 8px; }
.d-note { margin-top: 20px; font-size: 13px; color: var(--ink-3); line-height: 1.55; }

/* ---------- stats modal ---------- */
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(10,14,22,.42); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-panel {
  background: var(--panel); border-radius: 14px; width: min(720px, 100%);
  max-height: 86vh; overflow-y: auto; padding: 26px 28px; position: relative; box-shadow: var(--shadow);
}
.modal-panel h2 { margin: 0 0 18px; font-size: 19px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat-card .n { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .l { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 54px; gap: 10px; align-items: center; margin-bottom: 7px; font-size: 13.5px; }
.bar-track { background: var(--line-2); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 6px; }
.bar-row .num { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
h3.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 22px 0 10px; }

.foot { padding: 24px 0 40px; color: var(--ink-3); font-size: 13px; }
.foot p { margin: 0 0 5px; }
.foot .fine { font-size: 12px; }

@media (max-width: 860px) {
  .c-code, .c-city { display: none; }
  .filters { grid-template-columns: 1fr 1fr; }
  .top-inner { height: auto; padding: 12px 0; flex-wrap: wrap; }
  .c-name { max-width: 190px; }
}
@media (max-width: 620px) {
  .c-mgr { display: none; }
  .filters { grid-template-columns: 1fr; }
  .d-row { grid-template-columns: 1fr; gap: 3px; }
}
