:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #627084;
  --line: #e1e6ed;
  --brand: #1f4e79;
  --brand-2: #2d6aa3;
  --brand-soft: #e8f0f8;
  --brand-btn: #1f4e79;
  --brand-btn-hover: #2d6aa3;
  --panel-2: #f8fafc;
  --line-strong: #c5cdd8;
  --col: #eef1f5;
  --drop-line: #c5d3e3;
  --drop-bg: #fafcfe;
  --savebar: rgba(244, 246, 249, .95);
  --focus: #9cc0e4;
  --warn-ink: #6b4500;
  --bad-ink: #7a1a12;
  --info-ink: #173c5e;
  --toast: #1b2430;
  color-scheme: light;
  --ok: #1e7b4f;
  --ok-soft: #e4f4ec;
  --warn: #9a6100;
  --warn-soft: #fff4dc;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
/* ---------- темная тема ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --panel: #171e27;
  --panel-2: #1c2430;
  --ink: #e4e9ef;
  --muted: #95a3b4;
  --line: #2a3441;
  --line-strong: #3b4757;
  --brand: #6ea8e0;
  --brand-2: #86b8e8;
  --brand-soft: #1b2c3f;
  --brand-btn: #2b69a8;
  --brand-btn-hover: #3778ba;
  --ok: #4fc38b;
  --ok-soft: #14301f;
  --warn: #e3aa45;
  --warn-soft: #33280f;
  --bad: #f2756e;
  --bad-soft: #3a1b19;
  --col: #131a22;
  --drop-line: #34465b;
  --drop-bg: #141b24;
  --savebar: rgba(15, 20, 27, .94);
  --focus: #3f6f9f;
  --warn-ink: #f0c56f;
  --bad-ink: #f6a39c;
  --info-ink: #a9cdf0;
  --toast: #2a3441;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .3);
}
:root[data-theme="dark"] .auth-promo { background: linear-gradient(160deg, #0f2236, #163a5c 55%, #1f4e79); }
:root[data-theme="dark"] dialog { background: var(--panel); color: var(--ink); }
:root[data-theme="dark"] .logo i::after { background: #e4e9ef; }
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand-2); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- кнопки и поля ---------- */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--line-strong); }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--brand-btn); border-color: var(--brand-btn); color: #fff; }
.primary:hover { background: var(--brand-btn-hover); border-color: var(--brand-btn-hover); }
.danger { color: var(--bad); }
.link { border: 0; background: none; padding: 0; color: var(--brand-2); }
.big { padding: 11px 20px; font-size: 16px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--brand-2); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-promo { background: linear-gradient(160deg, #173c5e, #1f4e79 55%, #2d6aa3); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; }
.auth-promo h1 { font-size: 34px; margin-bottom: 16px; }
.auth-promo p { font-size: 17px; opacity: .92; max-width: 520px; }
.auth-promo ul { padding: 0; list-style: none; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-promo li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
.auth-promo li b { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.18); flex: none; font-size: 13px; }
.auth-form { display: grid; place-items: center; padding: 40px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 22px; margin-bottom: 6px; }
.auth-card form { margin-top: 22px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.logo i { width: 30px; height: 30px; border-radius: 8px; background: var(--brand-btn); display: inline-block; position: relative; }
.logo i::after { content: ""; position: absolute; inset: 7px 9px; background: #fff; border-radius: 2px; }
.auth-promo .logo i { background: #fff; }
.auth-promo .logo i::after { background: var(--brand); }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .logo { padding: 4px 10px 18px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: 13px; }
/* ширина подстраивается под экран: на ноутбуке как раньше, на мониторе - шире (до 1920 px, чтобы строки не растягивались бесконечно) */
.main { padding: 26px clamp(18px, 2.2vw, 48px) 60px; max-width: 1920px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 3px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card > h2, .card > .card-head { margin-bottom: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; display: flex; gap: 12px; align-items: center; }
.banner.warn { background: var(--warn-soft); color: var(--warn-ink); }
.banner.bad { background: var(--bad-soft); color: var(--bad-ink); }
.banner.info { background: var(--brand-soft); color: var(--info-ink); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
td input, td select { padding: 6px 8px; }
.table-wrap { overflow-x: auto; }

/* ---------- шаги дела ---------- */
.steps { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.steps button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); font-weight: 600; }
.steps button.active { color: var(--brand); border-bottom-color: var(--brand); }
.steps button .num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--bg); font-size: 12px; }
.steps button.active .num { background: var(--brand-btn); color: #fff; }
.steps button.done .num { background: var(--ok-soft); color: var(--ok); }

.drop { border: 2px dashed var(--drop-line); border-radius: var(--radius); padding: 30px; text-align: center; background: var(--drop-bg); transition: .15s; }
.drop.over { border-color: var(--brand-2); background: var(--brand-soft); }
.drop h3 { margin-bottom: 6px; font-size: 16px; }
.drop .row { justify-content: center; margin-top: 14px; }

.files li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.files { list-style: none; padding: 0; margin: 0; }
.files .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files select { width: auto; max-width: 260px; padding: 5px 8px; }
.ext { font-size: 11px; font-weight: 700; padding: 3px 6px; border-radius: 5px; background: var(--bg); color: var(--muted); text-transform: uppercase; min-width: 42px; text-align: center; }

.notes { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font-size: 14px; margin-top: 14px; }

.form-section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-section > h3 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.savebar { position: sticky; bottom: 0; background: var(--savebar); backdrop-filter: blur(4px); padding: 12px 0; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); margin-top: 8px; z-index: 2; }

.docs-section { margin-bottom: 8px; }
.docs-section summary { cursor: pointer; padding: 10px 4px; font-weight: 600; display: flex; align-items: center; gap: 10px; list-style: none; }
.docs-section summary::-webkit-details-marker { display: none; }
.docs-section summary::before { content: "▸"; color: var(--muted); transition: .15s; }
.docs-section[open] summary::before { transform: rotate(90deg); }
.doc { display: flex; align-items: center; gap: 10px; padding: 7px 4px 7px 26px; border-top: 1px dashed var(--line); font-size: 14px; }
.doc .t { flex: 1; min-width: 0; }
.doc .t small { display: block; color: var(--muted); }
.doc input[type=checkbox] { width: auto; }
.left-list { font-size: 12px; color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }

.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.plan { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--panel); display: flex; flex-direction: column; gap: 8px; }
.plan.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.plan .price { font-size: 26px; font-weight: 700; }
.plan .price small { font-size: 14px; color: var(--muted); font-weight: 400; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

#toast { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; }
#toast div { background: var(--toast); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 420px; animation: in .2s; }
#toast div.err { background: var(--bad); }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
button:not(.primary) .spinner { border-color: var(--line-strong); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { border: 0; border-radius: 12px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); width: min(480px, 92vw); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h2 { margin-bottom: 14px; }

@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-promo { padding: 32px; }
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .side .logo, .side-foot { display: none; }
  .nav { display: flex; flex-wrap: wrap; }
  .main { padding: 18px; }
}

/* ---------- CRM ---------- */
.red { color: var(--bad); }
.stat.bad b { color: var(--bad); }
.stats.mini { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stats.mini .stat { padding: 10px 12px; }
.stats.mini .stat b { font-size: 17px; }
.dash { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.dash .card { margin-bottom: 18px; }
.dash h2 { font-size: 15px; margin-bottom: 10px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
.dash ul.plain li { padding: 7px 0; border-top: 1px solid var(--line); display: grid; gap: 2px; font-size: 14px; }
.dash ul.plain li:first-child { border-top: 0; padding-top: 0; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; border-radius: 0; padding: 7px 14px; }
.seg button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; color: var(--ink); }
label.check input { width: auto; }

.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.col { flex: 1 0 236px; max-width: 360px; background: var(--col); border-radius: var(--radius); padding: 10px; min-height: 140px; transition: .15s; }
.col.over { background: var(--brand-soft); outline: 2px dashed var(--brand-2); }
.col header { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.col .cards { display: grid; gap: 8px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; cursor: grab; box-shadow: var(--shadow); display: grid; gap: 3px; font-size: 14px; }
.kcard:hover { border-color: var(--line-strong); }
.kcard.dragging { opacity: .5; }
.kcard .pay { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.pipeline { display: flex; gap: 4px; overflow-x: auto; }
.pstep { flex: 1 1 0; min-width: 96px; flex-direction: column; gap: 4px; border: 0; background: none; padding: 6px 4px; text-align: center; white-space: normal; font-size: 12px; color: var(--muted); position: relative; }
.pstep::before { content: ""; position: absolute; top: 19px; left: -50%; right: 50%; height: 2px; background: var(--line); z-index: 0; }
.pstep:first-child::before { display: none; }
.pstep i { font-style: normal; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 2px solid var(--line); font-weight: 700; position: relative; z-index: 1; }
.pstep small { color: var(--muted); }
.pstep.done { color: var(--ink); }
.pstep.done i { background: var(--ok); border-color: var(--ok); color: #fff; }
.pstep.done::before, .pstep.active::before { background: var(--ok); }
.pstep.active { color: var(--brand); font-weight: 700; }
.pstep.active i { background: var(--brand-btn); border-color: var(--brand-btn); color: #fff; box-shadow: 0 0 0 4px var(--brand-soft); }
.pstep:hover i { border-color: var(--brand-2); }

.crm-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; }
table.compact td, table.compact th { padding: 7px 8px; }
.sub-form { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.sub-form summary { cursor: pointer; color: var(--brand-2); font-weight: 600; font-size: 14px; }
.sub-form form { margin-top: 12px; }
.task-form { display: grid; gap: 8px; margin: 12px 0 4px; }
.tasks li, .events li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.tasks li input { width: auto; margin-top: 3px; }
.tasks li.done .t > div { text-decoration: line-through; color: var(--muted); }
.tasks .t, .events .t { flex: 1; min-width: 0; }
.tasks small, .events small { display: block; color: var(--muted); font-size: 12px; }
.tasks small.red { color: var(--bad); }
.tasks li.over { background: var(--drop-bg); outline: 2px dashed var(--drop-line); outline-offset: -2px; border-radius: 8px; }
.tasks .attach { white-space: nowrap; font-size: 13px; }
.task-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tasks li.done .t > .task-files { text-decoration: none; color: inherit; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--ink); font-size: 12px; font-weight: 400; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip:hover { border-color: var(--line-strong); }
.file-chip .ext { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.events { margin-top: 10px; max-height: 520px; overflow-y: auto; }
.events i { font-style: normal; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); flex: none; font-size: 13px; color: var(--muted); }
.events .ev-stage i { background: var(--brand-soft); color: var(--brand); }
.events .ev-payment i { background: var(--ok-soft); color: var(--ok); }

.dash-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tasks-card { margin-top: 18px; }
.tasks-filter select { width: auto; }
.tasks-filter input { flex: 1; min-width: 180px; }
.tasks-table td { font-size: 14px; }

.theme-switch { margin: 10px 10px 0; display: flex; }
.theme-switch button { flex: 1; padding: 6px 8px; font-size: 13px; justify-content: center; }

@media (max-width: 1100px) {
  .dash, .crm-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .theme-switch { margin: 0 0 0 auto; }
}

[hidden] { display: none !important; }
.kit-switch button { padding: 8px 16px; }
textarea { resize: vertical; min-height: 64px; }

/* широкие экраны: карточка клиента и поля анкеты располагаются свободнее */
@media (min-width: 1700px) {
  .crm-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
