/* ============================================================
   Lead App — design system adopted from wireframes
   ============================================================ */
:root {
  --bg: oklch(0.985 0.003 80);
  --surface: #ffffff;
  --surface-2: oklch(0.97 0.004 80);
  --line: oklch(0.90 0.004 80);
  --line-strong: oklch(0.82 0.005 80);
  --ink: oklch(0.22 0.01 60);
  --ink-2: oklch(0.42 0.008 60);
  --ink-3: oklch(0.60 0.006 60);
  --accent: oklch(0.62 0.09 200);
  --accent-ink: oklch(0.28 0.06 200);
  --accent-soft: oklch(0.95 0.02 200);
  --warn: oklch(0.62 0.12 30);
  --warn-soft: oklch(0.96 0.03 30);
  --good: oklch(0.65 0.10 150);
  --good-soft: oklch(0.95 0.03 150);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20,16,10,0.04), 0 4px 12px rgba(20,16,10,0.05);
  --shadow-up: 0 -8px 30px rgba(20,16,10,0.12);
}

/* Dark theme — activated by data-theme="dark" on <html>. See
   src/ui/theme.js for persistence. */
:root[data-theme="dark"] {
  --bg:          oklch(0.16 0.01 240);
  --surface:     oklch(0.21 0.01 240);
  --surface-2:   oklch(0.25 0.01 240);
  --line:        oklch(0.32 0.008 240);
  --line-strong: oklch(0.42 0.008 240);
  --ink:         oklch(0.96 0.005 80);
  --ink-2:       oklch(0.78 0.008 80);
  --ink-3:       oklch(0.60 0.008 80);
  --accent:      oklch(0.72 0.10 200);
  --accent-ink:  oklch(0.92 0.03 200);
  --accent-soft: oklch(0.30 0.06 200);
  --warn:        oklch(0.72 0.13 30);
  --warn-soft:   oklch(0.30 0.08 30);
  --good:        oklch(0.70 0.13 150);
  --good-soft:   oklch(0.28 0.08 150);
  --shadow:      0 1px 2px rgba(0,0,0,0.30), 0 6px 16px rgba(0,0,0,0.40);
  --shadow-up:   0 -8px 30px rgba(0,0,0,0.40);
  /* Native form controls — tell Chrome/Safari to render inputs and
     scrollbars in dark style without any JS. */
  color-scheme: dark;
}

/* Dark-mode overrides for blocks that use hand-mixed colours. */
:root[data-theme="dark"] .rank-card[style*="good"] {
  /* The inline gold gradient used good → good-soft, which in dark
     reads as "dark teal → dark teal" and loses the #1 feeling. Pop
     with a brighter accent instead. */
  background: linear-gradient(135deg, var(--good), oklch(0.55 0.14 150)) !important;
  color: #fff !important;
}
:root[data-theme="dark"] .shift-badge {
  /* The white-on-accent gradient stayed legible but the border blended
     with the background. Add an explicit border so the card pops. */
  border: 1px solid var(--accent);
}
:root[data-theme="dark"] .install-prompt {
  /* default shadow was tuned for white backgrounds; tighten it up. */
  box-shadow: 0 10px 24px rgba(0,0,0,0.5);
}

/* Scrollbars for operator app. color-scheme: dark handles most of it
   on Firefox; WebKit needs these explicit rules. */
:root[data-theme="dark"] ::-webkit-scrollbar-track  { background: var(--bg); }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb  { background: var(--line-strong); border-radius: 6px; }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* Focus ring: the default outline: 2px solid var(--accent) looks too
   dim against the dark surface; brighten it for keyboard users. */
:root[data-theme="dark"] button:focus-visible,
:root[data-theme="dark"] input:focus-visible,
:root[data-theme="dark"] textarea:focus-visible,
:root[data-theme="dark"] .chip:focus-visible,
:root[data-theme="dark"] .shift-chip:focus-visible {
  outline: 2px solid oklch(0.85 0.10 200);
  outline-offset: 2px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px; line-height: 1.4;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; border: 0; background: none; }
