:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2f6fde; --accent-dark: #2459b8; --ok: #1f9d55; --bad: #d64545; --head: #eef2f8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 6px; }
.muted { color: var(--muted); margin: 0 0 16px; }

/* Шапка */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1200px; margin: 0 auto; padding: 10px 16px 4px;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: .02em; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 14px; }
.who-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who form { margin: 0; }
.menu {
  display: flex; gap: 4px; max-width: 1200px; margin: 0 auto; padding: 4px 12px 8px;
  overflow-x: auto; scrollbar-width: none;
}
.menu::-webkit-scrollbar { display: none; }
.menu a {
  flex: none; padding: 6px 12px; border-radius: 16px; color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.menu a:hover { background: var(--head); }
.menu a.on { background: var(--accent); color: #fff; }

/* Страница */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card.narrow { max-width: 380px; margin: 40px auto 0; }

/* Формы */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px — без автозума на iPhone */
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fafbfc;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.btn {
  display: inline-block; border: 0; border-radius: 6px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn.wide { width: 100%; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.error { color: var(--bad); background: #fdecec; border-radius: 6px; padding: 8px 10px; margin: 0 0 12px; }

/* Таблицы */
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
th { background: var(--head); font-weight: 600; }
td.num { text-align: right; white-space: nowrap; }

/* Общие элементы страниц */
h2 { font-size: 17px; margin: 0 0 10px; }
h2.mt { margin-top: 22px; }
.small { font-size: 13px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { margin: 0 0 2px; overflow-wrap: anywhere; }
.page-head .muted { margin: 0; }
.btn.ghost { background: var(--card); color: var(--accent); border: 1px solid var(--accent); }
.btn.ghost:hover { background: var(--head); }
.flash { border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; background: #e8f6ee; color: #14663a; }
.flash.error { background: #fdecec; color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-error { font-size: 13px; color: var(--bad); margin-top: 4px; }
.has-error input, .has-error select { border-color: var(--bad); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--head); white-space: nowrap; }
.badge.st-active { background: #e8f0fd; color: var(--accent-dark); }
.badge.st-done { background: #e8f6ee; color: #14663a; }
.badge.st-terminated { background: #f1f2f4; color: var(--muted); }

/* Список */
.filters { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
@media (min-width: 720px) { .filters { grid-template-columns: 2fr 1fr 1fr auto; } }
table.list td { white-space: nowrap; }
table.list td:nth-child(2) { white-space: normal; min-width: 160px; }
td.bad { color: var(--bad); font-weight: 600; }

/* Форма договора */
.form-grid { display: grid; gap: 16px; }
@media (min-width: 1000px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid > section:last-of-type { grid-column: 1 / -1; } }
.two, .three { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .two { grid-template-columns: 1fr 1fr; } .three { grid-template-columns: 1fr 1fr 1fr; } }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.check input { width: auto; }
details { margin-bottom: 12px; }
summary { cursor: pointer; color: var(--accent); margin-bottom: 10px; }
fieldset.calc { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 4px 0 12px; }
fieldset.calc legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.sched { display: grid; gap: 6px; margin-bottom: 6px; }
.sched-row { display: grid; grid-template-columns: 18px minmax(0, 1.5fr) minmax(0, 1fr) 34px; gap: 6px; align-items: center; }
.sched-row input { padding: 8px 6px; }
@media (min-width: 560px) { .sched-row { grid-template-columns: 24px 180px 160px 36px; } }
.sched-n { color: var(--muted); font-size: 13px; text-align: right; }
button.icon { border: 1px solid var(--line); background: var(--card); border-radius: 6px; height: 38px; font-size: 18px; cursor: pointer; color: var(--muted); }
button.icon:hover { color: var(--bad); border-color: var(--bad); }
.sched-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: baseline; }
.sched-foot .hint b.bad { color: var(--bad); }
.actions { display: flex; align-items: center; gap: 16px; }

/* Карточка договора */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { display: block; font-size: 17px; white-space: nowrap; }
.stat small { display: block; font-size: 12px; color: var(--muted); }
.stat.is-bad { border-color: var(--bad); }
.stat.is-bad b, .stat.is-bad small { color: var(--bad); }
.cols { display: grid; gap: 16px; }
@media (min-width: 1000px) { .cols { grid-template-columns: 3fr 2fr; } }
.cols > .card, .side { min-width: 0; }
.side { display: grid; gap: 16px; align-content: start; }
tr.mark-paid td:last-child { color: var(--ok); }
tr.mark-partial td:last-child { color: #a86b00; }
tr.mark-overdue td { color: var(--bad); }
tr.mark-today td:last-child { color: #a86b00; font-weight: 600; }
tr.muted-row td { color: var(--muted); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
form.inline { display: flex; gap: 8px; }
form.inline select { flex: 1; min-width: 0; }

/* Ввод оплаты */
.pay { max-width: 560px; margin: 0 auto; }
.pay-form { display: grid; gap: 4px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
input.big { font-size: 20px; font-weight: 600; }
.search { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }
ul.results { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
ul.results li + li { border-top: 1px solid var(--line); }
ul.results a { display: block; padding: 8px 10px; color: var(--text); text-decoration: none; }
ul.results a:hover, ul.results a:focus { background: var(--head); }
ul.results .muted { display: block; font-size: 13px; margin: 0; }
.picked { border: 1px solid var(--accent); background: #f3f7fe; border-radius: 8px; padding: 10px 12px; }
.picked-name b { display: block; }
.picked-name .muted { font-size: 13px; margin: 0; }
.picked-hint { margin: 6px 0 4px; font-size: 14px; }
fieldset.chips { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
fieldset.chips legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
fieldset.chips label.chip { display: inline-block; margin: 0 6px 6px 0; cursor: pointer;
  font-size: 15px; color: var(--text); }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span { display: inline-block; border: 1px solid var(--line); border-radius: 18px; padding: 7px 14px; background: #fafbfc; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.has-error .chip span { border-color: var(--bad); }
.danger-zone { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
button.link.bad { color: var(--bad); }

/* Касса */
.period { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.period > a[aria-label] { font-size: 22px; text-decoration: none; padding: 0 6px; line-height: 1; }
.period b { font-size: 17px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
@media (min-width: 720px) { .stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } .stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
table.cash td, table.cash th { white-space: nowrap; }
table.cash th.c { text-align: center; }
table.cash th.sub { font-weight: 500; font-size: 12px; color: var(--muted); }
table.cash tfoot th { background: var(--head); }
table.cash td.bad { color: var(--bad); font-weight: 400; }
table.year th a { color: inherit; }
.only-narrow { display: none; }
@media (max-width: 767px) { .only-wide { display: none; } .only-narrow { display: grid; } }
.mcards { gap: 10px; margin-bottom: 12px; }
.mcard-head { display: flex; justify-content: space-between; gap: 8px; }
.mcard-total { margin: 4px 0 2px; }
.mcard-total b { font-size: 20px; }
.mcard .kv { margin-top: 10px; }
.method-line { margin: 12px 0 16px; }

/* Должники */
.filters.one { grid-template-columns: 1fr; max-width: 360px; }
.dcard { display: grid; gap: 6px; }
.dcard .today { color: #a86b00; }
.dcard .call { justify-self: start; margin-top: 4px; padding: 8px 14px; }

/* Планы и сотрудники */
.plans { display: grid; gap: 16px; }
.pgrid { display: grid; grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; align-items: center; max-width: 520px; }
.pgrid-h { font-size: 12px; color: var(--muted); }
.pgrid-dir { font-size: 14px; font-weight: 600; }
.pgrid-sum { font-size: 14px; font-variant-numeric: tabular-nums; padding: 0 10px; }
.pcell input { padding: 7px 9px; }
.pcell .field-error { font-size: 12px; }
.plan-all { max-width: 300px; margin-top: 14px; }
.plan-people { display: grid; gap: 18px; }
@media (min-width: 1000px) { .plan-people { grid-template-columns: 1fr 1fr; } }
.plan-person { min-width: 0; }
.plan-who { margin-bottom: 8px; }
.plan-who .muted { margin: 0; }
.people { display: grid; gap: 10px; margin-top: 16px; }
@media (min-width: 1000px) { .people { grid-template-columns: 1fr 1fr; align-items: start; } }
.person { display: grid; gap: 6px; }
.person-head .muted { margin: 0; }
.person.is-off { background: #fafafa; }
.person details { margin: 4px 0 0; }
.new-user summary { margin: 0; font-weight: 600; }
.new-user[open] summary { margin-bottom: 12px; }
.warn { background: #fff6e0; color: #7a4d00; border-radius: 6px; padding: 8px 10px; margin: 0; }

/* Передача договора */
form.reassign { display: grid; gap: 10px; }
fieldset.history { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.history legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
fieldset.history .check { margin-bottom: 4px; }
form.reassign .btn { justify-self: start; }
.stat.money { border-color: var(--ok); }
.stat.money b { color: var(--ok); }
table.cash .cell-plan { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
table.cash .cell-plan b { color: var(--text); font-weight: 600; }
