/* Конструктор КП — Управляй Светом */
:root {
  --bg: #f5f6f8; --card: #fff; --line: #e3e6ea; --text: #1c1f24; --muted: #6b7280;
  --accent: #2563eb; --accent-soft: #eff4ff; --ok: #16a34a; --warn: #d97706; --danger: #dc2626;
  --section: #eef1f5; --thead: #fafbfc; --hover: #fcfdff; --btn2: #f3f5f8;
  --info-bg: #f8fafc; --err-bg: #fef2f2; --err-line: #fecaca; --toast: #111827;
  --toast-text: #fff; --slider: #cbd5e1; --shadow: rgba(16, 24, 40, .06);
}
:root[data-theme="dark"] {
  --bg: #131518; --card: #1c1f24; --line: #2b2f36; --text: #e7e9ec; --muted: #9aa2ad;
  --accent: #5b93f5; --accent-soft: #1d2b47; --ok: #34d399; --warn: #fbbf24; --danger: #f87171;
  --section: #23262c; --thead: #191c21; --hover: #21252b; --btn2: #262a31;
  --info-bg: #191d23; --err-bg: #331c1c; --err-line: #5f2b2b; --toast: #e7e9ec;
  --toast-text: #16181c; --slider: #3c434d; --shadow: rgba(0, 0, 0, .35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #131518; --card: #1c1f24; --line: #2b2f36; --text: #e7e9ec; --muted: #9aa2ad;
    --accent: #5b93f5; --accent-soft: #1d2b47; --ok: #34d399; --warn: #fbbf24; --danger: #f87171;
    --section: #23262c; --thead: #191c21; --hover: #21252b; --btn2: #262a31;
    --info-bg: #191d23; --err-bg: #331c1c; --err-line: #5f2b2b; --toast: #e7e9ec;
    --toast-text: #16181c; --slider: #3c434d; --shadow: rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
[v-cloak] { display: none; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; background: var(--card); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 36px 40px; width: 380px; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 8px 30px var(--shadow); }
.login-logo { color: var(--accent); font-weight: 700; letter-spacing: .4px; margin-bottom: 6px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-sub { color: var(--muted); margin: 0 0 18px; }
.login-error { background: var(--err-bg); color: var(--danger); border: 1px solid var(--err-line);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form input { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.login-form button { background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 12px; font-weight: 600; }
.login-form button:hover { filter: brightness(1.05); }
.login-note { color: var(--muted); font-size: 12px; margin-top: 14px; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted);
  font-size: 12px; margin: 16px 0; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tg-widget { display: flex; justify-content: center; margin: 6px 0; }

/* ---------- App layout ---------- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.topbar .brand { color: var(--accent); font-weight: 700; white-space: nowrap; }
.topbar .deal { font-weight: 600; }
.topbar .deal a { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--muted); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.saved-dot { font-size: 12px; color: var(--ok); transition: opacity .4s; }
.saved-dot.hidden { opacity: 0; }

.wrap { max-width: 1180px; margin: 18px auto 80px; padding: 0 16px; }

/* ---------- Variants tabs ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tab { background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; display: flex; gap: 7px; align-items: center; }
.tab.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tab .star { color: #d1d5db; }
.tab .star.primary { color: #f59e0b; }
.tab-new { border-style: dashed; color: var(--muted); background: transparent; }

/* ---------- Header card ---------- */
.head-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 14px; display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-end; }
.head-field { display: flex; flex-direction: column; gap: 4px; }
.head-field label { font-size: 12px; color: var(--muted); }
.head-field input[type="text"] { min-width: 180px; }
.head-field input, .head-field select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.head-field .hint { font-size: 11px; color: var(--muted); }
.rate-row { display: flex; gap: 6px; align-items: center; }
.rate-row input { width: 90px; }
.btn-ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.vat-toggle { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.switch { position: relative; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--slider); border-radius: 999px; transition: .15s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---------- Table ---------- */
/* overflow:visible — иначе выпадающий комбобокс обрезается; углы скругляем ячейками */
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: visible; }
table.kp { width: 100%; border-collapse: separate; border-spacing: 0; }
table.kp thead th:first-child { border-top-left-radius: 12px; }
table.kp thead th:last-child { border-top-right-radius: 12px; }
table.kp tbody tr:last-child td:first-child { border-bottom-left-radius: 12px; }
table.kp tbody tr:last-child td:last-child { border-bottom-right-radius: 12px; }
table.kp th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 10px 10px; border-bottom: 1px solid var(--line); background: var(--thead); }
table.kp td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.kp tr:last-child td { border-bottom: 0; }
tr.row-product:hover, tr.row-service:hover { background: var(--hover); }
tr.row-section td { background: var(--section); font-weight: 700; padding: 7px 10px; }
tr.row-section .sec-input { border: 0; background: transparent; font-weight: 700; width: 60%;
  padding: 2px 4px; border-radius: 6px; }
tr.row-section .sec-input:focus { outline: 1px solid var(--accent); background: var(--card); }
.sec-total { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
.drag-handle { cursor: grab; color: #c3c9d1; user-select: none; padding: 0 2px; }
.drag-handle:hover { color: var(--accent); }
.name-cell { max-width: 480px; }
.name-main { font-weight: 600; }
.name-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.warn-badge { color: var(--warn); cursor: help; }
.qty-input, .disc-input { width: 62px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; }
.disc-cell { display: inline-flex; align-items: stretch; }
.disc-cell .disc-input, .disc-cell input { width: 66px; border-radius: 7px 0 0 7px; border: 1px solid var(--line); padding: 5px 7px; }
.disc-mode { border: 1px solid var(--line); border-left: 0; border-radius: 0 7px 7px 0;
  background: var(--btn2); padding: 0 8px; font-weight: 700; color: var(--muted); }
.disc-mode:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
.disc-mode:disabled { opacity: .5; cursor: not-allowed; }
.manual-mark { color: var(--warn); margin-left: 4px; font-size: 12px; }
.muted-inline { color: var(--muted); font-weight: 400; font-size: 11px; }
.pricebox { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
  border-top: 1px dashed var(--line); padding-top: 12px; }
@media (max-width: 760px) { .pricebox { grid-template-columns: 1fr; } }
.price-cell { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.price-rrc { color: var(--muted); font-size: 12px; text-decoration: line-through; }
.price-main { font-weight: 600; }
.sum-cell { text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; text-align: right; }
.icon-btn { background: transparent; border: 0; border-radius: 7px; padding: 5px 7px; color: var(--muted); }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }
.empty-note { padding: 34px; text-align: center; color: var(--muted); }

/* ---------- Add buttons ---------- */
.addbar { display: flex; gap: 10px; margin: 12px 0 16px; flex-wrap: wrap; position: relative; }
.btn { border-radius: 9px; padding: 9px 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { color: #fff; filter: brightness(1.06); }
.btn-primary:disabled { background: #9db7ee; border-color: #9db7ee; cursor: not-allowed; }
.menu { position: absolute; top: 100%; left: 0; margin-top: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px var(--shadow);
  min-width: 320px; z-index: 30; max-height: 55vh; overflow: auto; }
.menu .group { padding: 8px 12px 2px; font-size: 11px; text-transform: uppercase; color: var(--muted); }
.menu .mi { display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 8px 14px; }
.menu .mi:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- Totals ---------- */
.totals { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; min-width: 300px; }
.totals-card .tr { display: flex; justify-content: space-between; gap: 30px; padding: 3px 0; }
.totals-card .muted { color: var(--muted); }
.totals-card .grand { font-size: 18px; font-weight: 800; border-top: 1px solid var(--line);
  margin-top: 6px; padding-top: 8px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; }
.modal { background: var(--card); border-radius: 14px; width: 560px; max-width: 100%;
  max-height: calc(100vh - 80px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-h { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-b { padding: 16px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.modal-b .full { grid-column: 1 / -1; }
.f-field { display: flex; flex-direction: column; gap: 4px; }
.f-field label { font-size: 12px; color: var(--muted); }
.f-field input, .f-field select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.f-check { display: flex; gap: 8px; align-items: center; padding-top: 18px; }
.modal-price { grid-column: 1 / -1; background: var(--accent-soft); border-radius: 10px;
  padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; }
.modal-price .big { font-size: 20px; font-weight: 800; color: var(--accent); }
.modal-warn { grid-column: 1 / -1; color: var(--warn); font-size: 12px; }
.modal-info { grid-column: 1 / -1; background: var(--info-bg); border: 1px dashed var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--muted); }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex;
  justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: var(--card); }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--toast); color: var(--toast-text); border-radius: 10px; padding: 11px 18px; z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.err { background: var(--danger); }

.sortable-ghost { opacity: .4; background: var(--accent-soft) !important; }
@media (max-width: 760px) {
  .modal-b { grid-template-columns: 1fr; }
  .name-cell { max-width: 220px; }
}

/* ---------- Комбобокс добавления позиции ---------- */
tr.row-pending td { background: var(--accent-soft); }
.combo { position: relative; }
.combo input { width: 100%; border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 11px; background: var(--card); }
.combo input:focus { outline: 2px solid var(--accent-soft); }
.combo-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 34px var(--shadow); max-height: 320px; overflow: auto; }
.combo-item { display: flex; justify-content: space-between; gap: 14px; align-items: center;
  width: 100%; text-align: left; background: none; border: 0; padding: 9px 13px; color: var(--text); }
.combo-item:hover { background: var(--accent-soft); }
.combo-item .hl { color: var(--accent); }
.combo-group { color: var(--muted); font-size: 11px; white-space: nowrap; }
.combo-empty { padding: 12px 14px; color: var(--muted); font-size: 13px; }
.theme-btn { font-size: 15px; }
tr.row-pending:hover { background: transparent; }

/* ---------- Ссылки на Базу знаний и ⓘ-подсказки ---------- */
.kb-link { display: inline-block; margin-left: 4px; color: var(--accent); text-decoration: none;
  font-weight: 700; font-size: 13px; border-radius: 5px; padding: 0 4px; vertical-align: baseline; }
.kb-link:hover { background: var(--accent-soft); }
.modal-h .kb-link { font-size: 15px; }
.info { position: relative; display: inline-block; vertical-align: middle; margin-left: 4px; }
.i-ico { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px;
  border-radius: 50%; border: 1px solid var(--muted); color: var(--muted); font-size: 10px;
  font-style: italic; font-weight: 700; font-family: Georgia, serif; cursor: help; line-height: 1; }
.info:hover .i-ico { border-color: var(--accent); color: var(--accent); }
.i-pop { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  width: 260px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px var(--shadow); padding: 10px 12px; z-index: 60;
  font-size: 12px; font-weight: 400; color: var(--text); line-height: 1.45; text-transform: none;
  white-space: normal; cursor: default; }
.info:hover .i-pop { display: block; }
.i-pop::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--line); }
.i-pop a { display: block; margin-top: 6px; color: var(--accent); font-weight: 600; text-decoration: none; }
.i-pop a:hover { text-decoration: underline; }
