/* ================= токены ================= */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --hover: #f3f4f6;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #2547d0;
  --accent-hover: #1d3bb3;
  --accent-soft: #eef2ff;
  --accent-text: #2547d0;

  --red: #c4320a;   --red-soft: #fef3f2;   --red-line: #fecdca;
  --amber: #b54708; --amber-soft: #fffaeb; --amber-line: #fedf89;
  --blue: #175cd3;  --blue-soft: #eff8ff;  --blue-line: #b2ddff;
  --green: #067647; --green-soft: #ecfdf3; --green-line: #abefc6;
  --gray: #475467;  --gray-soft: #f2f4f7;  --gray-line: #e4e7ec;

  --side: #0c111d;
  --side-2: #161b26;
  --side-text: #98a2b3;
  --side-active: #ffffff;
  --side-border: #1f242f;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 20px 40px -8px rgba(16, 24, 40, 0.18), 0 4px 8px -2px rgba(16, 24, 40, 0.06);
  --nav-h: 64px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0b0e14;
  --surface: #12161f;
  --surface-2: #161b25;
  --hover: #1a2030;
  --border: #232937;
  --border-strong: #2f3647;
  --text: #f0f2f5;
  --text-2: #cfd4dc;
  --muted: #8b93a3;
  --faint: #5f6878;
  --accent: #4f6ef7;
  --accent-hover: #6680ff;
  --accent-soft: rgba(79, 110, 247, 0.14);
  --accent-text: #8ca0ff;
  --red: #f97066;   --red-soft: rgba(249, 112, 102, 0.1);   --red-line: rgba(249, 112, 102, 0.3);
  --amber: #fdb022; --amber-soft: rgba(253, 176, 34, 0.1);  --amber-line: rgba(253, 176, 34, 0.3);
  --blue: #53b1fd;  --blue-soft: rgba(83, 177, 253, 0.1);   --blue-line: rgba(83, 177, 253, 0.3);
  --green: #47cd89; --green-soft: rgba(71, 205, 137, 0.1);  --green-line: rgba(71, 205, 137, 0.3);
  --gray: #98a2b3;  --gray-soft: rgba(152, 162, 179, 0.1);  --gray-line: rgba(152, 162, 179, 0.25);
  --side: #080a0f;
  --side-2: #12161f;
  --side-border: #1a1f2a;
  --shadow-xs: none;
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ================= база ================= */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-feature-settings: 'cv11', 'ss01';
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
svg.i { width: 18px; height: 18px; flex-shrink: 0; }

/* ================= вход ================= */
.auth { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.auth-side {
  background: var(--side); color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-side::after {
  content: ''; position: absolute; right: -180px; bottom: -180px; width: 520px; height: 520px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.06); box-shadow: 0 0 0 80px rgba(255, 255, 255, 0.015), 0 0 0 160px rgba(255, 255, 255, 0.01);
}
.auth-side h2 { font-size: 36px; line-height: 1.15; letter-spacing: -0.025em; margin: 0 0 16px; font-weight: 600; max-width: 460px; }
.auth-side p { color: #98a2b3; font-size: 16px; max-width: 420px; margin: 0; }
.auth-feats { display: grid; gap: 18px; margin-top: 44px; max-width: 440px; }
.auth-feat { display: flex; gap: 14px; align-items: flex-start; }
.auth-feat .ic {
  width: 36px; height: 36px; border-radius: 9px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid; place-items: center; flex-shrink: 0; color: #c7d2fe;
}
.auth-feat b { display: block; font-weight: 600; font-size: 14px; }
.auth-feat span { color: #98a2b3; font-size: 13px; }
.auth-foot { color: #667085; font-size: 12px; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 28px; letter-spacing: -0.02em; margin: 0 0 6px; font-weight: 600; }
.auth-form .sub { color: var(--muted); margin: 0 0 28px; }
.auth-form .mobile-logo { display: none; margin-bottom: 32px; }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-form .mobile-logo { display: flex; }
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--side-text); letter-spacing: 0; }

/* ================= формы ================= */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; box-shadow: var(--shadow-xs); min-height: 40px;
}
.input::placeholder { color: var(--faint); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 110px; line-height: 1.5; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row3 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--text-2); margin-bottom: 16px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  border-radius: var(--radius-sm); padding: 9px 16px; font-weight: 600; font-size: 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-2); box-shadow: var(--shadow-xs);
  transition: background 0.15s, border-color 0.15s, color 0.15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.dark { background: var(--text); border-color: var(--text); color: var(--surface); }