button { cursor: pointer; padding: 0; }
input, textarea { outline: none; }
/* Keyboard-only focus ring. No outline on pointer clicks. */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.chip:focus-visible,
.shift-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
/* When the input lives inside a .field wrapper (e.g. PIN box on
   login + create-operator modal), the WRAPPER already gets a
   border + soft halo via .field:focus-within. Stacking another
   outline on the input itself produced the «всё горит» look —
   inner cyan ring inside the outer cyan ring inside the halo.
   Suppress the inner outline; the wrapper alone is enough. */
.field input:focus-visible,
.field textarea:focus-visible {
  outline: none;
}

.num { font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.tiny { font-size: 11px; }
.small { font-size: 12px; }
.hidden { display: none !important; }
.hstack { display: flex; align-items: center; gap: 8px; }
.vstack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ------ App shell ------ */
/* Phone portrait (default): full-bleed 420px column. Tablet portrait
   (480-720): the 420px hard cap left ~150px of empty whitespace on
   each side of the card on a 600-700px iPad-mini-portrait viewport,
   making the app look broken. Bumping to 480px stays within reading-
   line norms while filling the visible space comfortably. Tablet
   landscape / desktop (≥720) gets the bordered-card look unchanged. */
#app {
  max-width: 420px;
  min-height: 100vh;
  margin: 0 auto;
  display: flex; flex-direction: column;
  background: var(--bg);
  position: relative;
}
@media (min-width: 480px) and (max-width: 719px) {
  #app { max-width: 480px; }
}
@media (min-width: 720px) {
  #app {
    max-width: 520px;
    margin: 24px auto;
    min-height: calc(100vh - 48px);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

.screen {
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}
@media (min-width: 720px) {
  .screen { min-height: auto; }
}
.screen:not(.active) { display: none; }

.web-header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.web-header .brand { font-weight: 700; letter-spacing: -0.2px; font-size: 15px; }
.web-header .brand .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.web-header .spacer { flex: 1; }
.web-header .avatar {
  width: 30px; height: 30px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  border: 1px solid var(--accent); cursor: pointer;
}
/* Avatar-button: same shape as the static avatar, but a real <button>
   so the operator can upload their own photo. Reset native button
   chrome so the visual stays identical to the original div. */
.web-header .avatar-btn {
  padding: 0;
  font-family: inherit;
  overflow: hidden;            /* clip <img> to the round shape */
  transition: transform 120ms ease, filter 120ms ease;
}
.web-header .avatar-btn:hover { filter: brightness(0.95); }
.web-header .avatar-btn:active { transform: scale(0.94); }
.web-header .avatar-btn.avatar-uploading {
  opacity: 0.6;
  cursor: wait;
}

.page-title {
  padding: 14px 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 10px;
  flex-shrink: 0;
}
.page-title .back {
  margin-top: 2px;
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--ink-2);
  font-size: 16px; cursor: pointer; flex-shrink: 0;
}
.page-title .back:hover { background: var(--surface-2); }
.page-title .col { flex: 1; min-width: 0; }
.page-title h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.page-title .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.page-title .right { flex-shrink: 0; }

.content { flex: 1; overflow-y: auto; padding: 12px 14px 20px; }

/* ------ Action bar (bottom sticky) ------ */
.action-bar {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 8px;
  position: sticky; bottom: 0;
  flex-shrink: 0;
}

/* ------ Buttons ------ */
.btn {
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--accent); color: white;
  font-weight: 600; font-size: 15px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn.ghost { background: transparent; color: var(--accent-ink); border: 1px dashed var(--line-strong); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; min-height: 32px; }
.btn.xl { padding: 14px 20px; font-size: 16px; font-weight: 700; }

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--ink-2); font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); }

/* ------ Cards ------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.divider { height: 1px; background: var(--line); margin: 0; }

/* ------ Fields ------ */
.field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.field .label { font-size: 11px; color: var(--ink-3); font-weight: 500; }
.field input, .field .value {
  background: transparent;
  font-size: 15px; color: var(--ink); font-weight: 500;
  padding: 0; border: 0; width: 100%;
}
.field input::placeholder, .field .value.ph { color: var(--ink-3); font-weight: 400; }
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* PIN inputs on the operator login screen — match the admin variant
   from admin.css: monospaced, generous letter-spacing so each dot/
   digit reads as a distinct PIN slot. The placeholder («——————»)
   is replaced with «••••» for the «4 цифры» visual hint. */
