:root {
  --bg: #0e0e10;
  --panel: #18181c;
  --panel2: #1f1f24;
  --text: #f0f0f2;
  --muted: #8a8a96;
  --line: #2a2a32;
  --accent: #f97316;
  --accent2: #fb923c;
  --danger: #ef4444;
  --good: #22c55e;
  --warn: #f59e0b;
  --info: #3b82f6;
  --side-w: 240px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }
.side {
  width: var(--side-w); background: #0a0a0d; border-right: 1px solid var(--line);
  position: fixed; height: 100vh; display: flex; flex-direction: column; z-index: 10;
}
.main { margin-left: var(--side-w); flex: 1; min-height: 100vh; }

/* ── Sidebar ── */
.brand-wrap { padding: 20px 18px 14px; border-bottom: 1px solid var(--line); }
.brand { font-size: 18px; font-weight: 900; letter-spacing: -.04em; color: #fff; }
.brand span { color: var(--accent); }
.brand-sub { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 2px; }
.nav { flex: 1; overflow-y: auto; padding: 10px 10px; }
.nav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border-radius: 10px; color: var(--muted); font-size: 13px; font-weight: 500;
  margin-bottom: 2px; transition: all .18s; border-left: 2px solid transparent;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel2); color: #fff; border-left-color: var(--accent); font-weight: 700; }
.nav a .icon { font-size: 16px; width: 20px; text-align: center; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.nav-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 6px 10px 2px; }
.side-footer { padding: 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--panel); }
.user-av { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 12px; }
.user-name { font-size: 12px; font-weight: 700; }
.user-role { font-size: 10px; color: var(--muted); }