.btn.success { background: var(--green-soft); border-color: var(--green-line); color: var(--green); }
.btn.danger { background: var(--surface); border-color: var(--red-line); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.sm { min-height: 32px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 36px; min-height: 36px; }
.btn.icon.sm { width: 32px; min-height: 32px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 10px; }

/* ================= каркас ================= */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 12px;
}
.sidebar .brand { color: #fff; padding: 4px 10px 24px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #475467; padding: 16px 12px 6px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
  color: var(--side-text); font-weight: 500; text-decoration: none; transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--side-2); color: #e4e7ec; }
.nav-item.active { background: var(--side-2); color: var(--side-active); }
.nav-item.active svg { color: #8ca0ff; }
.nav-count {
  margin-left: auto; background: #b42318; color: #fff; font-size: 11px; font-weight: 600;
  border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.sidebar .spacer { flex: 1; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 10px 4px; border-top: 1px solid var(--side-border); margin-top: 12px; }
.side-user .who { flex: 1; min-width: 0; font-size: 13px; color: #e4e7ec; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .who small { display: block; color: #667085; font-weight: 400; font-size: 12px; }
.side-user .btn.ghost { color: #667085; }
.side-user .btn.ghost:hover { background: var(--side-2); color: #fff; }

main { flex: 1; min-width: 0; }
.content { max-width: 1240px; margin: 0 auto; padding: 28px 32px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; }

.mobile-top { display: none; }
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .sidebar { display: none; }
  .content { padding: 16px 16px calc(var(--nav-h) + 32px); }
  .page-head { margin-bottom: 18px; align-items: center; }
  .page-head h1 { font-size: 22px; }
  .mobile-top {
    display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    color: var(--faint); font-size: 11px; font-weight: 500; position: relative;
  }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--accent-text); }
  .bottom-nav .nav-count { position: absolute; top: 6px; left: calc(50% + 4px); margin: 0; font-size: 10px; padding: 0 5px; min-width: 16px; }
}

/* ================= панели ================= */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-head .count { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--gray-soft); border-radius: 10px; padding: 0 8px; }
.panel-head .total { color: var(--muted); font-size: 13px; }
.panel-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; margin-bottom: 20px; }
.panel, .kpis > * { min-width: 0; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: 20px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1080px) { .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.kpi { padding: 18px 20px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .label svg { width: 16px; height: 16px; color: var(--faint); }
.kpi .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 10px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .foot { color: var(--muted); font-size: 12px; margin-top: 6px; }
.kpi.alert .value { color: var(--red); }
.kpi.primary { background: var(--side); border-color: var(--side); color: #fff; }
.kpi.primary .label, .kpi.primary .foot { color: #98a2b3; }
.kpi.primary .label svg { color: #8ca0ff; }
@media (max-width: 560px) { .kpis { gap: 10px; } .kpi { padding: 14px; } .kpi .value { font-size: 19px; } }

/* строки списков */
.rows { display: flex; flex-direction: column; }
.r {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
}
.r:last-child { border-bottom: 0; }
.r:hover { background: var(--surface-2); }
.r .grow { flex: 1; min-width: 0; }
.r .t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r .amt { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.r .amt small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
@media (max-width: 560px) { .r { padding: 12px 14px; } }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  font-weight: 600; font-size: 13px; letter-spacing: 0.02em;
}
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }

.empty { color: var(--muted); text-align: center; padding: 36px 16px; }
.empty .ic { width: 40px; height: 40px; margin: 0 auto 10px; border-radius: 10px; background: var(--gray-soft); display: grid; place-items: center; color: var(--faint); }
.empty b { display: block; color: var(--text-2); font-weight: 500; margin-bottom: 2px; }

/* бейджи */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 2px 8px 2px 7px;
  border-radius: 999px; white-space: nowrap; border: 1px solid; line-height: 18px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-overdue { color: var(--red); background: var(--red-soft); border-color: var(--red-line); }
.b-today { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-line); }
.b-soon { color: var(--blue); background: var(--blue-soft); border-color: var(--blue-line); }
.b-ok { color: var(--green); background: var(--green-soft); border-color: var(--green-line); }
.b-closed, .b-none { color: var(--gray); background: var(--gray-soft); border-color: var(--gray-line); }

/* тулбар и фильтры */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); }
.search .input { padding-left: 36px; }
.seg { display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; scrollbar-width: none; max-width: 100%; box-shadow: var(--shadow-xs); }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; white-space: nowrap;
  font-weight: 500; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--text); color: var(--surface); }