.field input#loginPin {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.6em;
  text-align: center;
  padding: 6px 0;
}
.field input#loginPin::placeholder {
  color: var(--line-strong);
  letter-spacing: 0.6em;
  opacity: 1;
}

/* ------ Select-style fields (Targetologist / Platform pickers on the
   operator report screen). The native select arrow is replaced with an
   inline SVG via background-image so theming follows --ink without
   needing a wrapper element. The existing .field shell handles the
   border + focus ring; .select is just the inner control reset. */
.field-select {
  cursor: pointer;
  position: relative;
  padding-right: 34px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field-select:hover { border-color: var(--ink-3); }
.field-select::after {
  content: "";
  position: absolute;
  right: 12px; top: 50%;
  width: 12px; height: 12px;
  margin-top: -2px;
  background: no-repeat center / contain
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2.5 4.5l3.5 3.5 3.5-3.5' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  pointer-events: none;
  opacity: .75;
  transition: transform .15s ease, opacity .15s ease;
}
.field-select:focus-within::after { opacity: 1; transform: translateY(1px); }
.select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: transparent;
  border: 0; outline: none;
  padding: 0;
  width: 100%;
  font-size: 15px; color: var(--ink); font-weight: 500;
  font-family: inherit;
  line-height: 1.3;
  cursor: pointer;
}
.select::-ms-expand { display: none; }
.select option { color: var(--ink); background: var(--surface); }
.select:invalid, .select option[value=""] { color: var(--ink-3); }

/* Operator report: targetologist + platform sit side-by-side, equal
   width, with a small gap. On narrow phones (<420px) they stack so each
   field gets full width — the labels stay readable without overflow. */
.attribution-row {
  display: flex; gap: 10px;
  margin-bottom: 10px;
}
.attribution-row .field-select { flex: 1; min-width: 0; }
@media (max-width: 420px) {
  .attribution-row { flex-direction: column; gap: 8px; }
}

/* ------ Chips ------ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); font-weight: 500;
  white-space: nowrap; min-height: 26px;
  cursor: pointer; transition: all .12s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip.plain { cursor: default; }
.chip.plain:hover { border-color: var(--line); }

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ------ Table (core entry UI) ------ */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--ink-3);
  padding: 9px 8px; border-bottom: 1px solid var(--line);
  font-size: 11px; background: var(--surface-2);
  text-transform: uppercase; letter-spacing: 0.4px;
}
.tbl th.n { text-align: center; }
.tbl td { padding: 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.total { background: var(--surface-2); font-weight: 600; }
.tbl tr.total td { padding: 9px 10px; }
.tbl tr.total td.n { text-align: center; font-family: 'JetBrains Mono', monospace; }

/* Не давайте этой ячейке имя с рекламным префиксом `ad-`: блокировщики
   рекламы скрывают такие классы косметическим фильтром. Тогда первая
   колонка исчезает целиком, а Лиды/Бот/Опер. съезжают влево. */
.tbl td.creative-cell {
  padding: 10px 10px;
  cursor: pointer;
}
.tbl td.creative-cell:active { background: var(--accent-soft); }
.tbl td.creative-cell .name { font-weight: 600; font-size: 13.5px; color: var(--ink); display: flex; align-items: center; gap: 4px; }
.tbl td.creative-cell .name.empty { color: var(--ink-3); font-weight: 500; }
.tbl td.creative-cell .sub { font-size: 10.5px; color: var(--ink-3); margin-top: 2px; }
.tbl td.creative-cell .note-dot { color: var(--accent); font-size: 8px; }
/* Крестик удаления строки. Раньше убрать креатив можно было только
   через модалку за тапом по названию — это никто не находил. */
.tbl td.creative-cell { position: relative; padding-right: 30px; }
.tbl td.creative-cell .row-del {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 26px; height: 26px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--ink-3);
  font-size: 13px; line-height: 1; cursor: pointer;
}
.tbl td.creative-cell .row-del:hover,
.tbl td.creative-cell .row-del:active { background: var(--accent-soft); color: var(--ink); }

