:root {
  --bg: #0f1420;
  --panel: #181f2e;
  --panel-2: #202a3d;
  --line: #2b3750;
  --text: #e6ebf5;
  --muted: #8a97b0;
  --accent: #ffcf33;
  --accent-ink: #1a1a1a;
  --green: #3ddc84;
  --amber: #ffb020;
  --red: #ff5c6c;
  --gray: #6b7890;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin-top: 8px; min-height: 20px; font-size: 14px; }
button {
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 10px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--red); color: #fff; }
button.small { padding: 6px 10px; font-size: 13px; }
button:hover { filter: brightness(1.05); }
button:disabled { cursor: wait; opacity: .62; filter: none; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input, select {
  font: inherit; width: 100%; padding: 10px 12px; margin-top: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }

/* Вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; width: 100%; max-width: 360px;
}
.login-card h1 { margin: 0; color: var(--accent); }
.login-card p { margin: 4px 0 24px; }
.login-card button { width: 100%; margin-top: 8px; }

/* Шапка */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; color: var(--accent); font-size: 20px; }
.topbar nav { display: flex; gap: 6px; flex-wrap: wrap; }
.topbar nav a {
  padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px; cursor: pointer;
}
.topbar nav a.active { background: var(--panel-2); color: var(--text); }
.topbar nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spacer { flex: 1; }
main { padding: 20px; max-width: 1000px; margin: 0 auto; }

/* Панель управления списком */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h2 { margin: 0; margin-right: auto; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 13px; user-select: none;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Карточки-строки */
.grid { display: grid; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.rq { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.rq:hover { border-color: var(--accent); }
.phone-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rq .phone { font-size: 16px; font-weight: 600; letter-spacing: .3px; }
.copy-phone {
  display: inline-flex; align-items: center; justify-content: center; min-height: 30px;
  padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 12px; line-height: 1;
  transition: color .16s ease-out, border-color .16s ease-out, background-color .16s ease-out;
}
.copy-phone:hover { color: var(--text); border-color: var(--muted); }
.copy-phone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.copy-phone.copied { border-color: var(--green); background: rgba(61,220,132,.15); color: var(--green); }
.copy-phone.copy-failed { border-color: var(--red); background: rgba(255,92,108,.15); color: var(--red); }
.phone-line .tag-repl, .phone-line .tag-due { margin-left: 0; }
.rq .meta { color: var(--muted); font-size: 13px; }
.requisite-summary {
  display: grid; gap: 1px; margin-top: 6px;
  color: var(--muted); font-size: 13px; line-height: 1.45;
}
.requisite-summary + .requisite-summary { margin-top: 7px; }
.requisite-summary-title { color: var(--text); font-weight: 700; }
.rq .num { font-size: 13px; color: var(--muted); min-width: 28px; font-weight: 700; }
.rq .right { margin-left: auto; text-align: right; }
.rq-status-line { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.dead-toolbar { margin-bottom: 12px; }
.dead-list {
  display: grid; gap: 1px; overflow: hidden;
  background: var(--line); border-radius: var(--radius);
}
.dead-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(145px, 1fr) minmax(130px, .9fr) minmax(120px, .9fr) minmax(150px, 1fr);
  align-items: center; gap: 16px; min-width: 0; padding: 14px 16px;
  background: var(--panel); color: var(--text);
}
.dead-row-head { padding-block: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.dead-row[data-dead-row] { cursor: pointer; transition: background-color .16s ease-out; }
.dead-row[data-dead-row]:hover { background: var(--panel-2); }
.dead-row[data-dead-row]:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.dead-cell { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.dead-cell-label { display: none; color: var(--muted); font-size: 12px; font-weight: 500; }
.dead-phone { font-size: 15px; letter-spacing: .2px; }
.dead-turnover { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.readiness-age { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.inline-verify {
  display: inline-flex; align-items: center; justify-content: center; min-height: 32px;
  padding: 5px 10px; border-radius: 8px; font-size: 12px; line-height: 1.2; white-space: nowrap;
  transition: filter .16s ease-out, opacity .16s ease-out;
}
.inline-verify-error { display: block; margin-top: 4px; color: var(--red); font-size: 12px; }
.acting {
  background: rgba(255,207,51,.12); border-bottom: 1px solid var(--accent);
  color: var(--text); padding: 10px 20px; display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 4; font-size: 14px;
}
.acting button { padding: 5px 12px; font-size: 13px; }
.sync-notice {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  display: flex; align-items: center; gap: 14px; max-width: min(440px, calc(100vw - 28px));
  padding: 12px 14px; border: 1px solid var(--accent); border-radius: 12px;
  background: var(--panel); color: var(--text); box-shadow: 0 14px 40px rgba(0,0,0,.35);
  font-size: 14px;
}
.sync-notice button { padding: 7px 12px; flex: 0 0 auto; }

/* Календарь flatpickr под наш стиль */
.flatpickr-day.selected, .flatpickr-day.selected:hover {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.flatpickr-day.today { border-color: var(--accent); }
.flatpickr-calendar { border: 1px solid var(--line); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ready { background: rgba(61,220,132,.15); color: var(--green); }
.badge.otlezhka { background: rgba(255,176,32,.15); color: var(--amber); }
.badge.rashod { background: rgba(107,120,144,.2); color: var(--gray); }
.badge.umerla { background: rgba(255,92,108,.15); color: var(--red); }
.badge.later { background: rgba(255,92,108,.18); color: var(--red); border: 1px solid rgba(255,92,108,.4); font-weight: 700; }
.badge.checking { background: rgba(255,207,51,.14); color: var(--accent); border: 1px solid rgba(255,207,51,.32); }
.badge.verification-error { background: rgba(255,92,108,.18); color: var(--red); border: 1px solid rgba(255,92,108,.4); }
.next { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.queue-position { color: var(--text); font-weight: 700; }
.note-line { color: var(--text); opacity: .8; margin-top: 3px; }
.tag-repl, .tag-due { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.tag-repl { background: rgba(61,220,132,.15); color: var(--green); }
.tag-due { background: rgba(255,176,32,.18); color: var(--amber); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty button { margin-top: 16px; }
.loading-state, .error-state { padding: 22px; color: var(--muted); }
.error-state .error { margin: 0 0 12px; }
.safe-code { display: inline-block; color: var(--muted); overflow-wrap: anywhere; }

/* Модалка */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; position: relative;
}
.modal-card.modal-card-wide { max-width: 740px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; color: var(--muted); padding: 4px 8px; }
.modal.confirm-overlay { z-index: 40; }
.confirm-card { max-width: 400px; }
.confirm-msg { font-size: 16px; margin: 4px 0 22px; }
.modal-card h3 { margin-top: 0; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv .muted { color: var(--muted); }
.price-control { display: grid; grid-template-columns: 110px auto auto; align-items: center; gap: 8px; }
.price-control input { margin: 0; min-width: 0; }
.price-error { min-height: 0; text-align: right; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 20px 0 8px; }
.tr-list { display: grid; gap: 6px; }
.tr-item { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--panel-2); border-radius: 8px; font-size: 14px; }
.tr-item.tr-edit { cursor: pointer; }
.tr-item.tr-edit:hover { background: var(--line); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.stat-big { font-size: 34px; font-weight: 800; }

/* Дашборд */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-val { font-size: 26px; font-weight: 800; margin-top: 4px; }
.tile-val.green { color: var(--green); }
.tile-val.amber { color: var(--amber); }
.tile-val.red { color: var(--red); }
.tile-val.gray { color: var(--gray); }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dash-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.dashboard-section { margin-top: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.section-head .section-title { margin: 0; }
.section-caption { margin-top: 3px; color: var(--muted); font-size: 12px; }
.payout-list { display: grid; }
.payout-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px;
  min-height: 52px; padding: 9px 0; border-bottom: 1px solid var(--line);
}
.payout-row:last-child { border-bottom: 0; }
.payout-main { min-width: 0; }
.payout-phone { font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.payout-num { color: var(--muted); margin-right: 8px; font-weight: 700; }
.payout-time { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.payout-amount { white-space: nowrap; font-size: 15px; font-variant-numeric: tabular-nums; }
.turnover-row { grid-template-columns: 24px minmax(0, 1fr) auto; }
.turnover-rank { color: var(--accent); font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.payout-empty { padding: 18px 0; color: var(--muted); font-size: 14px; }
.payout-history-summary { margin: -4px 0 10px; font-size: 13px; }
.payout-history-scroll { max-height: 66vh; overflow-y: auto; padding-right: 6px; }
.chart { overflow-x: auto; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; min-width: 560px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.bar-val { font-size: 10px; font-weight: 700; color: var(--text); margin-bottom: 3px; white-space: nowrap; }
.bar-labels { display: flex; gap: 3px; margin-top: 6px; min-width: 560px; }
.bar-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--muted); white-space: nowrap; }
table { width: 100%; border-collapse: collapse; }
.table-scroll { overflow-x: auto; }
.user-actions { display: flex; justify-content: flex-end; gap: 6px; min-width: max-content; }
.password-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.password-control input { min-width: 0; }
.password-control button { margin-bottom: 0; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
.code-box { font-size: 24px; font-weight: 800; letter-spacing: 3px; color: var(--accent); text-align: center; padding: 16px; background: var(--panel-2); border-radius: 10px; margin: 12px 0; }
a { color: var(--accent); }
.tg-open {
  display: inline-block; margin: 4px 0 8px; padding: 10px 16px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none;
}
.tg-open:hover { filter: brightness(1.05); }
.telegram-grid { display: grid; gap: 16px; }
.telegram-card .section-title:first-child { margin-top: 0; }
.health-ok { color: var(--green); font-weight: 700; }
.health-warn { color: var(--amber); font-weight: 700; }
@media (max-width: 860px) {
  .dead-list { gap: 10px; overflow: visible; background: transparent; }
  .dead-row-head { display: none; }
  .dead-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 16px;
    padding: 14px; border: 1px solid var(--line); border-radius: var(--radius);
  }
  .dead-phone-cell { grid-column: 1 / -1; }
  .dead-cell-label { display: block; margin-bottom: 2px; }
  .dead-turnover { text-align: left; white-space: normal; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .topbar .spacer { display: none; }
  .brand { order: 1; }
  #whoami { order: 2; margin-left: auto; font-size: 13px; }
  #logout { order: 3; }
  .topbar nav { order: 4; width: 100%; }
  .rq { flex-wrap: wrap; }
  .rq .right { flex: 1 0 100%; margin-left: 0; text-align: left; }
  .rq-status-line { flex-direction: column; align-items: flex-start; justify-content: flex-start; }
  .inline-verify { min-height: 44px; padding: 8px 12px; }
  .copy-phone { min-height: 44px; padding: 8px 10px; }
  main { padding: 16px 14px; }
  .sync-notice { right: 14px; bottom: 14px; left: 14px; max-width: none; justify-content: space-between; }
  .section-head .small { min-height: 44px; }
  .payout-row { gap: 10px; padding: 10px 0; }
  .turnover-row { grid-template-columns: 22px minmax(0, 1fr) auto; }
  .modal-card.modal-card-wide { padding: 20px; }
  .modal-card .kv { align-items: flex-start; gap: 8px; }
  .modal-card .kv > :last-child { text-align: right; overflow-wrap: anywhere; }
  .price-kv { flex-direction: column; }
  .price-kv > :last-child { width: 100%; }
  .price-control { grid-template-columns: minmax(0, 1fr) auto; text-align: left; }
  .price-control button { grid-column: 1 / -1; min-height: 44px; }
  .modal-card .actions [data-status-action] { width: 100%; min-height: 44px; }
  .telegram-card .kv { align-items: flex-start; gap: 12px; }
  .telegram-card .kv > :last-child { text-align: right; overflow-wrap: anywhere; }
}
