:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #d9dce3;
  --text: #1a1d24;
  --muted: #5a6172;
  --accent: #1f5fbf;
  --on-accent: #ffffff;
  --agreed: #12703f;
  --agreed-soft: #e3f4ea;
  --refused: #b3261e;
  --refused-soft: #fbe9e7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1e2128;
    --line: #343843;
    --text: #eceef2;
    --muted: #a6adbb;
    --accent: #7fb0ff;
    --on-accent: #10131a;
    --agreed: #6fdc9f;
    --agreed-soft: #17352a;
    --refused: #ff9a90;
    --refused-soft: #3f2220;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

h1 { margin: 0; font-size: 20px; }
a { color: var(--accent); }

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input, select, textarea { padding: 8px 10px; width: 100%; min-height: 40px; }
textarea { resize: vertical; display: block; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.login label { display: grid; gap: 4px; color: var(--muted); }
.login button { min-height: 44px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.error { margin: 0; color: var(--refused); }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }
.ghost {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}

.page { max-width: 1560px; margin: 0 auto; padding: 16px; }

.counters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.counters button {
  display: grid;
  gap: 2px;
  padding: 10px;
  text-align: left;
  border-radius: 10px;
}
.counters b { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.counters span { color: var(--muted); font-size: 13px; }
.counters button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.shown { margin: 10px 0 8px; color: var(--muted); font-size: 13px; }

.head-row, .firm {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(170px, 1.5fr) 160px 90px 150px minmax(170px, 1.4fr) 150px;
  gap: 12px;
}
.head-row { padding: 0 12px 6px; color: var(--muted); font-size: 12px; }

.firm {
  padding: 12px;
  margin-bottom: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
}
.firm[data-status="agreed"] { border-left-color: var(--agreed); }
.firm[data-status="refused"] { border-left-color: var(--refused); }
.firm[data-status="seen"] { border-left-color: var(--accent); }

.cell { display: flex; flex-direction: column; gap: 3px; min-width: 0; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 13px; }
.phone { font-weight: 600; text-decoration: none; white-space: nowrap; }
.link { width: fit-content; }
.pending { color: var(--muted); font-size: 13px; }

.segment { display: grid; grid-template-columns: repeat(4, 1fr); }
.seg { min-height: 40px; border-radius: 0; font-size: 17px; font-weight: 700; margin-left: -1px; }
.seg:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg:last-child { border-radius: 0 8px 8px 0; }
.seg:focus-visible { position: relative; z-index: 1; }
.seg-none[aria-pressed="true"] { background: var(--line); }
.seg-agreed[aria-pressed="true"] { background: var(--agreed-soft); color: var(--agreed); border-color: var(--agreed); position: relative; }
.seg-refused[aria-pressed="true"] { background: var(--refused-soft); color: var(--refused); border-color: var(--refused); position: relative; }
.seg-seen[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); position: relative; }
.contact-name { display: grid; gap: 3px; margin-top: 6px; }
.contact-name span { color: var(--muted); font-size: 14px; }
.contact-name input { min-width: 0; }

.history { margin-top: 4px; font-size: 13px; color: var(--muted); }
.history summary { cursor: pointer; }
.history ul { margin: 4px 0 0; padding-left: 16px; }

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

@media (max-width: 1280px) {
  .head-row { display: none; }
  .firm { grid-template-columns: 1fr 1fr; }
  .note { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .page { padding: 12px 16px; }
  .counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .counters button:first-child { grid-column: 1 / -1; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .firm { grid-template-columns: 1fr; gap: 10px; }
  .phone { font-size: 17px; padding: 3px 0; }
  .links { flex-direction: row; gap: 16px; }
  .seg { min-height: 46px; }
  input, select, textarea { font-size: 16px; }
}