/* Tap-to-type cell */
.tbl td.cell { padding: 0; text-align: center; position: relative; }
.tbl td.cell input {
  width: 100%; height: 100%; min-height: 48px; padding: 0 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px; font-weight: 600; text-align: center;
  color: var(--ink); background: transparent;
  border: 0; outline: 0;
  transition: background .12s, box-shadow .12s;
}
.tbl td.cell input::placeholder { color: oklch(0.80 0.005 60); font-weight: 400; }
.tbl td.cell:focus-within { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); border-radius: 4px; }
.tbl td.cell input:focus { color: var(--accent-ink); }

/* Row hover (desktop) */
@media (hover: hover) {
  .tbl tbody tr:hover td { background: var(--surface-2); }
  .tbl tbody tr:hover td.cell:focus-within { background: var(--accent-soft); }
}

/* Note indicator */
.note-dot-wrap { display: inline-flex; align-items: center; gap: 3px; }

/* Empty state */
.empty {
  padding: 36px 24px 30px; text-align: center; background: var(--surface-2);
}
.empty .icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  border-radius: 14px; border: 1.5px dashed var(--line-strong);
  display: grid; place-items: center; color: var(--ink-3);
  font-size: 26px; font-weight: 300;
}
.empty .t { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty .s { font-size: 12px; color: var(--ink-3); margin-bottom: 14px; line-height: 1.5; }

/* ------ Home card (yesterday's missing report prompt) ------ */
.prompt-card {
  padding: 18px; background: var(--accent-soft); border-color: var(--accent); border: 1px solid var(--accent);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 10px;
}
.prompt-card .top { display: flex; align-items: center; gap: 10px; }
.prompt-card .icon {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent);
  color: white; display: grid; place-items: center; font-size: 18px; font-weight: 700;
}
.prompt-card .t { font-size: 15px; font-weight: 700; color: var(--accent-ink); }
.prompt-card .s { font-size: 11px; color: var(--accent-ink); opacity: 0.8; }

/* Home → submit-hub entry button: a `.prompt-card` rendered as a
   `<button>` so the whole card is clickable. Strip the default browser
   button chrome (background, border, alignment) and lean on the
   prompt-card frame for the styling — keeps the visual weight of the
   old in-line prompt without re-implementing it. The ::after arrow is
   inlined in the markup; this just kills focus-outline + tap halos. */
.prompt-card.submit-entry { padding: 14px 16px; }
.prompt-card.submit-entry:focus { outline: none; }
.prompt-card.submit-entry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.prompt-card.submit-entry:active {
  /* Subtle press feedback so the whole-card hit area reads as tappable. */
  transform: scale(0.997);
  transition: transform .08s;
}

/* Week stats */
.stats-card {
  padding: 14px 16px; border: 1px dashed var(--line-strong); border-radius: 12px;
}
.stats-card .label { font-size: 11px; color: var(--ink-3); font-weight: 600; letter-spacing: 0.5px; margin-bottom: 8px; text-transform: uppercase; }
.stats-card .row { display: flex; gap: 20px; }
.stats-card .row > div { flex: none; }
.stats-card .v { font-size: 22px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }

/* Recent list */
.list-label {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 2px 8px; margin-top: 20px;
}
.list-label .l { font-size: 11px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.5px; }
.list-label .a { font-size: 12px; color: var(--accent-ink); font-weight: 600; cursor: pointer; }