/* ── Topbar ── */
.top {
  height: 60px; background: rgba(10,10,13,.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
.top-title { font-size: 20px; font-weight: 900; letter-spacing: -.03em; }
.top-sub { font-size: 11px; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 12px; }

/* ── Content ── */
.content { padding: 24px; }
.flash { background: var(--accent); color: #fff; padding: 12px 16px; border-radius: 12px; margin-bottom: 20px; font-weight: 700; }
.flash.error { background: var(--danger); }
.flash.success { background: var(--good); }

/* ── Cards ── */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
}
.card + .card { margin-top: 18px; }

/* ── Grid ── */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g2-3 { grid-template-columns: 2fr 3fr; }
.g3-2 { grid-template-columns: 3fr 2fr; }

/* ── Stats ── */
.stat-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 28px; font-weight: 900; letter-spacing: -.04em; margin-top: 6px; }
.stat-value.orange { color: var(--accent); }
.stat-value.green { color: var(--good); }
.stat-value.red { color: var(--danger); }
.stat-delta { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── Section title ── */
.sec-title { font-size: 16px; font-weight: 900; margin-bottom: 16px; letter-spacing: -.02em; }
.sec-title span { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 0 12px 10px; border-bottom: 1px solid var(--line); font-weight: 600; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
.td-name { font-weight: 700; }
.td-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Buttons ── */
.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; font: 700 13px inherit;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success { background: var(--good); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 6px; }
.btn-ghost { background: none; border: 1px solid var(--line); color: var(--muted); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Forms ── */
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; display: block; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; color: var(--text); font: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
select option { background: var(--panel2); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700;
}
.badge-good { background: rgba(34,197,94,.15); color: var(--good); }
.badge-warn { background: rgba(245,158,11,.15); color: var(--warn); }
.badge-danger { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-orange { background: rgba(249,115,22,.15); color: var(--accent); }
.badge-info { background: rgba(59,130,246,.15); color: var(--info); }
.badge-muted { background: var(--panel2); color: var(--muted); }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; padding: 7px 10px; font-size: 12px; }

/* ── Code block ── */
.code { font-family: ui-monospace, monospace; background: var(--panel2); border: 1px solid var(--line); color: var(--accent); padding: 10px 12px; border-radius: 10px; display: block; overflow: auto; font-size: 12px; word-break: break-all; }

/* ── Notice ── */
.notice { border-left: 3px solid var(--accent); background: rgba(249,115,22,.08); padding: 12px 14px; border-radius: 10px; color: #fbbf24; font-size: 13px; margin-bottom: 16px; }
.notice-info { border-left-color: var(--info); background: rgba(59,130,246,.08); color: #93c5fd; }
.notice-success { border-left-color: var(--good); background: rgba(34,197,94,.08); color: #86efac; }

/* ── Product grid ── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.product-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; transition: border-color .2s; }
.product-card:hover { border-color: var(--accent); }
.product-img { height: 140px; background: var(--panel2); display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--muted); }
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 12px; }
.product-name { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.product-sku { font-size: 10px; color: var(--muted); margin-bottom: 6px; }
.product-price { font-size: 16px; font-weight: 900; color: var(--accent); }
.product-buy { font-size: 11px; color: var(--muted); }
.product-stock { margin-top: 8px; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 36px; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-title { font-size: 24px; font-weight: 900; text-align: center; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 28px; }

/* ── Pipeline / Kanban ── */
.pipeline { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.pipeline-col { min-width: 220px; max-width: 220px; }
.pipeline-col-head { padding: 8px 12px; border-radius: 10px 10px 0 0; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.pipeline-col-body { background: var(--panel); border: 1px solid var(--line); border-top: none; border-radius: 0 0 10px 10px; padding: 8px; min-height: 120px; }
.pipeline-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 12px; }
.pipeline-card-name { font-weight: 700; margin-bottom: 4px; }
.pipeline-card-meta { color: var(--muted); font-size: 11px; }

/* ── Document print ── */
@media print {
  .no-print { display: none !important; }
  .side, .top { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  .print-doc { display: block !important; }
  body { background: #fff !important; color: #000 !important; }
}
.print-doc { display: none; }
.doc-paper {
  background: #fff; color: #000; width: 210mm; min-height: 297mm;
  margin: 0 auto; padding: 20mm; font-family: Arial, sans-serif; font-size: 12px;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; border-bottom: 2px solid #e87c0a; padding-bottom: 16px; }
.doc-logo { font-size: 24px; font-weight: 900; color: #e87c0a; }
.doc-logo-sub { font-size: 11px; color: #666; }
.doc-number { text-align: right; }
.doc-number h2 { font-size: 18px; color: #e87c0a; margin-bottom: 4px; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 20px; }
.doc-party h4 { font-size: 11px; text-transform: uppercase; color: #888; margin-bottom: 8px; letter-spacing: .05em; }
.doc-party p { margin-bottom: 3px; font-size: 12px; }
.doc-party strong { font-weight: 700; font-size: 14px; display: block; margin-bottom: 6px; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.doc-table th { background: #f5f5f5; padding: 8px 10px; text-align: left; font-size: 11px; text-transform: uppercase; border: 1px solid #ddd; }
.doc-table td { padding: 8px 10px; border: 1px solid #ddd; vertical-align: top; }
.doc-table tr:nth-child(even) td { background: #fafafa; }
.doc-total { text-align: right; margin-bottom: 20px; }
.doc-total-row { display: flex; justify-content: flex-end; gap: 40px; margin-bottom: 4px; }
.doc-total-big { font-size: 18px; font-weight: 900; color: #e87c0a; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
.doc-sign-line { border-top: 1px solid #000; padding-top: 4px; font-size: 11px; color: #666; margin-top: 40px; }
.doc-footer { margin-top: 30px; padding-top: 12px; border-top: 1px solid #ddd; font-size: 10px; color: #999; text-align: center; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .side { position: fixed; left: -260px; transition: left .25s; width: 240px; }
  .side.open { left: 0; box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .main { margin-left: 0; }
  .g4, .g3, .g2, .g2-3, .g3-2 { grid-template-columns: 1fr; }
  .form-grid, .form-grid3 { grid-template-columns: 1fr; }
  .top { padding: 0 16px; }
  .content { padding: 14px; }
}

/* ── Misc ── */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 900; }
.w-full { width: 100%; }
.burger { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--text); cursor: pointer; }
@media (max-width: 768px) { .burger { display: block; } }

/* ══ NEW v2 additions ══ */

/* Lead cards grid */
.leads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.lead-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; transition: border-color .2s; }
.lead-card:hover { border-color: var(--accent); }
.lead-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.lead-name { font-size: 15px; font-weight: 900; letter-spacing: -.02em; }
.lead-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lead-obj { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.lead-prices { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.lead-price-item { font-size: 12px; color: var(--muted); }
.lead-price-item strong { color: var(--text); }
.lead-price-total { font-size: 13px; font-weight: 900; color: var(--accent); margin-left: auto; }
.lead-comment { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; margin-bottom: 8px; line-height: 1.5; }
.lead-footer { display: flex; align-items: center; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.ml-auto { margin-left: auto; }

/* Lead detail */
.lead-detail-wrap { max-width: 1100px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-grid .full { grid-column: 1 / -1; }
.detail-val { font-size: 14px; font-weight: 700; padding-top: 4px; color: var(--text); }
.detail-val a { color: var(--text); }
.detail-val a:hover { color: var(--accent); }
.detail-val.orange { color: var(--accent); }

/* Items table inside lead */
.items-table th, .items-table td { padding: 10px 12px; }
.totals-row td { background: var(--panel2) !important; border-top: 2px solid var(--line); }

/* KP summary block */
.kp-summary { max-width: 420px; }
.kp-sum-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kp-sum-row strong { font-weight: 700; }
.kp-sum-total { display: flex; justify-content: space-between; padding: 12px 0 0; font-size: 20px; font-weight: 900; color: var(--accent); }

/* KP builder rows */
.kp-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.kp-name { flex: 1; min-width: 180px; }
.kp-sum { min-width: 90px; text-align: right; color: var(--accent); font-weight: 700; font-size: 13px; }

/* Contractor cards */
.contractor-card { }
.contractor-header { display: flex; align-items: center; gap: 12px; }
.contractor-av { width: 44px; height: 44px; border-radius: 50%; background: rgba(249,115,22,.15); color: var(--accent); font-size: 18px; font-weight: 900; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.contractor-name { font-size: 15px; font-weight: 900; letter-spacing: -.02em; }
.contractor-person { font-size: 12px; color: var(--muted); }
.contractor-contacts div { font-size: 13px; margin-bottom: 4px; color: var(--text); }
.contractor-contacts a { color: var(--text); }
.contractor-contacts a:hover { color: var(--accent); }
.contractor-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.opacity-50 { opacity: .5; }

/* Modal close btn */
.modal-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; transition: color .15s; }
.modal-close:hover { color: var(--text); }

/* Viatec section inside modal */
#viatecSection { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
#viatecPreview { display: none; margin-top: 12px; }
#vp-img { width: 60px; height: 60px; object-fit: contain; border-radius: 8px; background: #fff; }

/* Empty state */
.empty-state { text-align: center; padding: 32px; color: var(--muted); font-size: 13px; font-style: italic; }

/* KP doc print additions */
.doc-subtotal td { background: #f0f9ff !important; font-weight: 600; }
.doc-notes { margin-top: 20px; padding: 12px 14px; background: #f9fafb; border-radius: 8px; font-size: 12px; color: #555; border: 1px solid #e5e7eb; }
.doc-total { margin-top: 16px; }
.doc-total > div { display: flex; justify-content: flex-end; gap: 32px; padding: 6px 0; font-size: 13px; }
.total-final { font-size: 18px; font-weight: 900; color: #e87c0a; border-top: 2px solid #e5e7eb; padding-top: 10px; margin-top: 6px; }

/* Section title flex */
.sec-title { display: flex; align-items: center; }
.sec-title a { font-size: 12px; font-weight: 600; }

/* Align / gap helpers */
.align-center { align-items: center; }
.gap-4 { gap: 4px; }
.gap-16 { gap: 16px; }
.text-center { text-align: center; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

@media (max-width: 768px) {
  .leads-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .g3 { grid-template-columns: 1fr; }
}

/* ── Timeline / Notes ── */
.timeline { display:grid; gap:0; }
.timeline-item { display:flex; gap:12px; padding:10px 0; border-bottom:1px solid var(--line); }
.timeline-item:last-child { border-bottom:0; }
.timeline-dot { width:32px; height:32px; border-radius:50%; background:var(--panel2); border:1px solid var(--line); display:flex; align-items:center; justify-content:center; font-size:14px; flex-shrink:0; margin-top:2px; }
.timeline-body { flex:1; min-width:0; }
.timeline-meta { display:flex; align-items:center; gap:10px; margin-bottom:4px; flex-wrap:wrap; }
.timeline-meta b { font-size:13px; color:var(--text); }
.timeline-meta span { font-size:11px; color:var(--muted); }
.timeline-text { font-size:14px; line-height:1.55; color:var(--text-sec); white-space:pre-wrap; }
.card-alert { border-color:rgba(239,68,68,.4) !important; }

/* ── Quick stage buttons on lead cards ── */
.lead-quick-stages { display:flex; gap:6px; align-items:center; flex-wrap:wrap; padding:8px 0 4px; border-top:1px solid var(--line); margin-top:8px; }

/* ── Filter bar improvements ── */
.filter-bar select { min-width:150px; }
#fCount { white-space:nowrap; }
