:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel2: #1f232c;
  --line: #2a2f3a;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --green: #35c46b;
  --red: #ef5b5b;
  --yellow: #f0b429;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ---- login ---- */
#login {
  position: fixed; inset: 0; display: none; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2333, var(--bg));
}
#login.show { display: grid; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; width: 340px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.login-card input, .login-card select { width: 100%; }
.login-card button {
  width: 100%; margin-top: 18px; background: var(--accent); color: #fff;
  border: 0; border-radius: 10px; padding: 11px; font-weight: 600;
}
.err { color: var(--red); min-height: 18px; margin-top: 10px; font-size: 13px; }

/* ---- topbar ---- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
header .logo { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
header .logo span { color: var(--accent); }
header .stat { color: var(--muted); font-size: 13px; }
header .stat b { color: var(--text); }
header .spacer { flex: 1; }
header input.search { width: 260px; }
header button.ghost {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
}
header button.ghost:hover { border-color: var(--accent); }
header .who { color: var(--muted); font-size: 13px; }

/* ---- app shell (flex-колонка: шапка авто + доска на всё остальное) ---- */
#app { flex-direction: column; height: 100vh; height: 100dvh; }

/* ---- board ---- */
#board {
  display: flex; gap: 12px; padding: 14px; overflow-x: auto;
  flex: 1; min-height: 0; align-items: flex-start;
  -webkit-overflow-scrolling: touch;
}
.col {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 290px; min-width: 290px; max-height: 100%; display: flex; flex-direction: column;
}
.col-head {
  padding: 10px 12px; font-weight: 600; display: flex; justify-content: space-between;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
.col-head .badge {
  background: var(--panel2); color: var(--muted); border-radius: 20px;
  padding: 1px 9px; font-size: 12px;
}
.col-body { padding: 8px; overflow-y: auto; flex: 1; min-height: 60px; }
.col-body.drag-over { background: rgba(79,140,255,.08); outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 10px; }

.card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; margin-bottom: 8px; cursor: grab; transition: border-color .12s;
}
.card:hover { border-color: var(--accent); }
.card.dragging { opacity: .5; }
.card .name { font-weight: 600; margin-bottom: 3px; }
.card .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px; }
.card .dates { color: var(--text); }
.card .src { font-size: 11.5px; color: var(--muted); }
.card .amount { color: var(--green); font-weight: 600; }
.card .tags { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.tag {
  font-size: 11px; padding: 1px 7px; border-radius: 20px;
  background: #232936; color: var(--muted); border: 1px solid var(--line);
}
.tag.repeat { background: #2a2440; color: #c4a6ff; border-color: #463a6b; }
.tag.cancel { background: #3a2326; color: #ff9b9b; border-color: #6b3a3a; }
.tag.assignee { background: #1f3326; color: #9be3b4; border-color: #2f5a3f; }

/* ---- drawer ---- */
#drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .2s ease; z-index: 20;
  display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,.4);
}
#drawer.open { transform: translateX(0); }
.drawer-head { padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head .x { float: right; background: none; border: 0; color: var(--muted); font-size: 22px; }
.drawer-head h2 { margin: 0 0 4px; font-size: 19px; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; margin-bottom: 14px; }
.kv .k { color: var(--muted); }
.kv a { color: var(--accent); text-decoration: none; }
.section-title { font-weight: 600; margin: 16px 0 8px; color: var(--text); }
.hist-item, .note {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 7px; font-size: 13px;
}
.note .meta { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.note-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.note-form textarea { resize: vertical; min-height: 56px; }
.note-form button, .stage-pick {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px;
  font-weight: 600;
}
.drawer-stage { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.drawer-stage button {
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 20px; padding: 5px 11px; font-size: 12.5px;
}
.drawer-stage button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); }
.welcome-box {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
.wl-row { display: flex; gap: 6px; align-items: flex-start; }
.wl-row input, .wl-row textarea { flex: 1; font-size: 12.5px; }
.wl-row textarea { resize: vertical; }
.mini {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 7px 10px; font-size: 12.5px; white-space: nowrap; text-decoration: none;
  display: inline-block;
}
.mini.open { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.wl-preview {
  white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; font-size: 12.5px; margin-top: 8px; color: var(--text);
}
details summary { cursor: pointer; }
/* ---- tape chart (шахматка) ---- */
#tapeOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 45;
  display: none; padding: 20px;
}
#tapeOverlay.open { display: block; }
.tape-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  height: 100%; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.tape-head {
  display: flex; align-items: center; gap: 16px; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.tape-head h2 { margin: 0; font-size: 18px; }
.tape-nav { display: flex; align-items: center; gap: 8px; flex: 1; }
.tape-head .x { background: none; border: 0; color: var(--muted); font-size: 24px; }
.tape-grid { flex: 1; overflow: hidden; padding: 0; }
.tg-scroll { height: 100%; overflow: auto; }
.tg-inner { display: inline-block; min-width: 100%; }
.tg-headrow { display: flex; position: sticky; top: 0; z-index: 3; background: var(--panel); }
.tg-headrow.occ { top: 44px; }
.tg-room {
  width: 110px; min-width: 110px; padding: 6px 10px; display: flex; align-items: center;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  position: sticky; left: 0; z-index: 2; background: var(--panel2); font-size: 13px; font-weight: 600;
}
.tg-room.head { background: var(--panel); color: var(--muted); }
.tg-dates { display: flex; }
.tg-d {
  width: 46px; min-width: 46px; text-align: center; padding: 4px 0; font-size: 12px;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.tg-d .wd { color: var(--muted); font-size: 10.5px; }
.tg-d.wknd, .tg-cell.wknd, .tg-occ.wknd { background: rgba(255,255,255,.035); }
.tg-d.today, .tg-cell.today { background: rgba(79,140,255,.14); }
.tg-occ {
  width: 46px; min-width: 46px; text-align: center; font-size: 12px; color: var(--muted);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 0;
}
.tg-catrow { display: flex; min-height: 26px; background: var(--bg); }
.tg-cat {
  width: 110px; min-width: 110px; position: sticky; left: 0; z-index: 2;
  background: var(--bg); color: var(--accent); font-weight: 700; font-size: 12px;
  padding: 5px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  display: flex; align-items: center;
}
.tg-catfill { border-bottom: 1px solid var(--line); background: var(--bg); }
.tg-row { display: flex; min-height: 34px; }
.tg-track { position: relative; min-height: 34px; display: flex; align-items: stretch; }
.tg-cell {
  flex: 0 0 46px; align-self: stretch;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.bar {
  position: absolute; height: 26px; line-height: 26px; border-radius: 6px;
  color: #fff; font-size: 12px; padding: 0 8px; overflow: hidden; white-space: nowrap;
  cursor: pointer; z-index: 1; text-overflow: ellipsis; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.bar:hover { filter: brightness(1.1); z-index: 4; }
.bar.conflict { outline: 2px solid var(--red); outline-offset: -1px; z-index: 3; }

/* ---- dashboard ---- */
#dashOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
#dashOverlay.open { display: flex; }
#missedOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
#missedOverlay.open { display: flex; }

/* ============ АДАПТИВ ПОД ТЕЛЕФОНЫ ============ */
@media (max-width: 760px) {
  /* инпуты 16px — чтобы iOS не зумил при фокусе */
  input, textarea, select { font-size: 16px; }

  /* логин */
  .login-card { width: min(340px, 92vw); padding: 22px; }

  /* шапка: перенос, компактно */
  header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  header .spacer { display: none; }
  header .logo { font-size: 16px; }
  header .stat { font-size: 11.5px; order: 2; }
  header .who { font-size: 11.5px; order: 3; margin-left: auto; }
  header input.search { order: 10; flex: 1 1 100%; width: auto; }
  header button.ghost { padding: 9px 11px; font-size: 13px; }

  /* доска: колонки почти во всю ширину, свайп по одной */
  #board { padding: 10px; gap: 10px; scroll-snap-type: x mandatory; }
  .col { width: 86vw; min-width: 86vw; max-height: 100%; scroll-snap-align: start; }

  /* дровер-карточка на весь экран */
  #drawer { width: 100vw; max-width: 100vw; }
  .kv { grid-template-columns: 92px 1fr; }
  .wl-row { flex-wrap: wrap; }
  .wl-row input, .wl-row textarea { flex-basis: 100%; }

  /* оверлеи на весь экран */
  #tapeOverlay, #callsOverlay { padding: 0; }
  .tape-wrap, .calls-card { border-radius: 0; height: 100dvh; }
  #dashOverlay, #missedOverlay { padding: 10px; align-items: stretch; }
  .dash-card { max-width: 100%; padding: 16px 14px; border-radius: 12px; }
  .dash-grid { grid-template-columns: 1fr; }

  /* шапка журнала звонков */
  .calls-head { gap: 8px; padding: 10px 12px; }
  .calls-head h2 { font-size: 16px; }
  .calls-filters { width: 100%; flex-wrap: wrap; }
  .calls-filters .search { flex: 1 1 auto; width: auto; }
  .calls-kpi { order: 9; flex-basis: 100%; font-size: 12px; }

  /* строка звонка: гибкий перенос вместо жёсткой сетки */
  .call-row { display: flex; flex-wrap: wrap; align-items: center; column-gap: 8px; row-gap: 3px; }
  .call-row .call-guestcell { flex-basis: 100%; order: 5; }
  .call-row .call-playcell { margin-left: auto; }
  .call-when { min-width: 74px; }

  /* шахматка: тянущийся горизонтальный скролл */
  .tape-head { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .tape-nav { flex-wrap: wrap; }
}

/* очень узкие экраны */
@media (max-width: 380px) {
  header button.ghost { padding: 8px 9px; font-size: 12.5px; }
  .col { width: 90vw; min-width: 90vw; }
}
.dash-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; width: 100%; max-width: 820px; position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.dash-card .x { position: absolute; top: 14px; right: 16px; background: none; border: 0; color: var(--muted); font-size: 24px; }
.dash-card h2 { margin: 0 0 18px; font-size: 20px; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.ds { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.ds-h { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.ds-badge { font-size: 11px; color: var(--muted); font-weight: 400; }
.ds-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; color: var(--muted); }
.ds-row b { color: var(--text); }

.danger { color: var(--red); font-weight: 700; }

/* ---- calls journal (Beeline) ---- */
#callsOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 46;
  display: none; padding: 20px;
}
#callsOverlay.open { display: block; }
.calls-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  height: 100%; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.calls-head {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.calls-head h2 { margin: 0; font-size: 18px; white-space: nowrap; }
.calls-head .spacer { flex: 1; }
.calls-kpi { color: var(--muted); font-size: 13px; }
.calls-kpi b { color: var(--text); }
.calls-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.calls-filters select, .calls-filters input { padding: 6px 9px; font-size: 13px; }
.calls-filters .search { width: 130px; }
.calls-head .x { background: none; border: 0; color: var(--muted); font-size: 24px; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.chk input { width: auto; }
.calls-list { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }

.call-row {
  display: grid; align-items: center; gap: 10px;
  grid-template-columns: 20px 92px 96px 140px 1fr 52px 118px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.call-row:hover { background: var(--panel2); }
.call-arrow { font-size: 16px; font-weight: 700; text-align: center; }
.call-when { color: var(--muted); font-size: 12.5px; }
.call-badge {
  font-size: 11px; padding: 1px 8px; border-radius: 20px; text-align: center;
  background: #232936; color: var(--muted); border: 1px solid var(--line); justify-self: start;
}
.call-phone { color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; }
.call-phone:hover { color: var(--accent); }
.call-guest { color: var(--accent); text-decoration: none; cursor: pointer; }
.call-guest:hover { text-decoration: underline; }
.call-unknown { color: var(--muted); font-size: 12.5px; }
.call-dur { color: var(--muted); font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.call-play {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; white-space: nowrap;
}
.call-play:hover { border-color: var(--accent); }
.call-audio { height: 30px; max-width: 100%; }

/* цветовые акценты по типу звонка */
.call-in  .call-arrow { color: var(--green); }
.call-out .call-arrow { color: var(--accent); }
.call-missed .call-arrow, .call-noans .call-arrow { color: var(--red); }
.call-in  .call-badge { background: #16301f; color: #9be3b4; border-color: #2f5a3f; }
.call-out .call-badge { background: #172436; color: #a9c8ff; border-color: #2f486b; }
.call-missed .call-badge { background: #3a1f22; color: #ff9b9b; border-color: #6b3a3a; }
.call-noans  .call-badge { background: #232936; color: var(--muted); }
/* пропущенный входящий = потенциально потерянный гость: выделяем */
.call-missed.call-row { background: rgba(239,91,91,.07); border-left: 3px solid var(--red); }

/* компактные звонки в карточке гостя */
.calls-inline { display: flex; flex-direction: column; gap: 5px; }
.call-line {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: 16px 74px 1fr 44px auto;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font-size: 12.5px;
}
.call-line.call-missed { border-left: 3px solid var(--red); }
.call-line .call-arrow { font-size: 14px; }
.call-line .call-play { padding: 3px 8px; }
.call-line .call-audio { height: 28px; grid-column: 1 / -1; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; z-index: 50;
}
.toast.show { opacity: 1; }