.list-item {
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
  cursor: pointer;
}
.list-item:hover { background: var(--surface-2); }
.list-item .bar { width: 4px; height: 28px; border-radius: 2px; background: var(--good); flex-shrink: 0; }
.list-item .bar.warn { background: var(--warn); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; font-size: 14px; }
.list-item .s { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.list-item .r { font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 13px; flex-shrink: 0; }

/* ------ Branch picker ------ */
.branch-item {
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  transition: all .12s;
}
.branch-item:hover { border-color: var(--accent); }
.branch-item.selected { background: var(--accent-soft); border-color: var(--accent); }
.branch-item .main { flex: 1; }
.branch-item .n { font-weight: 600; font-size: 15px; }
.branch-item.selected .n { color: var(--accent-ink); }
.branch-item .sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.branch-item .check { color: var(--accent); font-weight: 700; font-size: 16px; }

/* ------ Ad picker ------ */
.dd-search {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 12px;
  color: var(--ink-3);
}
.dd-search input { flex: 1; background: transparent; }
.dd-group-head {
  padding: 8px 14px; font-size: 10.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.6px;
  background: var(--surface-2);
  display: flex; justify-content: space-between; align-items: center;
}
.dd-item {
  padding: 11px 14px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; border-bottom: 1px solid var(--line);
  gap: 10px;
}
.dd-item:last-child { border-bottom: 0; }
.dd-item:hover, .dd-item.hot { background: var(--accent-soft); }
.dd-item .main { flex: 1; min-width: 0; }
.dd-item .n { font-weight: 500; font-size: 14px; }
.dd-item .s { font-size: 10.5px; color: var(--ink-3); margin-top: 2px; }
.dd-item .price { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--ink-3); flex-shrink: 0; }
.dd-item .check { color: var(--accent); font-weight: 700; font-size: 14px; }
.dd-item.added { opacity: 0.6; }
.dd-item.added .check-added {
  font-size: 10px; color: var(--good); font-weight: 600;
  background: var(--good-soft); padding: 2px 6px; border-radius: 999px;
  margin-left: 6px;
}

/* ------ Row sheet (modal) ------ */
.modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(20,16,10,0.35);
  display: flex; align-items: flex-end;
  animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-sheet {
  background: var(--surface); width: 100%; max-width: 520px; margin: 0 auto;
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-up);
  max-height: 85vh; overflow-y: auto;
  animation: slideUp .2s ease-out;
}

/* Global cap for any operator-side modal that uses the generic
   `[role="dialog"] > <div>` shape (date-pickers, ad-pickers, etc.).
   Same rationale as in admin.css: short-but-wide laptop screens
   don't trip width media-queries, so the constraint must be on
   height. `100dvh` follows the visible viewport on mobile; the
   `100vh` line is the fallback for browsers without dvh support. */
[role="dialog"] > div {
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { transform: translateY(20%); } to { transform: none; } }
.modal-handle {
  width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong);
  margin: 0 auto 14px;
}
.modal-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.modal-head .col { flex: 1; min-width: 0; }
.modal-head .t { font-size: 16px; font-weight: 700; }
.modal-head .s { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

.section-lbl {
  font-size: 10.5px; color: var(--ink-3); font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
  margin: 14px 0 6px;
}
.section-lbl .opt { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-3); }

/* Причины и доп-информация на уровне всего отчёта. Всегда открытая
   секция внизу экрана отчёта: сетка «метка + числовое поле», ввод
   руками. Прежние chip-стили (.rchip/.reasons/.note-field) убраны
   вместе с модалкой строки — см. docs/DESIGN-REPORT-LEVEL-REASONS.md. */