.seg button .n { font-variant-numeric: tabular-nums; opacity: 0.7; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.t td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--surface-2); }
table.t .r-align { text-align: right; }
table.t th:first-child, table.t td:first-child { padding-left: 20px; }
table.t th:last-child, table.t td:last-child { padding-right: 20px; }
.cell-client { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.cell-client b { font-weight: 500; display: block; }
.cell-client small { color: var(--muted); font-size: 13px; }
.bar { height: 6px; border-radius: 6px; background: var(--gray-soft); overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 6px; }
.bar.done > div { background: var(--green); }
.pct { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pct .bar { flex: 1; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-desktop { display: none !important; }
  .only-mobile { display: block; }
}

/* ================= модальные окна и панель клиента ================= */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(12, 17, 29, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade 0.15s;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 540px;
  max-height: calc(100vh - 40px); overflow: auto; box-shadow: var(--shadow-lg); animation: pop 0.16s;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 0; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.modal-body { padding: 20px 24px 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

.overlay.drawer { justify-content: flex-end; padding: 0; align-items: stretch; }
.overlay.drawer .modal {
  max-width: 680px; height: 100vh; max-height: 100vh; border-radius: 0; border-width: 0 0 0 1px; animation: slide 0.2s ease-out;
  display: flex; flex-direction: column;
}
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.drawer-body { padding: 24px; flex: 1; }
@media (max-width: 640px) {
  .overlay, .overlay.drawer { align-items: flex-end; padding: 0; }
  .modal, .overlay.drawer .modal {
    border-radius: 16px 16px 0 0; max-height: 94vh; height: auto; border-width: 1px 0 0; animation: up 0.2s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-head { padding: 18px 16px 0; }
  .modal-body, .drawer-body { padding: 16px; }
  .drawer-head { padding: 16px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0.6; } }

.client-head { display: flex; gap: 14px; align-items: center; }
.client-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.client-head .sub { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.client-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 24px; overflow: hidden; }
.summary > div { padding: 14px 16px; border-right: 1px solid var(--border); }
.summary > div:last-child { border-right: 0; }
.summary span { display: block; color: var(--muted); font-size: 12px; }
.summary b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .summary b { font-size: 14px; } .summary > div { padding: 12px; } }
.info-list { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.info-list > div { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.info-list > div:last-child { border-bottom: 0; }
.info-list span { color: var(--muted); font-size: 12px; width: 84px; flex-shrink: 0; }
.info-list b { font-weight: 500; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.note-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--text-2); white-space: pre-wrap; margin-bottom: 24px; font-size: 13px; }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin: 0 0 12px; }
.deal { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.deal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px; }
.deal-head .t { font-weight: 600; font-size: 15px; }
.deal-head .s { color: var(--muted); font-size: 13px; margin-top: 2px; }
.deal-figs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.deal-figs > div { background: var(--surface-2); padding: 10px 18px; }
.deal-figs span { display: block; color: var(--muted); font-size: 12px; }
.deal-figs b { font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .deal-figs { grid-template-columns: 1fr 1fr; } }
.deal-progress { padding: 14px 18px 4px; }
.deal-foot { display: flex; gap: 8px; padding: 12px 18px 16px; flex-wrap: wrap; }
.sched { width: 100%; border-collapse: collapse; font-size: 13px; }
.sched th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 18px; border-bottom: 1px solid var(--border); }
.sched td { padding: 9px 18px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.sched tr:last-child td { border-bottom: 0; }
.sched tr.next td { background: var(--accent-soft); }
.sched .r-align { text-align: right; }
.sched td, .sched th { white-space: nowrap; }
.deal, .drawer-body { min-width: 0; }
@media (max-width: 560px) {
  .sched th, .sched td { padding: 8px 10px; }
  .sched th:first-child, .sched td:first-child { padding-left: 14px; }
  .sched .hide-m { display: none; }
  .deal-head, .deal-progress, .deal-foot { padding-left: 14px; padding-right: 14px; }
  .deal-figs > div { padding: 10px 14px; }
}
details.more > summary {
  list-style: none; cursor: pointer; padding: 10px 18px; color: var(--accent-text); font-weight: 500; font-size: 13px;
  border-top: 1px solid var(--border); display: flex; align-items: center; gap: 6px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary svg { transition: transform 0.15s; width: 14px; height: 14px; }
details.more[open] > summary svg { transform: rotate(180deg); }

.calc { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 16px; }
.calc > div { padding: 12px 14px; border-right: 1px solid var(--border); }
.calc > div:last-child { border-right: 0; }
.calc span { display: block; color: var(--muted); font-size: 12px; }
.calc b { font-variant-numeric: tabular-nums; font-weight: 600; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 16px; }
.quick button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--text-2); font-variant-numeric: tabular-nums; }
.quick button:hover { border-color: var(--accent); color: var(--accent-text); }

/* ================= календарь ================= */
.day-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; }
.day-head b { font-weight: 600; }
.day-head .muted { font-variant-numeric: tabular-nums; }
.day-head.late b { color: var(--red); }

/* ================= ИИ ================= */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 460px; overflow: hidden; }
@media (max-width: 960px) { .chat { height: calc(100vh - var(--nav-h) - 170px); } }
.msgs { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.msg { display: flex; gap: 12px; max-width: 760px; width: 100%; }
.msg .who { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.msg.ai .who { background: var(--side); color: #8ca0ff; }
.msg.ai .who svg { width: 15px; height: 15px; }
.msg .body { padding-top: 3px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.6; color: var(--text); min-width: 0; }
.msg.me { align-self: flex-end; justify-content: flex-end; }
.msg.me .body { background: var(--surface-2); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px 12px 4px 12px; }
.msg.err .body { color: var(--red); }
.typing { display: flex; gap: 4px; padding-top: 10px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.composer { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; gap: 10px; align-items: flex-end; background: var(--surface); }
.composer textarea { min-height: 44px; max-height: 160px; resize: none; }
.composer .btn { min-height: 44px; }
.ai-empty { margin: auto; text-align: center; max-width: 520px; padding: 20px; }
.ai-empty .mark { width: 48px; height: 48px; border-radius: 12px; background: var(--side); color: #8ca0ff; display: grid; place-items: center; margin: 0 auto 16px; }
.ai-empty h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.ai-empty p { color: var(--muted); margin: 0 0 20px; }
.prompts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
@media (max-width: 560px) { .prompts { grid-template-columns: 1fr; } }
.prompts button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 12px 14px; cursor: pointer;
  font-size: 13px; color: var(--text-2); text-align: left; transition: border-color 0.12s, background 0.12s;
}
.prompts button:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ================= импорт ================= */
.imp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.imp-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 10px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.imp-table td { padding: 4px; border-bottom: 1px solid var(--border); }
.imp-table input { width: 100%; min-width: 84px; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.imp-table input:hover { border-color: var(--border); }
.imp-table input:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.imp-table td.name input { min-width: 150px; font-weight: 500; }
.imp-table tr.dup td { background: var(--red-soft); }
.imp-table tr.dup input { color: var(--muted); text-decoration: line-through; }
.imp-table td.flag { padding: 4px 10px 4px 16px; white-space: nowrap; }
.status-line .btn { font-weight: 600; }
.imp-table input.need { border-color: var(--amber-line); background: var(--amber-soft); }
.imp-table td.months input { min-width: 64px; }
.imp-table td.phone input { min-width: 150px; }
.imp-table td.product input { min-width: 140px; }
.imp-table td.start_date input, .imp-table td.first_due input { min-width: 110px; }
.imp-table td.note input { min-width: 200px; }

/* ================= настройки ================= */
.settings { display: grid; gap: 20px; max-width: 860px; }
.set-row { display: grid; grid-template-columns: 260px 1fr; gap: 32px; padding: 24px; }
.set-row + .set-row { border-top: 1px solid var(--border); }
.set-row h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.set-row p { margin: 0; color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .set-row { grid-template-columns: 1fr; gap: 14px; padding: 18px 16px; } }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
.status-line.ok { color: var(--green); }
.status-line.warn { color: var(--amber); }
.status-line.bad { color: var(--red); }

/* ================= фиксированная мобильная версия ================= */
html, body { overflow-x: hidden; max-width: 100%; }
body { overscroll-behavior-y: none; touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.msg .tok { font-size: 11px; color: var(--faint); margin-top: 6px; font-variant-numeric: tabular-nums; }
@media (max-width: 960px) {
  /* iOS увеличивает страницу при фокусе на поле со шрифтом < 16px — делаем 16px */
  .input, select.input, textarea.input, .imp-table input { font-size: 16px; }
  .app { min-height: 100dvh; }
  .mobile-top { position: fixed; left: 0; right: 0; top: 0; padding-top: calc(12px + env(safe-area-inset-top)); }
  main { padding-top: calc(57px + env(safe-area-inset-top)); }
  .content { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .page-head .actions .btn { min-height: 38px; padding: 8px 12px; }
  /* чат занимает ровно экран между шапкой и нижним меню, поле ввода всегда видно */
  .chat { height: calc(100dvh - 57px - env(safe-area-inset-top) - var(--nav-h) - env(safe-area-inset-bottom) - 110px); min-height: 320px; }
  .msgs { padding: 16px; }
  .msg { max-width: 100%; }
  .overlay { overscroll-behavior: contain; }
  .modal { overscroll-behavior: contain; }
}
@media (max-width: 960px) and (display-mode: standalone) {
  .bottom-nav { height: calc(var(--nav-h) + max(env(safe-area-inset-bottom), 8px)); }
}

/* ================= ИИ-чат во весь экран ================= */
.content.page-ai { padding-top: 24px; padding-bottom: 24px; }
.page-ai .chat { height: calc(100dvh - 48px); min-height: 420px; }
.chat-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-top .grow { flex: 1; min-width: 0; }
.chat-top b { display: block; font-weight: 600; }
.chat-top span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top .mark-sm { width: 32px; height: 32px; border-radius: 9px; background: var(--side); color: #8ca0ff; display: grid; place-items: center; flex-shrink: 0; }
.chat-top .mark-sm svg { width: 17px; height: 17px; }
.composer textarea { overflow-y: auto; }
@media (max-width: 960px) {
  .content.page-ai { padding: 8px 8px 0; }
  .page-ai .chat {
    position: fixed; left: 0; right: 0; top: calc(57px + env(safe-area-inset-top)); z-index: 15;
    height: calc(100dvh - 57px - env(safe-area-inset-top) - var(--nav-h) - env(safe-area-inset-bottom));
    min-height: 0; border-radius: 0; border-width: 0;
  }
  html.ai-lock, html.ai-lock body { overflow: hidden; height: 100%; overscroll-behavior: none; }
  body.kb-open .mobile-top { display: none; }
  .page-ai .msgs { padding: 14px 12px; gap: 16px; }
  .page-ai .composer { padding: 10px; padding-bottom: 10px; }
  .page-ai .composer .btn { width: 48px; padding: 0; }
  .page-ai .ai-empty { padding: 8px; }
  .page-ai .ai-empty .mark { display: none; }
  body.kb-open .bottom-nav { display: none; }
}

/* ================= настройки: вкладки ================= */
.set-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; max-width: 1000px; }
.set-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 24px; }
.set-nav button {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-weight: 500; cursor: pointer; text-align: left; white-space: nowrap;
}
.set-nav button:hover { background: var(--hover); color: var(--text); }
.set-nav button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); border: 1px solid var(--border); padding: 9px 11px; }
.set-nav button.active svg { color: var(--accent-text); }
.set-content { display: grid; gap: 16px; min-width: 0; }
.set-card .panel-head { align-items: flex-start; }
.set-card .panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 1.5; }
.set-card .panel-body > :last-child { margin-bottom: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hint-text { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.theme-seg { display: inline-flex; }
.theme-seg button { padding: 8px 16px; font-size: 14px; }
.theme-seg button svg { width: 16px; height: 16px; }
.account-line { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.account-line b { font-size: 16px; }
#devices .panel { box-shadow: none; }
#devices .r:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
@media (max-width: 960px) {
  .set-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .set-nav {
    flex-direction: row; overflow-x: auto; scrollbar-width: none; position: sticky; top: calc(57px + env(safe-area-inset-top)); z-index: 10;
    background: var(--bg); margin: -4px -16px 0; padding: 8px 16px; border-bottom: 1px solid var(--border);
  }
  .set-nav::-webkit-scrollbar { display: none; }
  .set-nav button { flex-shrink: 0; padding: 8px 12px; font-size: 14px; }
  .set-nav button.active { padding: 7px 11px; }
  .form-grid, .form-grid.two { grid-template-columns: minmax(0, 1fr); }
  .set-card .panel-head, .set-card .panel-body { padding: 14px 16px; }
  .btn-row .btn { flex: 1 1 auto; }
  .theme-seg { display: flex; }
  .theme-seg button { flex: 1; justify-content: center; }
}

/* мобильное меню настроек */
.set-menu .r { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; padding: 14px 16px; font: inherit; color: inherit; }
.set-menu .r:last-child { border-bottom: 0; }
.set-menu .set-ic { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex-shrink: 0; }
.set-menu .t { font-weight: 600; }
.set-menu .chev { color: var(--faint); }
.set-back { margin: -4px 0 4px -8px; }
.set-back .btn { color: var(--accent-text); padding-left: 6px; gap: 2px; }
.set-title { font-size: 22px; font-weight: 600; margin: 0 0 14px; letter-spacing: -0.02em; }

/* ================= ровная сетка форм ================= */
.fgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }
.fgrid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fgrid .full { grid-column: 1 / -1; }
.field { min-width: 0; }
.field label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.form-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: -4px 0 16px; }
.modal { overflow-x: hidden; }
/* поле даты на iPhone по умолчанию шире контейнера и «выталкивает» форму */
input[type='date'].input {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%;
  min-height: 40px; line-height: 1.25; text-align: left;
}
input[type='date'].input::-webkit-date-and-time-value { text-align: left; }
@media (max-width: 960px) {
  .fgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
  input[type='date'].input { min-height: 44px; }
}
@media (max-width: 640px) {
  .modal.tall { height: calc(100dvh - 16px - env(safe-area-inset-top)); max-height: none; display: flex; flex-direction: column; }
  .modal.tall { padding-bottom: 0; }
  .modal.tall > .modal-head { flex-shrink: 0; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
  .modal.tall > .modal-head .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .modal.tall > form, .modal.tall > .modal-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: 0; }
  .modal.tall .modal-actions {
    position: sticky; bottom: 0; z-index: 2; margin: 8px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); flex-wrap: nowrap;
  }
  .modal.tall .modal-actions .btn { flex: 1; }
  .modal.tall .calc > div { padding: 10px; }
  .modal.tall .calc b { font-size: 13px; }
}

/* ================= прочее ================= */
.banner { display: flex; gap: 14px; align-items: center; padding: 14px 18px; margin-bottom: 20px; }
.banner .ic { width: 36px; height: 36px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex-shrink: 0; }
.banner .grow { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }
.banner .grow b { display: block; color: var(--text); font-size: 14px; font-weight: 600; }
@media (max-width: 560px) { .banner { flex-wrap: wrap; } .banner .grow { flex-basis: calc(100% - 60px); } }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 100;
  background: var(--side); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 500; font-size: 13px; animation: up 0.2s; max-width: calc(100vw - 32px); display: flex; gap: 8px; align-items: center;
}
@media (max-width: 960px) { .toast { bottom: calc(var(--nav-h) + 16px); } }
.loader { display: grid; place-items: center; min-height: 60vh; }
.spin { width: 28px; height: 28px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: rot 0.7s linear infinite; }
.spin.sm { width: 16px; height: 16px; border-width: 2px; border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }
@keyframes rot { to { transform: rotate(360deg); } }
