/* FutureFlow CRM. Компоненты читают только токены; тёмная тема — переопределение токенов. */
@font-face { font-family: 'Manrope'; font-weight: 200 800; font-display: swap;
  src: url('/fonts/manrope-cyrillic-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Manrope'; font-weight: 200 800; font-display: swap;
  src: url('/fonts/manrope-latin-wght-normal.woff2') format('woff2-variations'); }

:root {
  --brand: #2571C2; --brand-logo: #3C8AD8; --grad: linear-gradient(135deg, #3c8ad8, #0f8fb5);
  --bg: #F4F7FB; --surface: #FFFFFF; --surface-2: #F0F4FA; --line: #E1E8F1; --text: #1C1C1B; --muted: #66717F;
  --ok: #1F9D55; --ok-bg: #E6F6EC; --warn: #B7791F; --warn-bg: #FFF4DE; --bad: #D64545; --bad-bg: #FDECEC;
  --info-bg: #EAF3FC; --shadow: 0 1px 2px rgba(16,40,72,.06), 0 8px 24px rgba(16,40,72,.06);
  --r: 14px; --r-sm: 10px; --nav-w: 232px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #6AA6EA; --bg: #0B1018; --surface: #131A25; --surface-2: #19222F; --line: #253142; --text: #E8EDF4; --muted: #94A1B2;
  --ok: #4CC184; --ok-bg: #12301F; --warn: #E3B04B; --warn-bg: #33270F; --bad: #F07272; --bad-bg: #3A1717; --info-bg: #15263A;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 Manrope, system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 800; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* каркас */
.layout { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh;
  background: linear-gradient(90deg, var(--surface) calc(var(--nav-w) - 1px), var(--line) 0 var(--nav-w), transparent 0); }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; }
.logo { display: block; color: var(--brand-logo); padding: 4px 10px 18px; }
:root[data-theme="dark"] .logo { color: #fff; }
.logo svg { width: 150px; height: auto; display: block; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--r-sm); color: var(--text); font-weight: 600; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--info-bg); color: var(--brand); }
.nav svg { width: 19px; height: 19px; flex: 0 0 auto; }
.nav .badge { margin-left: auto; }
.side-foot { margin-top: auto; display: flex; gap: 6px; padding: 8px 4px 0; border-top: 1px solid var(--line); }
.main { padding: 26px 30px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { margin-right: auto; }
.search { position: relative; }
.search input { width: 260px; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--muted); }
.search-res { position: absolute; top: calc(100% + 6px); right: 0; width: 360px; max-height: 420px; overflow: auto; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px; }
.search-res a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.search-res a:hover { background: var(--surface-2); text-decoration: none; }
.search-res .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px 2px; font-weight: 700; }

/* карточки и сетки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: 16px; }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: var(--grad); color: #fff; border: 0; }
.kpi.accent .label, .kpi.accent .sub { color: rgba(255,255,255,.85); }
.kpi.bad .value { color: var(--bad); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: rgba(255,255,255,.95); border-radius: 99px; }
.card .bar i { background: var(--brand); }
.kpi.accent .bar { background: rgba(255,255,255,.25); }

/* списки и таблицы */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row > svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--muted); }
.row .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-chip { flex: 0 0 52px; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 5px 0; line-height: 1.1; }
.date-chip b { display: block; font-size: 18px; }
.date-chip span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700;
  padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { cursor: pointer; }
.t tbody tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; margin: -6px -8px; padding: 0 8px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* бейджи */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); }
.b-paid { background: var(--ok-bg); color: var(--ok); }
.b-sent, .b-issued { background: var(--info-bg); color: var(--brand); }
.b-partial, .b-warn { background: var(--warn-bg); color: var(--warn); }
.b-overdue, .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-cancelled { text-decoration: line-through; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* формы и кнопки */
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.field { margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.fields .wide { grid-column: 1 / -1; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); font-size: 14px; }
.check input { width: auto; accent-color: var(--brand); }
input[type=checkbox] { accent-color: var(--brand); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 700; font-size: 14px;
  padding: 9px 15px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
  white-space: nowrap; transition: background .15s, transform .05s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 13px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 13px; font-weight: 700; border: 0; background: none; color: var(--muted); padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* модальное окно */
dialog { border: 0; padding: 0; border-radius: 18px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 18, 30, .5); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 4px; }
.dlg-head h2 { margin: 0; flex: 1; }
.dlg-body { padding: 14px 20px; overflow: auto; max-height: calc(100vh - 170px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--line); }
.items .item { display: grid; grid-template-columns: minmax(0, 1fr) 140px 36px; gap: 8px; margin-bottom: 8px; }
.total-line { display: flex; justify-content: space-between; font-weight: 800; font-size: 17px; padding: 8px 0 4px; }

/* уведомления */
.toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; z-index: 100; background: #16202D; color: #fff; padding: 12px 18px;
  border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; max-width: calc(100vw - 32px); animation: up .2s ease; }
.toast.err { background: var(--bad); }
@keyframes up { from { opacity: 0; translate: -50% 10px; } }

/* календарь */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal .wd { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; padding: 4px 0; }
.cal .day { min-height: 104px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-width: 0; }
.cal .day.out { opacity: .4; }
.cal .day.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal .n { font-size: 12px; font-weight: 800; color: var(--muted); }
.chip { display: block; font-size: 11.5px; font-weight: 700; padding: 2px 6px; border-radius: 6px; margin-top: 3px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; background: var(--surface-2); color: var(--text); }
.chip.plan { background: var(--info-bg); color: var(--brand); }
.chip.pay { background: var(--ok-bg); color: var(--ok); }
.chip.due { background: var(--warn-bg); color: var(--warn); }
.chip.rem { background: var(--surface-2); color: var(--muted); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }

/* диаграмма */
.chart svg { width: 100%; height: 190px; display: block; }
.chart .lg { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.chart .lg i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.auth-box { width: min(400px, 100%); }
.auth-box .logo { padding: 0 0 22px; text-align: center; }
.auth-box .logo svg { margin: 0 auto; width: 190px; }
.pdf-frame { width: 100%; height: 72vh; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.kv { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.note { background: var(--surface-2); border-radius: var(--r-sm); padding: 10px 12px; white-space: pre-wrap; }
.mob-nav { display: none; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); background: none; }
  .row { flex-wrap: wrap; }
  .row .grow { flex-basis: calc(100% - 64px); }
  .date-chip ~ .row-end { margin-left: 64px; }
  .side { display: none; }
  .main { padding: 16px 16px 96px; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .search input { width: 100%; }
  .search { order: 3; flex-basis: 100%; }
  .search-res { width: 100%; }
  .mob-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 40; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mob-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
  .mob-nav a.on { color: var(--brand); }
  .mob-nav svg { width: 22px; height: 22px; }
  .cal { gap: 3px; }
  .cal .day { min-height: 64px; padding: 3px; }
  .cal .chip { font-size: 10px; padding: 1px 3px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dd { margin-bottom: 8px; }
  .items .item { grid-template-columns: minmax(0, 1fr) 110px 36px; }
  .t .hide-m { display: none; }
  h1 { font-size: 21px; }
}
@media (max-width: 860px) {
  /* таблицы → карточки: строка становится блоком, ячейки идут столбиком */
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .t thead { display: none; }
  .t, .t tbody, .t tr { display: block; }
  .t tr { position: relative; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .t tr:last-child { border-bottom: 0; }
  .t td { display: inline-block; border: 0; padding: 2px 8px 2px 0; vertical-align: middle; }
  .t td:first-child { display: block; }
  .t td.right { text-align: left; }
  .t td:has(> input.sel) { position: absolute; right: 0; top: 12px; }
  .t td:has(> .actions) { display: block; padding-top: 6px; }
  .t td:has(> .actions) .actions { justify-content: flex-start !important; }
  .t tbody tr:hover td { background: none; }
  .t .empty { display: block; }
  .t td[data-l]::before { content: attr(data-l) ' '; color: var(--muted); font-size: 12px; font-weight: 600; }
}
@media (max-width: 520px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .g4 .kpi { padding: 12px; }
  .kpi .value { font-size: 18px; }
  .kpi .label { font-size: 12px; }
  .kpi .sub { font-size: 11.5px; }
  .cal .chip { display: none; }
  .cal .day.has::after { content: ''; display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); margin: 4px auto 0; }
}

/* проекты */
.row.lk { flex-wrap: wrap; }
.secret { margin-top: 4px; display: flex; align-items: center; gap: 8px; background: var(--warn-bg); color: var(--text); border-radius: 8px; padding: 4px 8px; width: fit-content; }
.secret.hidden { display: none; }

/* заявки, баннер, защита */
.nav a { position: relative; }
.nb { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--bad); color: #fff;
  font-size: 11.5px; font-weight: 800; display: inline-grid; place-items: center; line-height: 1; }
.nb.hidden { display: none; }
.banner { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; color: inherit; border-color: var(--warn); background: var(--warn-bg); }
.banner:hover { text-decoration: none; }
.banner > svg { width: 26px; height: 26px; flex-shrink: 0; color: var(--warn); }
.banner .grow { flex: 1; min-width: 0; }
.contact-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.contact-btns .btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.bad-t { color: var(--bad); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.btn svg, .row-end svg { width: 17px; height: 17px; flex-shrink: 0; }

/* телефон: удобство пальцем */
@media (max-width: 860px) {
  /* 16px — меньше iOS увеличивает страницу при фокусе на поле */
  input, select, textarea { font-size: 16px; padding: 11px 12px; }
  .btn { min-height: 44px; padding: 10px 15px; }
  .btn.sm { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  .btn.icon { min-width: 44px; }
  .btn.sm.icon { min-width: 40px; }
  .seg button { padding: 10px 13px; font-size: 14px; }
  .tabs a { padding: 12px 13px; }
  .check { min-height: 40px; }
  .check input { width: 22px; height: 22px; }
  input[type=checkbox].sel { width: 24px; height: 24px; }
  .mob-nav { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .mob-nav a { position: relative; font-size: 10.5px; min-height: 48px; justify-content: center; }
  .mob-nav .nb { position: absolute; top: 0; left: calc(50% + 4px); min-width: 17px; height: 17px; font-size: 10px; padding: 0 4px; }
  .main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  /* окно — лист снизу во всю ширину; кнопки сохранения всегда на виду */
  dialog { width: 100vw !important; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh; }
  dialog[open] { display: flex; flex-direction: column; }
  dialog > form { display: flex; flex-direction: column; min-height: 0; max-height: 92dvh; }
  .dlg-body { max-height: none; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
  .dlg-foot { flex-wrap: wrap; padding-bottom: calc(14px + env(safe-area-inset-bottom)); background: var(--surface); }
  .dlg-foot .btn { flex: 1 1 auto; }
  .contact-btns .btn { flex: 1 1 calc(50% - 8px); }
  .contact-btns .btn.primary { flex-basis: 100%; }
  .pdf-frame { height: 60dvh; }
}
.auth { min-height: 100dvh; }
.row.lr { flex-wrap: nowrap; align-items: flex-start; }
.row.lr .grow { min-width: 0; flex-basis: auto; }
.row.lr .meta { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@media (max-width: 860px) {
  .seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); width: 100%; }
}