.reasons-section {
  margin-top: 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); padding: 12px 14px 14px;
}
.reasons-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.reasons-title { font-weight: 600; font-size: 13.5px; color: var(--ink-1); }
.reasons-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px;
}
.reason-field {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; min-width: 0;
}
.reason-label {
  font-size: 13px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reason-input {
  width: 64px; flex: none; text-align: right;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px;
  font-family: 'JetBrains Mono', monospace; font-size: 14px;
  color: var(--ink-1);
}
.reason-input:focus { border-color: var(--accent); outline: none; }
@media (max-width: 420px) {
  .reasons-grid { grid-template-columns: 1fr; }
}

/* Строка причин в шапке экрана проверки (что уедет в отчёт). */
.review-reasons {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px; line-height: 1.5; color: var(--ink-1);
}

/* ------ Review screen ------ */
.review-card { padding: 16px; }
.review-card .big-date { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; margin-top: 2px; }
.review-card .meta-top { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.review-card .meta-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.kpi-3 .k { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.kpi-3 .k.ok { background: var(--good-soft); }
.kpi-3 .k .lbl { font-size: 11px; color: var(--ink-3); }
.kpi-3 .k.ok .lbl { color: var(--good); }
.kpi-3 .k .v { font-size: 20px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.kpi-3 .k.ok .v { color: var(--good); }

/* ------ Sent screen ------ */
.sent-hero { text-align: center; padding: 32px 0 24px; }
.sent-hero .check {
  width: 72px; height: 72px; margin: 0 auto 16px;
  border-radius: 999px; background: var(--good-soft); border: 2px solid var(--good);
  display: grid; place-items: center; color: var(--good); font-size: 32px; font-weight: 700;
}
.sent-hero .t { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.sent-hero .s { font-size: 13px; color: var(--ink-3); margin-top: 6px; line-height: 1.5; }

/* ------ Badges ------ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: var(--surface-2); color: var(--ink-3); }

/* ------ Toast ------ */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--ink); color: white;
  padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; box-shadow: var(--shadow);
  z-index: 1000; animation: toastIn .2s;
}
.toast.ok { background: var(--good); }
.toast.err { background: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translateX(-50%); } }

/* ------ Login screen ------ */
.login-hero { padding: 40px 24px 28px; display: flex; flex-direction: column; gap: 12px; }
.login-hero .logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.login-hero .logo {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent);
  color: white; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.login-hero .brand { font-weight: 700; font-size: 17px; letter-spacing: -0.3px; }
.login-hero h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.4px; }
.login-hero .h-sub { font-size: 13px; color: var(--ink-3); margin-top: -6px; }

/* Forced-logout notice above the login form. Shown only when the
   gateway sets la.forcedLogout (401/403 on a signed-in request). */
.login-notice {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
}

/* ------ Totals preview on report ------ */
.totals-bar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 10px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.totals-bar .tot { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.totals-bar .l {
  font-size: 10px; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: 0.4px; font-weight: 600;
  /* Allow long labels like «Конв. запись» to soft-wrap inside their
     column instead of overflowing the card on narrow phones. */
  text-align: center; line-height: 1.15;
  white-space: normal; overflow-wrap: anywhere;
}
.totals-bar .v { font-size: 17px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.totals-bar .tot.conv .v { color: var(--good); }

/* ------ Autosave chip ------ */
.autosave { font-size: 10px; }
.autosave::before { content: "● "; color: var(--good); }

/* ------ Operator "Мои приходы" card — mini 14-day bars ------ */
.arr-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 32px;
  margin-top: 10px;
}
.arr-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: height 200ms ease;
}
.arr-bar.muted { background: var(--surface-2); border: 1px solid var(--line); }

/* ------ Operator rank card (Вы #N из M) ------
   Compact strip showing the operator's position in the 7-day lead
   leaderboard. Subtle by default; turns gold when they're #1. */
.rank-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
}
.rank-card .rank-badge {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.rank-card .rank-body { flex: 1; min-width: 0; }
.rank-card .rank-title { font-weight: 600; font-size: 14px; }
.rank-card .rank-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.rank-card[style*="good"] .rank-badge {
  background: rgba(255,255,255,0.25);
  color: #fff;
}
.rank-card[style*="good"] .rank-sub { color: rgba(255,255,255,0.85); }
.rank-delta {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  vertical-align: middle;
}
.rank-delta.up   { background: var(--good-soft); color: var(--good); }
.rank-delta.down { background: var(--warn-soft); color: var(--warn); }
.rank-delta.flat { background: var(--surface-2); color: var(--ink-3); }

/* ------ Today-shift badge (Сегодня у тебя смена) ------
   High-contrast gradient strip at the top of the operator home so the
   reminder is the first thing they see on arrival. Hidden when they
   aren't scheduled today. */
.shift-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-ink));
  color: white;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.shift-badge[hidden] { display: none; }
