:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1c2430; --muted: #68758a;
  --primary: #2f6fed; --primary-dark: #2458c4; --border: #dde3ec;
  --green: #1f9d61; --red: #d64545; --amber: #c98a12;
  --radius: 10px; --shadow: 0 1px 3px rgba(20, 40, 80, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e3a6e, #2f6fed); }
.login-card { background: #fff; padding: 36px; border-radius: 14px; width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin-bottom: 20px; }
.login-card input { width: 100%; margin-bottom: 12px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #17223b; color: #cdd6e4; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { padding: 18px 20px; font-weight: 700; font-size: 16px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar nav a { display: block; padding: 11px 20px; color: #cdd6e4; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar nav a.active { background: rgba(47,111,237,.18); color: #fff; border-left-color: var(--primary); }
.sidebar .spacer { flex: 1; }
.userbox { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.userbox .role { color: #8fa1bd; font-size: 12px; }
.userbox button { margin-top: 8px; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #cdd6e4; border-radius: 6px; padding: 5px 12px; font-size: 12px; }
.userbox button:hover { border-color: #fff; color: #fff; }
.main { flex: 1; padding: 24px 28px; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar h1 { font-size: 22px; }

/* ---------- components ---------- */
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,111,237,.25); border-color: var(--primary); }
.btn { display: inline-block; border: none; background: var(--primary); color: #fff; padding: 9px 16px; border-radius: 7px; font-size: 14px; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #e8edf5; color: var(--text); }
.btn.secondary:hover { background: #dbe2ee; }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.link { background: none; color: var(--primary); padding: 2px 4px; }
.btn.link.danger { color: var(--red); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { width: 280px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.data tr:hover td { background: #f8fafd; }
.right { text-align: right; } .center { text-align: center; }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; background: #e8edf5; }
.badge.new { background: #e3edff; color: #2458c4; }
.badge.in_work { background: #fff3d6; color: var(--amber); }
.badge.won { background: #dcf5e8; color: var(--green); }
.badge.lost { background: #fde3e3; color: var(--red); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card .val { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .lbl { color: var(--muted); font-size: 13px; }

/* ---------- modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,25,45,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 12px; width: 640px; max-width: 94vw; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 16px 60px rgba(0,0,0,.3); }
.modal.wide { width: 900px; }
.modal h2 { margin-bottom: 16px; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* deal items editor */
.items-editor table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.items-editor th, .items-editor td { padding: 4px; }
.items-editor input, .items-editor select { width: 100%; padding: 6px 8px; }
.toast { position: fixed; bottom: 24px; right: 24px; background: #17223b; color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.3); z-index: 200; opacity: 0; transition: opacity .25s; }
.toast.show { opacity: 1; }
.toast.error { background: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.chart-bars .bar { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; }
.chart-bars .bar span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart-labels { display: flex; gap: 6px; margin-top: 4px; }
.chart-labels div { flex: 1; text-align: center; font-size: 10px; color: var(--muted); }
@media (max-width: 800px) {
  .sidebar { width: 64px; }
  .sidebar .logo, .sidebar nav a { font-size: 0; padding: 12px; text-align: center; }
  .sidebar nav a::first-letter { font-size: 18px; }
  .main { padding: 14px; max-width: none; }
}
/* ---------- калькулятор заказа ---------- */
.room-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px 4px; margin-bottom: 10px; background: #fbfcfe; }
.calc-res { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.calc-res h3 { margin-bottom: 10px; font-size: 15px; }
.calc-res table.data { font-size: 13px; }
.calc-hdr td { font-weight: 700; background: #f4f7fc; }
.calc-warn { margin-top: 10px; padding: 10px 12px; background: #fde3e3; color: #8c2f2f; border-radius: 8px; font-size: 13px; }
.calc-ok { margin-top: 10px; padding: 10px 12px; background: #dcf5e8; color: #14663f; border-radius: 8px; font-size: 13px; }
.calc-total { margin-top: 10px; font-size: 18px; font-weight: 700; text-align: right; }
.calc-thumb img { max-height: 160px; border-radius: 8px; border: 1px solid var(--border); }
.calc-vz label { margin-right: 16px; font-size: 13px; color: var(--text); }
.wrow { display: flex; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; align-items: center; }
.wrow input { width: 100px; }
.wrow select { width: 100px; }
.wrec { width: 100%; margin: -2px 0 6px; }
.wmode { display: flex; gap: 14px; flex-wrap: wrap; margin: 2px 0 8px; font-size: 13px; }
.wmode label { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: normal; }
.filter { margin-bottom: 4px; }
.filter-suggest {
  max-height: 240px; overflow-y: auto; margin: 4px 0 6px;
  border: 1px solid var(--border, #ccc); border-radius: 6px; background: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.suggest-item {
  padding: 6px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #eee;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: rgba(47,111,237,.10); }
/* печать спецификации: прячем приложение, печатаем только текст */
#calcPrint { display: none; }
@media print {
  #app, .toast { display: none !important; }
  #calcPrint { display: block !important; white-space: pre-wrap; font-family: 'Courier New', monospace; font-size: 12px; padding: 10mm; }
}
@media (max-width: 640px) {
  .calc-res { grid-template-columns: 1fr; }
  .wrow input { width: 45%; }
}

/* ---------- мобильные устройства (телефоны) ---------- */
@media (max-width: 640px) {
  .main { padding: 10px; }
  .topbar h1 { font-size: 18px; }
  /* таблицы с горизонтальной прокруткой — не ломают вёрстку */
  .panel { padding: 12px; overflow-x: auto; }
  table.data { display: block; overflow-x: auto; white-space: nowrap; }
  .items-editor table { display: block; overflow-x: auto; }
  /* формы в одну колонку */
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type=search] { width: 100%; }
  .toolbar { gap: 6px; }
  .toolbar .btn, .toolbar label { font-size: 13px; }
  .btn { padding: 10px 14px; } /* удобнее попадать пальцем */
  .login-card { width: 94vw; padding: 24px; }
  .modal { padding: 16px; }
  /* карточки показателей в 2 колонки */
  .cards { grid-template-columns: repeat(2, 1fr); }
  /* тост во всю ширину снизу */
  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

/* ================= CRM-слой: воронка, задачи, клиент, отчёты ================= */
/* Бейдж открытых задач в меню */
.nav-badge { display: inline-block; margin-left: 8px; min-width: 18px; padding: 1px 6px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 11px; line-height: 16px; text-align: center; vertical-align: middle; }
.nav-badge:empty { display: none; }

/* компактные метки */
.pill { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: #e8edf5; color: #43536b; white-space: nowrap; }
.pill.prio-high { background: #fde3e3; color: var(--red); }
.pill.prio-normal { background: #e8edf5; color: #43536b; }
.pill.prio-low { background: #eef1f6; color: var(--muted); }
.pill.pay-full { background: #dcf5e8; color: var(--green); }
.pill.pay-part { background: #fff3d6; color: var(--amber); }
.pill.pay-none { background: #fde3e3; color: var(--red); }
.pill.tasks { background: #e3edff; color: #2458c4; }
.pill.act-call { background: #e3edff; color: #2458c4; }
.pill.act-meeting { background: #fff3d6; color: #a56d05; }
.pill.act-email { background: #eee8ff; color: #5b3fbf; }
.pill.act-note { background: #e8edf5; color: #43536b; }
.text-red { color: var(--red); }
.meta { font-size: 12px; }

/* ---------- воронка (канбан) ---------- */
.kanban { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { flex: 1 0 236px; min-width: 236px; background: #eef1f7; border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; max-height: calc(100vh - 230px); }
.kanban-col.new { border-top: 3px solid var(--primary); }
.kanban-col.in_work { border-top: 3px solid var(--amber); }
.kanban-col.won { border-top: 3px solid var(--green); }
.kanban-col.lost { border-top: 3px solid var(--red); }
.kanban-col.over { background: #e3edff; border-color: var(--primary); box-shadow: inset 0 0 0 2px rgba(47, 111, 237, .15); }
.kanban-col-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.kanban-col-title { font-weight: 600; }
.kanban-col-sum { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.kanban-col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 80px; }
.kanban-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px; box-shadow: var(--shadow); cursor: grab; }
.kanban-card:hover { border-color: #c3cfe2; }
.kanban-card.dragging { opacity: .45; }
.kanban-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kanban-num { font-weight: 700; }
.kanban-client { margin-top: 3px; font-size: 13px; line-height: 1.3; overflow-wrap: anywhere; }
.kanban-sum { font-weight: 700; font-size: 15px; margin-top: 4px; }
.kanban-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.kanban-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.kanban-lost { color: var(--red); margin-top: 6px; }
.kanban-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 8px; border: 1px dashed #cdd6e4; border-radius: 8px; }

/* ---------- задачи ---------- */
.task-item { display: flex; align-items: flex-start; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--border); }
.task-item:last-child { border-bottom: none; }
.task-item input[type=checkbox] { width: 16px; height: 16px; margin-top: 3px; flex-shrink: 0; cursor: pointer; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-item.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-sub { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 3px; font-size: 12px; }
.task-sub a { font-size: 12px; }
.task-actions { display: flex; gap: 2px; flex-shrink: 0; }
.due { padding: 1px 6px; border-radius: 5px; }
.due.overdue { background: #fde3e3; color: var(--red); font-weight: 600; }
.due.today { background: #fff3d6; color: #a56d05; font-weight: 600; }
.task-group { margin-bottom: 14px; }
.task-group:last-child { margin-bottom: 0; }
.task-group h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 2px; }
.task-group h4.overdue { color: var(--red); }
.task-note { cursor: help; }

/* переключатель «Мои / Все» */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; background: #fff; }
.seg-btn { border: none; background: #fff; padding: 8px 16px; color: var(--muted); font-size: 14px; }
.seg-btn.active { background: var(--primary); color: #fff; }

/* ---------- история общения (таймлайн) ---------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 0 0 14px 6px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ''; position: absolute; left: -18px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timeline-text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13.5px; }
.timeline-del { margin-left: auto; opacity: .6; }
.timeline-del:hover { opacity: 1; }
.activity-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.activity-form select { max-width: 150px; }
.activity-form input[name=text] { flex: 1; min-width: 180px; }

/* ---------- оплаты (панель сделки) ---------- */
.pay-summary { display: flex; gap: 26px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.pay-summary .lbl { font-size: 12px; color: var(--muted); }
.pay-summary .val { font-size: 18px; font-weight: 700; }
.pay-summary .val.ok { color: var(--green); }
.pay-summary .val.due { color: var(--red); }
.report-table td, .report-table th { padding: 6px 8px; }
.report-table td.right { white-space: nowrap; }
.report-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

/* ---------- карточка клиента ---------- */
.client-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 18px; }
.client-fields .lbl { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.client-fields .v { overflow-wrap: anywhere; }
.funnel-card { display: block; color: var(--text); }
.funnel-card:hover { border-color: var(--primary); }

/* ---------- отчёты ---------- */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.report-grid .panel { margin-bottom: 0; }

/* ---------- адаптив нового слоя ---------- */
/* канбан прокручивается внутри себя, а не раздвигает всю страницу */
.layout > .main { min-width: 0; }
@media (max-width: 900px) {
  .report-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .nav-badge { display: none; }
}
@media (max-width: 640px) {
  .kanban { scroll-snap-type: x proximity; }
  .kanban-col { min-width: 84vw; max-width: 84vw; max-height: none; scroll-snap-align: start; }
  /* крупные суммы в карточках на телефоне — мельче, чтобы влезали в две колонки */
  .cards .card { min-width: 0; }
  .cards .card .val { font-size: 20px; overflow-wrap: anywhere; }
  .topbar .crm-hint { display: none; }
  .pay-summary { gap: 16px; }
  .pay-summary .val { font-size: 16px; }
  .task-item { flex-wrap: wrap; }
  .task-actions { width: 100%; justify-content: flex-end; }
  .activity-form select, .activity-form input[name=text] { width: 100%; max-width: none; flex: 1 1 100%; }
  .client-fields { grid-template-columns: 1fr; }
}

/* ---------- Кассовый чек (ККТ) в карточке документа ---------- */
.kkt-info {
  font-size: 13px;
  color: #1f7a45;
  background: #eefaf2;
  border: 1px solid #cde9d6;
  border-radius: 7px;
  padding: 10px 12px;
}

/* ---------- импорт прихода из документа поставщика (#/stock) ---------- */
.modal.xwide { width: 1180px; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: default; }
.imp-doctotal { margin-top: 10px; font-size: 13px; }
.imp-toolbar { display: flex; align-items: center; gap: 10px; margin: 14px 0 8px; flex-wrap: wrap; }
.imp-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.imp-wrap table.data { margin: 0; }
.imp-wrap table.data th { position: sticky; top: 0; background: #f8fafd; z-index: 1; white-space: nowrap; }
.imp-wrap table.data td { padding: 6px 8px; vertical-align: top; }
.imp-table input[type=number], .imp-table .imp-prod { padding: 6px 8px; }
.imp-table .imp-prod { width: 100%; }
.imp-table .imp-prod.miss { border-color: var(--red); background: #fff6f6; }
.imp-miss { color: var(--red); font-size: 11.5px; margin-top: 3px; }
.imp-fuzzy { color: var(--amber); font-size: 11.5px; margin-top: 3px; }
.imp-total { text-align: right; margin-top: 10px; font-size: 14px; }
.imp-hint { margin-top: 8px; font-size: 12px; color: var(--muted); }
.imp-warn { margin-top: 10px; padding: 8px 12px; background: #fff3d6; color: #8a5c04; border-radius: 8px; font-size: 12.5px; }
.imp-preview { margin-top: 10px; font-size: 12px; }
.imp-preview summary { cursor: pointer; color: var(--muted); }
.imp-preview pre { margin-top: 6px; max-height: 160px; overflow: auto; white-space: pre-wrap; background: #f8fafd; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 11.5px; }
@media (max-width: 640px) {
  .imp-wrap { max-height: none; }
  .imp-total { text-align: left; }
}

/* ---------- Среда разработки ---------- */
.dev-banner {
  background: #b91c1c;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
}
