:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1f6f5c; --accent-soft: #e3f1ec; --red: #c2410c; --red-soft: #fdece4; --warn: #b45309;
  --chip: #eef0f3; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
  --radius: 12px; --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --text: #e8eaed; --muted: #9aa3ae; --line: #262b35;
    --accent: #3fb391; --accent-soft: #15302a; --red: #f08a5d; --red-soft: #35201a; --warn: #f0b35d;
    --chip: #232833; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
h3 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.red { color: var(--red); }
.warn { color: var(--warn); font-weight: 600; }
.n { background: var(--chip); border-radius: 10px; padding: 0 8px; font-size: 12px; color: var(--muted); }

/* каркас */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100vh; }
html, body { overflow-x: hidden; }
main#main { min-width: 0; padding: 12px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); max-width: 980px; width: 100%; margin: 0 auto; }
.side { display: none; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); z-index: 20; }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); gap: 2px; }
.tabs a span { font-size: 20px; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.plus span { background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 26px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .tabs { display: none; }
  .side { display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; position: sticky; top: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--line); }
  .side a { padding: 9px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side a.add { margin-top: 10px; background: var(--accent); color: #fff; }
  .side a.bottom { margin-top: auto; }
  main#main { padding: 20px 28px 40px; max-width: none; }
}
.brand { font-weight: 800; font-size: 18px; padding: 4px 12px 14px !important; }
.brand span { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.brand.big { font-size: 28px; text-align: center; }

/* шапка страницы */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.client-head { align-items: flex-start; }
.search input, input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0; }
.search { flex: 1 1 220px; max-width: 420px; min-width: 0; }
.search.big { max-width: none; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }

/* блоки и строки */
.block { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.block h2 + .row, .row:first-child { border-top: 0; }
.row.overdue .row-title { color: var(--red); }
.row-main { flex: 1; min-width: 0; display: block; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-step { font-size: 13px; margin-top: 2px; }
.row-step.red { color: var(--red); }
.row-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
@media (max-width: 600px) {
  .row { flex-wrap: wrap; }
  .row-actions { width: 100%; }
  .row-actions .done { margin-left: auto; }
}
.chip { background: var(--chip); border-radius: 6px; padding: 0 6px; font-size: 12px; }
.t-hozblok { background: #fdf0d5; color: #7a5200; } .t-modular { background: #dff0ff; color: #0b5394; }
.t-frame { background: #e3f1ec; color: #1f6f5c; } .t-banya { background: #fde4e4; color: #9b2c2c; }
.t-company { background: #ede4fd; color: #5b2c9b; } .t-finish { background: #eef0f3; color: #444; }
@media (prefers-color-scheme: dark) { .chip[class*="t-"] { background: var(--chip); color: var(--text); } }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* кнопки связи */
.contacts { display: flex; gap: 6px; flex-wrap: wrap; }
.cbtn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 10px; font-size: 16px; line-height: 1; cursor: pointer; color: var(--text); }
.contacts.compact .cbtn { padding: 7px; min-width: 36px; justify-content: center; }
.cbtn span { font-size: 14px; }
.cbtn.done { color: var(--accent); font-weight: 700; }

/* формы */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.grid .wide, .grid textarea { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; grid-column: 1 / -1; }
.check input { width: auto; }
.note-form textarea { margin-bottom: 10px; }
.note-form .btn { margin-top: 10px; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { color: var(--accent); }
.btn.wide { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 2px 4px; }
.link.red { color: var(--red); }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
details.more { margin-top: 10px; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; padding: 4px 0; }
details.more > summary::-webkit-details-marker { display: none; }
details.more[open] > summary { margin-bottom: 10px; }
details.tiny > summary { font-size: 12px; font-weight: 400; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

/* этапы сделки */
.stages { display: flex; gap: 6px; flex-wrap: wrap; }
.stage { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 20px; padding: 6px 12px; cursor: pointer; }
.stage.on { background: var(--accent); color: #fff; border-color: var(--accent); cursor: default; }
.stage.lost { color: var(--red); }
.stage.lost.on { background: var(--red); color: #fff; }

/* таблицы-строки */
.trow { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.trow:first-child { border-top: 0; }
.trow .grow { flex: 1; min-width: 0; }
.trow.paid { opacity: .6; }
.trow.red .grow b, .trow.red { color: var(--red); }
.pay input[name=amount] { width: 110px; }
.pay input[type=date] { width: 150px; }
@media (max-width: 600px) { .trow { flex-wrap: wrap; } .pay { width: 100%; } .pay input[name=amount] { flex: 1; } }

/* деньги */
.cards3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.paycard { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.paycard summary { cursor: pointer; list-style: none; }
.paycard summary::-webkit-details-marker { display: none; }
.big { font-size: 24px; font-weight: 700; }

/* лента */
.feed { display: flex; flex-direction: column; gap: 8px; }
.ev { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; }
.ev.in { border-left-color: var(--accent); }
.ev-stage, .ev-system, .ev-step { opacity: .8; }
.ev-payment { border-left-color: #d4a017; }
.ev-meta { font-size: 12px; color: var(--muted); }
.ev-text { white-space: pre-wrap; word-break: break-word; }

/* воронка */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; padding: 6px 10px; }
.pill { border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; font-size: 13px; background: var(--panel); }
.pill.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.col { flex: 0 0 82vw; max-width: 300px; background: var(--chip); border-radius: var(--radius); padding: 8px; scroll-snap-align: start; display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
@media (min-width: 900px) { .col { flex-basis: 250px; } .board { margin: 0; padding-left: 0; } }
.col.closed { opacity: .8; }
.col-head { display: flex; flex-direction: column; padding: 2px 4px 8px; font-size: 14px; }
.col-head .muted { font-size: 12px; }
.col-body { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 60px; flex: 1; }
.card { display: block; background: var(--panel); border-radius: 10px; padding: 8px 10px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.card.overdue { border-color: var(--red); }
.card-title { font-weight: 600; font-size: 14px; }
.card-sub { font-size: 12px; margin-top: 2px; }
.card-step { font-size: 12px; margin-top: 2px; }
.card-step.red { color: var(--red); }
.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.hint { margin-top: 8px; }

/* окна */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--panel); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; }
.modal.error { border-top: 4px solid var(--red); }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }

/* вход */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.auth-error { color: var(--red); min-height: 1em; margin: 0; }
.device-link { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.qr svg { width: 220px; height: 220px; background: #fff; border-radius: 8px; }
.phone-line { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