.shift-badge .shift-badge-icon {
  font-size: 14px;
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.shift-badge .shift-badge-body { flex: 1; min-width: 0; }
.shift-badge .shift-badge-title { font-weight: 700; font-size: 15px; }
.shift-badge .shift-badge-sub { font-size: 12px; opacity: 0.9; margin-top: 2px; }

/* ------ Operator shifts card (Мой график · 14 дней) ------ */
.shift-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 2px 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.shift-chip {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  text-align: center;
  scroll-snap-align: start;
  border: 1px solid transparent;
}
.shift-chip.on {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.shift-chip.off { color: var(--ink-3); }
.shift-chip.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.shift-chip .wd {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.7;
}
.shift-chip .dn {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
  margin-top: 2px;
}

/* ------ Operator monthly-target card (Мои цели) ------ */
.stats-my-target .label {
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}
.mt-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 6px 0;
  font-size: 12px;
}
.mt-lbl { color: var(--ink-2); }
.mt-track {
  background: var(--surface-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.mt-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
  transition: width 240ms ease;
}
.mt-fill.good { background: var(--good); }
.mt-nums { font-size: 11px; white-space: nowrap; }
.mt-pct { color: var(--ink-3); margin-left: 4px; }
.mt-pct.good { color: var(--good); font-weight: 700; }

/* ------ Operator Мои дни compact table ------ */
.stats-daytable { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-daytable th,
.stats-daytable td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.stats-daytable th {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--surface-2);
}
.stats-daytable td.n,
.stats-daytable th.n { text-align: right; }
.stats-daytable tbody tr:last-child td { border-bottom: 0; }

/* ------ PWA install prompt (bottom-sheet card) ------ */
.install-prompt {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(20,16,10,0.12);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 999;
  animation: installSlide 0.3s ease-out;
}
.install-prompt.hidden { display: none; }
.install-body { flex: 1; min-width: 0; }
.install-title { font-weight: 700; font-size: 14px; }
.install-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.install-actions { display: flex; gap: 6px; flex-shrink: 0; }
@keyframes installSlide {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------ Safe-area insets for iOS (standalone PWA + Safari) ------ */
body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
/* Install prompt sticks to the actual bottom, not below the home bar. */
.install-prompt { bottom: max(12px, calc(env(safe-area-inset-bottom) + 4px)); }

/* ------ Fine tweaks on small screens ------ */
/* Phone-width breakpoint covers any iPhone / mid-range Android in
   portrait (≤420px). Bumped from 360 → 420 because the longer
   «Конв. запись» label was being clipped between 360 and 420. */
@media (max-width: 420px) {
  .kpi-3 { grid-template-columns: 1fr 1fr; }
  /* 2×2 grid leaves enough horizontal room for the long conversion
     label on every phone width without forcing it to ellipsis. */
  .totals-bar { grid-template-columns: 1fr 1fr; gap: 10px; }
  .totals-bar .v { font-size: 16px; }
  /* The report rows table is bounded by #app's 420px max-width, but
     the cells themselves can squeeze on the narrowest phones. Trim
     padding so all four columns stay visible without horizontal scroll. */
  .tbl th, .tbl td.creative-cell, .tbl tr.total td { padding: 6px 8px; }
  .tbl td.cell input { font-size: 14px; }
  /* Sent / history / detail cards: stack metadata vertically. */
  .list-item { flex-wrap: wrap; gap: 6px; }
  /* Bottom action bars (review, report submit) keep buttons stacked
     when there isn't horizontal room for them side-by-side. */
  .actions-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .actions-bar .btn { width: 100%; }
  .install-prompt { flex-direction: column; align-items: stretch; }
  .install-actions { justify-content: flex-end; }
  .stats-daytable th, .stats-daytable td { padding: 6px 8px; font-size: 12px; }
  .shift-chip { min-width: 40px; padding: 5px 6px; }
  .rank-card .rank-badge { width: 42px; height: 42px; font-size: 14px; }
  /* Modals (row-modal, paste-modal) on tiny screens: leave 8px margin
     so the rounded card doesn't kiss the screen edge. */
  .modal { padding: 8px; }
  .modal-card { width: 100% !important; }
}

/* ------ Touch-target floor on every phone+tablet-width screen ------ */
/* iOS HIG calls for a minimum 44×44pt tap target; Android Material is
   48dp. Keep the operator buttons + chips above that to avoid the
   "missed-tap on a moving train" failure mode. Bumped from <420px to
   <720px so iPad-portrait operators (rare but real on shared salon
   tablets) also get the comfortable hit areas. The font-size:16px
   on inputs is what prevents iOS Safari from auto-zooming on focus
   — the trigger threshold is 16px, applies to all touch-class
   widths regardless of device. */
@media (max-width: 720px) {
  .btn { min-height: 44px; }
  .btn.sm { min-height: 36px; }
  .chip { min-height: 32px; padding: 7px 12px; }
  .field input, .select { font-size: 16px; /* prevents iOS auto-zoom on focus */ }
  /* Larger tap area on the row-modal trigger cells — operators add
     reasons there with their thumbs, often while walking. */
  .tbl td.creative-cell { min-height: 44px; }
}
