:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #161a23;
  --muted: #5f6677;
  --line: #e3e6ee;
  --soft: #eef0f6;
  --side: #141a2b;
  --side-ink: #eef1fa;
  --side-muted: #98a1bb;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eceafd;
  --good: #0f7a4a;
  --good-soft: #e2f5eb;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --bad: #b3261e;
  --bad-soft: #fde7e5;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(20 25 40 / 6%), 0 8px 24px rgb(20 25 40 / 7%);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --panel: #171a23;
    --ink: #e8ebf3;
    --muted: #9aa2b6;
    --line: #2a2f3d;
    --soft: #1f2330;
    --side: #0b0d13;
    --side-ink: #e8ebf3;
    --side-muted: #8a93ab;
    --accent: #8b85ff;
    --accent-ink: #0f1117;
    --accent-soft: #25234a;
    --good: #5fd39a;
    --good-soft: #15301f;
    --warn: #f0b85a;
    --warn-soft: #36290f;
    --bad: #ff8a80;
    --bad-soft: #3a1714;
    --focus: #7cb4ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }

.side {
  background: var(--side);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; padding: 4px 8px 18px; font-size: 15px; }
.brand svg, .login-card svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { position: relative; display: block; text-decoration: none; padding: 9px 10px; border-radius: 9px; }
.nav a b { display: block; font-weight: 600; }
.nav a span { display: block; font-size: 12.5px; color: var(--side-muted); }
.nav a:hover { background: rgb(255 255 255 / 6%); }
.nav a.on { background: rgb(255 255 255 / 11%); }
.badge { position: absolute; top: 10px; right: 10px; font-style: normal; font-size: 11.5px; font-weight: 700; background: var(--accent); color: #fff; border-radius: 99px; padding: 1px 7px; }
.side-foot { margin-top: auto; display: grid; gap: 10px; font-size: 12.5px; color: var(--side-muted); padding: 0 8px; }
.side-foot .ghost { color: var(--side-ink); border-color: rgb(255 255 255 / 18%); }

main { padding: 22px 26px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 22px 0 8px; }
.sub { color: var(--muted); margin: 0 0 16px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  border-radius: 9px; padding: 8px 14px; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 38px; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.06); }
button:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: none; }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost:hover { background: var(--soft); filter: none; }
.small { padding: 5px 10px; min-height: 30px; font-size: 13px; }
.btn svg, button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0 0 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 20px; letter-spacing: -0.01em; }
.stat span { color: var(--muted); font-size: 12.5px; }

.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="search"], input[type="password"], input[type="email"], input[type="tel"], input[type="url"], input[type="date"], select, textarea {
  width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 10px; min-height: 38px;
}
textarea { resize: vertical; line-height: 1.45; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px; cursor: pointer; font-size: 13px; background: var(--panel); user-select: none; min-height: 32px; }
.chip input { margin: 0; accent-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

.resbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin: 4px 0 10px; color: var(--muted); font-size: 13.5px; }
.resbar .acts { display: flex; gap: 8px; flex-wrap: wrap; }

.list { display: grid; gap: 8px; }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 14px; cursor: pointer;
}
.row:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.row.cur { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.row .nm { font-weight: 650; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; column-gap: 12px; }
.row .meta .ph { font-variant-numeric: tabular-nums; color: var(--ink); }
.row .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.row .quick { display: flex; gap: 6px; }
.tag { font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 2px 7px; background: var(--soft); color: var(--muted); }
.tag.email { background: var(--good-soft); color: var(--good); }
.tag.st-contacted { background: var(--accent-soft); color: var(--accent); }
.tag.st-interested, .tag.st-won { background: var(--good-soft); color: var(--good); }
.tag.st-not_interested, .tag.st-do_not_contact, .tag.st-has_site { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.score { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; color: var(--muted); min-width: 28px; text-align: right; }

.more { display: flex; justify-content: center; margin: 14px 0; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card h3 { margin: 0 0 4px; font-size: 15px; overflow-wrap: anywhere; }
.card p { margin: 6px 0; color: var(--muted); overflow-wrap: anywhere; }
.card .acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 30; overflow-y: auto; padding: 16px 18px 40px; overscroll-behavior: contain;
}
.scrim { position: fixed; inset: 0; background: rgb(10 12 20 / 35%); z-index: 25; }
.ptop { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.ptop .nav2 { display: flex; gap: 6px; }
.panel h2 { margin: 6px 0 2px; font-size: 19px; overflow-wrap: anywhere; }
.panel .meta { color: var(--muted); margin: 0 0 4px; overflow-wrap: anywhere; }
.contact { display: grid; gap: 8px; margin: 14px 0; }
.cline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.cline .val { font-weight: 600; flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.cline .lab { font-size: 12px; color: var(--muted); width: 100%; }
.split { display: inline-flex; }
.split > :first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split > select { width: auto; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; min-height: 38px; padding: 0 6px; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.statuses { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.statuses button { background: var(--soft); color: var(--ink); border-color: var(--line); font-weight: 500; }
.statuses button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.script { white-space: pre-wrap; background: var(--soft); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
details summary { cursor: pointer; font-weight: 600; margin: 12px 0 6px; }
.kbd { font-size: 12px; color: var(--muted); margin-top: 18px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font: 12px ui-monospace, monospace; }
.note-saved { font-size: 12px; color: var(--muted); }
.found { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 9px 11px; margin: 8px 0; overflow-wrap: anywhere; }
.found a { font-weight: 600; }

.settings { display: grid; gap: 14px; max-width: 860px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.tpl { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; background: var(--panel); }
.tpl textarea { min-height: 220px; }
.hint { font-size: 12.5px; color: var(--muted); }
.statebar { display: grid; gap: 4px; }
.sbar { display: grid; grid-template-columns: 120px minmax(0, 1fr) 70px; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.sbar i { display: block; height: 8px; border-radius: 4px; background: var(--accent); opacity: .8; }
.sbar span:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; font-weight: 600; max-width: calc(100vw - 32px); }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 16px; z-index: 60; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; width: min(380px, 100%); display: grid; gap: 10px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; }

@media (pointer: coarse) {
  button, .btn, input[type="text"], input[type="search"], input[type="password"], input[type="email"], input[type="tel"], input[type="url"], input[type="date"], select, summary, .chip, .nav a, .brand { min-height: 44px; }
  .small { min-height: 44px; min-width: 44px; padding: 8px 12px; }
  .split > select { min-height: 44px; }
  summary { display: flex; align-items: center; }
  .chip input { width: 18px; height: 18px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 10px 16px; }
  .brand { padding: 4px 0 8px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { flex: 0 0 auto; padding: 7px 10px; display: flex; align-items: center; }
  .nav a span { display: none; }
  .badge { position: static; margin-left: 6px; }
  .nav a b { display: inline; }
  .side-foot { display: none; }
  main { padding: 16px 16px 60px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .row .quick { justify-content: flex-start; }
  .sbar { grid-template-columns: 90px minmax(0, 1fr) 60px; }
}
