/* ── Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --sidebar-w: 240px;
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --sidebar-bg:#0f172a;
  --sidebar-hover: #1e293b;
  --accent:    #6366f1;
  --accent-hover: #4f46e5;
  --text:      #0f172a;
  --text-muted:#64748b;
  --border:    #e2e8f0;
  --radius:    12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --input-bg:  #ffffff;
  --card-hover:#f8fafc;
  --badge-muted-bg: #f1f5f9;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --hover: #f1f5f9;
  --border-light: #f1f5f9;
  /* ── Aliases (для совместимости с разными именованиями в шаблонах) ── */
  --card-bg:          var(--surface);
  --card:             var(--surface);
  --bg-primary:       var(--surface);
  --bg-secondary:     var(--bg);
  --surface-secondary:var(--bg);
  --bg-hover:         var(--hover);
  --active-bg:        var(--card-hover);
  --primary:          var(--accent);
  --primary-hover:    var(--accent-hover);
  --accent-light:     #eef2ff;
  --text-primary:     var(--text);
  --text-secondary:   var(--text-muted);
  --muted:            var(--text-muted);
  --info:             #3b82f6;
  --blue:             #3b82f6;
  --navy:             #0f172a;
  --green:            var(--success);
  --red:              var(--danger);
  --amber:            var(--warning);
  --light:            #f8fafc;
  /* Stage colors (dynamic via inline --stage-color) */
}

/* ── Dark Theme ──────────────────────────────────────────── */
body.dark {
  --bg:        #0f172a;
  --hover:     #1e293b;
  --border-light: #1e293b;
  --surface:   #1e293b;
  --sidebar-bg:#0b1120;
  --sidebar-hover: #1e293b;
  --accent:    #818cf8;
  --accent-hover: #6366f1;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --border:    #334155;
  --shadow:    0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.4);
  --input-bg:  #1e293b;
  --card-hover:#263348;
  --badge-muted-bg: #334155;
  --success:   #34d399;
  --danger:    #f87171;
  --warning:   #fbbf24;
  /* ── Dark aliases (явно переопределяем, чтобы custom-property-алиасы перевычислились на body.dark) ── */
  --card-bg:          #1e293b;
  --card:             #1e293b;
  --bg-primary:       #1e293b;
  --bg-secondary:     #0f172a;
  --surface-secondary:#0f172a;
  --bg-hover:         #1e293b;
  --active-bg:        #263348;
  --primary:          #818cf8;
  --primary-hover:    #6366f1;
  --accent-light:     #312e81;
  --text-primary:     #e2e8f0;
  --text-secondary:   #94a3b8;
  --muted:            #94a3b8;
  --info:             #60a5fa;
  --blue:             #60a5fa;
  --navy:             #0b1120;
  --green:            #34d399;
  --red:              #f87171;
  --amber:            #fbbf24;
  --light:            #1e293b;
}

/* Dark overrides for Bootstrap & global elements */
body.dark .form-control,
body.dark .form-select {
  background-color: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}
body.dark .form-control:focus,
body.dark .form-select:focus {
  background-color: #263348;
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(129,140,248,.25);
}
body.dark .form-control::placeholder { color: #64748b; }
body.dark .btn-outline-secondary {
  color: var(--text-muted);
  border-color: var(--border);
}
body.dark .btn-outline-secondary:hover {
  background: var(--border);
  color: var(--text);
}
body.dark .btn-light {
  background: #334155;
  color: var(--text);
  border-color: #475569;
}
body.dark .btn-light:hover {
  background: #475569;
}
body.dark .modal-content {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
body.dark .modal-header { border-color: var(--border); }
body.dark .modal-footer { border-color: var(--border); }
body.dark .dropdown-menu {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-lg);
}
body.dark .dropdown-item {
  color: var(--text);
}
body.dark .dropdown-item:hover {
  background: var(--card-hover);
}
body.dark .table { color: var(--text); }
body.dark .table > :not(caption) > * > * {
  background-color: transparent;
  border-color: var(--border);
  color: var(--text);
}
body.dark .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(255,255,255,.03);
}
body.dark a { color: var(--accent); }
body.dark hr { border-color: var(--border); }
body.dark .text-muted { color: var(--text-muted) !important; }
body.dark .bg-white { background-color: var(--surface) !important; }
body.dark .bg-light { background-color: var(--bg) !important; }
body.dark .card { background: var(--surface); border-color: var(--border); }
body.dark .border { border-color: var(--border) !important; }
body.dark .border-bottom { border-color: var(--border) !important; }
body.dark .border-top { border-color: var(--border) !important; }
body.dark .shadow-sm { box-shadow: var(--shadow) !important; }
body.dark .text-dark { color: var(--text) !important; }

/* Dark: Kanban cards */
body.dark .kanban-card {
  background: var(--surface);
  border-color: var(--border);
}
body.dark .kanban-card:hover {
  background: var(--card-hover);
}
body.dark .kanban-card.has-unread {
  background: #1a1a2e;
  border-left-color: #f87171;
}
body.dark .kanban-comment-input {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
body.dark .kanban-comment-input:focus {
  border-color: var(--accent);
}
body.dark .kanban-col {
  background: rgba(255,255,255,.03);
}
body.dark .kanban-col-body {
  background: #131c2e;
  border-color: var(--border);
}
body.dark .kanban-col-header {
  color: var(--text);
}

/* Dark: Dashboard bar */
body.dark .dashboard-bar {
  background: #0b1120;
  border-color: #1e293b;
}

/* Dark: Source badges - muted */
body.dark .source-badge.src-telegram { background: #1e3a5f; color: #60a5fa; }
body.dark .source-badge.src-website_telegram { background: #14532d; color: #4ade80; }
body.dark .source-badge.src-website { background: #3b0764; color: #c084fc; }
body.dark .source-badge.src-call { background: #431407; color: #fb923c; }
body.dark .source-badge.src-missed_call { background: #450a0a; color: #fca5a5; }
body.dark .source-badge.src-instagram { background: #4a0e2e; color: #f472b6; }
body.dark .source-badge.src-manual { background: #1e293b; color: #94a3b8; }
body.dark .source-badge.src-showroom { background: #451a03; color: #fbbf24; }

/* Dark: Chat bubbles & chat area */
body.dark .chat-bubble.user .bubble-content { background: #334155; color: var(--text); }
body.dark .chat-bubble.bot .bubble-content { background: #4338ca; }
body.dark .chat-bubble.manager .bubble-content { background: #1e3a5f; }
body.dark .call-card { background: var(--surface); border-color: var(--border); }
body.dark .chat-send-area { background: var(--surface); border-color: var(--border); }
body.dark .chat-send-input { background: var(--input-bg); color: var(--text); border-color: var(--border); }
body.dark .chat-send-input:focus { background: #263348; border-color: var(--accent); }
body.dark .chat-templates { background: var(--bg); border-color: var(--border); }
body.dark .quick-tpl-btn { background: var(--surface); color: var(--text-muted); border-color: var(--border); }
body.dark .quick-tpl-btn:hover { background: #312e81; color: #a5b4fc; border-color: var(--accent); }
body.dark .screen-trigger-area { background: var(--bg); border-color: var(--border); }
body.dark .screen-trigger-btn { background: #1e1b4b; color: #a78bfa; border-color: #5b21b6; }
body.dark .screen-trigger-btn:hover { background: #312e81; color: #c4b5fd; border-color: #7c3aed; }
body.dark .chat-header { background: var(--surface); border-color: var(--border); }
body.dark .send-error { background: #450a0a; color: #fca5a5; }

/* Dark: Tabs & pills */
body.dark .nav-tabs { border-color: var(--border); }
body.dark .nav-tabs .nav-link { color: var(--text-muted); }
body.dark .nav-tabs .nav-link.active { background: var(--surface); color: var(--text); border-color: var(--border) var(--border) var(--surface); }
body.dark .nav-pills .nav-link { color: var(--text-muted); }
body.dark .nav-pills .nav-link.active { background: var(--accent); color: #fff; }

/* Dark: Scrollbar */
body.dark ::-webkit-scrollbar { width: 8px; height: 8px; }
body.dark ::-webkit-scrollbar-track { background: var(--bg); }
body.dark ::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
body.dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Dark: Login page */
body.dark .login-container,
body.dark .setup-container {
  background: var(--surface);
}

/* Dark: Tags — keep original colors */
body.dark .kanban-tag.auto-tag.tag-client   { background: #1e3a5f !important; color: #93c5fd !important; }
body.dark .kanban-tag.auto-tag.tag-payment  { background: #2e1065 !important; color: #c4b5fd !important; }
body.dark .kanban-tag.auto-tag.tag-model    { background: #500724 !important; color: #f9a8d4 !important; }
body.dark .kanban-tag.auto-tag.tag-region   { background: #064e3b !important; color: #6ee7b7 !important; }
body.dark .kanban-tag.auto-tag.tag-license  { background: #451a03 !important; color: #fcd34d !important; }
body.dark .kanban-tag.custom-tag { opacity: 0.9; }
body.dark .auto-tag.tag-client   { background: #1e3a5f; color: #93c5fd; }
body.dark .auto-tag.tag-payment  { background: #2e1065; color: #c4b5fd; }
body.dark .auto-tag.tag-model    { background: #500724; color: #f9a8d4; }
body.dark .auto-tag.tag-region   { background: #064e3b; color: #6ee7b7; }
body.dark .auto-tag.tag-license  { background: #451a03; color: #fcd34d; }

/* Dark: Unread preview */
body.dark .kanban-card-unread-preview {
  color: #a5b4fc;
}

/* Dark: Content sections with white bg */
body.dark [style*="background:#fff"],
body.dark [style*="background: #fff"],
body.dark [style*="background:white"],
body.dark [style*="background: white"] {
  background: var(--surface) !important;
}

/* Dark: Analytics charts */
body.dark .chart-bars { background: var(--surface); }

/* Dark: Hardcoded white backgrounds → surface */
body.dark .lead-card,
body.dark .lead-info-card,
body.dark .inline-edit,
body.dark .sa-config-row,
body.dark .sa-condition-item,
body.dark .funnel-screen-item,
body.dark .validation-item,
body.dark .scenario-card,
body.dark .task-card,
body.dark .showroom-card,
body.dark .automation-card {
  background: var(--surface) !important;
  color: var(--text);
  border-color: var(--border);
}
body.dark .lead-card.paused,
body.dark .kanban-card.paused {
  background: #1c1917 !important;
  border-color: #92400e;
}
body.dark .inline-edit.saving {
  background: #1c1917 !important;
  border-color: #92400e;
}
body.dark .funnel-screen-item.modified {
  background: #1c1917 !important;
}
/* Dark: Popover / tooltips */
body.dark [style*="background:#fff"],
body.dark [style*="background: #fff"],
body.dark [style*="background:#ffffff"],
body.dark [style*="background: #ffffff"],
body.dark [style*="background:white"],
body.dark [style*="background: white"],
body.dark [style*="background-color:#fff"],
body.dark [style*="background-color: #fff"],
body.dark [style*="background-color:white"],
body.dark [style*="background-color: white"] {
  background: var(--surface) !important;
  background-color: var(--surface) !important;
  color: var(--text) !important;
}
/* Dark: Specific component fixes */
body.dark .content-area > div,
body.dark .content-area > section {
  color: var(--text);
}
body.dark textarea {
  background: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}
body.dark textarea:focus {
  background: #263348;
  border-color: var(--accent);
}
body.dark select option {
  background: var(--surface);
  color: var(--text);
}
body.dark .badge.bg-light {
  background: var(--badge-muted-bg) !important;
  color: var(--text) !important;
}
body.dark .alert {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
/* Dark: Funnel Constructor — full dark theme */
body.dark .constructor-page { background: var(--surface); border-color: var(--border); }

/* Left panel (palette) */
body.dark .constructor-left { background: #111827; }
body.dark .palette-group-title { color: #94a3b8; }
body.dark .palette-group-title:hover { background: #1e293b; }
body.dark .palette-item { color: var(--text); }
body.dark .palette-item:hover { background: #1e293b; }
body.dark .palette-item-active { background: #1e3a5f !important; border-left-color: var(--accent); }
body.dark .palette-count { background: #334155; color: #94a3b8; }
body.dark .palette-group { border-bottom-color: var(--border); }

/* Center panel (canvas) */
body.dark #drawflow { background: #0b1120; }
body.dark .drawflow .drawflow-node {
  background: none !important;
  border: none !important;
  color: var(--text);
}
body.dark .flow-toolbar { background: #111827; border-bottom-color: var(--border); }
body.dark .flow-toolbar .btn { color: var(--text); border-color: var(--border); }
body.dark .flow-toolbar .btn:hover { background: #1e293b; }

/* Node cards */
body.dark .node-card {
  background: #1e293b;
  border-color: #475569;
  color: var(--text);
}
body.dark .node-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.4); }
body.dark .node-header { background: #111827; border-bottom-color: #334155; color: var(--text); }
body.dark .node-preview { color: #94a3b8; }
body.dark .node-count { color: #94a3b8; }
body.dark .node-btns { border-top-color: #334155; }
body.dark .node-btn-label { color: #cbd5e1; border-bottom-color: #1e293b; }

/* Node type colors (keep borders but darken backgrounds) */
body.dark .node-type-terminal { background: #0d2818; }
body.dark .node-type-checklist { background: #0c2233; }

/* Start/finish node overrides */
body.dark .node-start .node-header,
body.dark .node-card.node-start .node-header { background: #0d3320; }
body.dark .node-finish .node-header,
body.dark .node-card.node-finish .node-header { background: #3b1111; }

/* Connection lines */
body.dark .drawflow .connection .main-path { stroke: #475569; }
body.dark .drawflow .connection .main-path:hover { stroke: #60a5fa; }

/* Selected node */
body.dark .drawflow .drawflow-node.selected .node-card {
  box-shadow: 0 0 0 3px var(--accent);
}

/* Input/output dots */
body.dark .drawflow .drawflow-node .input,
body.dark .drawflow .drawflow-node .output {
  background: #1e293b !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.4) !important;
}

/* Right panel (editor) */
body.dark .constructor-right { background: #111827; border-left-color: var(--border); }
body.dark .constructor-right .form-label { color: #94a3b8; }
body.dark .constructor-right h6 { color: var(--text); }
body.dark .editor-section { border-bottom-color: var(--border); }

/* Modals in constructor */
body.dark .modal-overlay { background: rgba(0,0,0,.7); }
body.dark .modal-overlay .modal-box,
body.dark .modal-overlay > div[style*="background"] {
  background: #1e293b !important;
  color: var(--text);
  border-color: var(--border);
}

/* Search input in palette */
body.dark .constructor-left input[type="text"],
body.dark .constructor-left input[type="search"],
body.dark .constructor-left .form-control {
  background: #1e293b;
  border-color: var(--border);
  color: var(--text);
}

/* Zoom level text */
body.dark .zoom-level { color: #94a3b8; }

/* Badges keep their own colors but ensure readability */
body.dark .node-off-badge { background: #5c1a1a; color: #fca5a5; }
body.dark .node-custom-badge { background: #1e3a5f; color: #93c5fd; }
body.dark .node-pause-badge { background: #4a3520; color: #fcd34d; }

/* Minimap */
body.dark #minimap { filter: invert(0.85) hue-rotate(180deg); }

/* Funnel selector buttons */
body.dark .funnel-selector .btn { color: var(--text); border-color: var(--border); }
body.dark .funnel-selector .btn:hover { background: #1e293b; }
body.dark .funnel-selector .form-select {
  background-color: #1e293b;
  border-color: var(--border);
  color: var(--text);
}

/* Validation badge */
body.dark .validation-badge { background: #dc2626; }

/* Dark: Settings page */
body.dark .info-card-title { background: #1a2236; color: var(--text-muted); }
body.dark .excluded-item { background: var(--surface); }
body.dark .info-row { border-bottom-color: var(--border); }
body.dark .stt-provider-card {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text);
}
body.dark .stt-provider-card[style*="background"] {
  border-color: var(--accent) !important;
}
body.dark .settings-page label { color: var(--text); }
body.dark .settings-page strong { color: var(--text); }
body.dark .settings-page hr { border-color: var(--border) !important; }
body.dark .settings-page [style*="background:#f8fafc"],
body.dark .settings-page [style*="background: #f8fafc"] {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
body.dark .settings-page [style*="background:#f1f5f9"],
body.dark .settings-page [style*="background: #f1f5f9"],
body.dark .settings-page [style*="background:#e2e8f0"],
body.dark .settings-page [style*="background: #e2e8f0"],
body.dark .settings-page tr[style*="background:#e2e8f0"],
body.dark .settings-page tr[style*="background:#f1f5f9"] {
  background: #1a2236 !important;
}
body.dark .settings-page th,
body.dark .settings-page td {
  border-color: var(--border) !important;
  color: var(--text);
}
body.dark .settings-page [style*="border-bottom:1px solid #f1f5f9"],
body.dark .settings-page [style*="border-bottom: 1px solid #f1f5f9"] {
  border-bottom-color: var(--border) !important;
}
body.dark .settings-page [style*="color:#64748b"] { color: var(--text-muted) !important; }
body.dark .settings-page [style*="color:#1e293b"] { color: var(--text) !important; }
body.dark .settings-page [style*="color:#94a3b8"] { color: #64748b !important; }
body.dark .settings-page [style*="border:2px dashed"] {
  border-color: #475569 !important;
  background: var(--surface) !important;
}
body.dark .settings-page [style*="border:2px solid #e2e8f0"] {
  border-color: var(--border) !important;
}
body.dark .settings-page [style*="border:1px solid #e2e8f0"] {
  border-color: var(--border) !important;
}
body.dark .settings-page [style*="border:1px solid #cbd5e1"],
body.dark .settings-page th[style*="#cbd5e1"],
body.dark .settings-page td[style*="#cbd5e1"] {
  border-color: var(--border) !important;
}
body.dark .info-card { background: var(--surface); }
body.dark .info-card .form-label { color: var(--text); }
body.dark .inline-edit:hover { background: var(--surface); border-color: var(--border); }
body.dark .inline-edit:focus { background: #263348; border-color: var(--accent); }
body.dark .inline-edit-textarea:hover { background: var(--surface); border-color: var(--border); }
body.dark .inline-edit-textarea:focus { background: #263348; border-color: var(--accent); }
body.dark .stage-auto-popover { background: var(--surface); border-color: var(--border); }
body.dark .sa-header { background: #1a2236; border-color: var(--border); color: var(--text); }
body.dark .sa-item { background: var(--bg); }
body.dark .sa-item-name { color: var(--text); }
body.dark .sa-link { color: var(--accent); border-color: var(--border); }
body.dark .sa-link:hover { background: #1e1b4b; }
body.dark .tag-add-popover { background: var(--surface); border-color: var(--border); }
body.dark .btn-stage-auto:hover { background: #1e1b4b; color: #a78bfa; }

/* Dark: Archive filter buttons */
body.dark .archive-filter-btn {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text-muted) !important;
}
body.dark .archive-filter-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

/* Dark: Showroom readonly input */
body.dark input[readonly] {
  background: var(--bg) !important;
  color: var(--text-muted);
}

/* Dark: Automations page */
body.dark .auto-badge-fires { background: var(--surface); }
body.dark .config-section { background: var(--bg); }
body.dark .mode-toggle { background: var(--bg); }
body.dark .mode-toggle-btn.active { background: var(--surface); }
body.dark .chain-step.wait-step { background: #451a03; border-color: #92400e; }

/* Dark: Stage scenarios page */
body.dark .sc-stage-badge.inactive { background: var(--surface); color: var(--text-muted); }
body.dark .sc-scenario-item { background: var(--bg); }
body.dark .sc-form-section { background: var(--bg); }
body.dark .sc-add-btn:hover { background: #1e1b4b; }

/* Dark: Funnel constructor borders */
body.dark [style*="border-bottom:1px solid #f1f5f9"] {
  border-bottom-color: var(--border) !important;
}

/* Theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.15);
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 18px;
  transition: all .2s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: rgba(255,255,255,.1);
  color: #e2e8f0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon { font-size: 24px; }
.brand-text  { color: rgba(255,255,255,.7); font-size: 16px; }
.brand-text strong { color: #fff; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item i { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.manager-info { flex: 1; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.manager-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.manager-name { color: rgba(255,255,255,.8); font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { color: rgba(255,255,255,.5); text-decoration: none; font-size: 18px; transition: color .15s; }
.btn-logout:hover { color: #f87171; }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}
.content-area {
  padding: 28px 32px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}
/* Страница Лиды (канбан) — на всю ширину */
.content-area:has(.kanban-board) {
  max-width: 100%;
  min-width: fit-content;
  padding-top: 8px;
  padding-right: 16px;
  padding-left: 16px;
}

/* ── Mobile topbar ────────────────────────────────────────── */
.mobile-topbar {
  position: sticky; top: 0;
  background: var(--sidebar-bg);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 14px;
  z-index: 90;
}
.btn-hamburger {
  background: none; border: none;
  color: #fff; font-size: 22px;
  cursor: pointer; padding: 2px;
  line-height: 1;
}
.mobile-brand { color: #fff; font-weight: 600; font-size: 16px; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .content-area { padding: 16px; }
  .content-area:has(.kanban-board) { padding: 8px 4px; }
}

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-title  { font-size: 22px; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--text-muted); margin: 2px 0 0; font-size: 13px; }

/* ── Leads header (канбан страница) ──────────────────────── */
.leads-header {
  margin-bottom: 12px;
  min-width: fit-content;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-bottom: 6px;
}
/* ── Dashboard stats bar ── */
.leads-dashboard {
  display: flex;
  align-items: center;
  gap: 0;
  background: #1e293b;
  border-radius: 10px;
  padding: 0;
  margin-bottom: 12px;
  overflow-x: auto;
  min-height: 52px;
}
.dash-item {
  display: flex;
  flex-direction: column;
  padding: 8px 20px;
  border-right: 1px solid #334155;
  white-space: nowrap;
}
.dash-item:last-child { border-right: none; }
.dash-item-right { border-right: none; }
.dash-label {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  line-height: 1.2;
}
.dash-value {
  font-size: 18px;
  font-weight: 700;
  color: #f1f5f9;
  line-height: 1.3;
}
.dash-value.dash-warn { color: #fbbf24; }
.dash-value.dash-danger { color: #f87171; }
.dash-value.dash-accent { color: #34d399; font-size: 14px; }
@media (max-width: 768px) {
  .leads-dashboard { border-radius: 8px; gap: 0; }
  .dash-item { padding: 6px 12px; }
  .dash-value { font-size: 15px; }
  .dash-item-right { margin-left: 0; border-left: none; border-right: 1px solid #334155; }
}

.leads-header-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.leads-header-row2 {
  display: flex;
  align-items: center;
  gap: 12px;
}
.page-subtitle-inline {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
}
@media (max-width: 991px) {
  .leads-header { min-width: auto; }
  .leads-header-row1 { flex-wrap: wrap; }
  .leads-header-row1 select { flex: 1; min-width: 140px !important; }
  .leads-header-row2 { flex-wrap: wrap; }
  .leads-header-row2 .search-input-wrap { max-width: 100% !important; }
  .leads-header-row2 .page-title { font-size: 16px; }
}

/* ── Filters bar ──────────────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}
.stage-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.stage-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  text-decoration: none;
  background: var(--surface);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  transition: all .15s;
  white-space: nowrap;
}
.stage-pill:hover { border-color: var(--accent); color: var(--accent); }
.stage-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pill-count {
  background: rgba(0,0,0,.1);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}
.stage-pill.active .pill-count { background: rgba(255,255,255,.25); }

.search-form { flex: 1; min-width: 200px; max-width: 360px; }
.search-input-wrap { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input { padding-left: 36px; padding-right: 32px; border-radius: 20px; border-color: var(--border); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.search-clear { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); text-decoration: none; font-size: 15px; }
.search-clear:hover { color: var(--text); }

/* ── Leads grid ───────────────────────────────────────────── */
.leads-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.lead-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .18s, box-shadow .18s;
  overflow: hidden;
  border: 1.5px solid var(--border);
}
.lead-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.lead-card.paused { border-color: #f59e0b; background: #fffbeb; }

.lead-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}
.paused-badge {
  font-size: 11px; font-weight: 600;
  color: #d97706;
  background: #fef3c7;
  padding: 2px 8px; border-radius: 10px;
}

.lead-card-body { padding: 0 14px 12px; flex: 1; }
.lead-name { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.lead-username { font-size: 12px; font-weight: 400; color: var(--text-muted); }

.lead-details { margin-top: 8px; }
.detail-row {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 3px;
}
.detail-row i { width: 14px; flex-shrink: 0; }

.lead-last-seen {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 5px;
}

.lead-card-footer { padding: 10px 14px; border-top: 1px solid var(--border); }

/* ── Stage badges ─────────────────────────────────────────── */
.lead-stage-badge {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
  white-space: nowrap;
}
.stage-badge {
  background: var(--stage-bg, #e2e8f0);
  color: var(--stage-color, #475569);
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h4 { font-weight: 600; color: var(--text); }

/* ── Lead detail ──────────────────────────────────────────── */
.lead-detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13px; font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: all .15s;
  white-space: nowrap;
}
.btn-back:hover { border-color: var(--accent); color: var(--accent); }
.lead-detail-title { flex: 1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lead-detail-title h2 { margin: 0; font-size: 20px; font-weight: 700; }
.btn-pause {
  white-space: nowrap;
  font-weight: 500;
  border-radius: 8px;
}

.lead-detail-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .lead-detail-grid { grid-template-columns: 1fr; }
}

/* ── Info card ────────────────────────────────────────────── */
.info-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  overflow: hidden;
}
.info-card-title {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  background: #f8fafc;
}
.info-rows { padding: 4px 0; }
.info-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}
.info-row:last-child { border-bottom: none; }
.info-label {
  display: flex;
  flex-direction: column;
  color: var(--text-muted);
  font-size: 12px;
  min-width: 130px;
  flex-shrink: 0;
}
.info-label-db {
  display: block;
  font-size: 10px; color: #94a3b8;
  font-weight: 400; margin-top: 0;
  font-family: 'Courier New', monospace;
  padding-left: 20px;
  line-height: 1.3;
}
.info-value { font-weight: 500; font-size: 13px; word-break: break-word; }

/* ── Stage select ─────────────────────────────────────────── */
.stage-select-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px 14px; }
.stage-select-grid .stage-option:last-child { grid-column: 1 / -1; }
.stage-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  transition: all .15s;
  color: var(--text-muted);
}
.stage-option input[type=radio] { display: none; }
.stage-option:hover { border-color: currentColor; }
.stage-option.selected {
  background: var(--stage-bg, #e2e8f0);
  color: var(--stage-color, #475569);
  border-color: var(--stage-color, #94a3b8);
}

/* ── Chat ─────────────────────────────────────────────────── */
.chat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 520px;
}
.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-count { font-size: 12px; font-weight: 400; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty { text-align: center; color: var(--text-muted); padding: 32px; font-size: 13px; }

.chat-bubble {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}
.chat-bubble.user { align-self: flex-start; align-items: flex-start; }
.chat-bubble.bot  { align-self: flex-end;   align-items: flex-end; }

.bubble-content {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-bubble.user .bubble-content {
  background: #f1f5f9;
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-bubble.bot .bubble-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* ── Notes ────────────────────────────────────────────────── */
.notes-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  overflow: hidden;
  margin-top: 16px;
}
.notes-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  background: #f8fafc;
}
.note-form { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.note-textarea {
  resize: none;
  font-size: 13px;
  border-color: var(--border);
}
.note-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }

.notes-list { padding: 8px 0; }
.note-item { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; }
.note-item:last-child { border-bottom: none; }
.note-meta { display: flex; justify-content: space-between; margin-bottom: 5px; }
.note-author { font-size: 12px; font-weight: 600; color: var(--accent); }
.note-date   { font-size: 11px; color: var(--text-muted); }
.note-text   { font-size: 13px; line-height: 1.5; color: var(--text); white-space: pre-wrap; }

/* ── Login page ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.logo-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.login-logo p  { color: var(--text-muted); font-size: 13px; margin: 0; }

.form-label { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.input-group-text { background: #f8fafc; border-color: var(--border); color: var(--text-muted); }
.form-control { border-color: var(--border); font-size: 14px; }
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }

.btn-login {
  background: var(--accent); border-color: var(--accent);
  padding: 10px; font-weight: 600; font-size: 14px;
  border-radius: 10px;
}
.btn-login:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
}
.btn-primary:hover {
  background: var(--accent-hover) !important;
  border-color: var(--accent-hover) !important;
}
.btn-outline-primary {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}
.btn-outline-primary:hover {
  background: var(--accent) !important;
  color: #fff !important;
}

/* ── Nav badge ────────────────────────────────────────────── */
.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* ── Kanban board ─────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 14px;
  overflow: visible;
  align-items: stretch;
  padding-bottom: 16px;
  min-height: calc(100vh - 160px);
  cursor: grab;
}
.kanban-board.board-grabbing {
  cursor: grabbing;
  user-select: none;
}

.kanban-col {
  flex: 0 0 252px;
  min-width: 252px;
  display: flex;
  flex-direction: column;
  background: transparent;
  border: none;
  overflow: visible;
}

/* ── Мобильный канбан — компактный дизайн ──────────────── */
@media (max-width: 991px) {
  .leads-header { min-width: auto; }
  /* Канбан — убираем overflow чтобы sticky работал */
  .kanban-board {
    gap: 6px;
    min-height: auto;
    overflow: visible;
    -webkit-overflow-scrolling: touch;
  }
  /* Закреплённые заголовки колонок */
  .kanban-col { overflow: visible; }
  .kanban-col-header {
    position: sticky;
    z-index: 10;
    padding: 6px 8px;
    gap: 2px;
  }
  .kanban-col {
    flex: 0 0 11%;
    min-width: 11%;
  }
  .kanban-col-title { font-size: 11px; }
  .kanban-col-count { font-size: 10px; padding: 1px 6px; min-width: 18px; }
  .kanban-col-budget { font-size: 10px; }
  .kanban-col-hint { display: none; }
  .kanban-col-body {
    padding: 4px;
    gap: 4px;
    min-height: 40px;
  }
  /* Карточки — компактные */
  .kanban-card { border-radius: 6px; border-width: 1px; }
  .kanban-card-link { padding: 6px 8px; }
  .kanban-card-name { font-size: 11px; margin-bottom: 2px; gap: 3px; }
  .kanban-card-meta { font-size: 10px; gap: 3px; margin-bottom: 1px; }
  .kanban-card-meta i { font-size: 9px; }
  .kanban-card-time { font-size: 9px !important; }
  .kanban-card-tags { padding: 1px 8px 4px; gap: 3px; }
  .kanban-tag { font-size: 8px; padding: 1px 5px; }
  .source-badge { font-size: 8px; width: 18px; height: 14px; margin-right: 2px; }
  .source-badge i { font-size: 8px; }
  .source-badge.src-website_telegram { width: 28px; font-size: 7px; }
  .kanban-paused-dot { font-size: 8px; }
  /* Комментарий */
  .kanban-card-comment { padding: 2px 8px 0; }
  .kanban-card-comment.comment-empty { display: none; }
  .kanban-comment-input { font-size: 10px; min-height: 22px; padding: 2px 6px; }
  /* Кнопки действий */
  .kanban-card-actions { padding: 0 8px 4px; }
}

.kanban-col-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  border-top: 4px solid transparent;
  border-left: 1.5px solid var(--border);
  border-right: 1.5px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.kanban-col-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
/* Dynamic stage colors via inline CSS variables */
.kanban-col-header {
  border-top-color: var(--stage-color, #3b82f6);
  background: var(--stage-bg, #eff6ff);
}
.kanban-col-budget {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.kanban-col-hint {
  font-size: 10px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  padding-top: 2px;
  opacity: 0.75;
}
.kanban-col-hint .bi { font-size: 9px; margin-right: 2px; }

.kanban-col-title { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanban-col-count {
  background: rgba(0,0,0,.08);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  min-width: 22px;
  text-align: center;
}

.kanban-col-body {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: calc(100vh - 250px);
  background: #f8fafc;
  border-left: 1.5px solid var(--border);
  border-right: 1.5px solid var(--border);
  border-bottom: 1.5px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}

.kanban-card {
  background: var(--surface);
  border-radius: 8px;
  border: 1.5px solid var(--border);
  cursor: grab;
  transition: box-shadow .15s;
  /* Блокируем контекстное меню и выделение при удержании на мобильных */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.kanban-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.kanban-card.paused { border-color: #f59e0b; background: #fffbeb; }
.kanban-card.deal-closed { opacity: 0.6; border-color: #94a3b8; background: #f1f5f9; }
.kanban-card.deal-closed:hover { border-color: #94a3b8; }
.kanban-ghost { opacity: 0.4; background: #e0e7ff; border: 2px dashed var(--accent); }
.kanban-dragging { box-shadow: var(--shadow-lg); transform: rotate(1deg); cursor: grabbing; }
/* Drag mode active: карточка готова к перетаскиванию (двойной клик/тап) */
.kanban-card.drag-mode-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(99,102,241,.18), var(--shadow-lg);
  cursor: grab;
  animation: drag-pulse .8s ease-in-out infinite alternate;
}
@keyframes drag-pulse {
  from { outline-color: var(--accent); }
  to   { outline-color: #818cf8; }
}

.kanban-card-link {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
}
.kanban-card-link:hover { color: var(--text); }
.kanban-card-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.kanban-paused-dot { font-size: 10px; }
.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.kanban-card-meta i { font-size: 11px; }

/* ── Chat send area ───────────────────────────────────────── */
.chat-card { max-height: none; }
.chat-messages { max-height: 380px; }

.chat-send-area {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}
.chat-send-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color .15s;
  background: #fff;
}
.chat-send-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background .15s;
}
.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-error {
  padding: 6px 12px;
  background: #fef2f2;
  color: #dc2626;
  font-size: 12px;
  border-top: 1px solid #fee2e2;
}

/* ── Tasks (lead page) ────────────────────────────────────── */
.task-create-form {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.tasks-list {
  padding: 6px 0;
}
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s;
}
.task-item:last-child { border-bottom: none; }
.task-item:hover { background: #f8fafc; }
.task-item.completed { opacity: 0.55; }
.task-item.completed .task-title { text-decoration: line-through; }

.task-check {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  font-size: 17px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 1px;
  transition: color .15s;
}
.task-check:hover { color: var(--accent); }
.task-item.completed .task-check { color: #10b981; }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 13px; font-weight: 500; line-height: 1.4; }
.task-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.task-meta  { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.task-due   { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.task-due.overdue { color: #dc2626; font-weight: 600; }
.task-auto-badge {
  font-size: 10px;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
  padding: 1px 6px;
  border-radius: 6px;
}

.task-delete {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  font-size: 14px;
  color: #cbd5e1;
  transition: color .15s;
  flex-shrink: 0;
}
.task-delete:hover { color: #ef4444; }
.task-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Tasks page ───────────────────────────────────────────── */
.new-task-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--accent);
  padding: 16px;
  box-shadow: var(--shadow);
}

.tasks-group-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 4px;
}
.tasks-group-header.group-overdue  { color: #dc2626; border-color: #fca5a5; }
.tasks-group-header.group-today    { color: #b45309; border-color: #fcd34d; }
.tasks-group-header.group-tomorrow { color: #1d4ed8; border-color: #93c5fd; }
.tasks-group-header.group-done     { color: #64748b; }
.tasks-group-count {
  background: rgba(0,0,0,.07);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  margin-left: 4px;
}

.tasks-table {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  overflow: hidden;
}

.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s;
}
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: #f8fafc; }
.task-row.completed { opacity: 0.5; }
.task-row.completed .task-title { text-decoration: line-through; }

.task-row-body { flex: 1; min-width: 0; }
.task-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}
.task-lead-link {
  text-decoration: none;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  white-space: nowrap;
}
.task-lead-link:hover { color: var(--accent-hover); }

/* ── Kanban card comment ─────────────────────────────────── */
.kanban-card-comment {
  padding: 4px 10px 0;
}
.kanban-comment-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  resize: none;
  min-height: 28px;
  max-height: 60px;
  background: #fafafa;
  color: var(--text);
  transition: border-color .2s;
  overflow-y: auto;
}
.kanban-comment-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.kanban-comment-input::placeholder {
  color: #aaa;
}

/* ── Source badges (icons) ────────────────────────────── */
.source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  width: 22px;
  height: 16px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 3px;
  line-height: 1;
  flex-shrink: 0;
}
.source-badge i { font-size: 10px; }
/* Telegram напрямую */
.source-badge.src-telegram {
  background: #e3f0ff;
  color: #0088cc;
}
/* Сайт → Telegram */
.source-badge.src-website_telegram {
  background: #e8f5e9;
  color: #2e7d32;
  width: 32px;
  font-size: 9px;
  gap: 1px;
}
/* Сайт (форма) */
.source-badge.src-website {
  background: #f3e5f5;
  color: #7b1fa2;
}
/* Звонок */
.source-badge.src-call {
  background: #fff3e0;
  color: #e65100;
}
/* Пропущенный звонок */
.source-badge.src-missed_call {
  background: #ffebee;
  color: #c62828;
}
/* Instagram */
.source-badge.src-instagram {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 50%, #e8a0bf 100%);
  color: #c13584;
}
/* Вручную */
.source-badge.src-manual {
  background: #eceff1;
  color: #607d8b;
}
/* Самоход (шоурум) */
.source-badge.src-showroom {
  background: linear-gradient(135deg, #fef3c7 0%, #fbbf24 100%);
  color: #92400e;
}

/* ── Unread badge & card highlight ────────────────────────── */
.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  margin-left: auto;
  line-height: 1;
  flex-shrink: 0;
  animation: unreadPulse 2s ease-in-out infinite;
}
@keyframes unreadPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 4px rgba(239,68,68,0); }
}
.kanban-card.has-unread {
  border-left: 3px solid #ef4444;
  background: #fef2f2;
}
.kanban-card-unread-preview {
  padding: 3px 10px 4px;
  font-size: 11px;
  color: #6366f1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kanban-card-unread-preview i {
  font-size: 10px;
  margin-right: 3px;
}

/* ── Kanban card actions ──────────────────────────────────── */
.kanban-card-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 10px 8px;
  gap: 4px;
}
.kanban-action-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all .15s;
}
.kanban-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #f0f0ff;
}
.kanban-card-time {
  font-size: 11px !important;
  color: #94a3b8 !important;
}
.kanban-task-dot { font-size: 9px; }
.kanban-empty-placeholder {
  text-align: center;
  padding: 24px 12px;
  color: #cbd5e1;
  font-size: 12px;
  font-style: italic;
  border: 2px dashed #e2e8f0;
  border-radius: 8px;
  background: transparent;
}
body.dark .kanban-empty-placeholder {
  color: #475569;
  border-color: #334155;
  background: transparent;
}

/* ── Funnel Edit Mode ────────────────────────────────────── */
.funnel-edit-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; margin-bottom: 12px;
  background: #fef9c3; border: 1px solid #fde047;
  border-radius: var(--radius); font-size: 13px;
}
.funnel-edit-toolbar .toolbar-label {
  font-weight: 600; color: #854d0e; margin-right: auto;
}
.edit-mode .kanban-card { pointer-events: none; opacity: .5; }
.edit-mode .kanban-col-body { min-height: 40px; }
.edit-mode .kanban-col-header { cursor: grab; }
.edit-mode .kanban-col-header:active { cursor: grabbing; }

.edit-header-row {
  display: flex; align-items: center; gap: 6px; width: 100%;
}
.edit-header-row input.edit-label-input {
  flex: 1; font-size: 12px; font-weight: 600;
  padding: 2px 6px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; min-width: 0;
}
.edit-header-row .edit-icon-btn,
.edit-header-row .edit-color-btn,
.edit-header-row .edit-delete-btn {
  border: none; background: none; cursor: pointer;
  font-size: 14px; padding: 2px 4px; border-radius: 4px;
  line-height: 1;
}
.edit-header-row .edit-delete-btn { color: #ef4444; }
.edit-header-row .edit-delete-btn:hover { background: #fee2e2; }
.edit-header-row .edit-color-btn:hover,
.edit-header-row .edit-icon-btn:hover { background: #f1f5f9; }

.edit-autotask-row {
  display: flex; gap: 6px; margin-top: 6px; font-size: 11px;
}
.edit-autotask-row input {
  padding: 2px 6px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; font-size: 11px;
}
.edit-autotask-row input.at-text { flex: 1; min-width: 0; }
.edit-autotask-row input.at-days { width: 50px; text-align: center; }

.edit-require-reason-row {
  margin-top: 6px; font-size: 11px; color: var(--text-muted);
}
.edit-require-reason-row label {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
}
.edit-require-reason-row input[type="checkbox"] {
  accent-color: var(--primary); width: 14px; height: 14px;
}

.kanban-add-col {
  min-width: 180px; display: flex; align-items: center;
  justify-content: center; border: 2px dashed var(--border);
  border-radius: var(--radius); cursor: pointer;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: all .15s;
}
.kanban-add-col:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

/* Color picker popup */
.color-picker-popup {
  position: absolute; top: 100%; left: 0; z-index: 200;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; box-shadow: var(--shadow-lg);
  display: flex; flex-wrap: wrap; gap: 6px; width: 168px;
}
.color-picker-popup .cp-swatch {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform .1s;
}
.color-picker-popup .cp-swatch:hover { transform: scale(1.2); }
.color-picker-popup .cp-swatch.active { border-color: #0f172a; }

/* Icon picker popup */
.icon-picker-popup {
  position: absolute; top: 100%; left: 0; z-index: 200;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; box-shadow: var(--shadow-lg);
  display: flex; flex-wrap: wrap; gap: 4px; width: 220px;
}
.icon-picker-popup .ip-item {
  width: 28px; height: 28px; display: flex;
  align-items: center; justify-content: center;
  border-radius: 6px; cursor: pointer; font-size: 16px;
}
.icon-picker-popup .ip-item:hover { background: #f1f5f9; }
.icon-picker-popup .ip-item.active { background: #e0e7ff; }

/* Delete stage modal */
.stage-delete-modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.4); display: flex;
  align-items: center; justify-content: center;
}
.stage-delete-modal .sdm-box {
  background: #fff; border-radius: var(--radius);
  padding: 24px; max-width: 400px; width: 90%;
  box-shadow: var(--shadow-lg);
}
.stage-delete-modal .sdm-box h4 { margin: 0 0 12px; font-size: 16px; }
.stage-delete-modal .sdm-box select { width: 100%; padding: 6px 10px; margin: 8px 0 16px; border-radius: 8px; border: 1px solid var(--border); }
.stage-delete-modal .sdm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Manager chat bubble ─────────────────────────────────── */
.chat-bubble.manager { align-self: flex-end; align-items: flex-end; }
.chat-bubble.manager .bubble-content {
  background: #1e40af;
  color: #fff;
  border-bottom-right-radius: 4px;
}
/* Deleted messages — pink tint */
.chat-bubble.deleted .bubble-content {
  background: #fce4ec !important;
  color: #880e4f !important;
  opacity: 0.75;
}
.chat-bubble.deleted .bubble-time { color: #c2185b; }
/* System messages — centered info line */
.chat-bubble.system {
  align-self: center;
  align-items: center;
  max-width: 100%;
}
.chat-bubble.system .bubble-content {
  background: #fff3e0;
  color: #e65100;
  font-size: 11px;
  font-weight: 600;
  border-radius: 12px;
  text-align: center;
  border: 1px dashed #ffcc80;
}
.bubble-sender {
  font-size: 11px;
  font-weight: 600;
  color: #1e40af;
  margin-bottom: 2px;
  padding: 0 4px;
}

/* ── Call bubbles (AmoCRM style) ──────────────────────────── */
.call-bubble {
  align-self: center !important;
  max-width: 95% !important;
  width: 100%;
}
.call-card {
  background: var(--surface, #f8f9fb);
  border: 1px solid var(--border, #e2e4e9);
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
}
.call-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.call-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.call-icon-incoming {
  background: #dbeafe;
  color: #2563eb;
}
.call-icon-outgoing {
  background: #d1fae5;
  color: #059669;
}
.call-info {
  flex: 1;
  min-width: 0;
}
.call-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #1a1a2e);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.call-status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.call-status-answered { background: #d1fae5; color: #065f46; }
.call-status-missed   { background: #fee2e2; color: #991b1b; }
.call-status-busy     { background: #fef3c7; color: #92400e; }
.call-status-cancelled { background: #f3f4f6; color: #6b7280; }
.call-status-initiated { background: #e0e7ff; color: #3730a3; }
.call-status-ringing  { background: #dbeafe; color: #1e40af; }
.call-status-unknown  { background: #f3f4f6; color: #6b7280; }
.call-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted, #888);
  flex-wrap: wrap;
}
.call-meta i { font-size: 10px; }
.call-phone { font-weight: 500; }
.call-duration { color: var(--text, #1a1a2e); font-weight: 600; }
.call-record {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border, #e2e4e9);
}
.call-audio-player {
  width: 100%;
  height: 36px;
  border-radius: 8px;
}
.call-audio-player::-webkit-media-controls-panel {
  background: var(--surface, #f0f2f5);
  border-radius: 8px;
}
/* Missed call — subtle red border */
.call-bubble.call-missed .call-card {
  border-left: 3px solid #ef4444;
}
/* Answered call — subtle green border */
.call-bubble.call-answered .call-card {
  border-left: 3px solid #10b981;
}
/* Transcription button & text */
.call-transcription-area {
  margin-top: 8px;
}
.call-transcribe-btn {
  background: none;
  border: 1px dashed var(--border, #d1d5db);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--accent, #3b82f6);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
}
.call-transcribe-btn:hover {
  background: var(--accent, #3b82f6);
  color: #fff;
  border-color: var(--accent, #3b82f6);
}
.call-transcribe-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}
.call-transcription-text {
  background: var(--bg, #f0f2f5);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text, #1a1a2e);
  white-space: pre-wrap;
  word-break: break-word;
}
.call-transcription-text i {
  color: var(--accent, #3b82f6);
}
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 1s linear infinite; }

/* ── Chat templates ──────────────────────────────────────── */
.chat-templates {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  background: #fafbfc;
}
.quick-tpl-btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  font-weight: 500;
  white-space: nowrap;
}
.quick-tpl-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #f0f0ff;
}

/* ── Screen trigger (bot screen picker) ──────────────────── */
.screen-trigger-area {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  position: relative;
}
.screen-trigger-row {
  display: flex;
  gap: 6px;
}
.screen-trigger-btn {
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 14px;
  border: 1.5px solid #7c3aed;
  background: linear-gradient(135deg, #f5f3ff, #ede9fe);
  color: #7c3aed;
  cursor: pointer;
  transition: all .15s;
  font-weight: 600;
  white-space: nowrap;
}
.screen-trigger-btn:hover {
  background: linear-gradient(135deg, #ede9fe, #ddd6fe);
  border-color: #6d28d9;
  color: #6d28d9;
  box-shadow: 0 2px 8px rgba(124,58,237,.15);
}
.screen-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  z-index: 100;
  max-height: 400px;
  display: flex;
  flex-direction: column;
}
.screen-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: #7c3aed;
}
.screen-picker-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.screen-picker-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.screen-picker-list {
  overflow-y: auto;
  max-height: 300px;
  padding: 6px 0;
}
.screen-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 8px 14px 4px;
}
.screen-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: background .1s;
  color: var(--text);
}
.screen-item:hover {
  background: #f5f3ff;
}
.screen-item.current {
  background: #ede9fe;
  font-weight: 600;
}
.screen-item-label {
  flex: 1;
}
.screen-current-badge {
  font-size: 9px;
  background: #7c3aed;
  color: white;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 600;
}
.screen-trigger-success {
  color: #16a34a;
  font-size: 12px;
  padding: 6px 0 2px;
  font-weight: 500;
}
.screen-picker-loading {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
}
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 1s linear infinite; }

/* ── Modal overlay ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 440px;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 18px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

/* ── Priority badges & icons ─────────────────────────────── */
.priority-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
  margin-right: 4px;
  flex-shrink: 0;
}
.priority-icon.high {
  background: #fef2f2;
  color: #dc2626;
  border: 1.5px solid #fca5a5;
}
.priority-icon.low {
  background: #f0fdf4;
  color: #16a34a;
  border: 1.5px solid #86efac;
}
.task-priority-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
}
.task-priority-badge.priority-high {
  background: #fef2f2;
  color: #dc2626;
}
.task-priority-badge.priority-low {
  background: #f0fdf4;
  color: #16a34a;
}

/* ── Settings ─────────────────────────────────────────────── */
.settings-page { max-width: 700px; }
.excluded-list { display: flex; flex-direction: column; gap: 8px; }
.excluded-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: #f8fafc; border-radius: 10px;
  border: 1px solid var(--border);
}
.excluded-info { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.excluded-name { font-weight: 600; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Inline editing ──────────────────────────────────────── */
.inline-edit {
  width: 100%;
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  background: transparent;
  color: var(--text);
  transition: all .15s;
}
.inline-edit:hover { border-color: var(--border); background: #f8fafc; }
.inline-edit:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
.inline-edit.saving { border-color: #f59e0b; background: #fffbeb; }
.inline-edit.saved  { border-color: #10b981; background: #ecfdf5; }
.inline-edit.save-error { border-color: #ef4444; background: #fef2f2; }

.inline-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
  cursor: pointer;
}

.inline-edit-textarea {
  width: 100%;
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  resize: none;
  min-height: 32px;
  transition: all .15s;
}
.inline-edit-textarea:hover { border-color: var(--border); background: #f8fafc; }
.inline-edit-textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}

/* ── Toggle switch ───────────────────────────────────────── */
.inline-toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.inline-toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cbd5e1; border-radius: 22px; transition: .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: .2s;
}

/* Stage automation button */
.btn-stage-auto {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  color: #a78bfa; font-size: 12px; opacity: 0.5; transition: all .2s;
  border-radius: 4px;
}
.btn-stage-auto:hover { opacity: 1; background: #ede9fe; color: #7c3aed; }

/* Stage automation popover */
.stage-auto-popover {
  position: fixed; z-index: 9999; width: 270px;
  background: #fff; border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); border: 1px solid #e2e8f0;
  overflow: hidden; animation: popIn .15s ease;
}
@keyframes popIn { from { opacity:0; transform: translateY(-4px); } to { opacity:1; transform: none; } }
.sa-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #f8fafc; border-bottom: 1px solid #e2e8f0;
  font-weight: 600; font-size: 13px; color: #1e293b;
}
.sa-close { background: none; border: none; cursor: pointer; color: #94a3b8; font-size: 16px; }
.sa-list { max-height: 240px; overflow-y: auto; padding: 8px; }
.sa-item {
  display: flex; align-items: center; gap: 8px; padding: 8px;
  border-radius: 8px; margin-bottom: 4px; background: #f8fafc;
}
.sa-item-name { flex: 1; font-size: 12px; font-weight: 600; color: #1e293b; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sa-item-badges { display: flex; gap: 3px; }
.sa-badge { font-size: 9px; padding: 2px 5px; border-radius: 4px; white-space: nowrap; }
.sa-badge.trigger { background: #dbeafe; color: #1d4ed8; }
.sa-badge.action { background: #f3e8ff; color: #7c3aed; }
.sa-toggle { position: relative; width: 28px; height: 16px; flex-shrink: 0; }
.sa-toggle input { opacity: 0; width: 0; height: 0; }
.sa-slider { position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; border-radius: 16px; transition: .2s; }
.sa-slider::before { content:''; position: absolute; height: 12px; width: 12px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: .2s; }
.sa-toggle input:checked + .sa-slider { background: #22c55e; }
.sa-toggle input:checked + .sa-slider::before { transform: translateX(12px); }
.sa-empty { text-align: center; padding: 16px; color: #94a3b8; font-size: 12px; }
.sa-link {
  display: block; text-align: center; padding: 10px; font-size: 12px;
  color: #7c3aed; text-decoration: none; border-top: 1px solid #e2e8f0;
  font-weight: 600;
}
.sa-link:hover { background: #f5f3ff; }
.inline-toggle input:checked + .toggle-slider { background: var(--accent); }
.inline-toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Auto-tags ───────────────────────────────────────────── */
.tags-container { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px; }
.auto-tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 14px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.auto-tag.tag-client   { background: #dbeafe; color: #1d4ed8; }
.auto-tag.tag-payment  { background: #ede9fe; color: #5b21b6; }
.auto-tag.tag-model    { background: #fce7f3; color: #9d174d; }
.auto-tag.tag-region   { background: #d1fae5; color: #065f46; }
.auto-tag.tag-license  { background: #fef3c7; color: #92400e; }

/* ── Kanban card tags ────────────────────────────────────── */
.kanban-card-tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 12px 8px; }
.kanban-tag { font-size: 9px; font-weight: 600; padding: 2px 7px; border-radius: 8px; white-space: nowrap; line-height: 1.3; }
.kanban-tag.custom-tag { border: 1px solid; }

/* ── Lead tags editor ────────────────────────────────────── */
.lead-tags-wrap { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 8px; }
.lead-tag-chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 12px; border: 1px solid;
}
.lead-tag-chip .tag-remove {
  cursor: pointer; font-size: 10px; opacity: .6; margin-left: 2px;
}
.lead-tag-chip .tag-remove:hover { opacity: 1; }
.lead-tag-add-btn {
  font-size: 11px; padding: 2px 8px; border-radius: 12px; border: 1px dashed #94a3b8;
  background: transparent; color: #64748b; cursor: pointer;
}
.lead-tag-add-btn:hover { border-color: #3b82f6; color: #3b82f6; }
.tag-add-popover {
  position: absolute; z-index: 100; background: white; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.12);
  display: flex; flex-direction: column; gap: 6px; min-width: 200px;
}
.tag-add-popover .tag-color-dots { display: flex; gap: 4px; }
.tag-add-popover .tag-dot {
  width: 16px; height: 16px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.tag-add-popover .tag-dot.active { border-color: #1e293b; }

/* ── Info section headers ────────────────────────────────── */
.info-section-title {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 16px 6px; border-bottom: 1px solid var(--border);
}
.info-row .info-value.editable { flex: 1; }

/* ── Funnel Text Editor ─────────────────────────────────── */
.funnel-editor-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .funnel-editor-grid { grid-template-columns: 1fr; }
}

.funnel-screen-list {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  position: sticky;
  top: 20px;
}

.funnel-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.funnel-screen-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: all .15s;
  flex-wrap: wrap;
}
.funnel-screen-item:hover { background: #f8fafc; }
.funnel-screen-item.active {
  background: #eef2ff;
  border-left: 3px solid var(--accent);
}
.funnel-screen-item.modified { background: #fffbeb; }
.funnel-screen-item.active.modified { background: #eef2ff; }

.screen-name { font-weight: 500; font-size: 13px; flex: 1; min-width: 80px; }
.screen-id-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
}
.override-badge {
  font-size: 10px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  padding: 2px 6px;
  border-radius: 10px;
}

.editor-content { padding: 16px; }
.editor-section { margin-bottom: 20px; }
.editor-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.editor-textarea {
  font-family: 'Inter', monospace;
  font-size: 13px;
  line-height: 1.6;
  min-height: 160px;
  resize: vertical;
}

.editor-preview {
  margin-top: 8px;
  padding: 12px 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
}

.button-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.btn-label-input { flex: 1; font-size: 13px; }
.btn-callback-id {
  font-size: 11px;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  min-width: 100px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.save-status {
  font-size: 13px;
  font-weight: 500;
  margin-left: 8px;
}
.status-success { color: #10b981; }
.status-error   { color: #ef4444; }
.status-info    { color: #6366f1; }

/* ── Passport Photos ─────────────────────────────────────── */
.passport-photos { display: flex; gap: 16px; flex-wrap: wrap; padding: 8px 0; }
.passport-photo-card { text-align: center; }
.passport-photo-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.passport-photo-card img {
  width: 113px; height: 85px; border-radius: 8px;
  border: 2px solid var(--border); cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  object-fit: cover;
}
.passport-photo-card img:hover { transform: scale(1.03); box-shadow: var(--shadow); }
.passport-pdf-link {
  display: flex; align-items: center; gap: 8px; padding: 20px 24px;
  border: 2px dashed var(--border); border-radius: 8px; color: #dc2626;
  font-weight: 600; font-size: 14px; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.passport-pdf-link:hover { background: #fef2f2; border-color: #dc2626; }
.passport-pdf-link i { font-size: 28px; }
.btn-delete-doc { background:none; border:none; color:#ef4444; cursor:pointer;
  font-size:14px; font-weight:700; margin-left:6px; vertical-align:middle; }
.btn-delete-doc:hover { color:#dc2626; }
.btn-download-doc { color:#6366f1; font-size:13px; margin-left:6px; vertical-align:middle;
  text-decoration:none; transition: color .15s; }
.btn-download-doc:hover { color:#4f46e5; }
.doc-empty { text-align:center; padding:24px 16px; }
.doc-thumb { cursor:pointer; }
.doc-date { font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.doc-date .bi { font-size: 9px; margin-right: 2px; }

/* ── Chat photo thumbnails ──────────────────────────────── */
.chat-photo-thumb {
  width: 113px; height: 85px; border-radius: 8px; cursor: pointer;
  object-fit: cover; border: 1px solid rgba(255,255,255,.2);
  transition: transform .15s, opacity .15s;
}
.chat-photo-thumb:hover { transform: scale(1.03); opacity: .9; }

/* ── Lightbox ───────────────────────────────────────────── */
.lightbox-overlay {
  display:none; position:fixed; top:0; left:0; width:100%; height:100%;
  background:rgba(0,0,0,.85); z-index:9999; justify-content:center; align-items:center;
}
.lightbox-overlay.active { display:flex; }
.lightbox-content { position:relative; max-width:90vw; max-height:90vh; text-align:center; }
.lightbox-content img { max-width:90vw; max-height:85vh; border-radius:8px; object-fit:contain; }
.lightbox-close {
  position:absolute; top:-16px; right:-16px; width:36px; height:36px;
  background:#fff; border:none; border-radius:50%; font-size:22px; font-weight:700;
  color:#333; cursor:pointer; display:flex; align-items:center; justify-content:center;
  box-shadow:0 2px 8px rgba(0,0,0,.3); transition: transform .15s;
}
.lightbox-close:hover { transform:scale(1.1); }
.lightbox-download {
  display:inline-flex; align-items:center; gap:6px; margin-top:12px;
  padding:8px 20px; background:#fff; color:#333; border-radius:8px;
  text-decoration:none; font-weight:600; font-size:14px;
  transition: background .15s, transform .15s;
}
.lightbox-download:hover { background:#e5e7eb; transform:scale(1.03); }

/* ── Funnel Map ──────────────────────────────────────────── */
.funnel-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  padding: 24px;
  margin-bottom: 24px;
  overflow-x: auto;
}
.funnel-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.funnel-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-width: 700px;
}
.fn-level {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: nowrap;
  padding: 4px 0;
}
.fn-arrow-down {
  width: 2px;
  height: 20px;
  background: #cbd5e1;
  margin: 2px auto;
  position: relative;
}
.fn-arrow-down::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: -4px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #cbd5e1;
}
.fn-arrow-right {
  width: 20px;
  height: 2px;
  background: #cbd5e1;
  align-self: center;
  position: relative;
}
.fn-arrow-right::after {
  content: '';
  position: absolute;
  right: -4px;
  top: -4px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #cbd5e1;
}
/* Node card */
.fn-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid;
  background: var(--surface);
  min-width: 110px;
  max-width: 160px;
  text-align: center;
  transition: transform .15s, box-shadow .15s;
  cursor: default;
}
.fn-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.fn-node-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.fn-node-count {
  font-size: 16px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 12px;
  min-width: 32px;
}
/* Color types */
.fn-type-buttons        { border-color: #3b82f6; }
.fn-type-buttons .fn-node-count  { background: #dbeafe; color: #1d4ed8; }
.fn-type-text           { border-color: #10b981; }
.fn-type-text .fn-node-count     { background: #d1fae5; color: #065f46; }
.fn-type-photo          { border-color: #f59e0b; }
.fn-type-photo .fn-node-count    { background: #fef3c7; color: #92400e; }
.fn-type-terminal       { border-color: #22c55e; background: #f0fdf4; }
.fn-type-terminal .fn-node-count { background: #dcfce7; color: #166534; }
.fn-type-warmup         { border-color: #8b5cf6; }
.fn-type-warmup .fn-node-count   { background: #ede9fe; color: #5b21b6; }
/* Legend */
.fn-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.fn-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.fn-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 2px solid;
}
/* Branch lines */
.fn-branch-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  margin-bottom: 2px;
}
.fn-branch-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
/* Horizontal flow row */
.fn-hflow {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px 0;
}
/* Responsive */
@media (max-width: 991px) {
  .funnel-flow { min-width: 600px; }
  .fn-node { min-width: 90px; max-width: 130px; padding: 6px 10px; }
  .fn-node-label { font-size: 10px; }
  .fn-node-count { font-size: 13px; }
}

/* ── Funnel Constructor (node editor) ────────────────── */
.constructor-page {
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  gap: 0;
  height: calc(100vh - 120px);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.btn-xs { padding: 2px 8px; font-size: 12px; border-radius: 4px; }

/* Left panel - palette */
.constructor-left {
  border-right: 1.5px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}
.palette-group { border-bottom: 1px solid var(--border); }
.palette-group.collapsed .palette-item { display: none; }
.palette-group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); padding: 8px 12px; cursor: pointer;
  user-select: none; letter-spacing: 0.5px;
}
.palette-group-title:hover { background: var(--hover); }
.palette-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px 6px 16px; cursor: pointer; font-size: 13px;
  border-left: 3px solid transparent; transition: all .1s;
}
.palette-item:hover { background: var(--hover); }
.palette-item-active { background: rgba(59,130,246,.15) !important; border-left-color: var(--accent); font-weight: 600; }
.palette-item-disabled { opacity: 0.4; }
.palette-count {
  font-size: 11px; background: var(--hover); color: var(--text-muted);
  padding: 1px 6px; border-radius: 8px; font-weight: 600;
}

/* Center panel - canvas */
.constructor-center {
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}
.flow-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface); min-height: 40px;
}

/* Drawflow overrides */
#drawflow { background: var(--bg); }
.drawflow .drawflow-node {
  background: none !important; border: none !important;
  box-shadow: none !important; padding: 0 !important;
  min-height: auto !important; width: auto !important;
}
.drawflow .drawflow-node .inputs {
  display: flex !important;
  position: absolute !important; left: 2px !important; top: 50% !important;
  transform: translateY(-50%) !important; z-index: 6 !important;
}
.drawflow .drawflow-node .outputs {
  display: block !important;
  position: absolute !important; right: -6px !important; top: 0 !important;
  bottom: 0 !important; width: 14px !important;
}
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output {
  width: 12px !important; height: 12px !important; border-radius: 50% !important;
  border: 2.5px solid #94a3b8 !important; background: white !important;
  cursor: crosshair; z-index: 5 !important; position: relative !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.15) !important;
  transition: all .15s ease !important;
}
.drawflow .drawflow-node .input {
  border-color: #10b981 !important;
}
.drawflow .drawflow-node .output {
  border-color: #3b82f6 !important;
  position: absolute !important; right: 0 !important;
}
.drawflow .drawflow-node .input:hover {
  background: #10b981 !important; border-color: #059669 !important;
  transform: scale(1.3) !important;
}
.drawflow .drawflow-node .output:hover {
  background: #3b82f6 !important; border-color: #1d4ed8 !important;
  transform: scale(1.3) !important;
}
.drawflow .connection .main-path {
  stroke: #94a3b8; stroke-width: 2;
}
.drawflow .connection .main-path:hover { stroke: #3b82f6; stroke-width: 3; }
.drawflow .drawflow-node.selected .node-card {
  box-shadow: 0 0 0 3px var(--accent); transform: scale(1.02);
}
.drawflow .drawflow-delete { display: none; }

/* Node card inside Drawflow */
.node-card {
  background: var(--surface); border: 2px solid #94a3b8;
  border-radius: 10px; min-width: 160px; max-width: 220px;
  font-size: 12px; overflow: hidden; transition: box-shadow .15s, transform .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.node-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.node-type-buttons { border-color: #3b82f6; }
.node-type-text { border-color: #10b981; }
.node-type-photo { border-color: #f59e0b; }
.node-type-mixed { border-color: #8b5cf6; }
.node-type-terminal { border-color: #22c55e; background: #f0fdf4; }
.node-type-checklist { border-color: #0ea5e9; background: #f0f9ff; }
.node-disabled .node-card { opacity: 0.4; border-style: dashed; }
.node-stage-bar {
  height: 4px;
  border-radius: 10px 10px 0 0;
}
.node-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; font-weight: 600; font-size: 12px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.node-off-badge {
  font-size: 9px; background: #fecaca; color: #dc2626;
  padding: 1px 4px; border-radius: 3px; font-weight: 700;
}
.node-custom-badge {
  font-size: 9px; background: #dbeafe; color: #1d4ed8;
  padding: 1px 4px; border-radius: 3px; font-weight: 700;
}
.node-pause-badge {
  font-size: 9px; background: #fef3c7; color: #d97706;
  padding: 1px 4px; border-radius: 3px; font-weight: 700;
}
.node-preview {
  padding: 4px 10px; font-size: 11px; color: var(--text-muted);
  max-height: 36px; overflow: hidden;
}
.node-count {
  padding: 2px 10px 4px; font-size: 11px; font-weight: 600; color: var(--text-muted);
}
.node-btns { border-top: 1px solid var(--border); }
.node-btn-label {
  padding: 3px 10px; font-size: 11px; color: var(--text);
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}
.node-btn-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%;
  background: #3b82f6; color: white; font-size: 8px; font-weight: 700;
  margin-right: 3px; flex-shrink: 0;
}
/* Output dots: hide numbers, keep dots small and clean */
.drawflow .drawflow-node .output[data-num] {
  position: relative;
}
.node-input-label { color: #10b981; font-style: italic; }

/* Start node (welcome) — green */
.node-start .node-card,
.node-card.node-start {
  border-color: #16a34a !important;
  border-width: 3px;
  box-shadow: 0 0 12px rgba(22, 163, 74, 0.25);
}
.node-start .node-header,
.node-card.node-start .node-header {
  background: #dcfce7;
}
.node-start-icon {
  color: #16a34a;
  font-weight: 700;
}

/* Finish nodes (terminal) — red */
.node-finish .node-card,
.node-card.node-finish {
  border-color: #dc2626 !important;
  border-width: 3px;
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.2);
  background: #fff5f5;
}
.node-finish .node-header,
.node-card.node-finish .node-header {
  background: #fef2f2;
}
.node-finish-icon {
  font-size: 11px;
}

/* Telegram Preview */
.tg-preview {
  margin-top: 10px;
  padding: 14px;
  background: #e8dfd5;
  border-radius: 10px;
  max-width: 300px;
}
.tg-bubble {
  background: #dcf8c6;
  border-radius: 8px 8px 0 8px;
  padding: 8px 10px;
  position: relative;
  font-size: 13px;
  line-height: 1.5;
  color: #111;
  word-wrap: break-word;
}
.tg-bubble a { color: #5b9dff; text-decoration: underline; }
.tg-time {
  text-align: right;
  font-size: 10px;
  color: #8fad80;
  margin-top: 2px;
}
.tg-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.tg-btn {
  text-align: center;
  padding: 7px 12px;
  background: #fff;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #4ea4f6;
  cursor: default;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* Trace Path */
.node-traced .node-card {
  box-shadow: 0 0 0 3px #f59e0b, 0 4px 12px rgba(245, 158, 11, 0.3) !important;
  z-index: 5;
}
.drawflow .connection.connection-traced .main-path {
  stroke: #f59e0b !important;
  stroke-width: 3 !important;
  stroke-dasharray: 8 4;
  animation: traceDash 1s linear infinite;
}
@keyframes traceDash {
  to { stroke-dashoffset: -12; }
}

/* Minimap */
#minimap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  cursor: crosshair;
  z-index: 10;
}

/* Right panel - properties */
.constructor-right {
  border-left: 1.5px solid var(--border);
  overflow-y: auto; background: var(--surface);
}
.props-section { margin-bottom: 16px; }
.props-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 8px; letter-spacing: 0.5px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.form-label-sm { font-size: 11px; font-weight: 600; color: #475569; margin-bottom: 2px; display: block; }
.props-btn-row-wrap {
  margin-bottom: 6px;
}
.props-btn-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; background: white; border-radius: 6px; border: 1px solid var(--border);
}
.props-btn-row.has-data, .props-btn-row.has-tag {
  border-radius: 6px 6px 0 0;
  margin-bottom: 0;
}
.props-btn-row.has-data { border-bottom-color: #93c5fd; }
.props-btn-row.has-tag { border-bottom-color: #fbbf24; }
.props-btn-row.has-data.has-tag { border-bottom-color: #93c5fd; }
.props-btn-data-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 6px;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-top: none;
}
.props-btn-data-row + .props-btn-tag-row { border-radius: 0 0 6px 6px; }
.props-btn-data-row:last-child { border-radius: 0 0 6px 6px; }
.props-btn-tag-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 6px;
  background: #fefce8;
  border-radius: 0 0 6px 6px;
  border: 1px solid #fbbf24;
  border-top: none;
}
.tag-color-dots { display: flex; gap: 3px; }
.tag-dot {
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: border-color .15s;
}
.tag-dot:hover { opacity: .8; }
.tag-dot.active { border-color: #1e293b; }
.props-kv-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
}
.props-screen-name-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 2px 6px;
  width: 100%;
  border-radius: 6px;
  color: var(--text);
  transition: all .15s;
}
.props-screen-name-input:hover {
  background: #f0f4f8;
  border-color: var(--border);
}
.props-screen-name-input:focus {
  background: white;
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(99,102,241,.15);
}

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.4); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 24px; width: 420px; max-width: 90vw;
}

/* Funnel selector */
.funnel-selector {
  display: flex;
  align-items: center;
  gap: 4px;
}
.funnel-selector select {
  font-weight: 500;
}
.btn-xs {
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 6px;
}

/* ── Validation ── */
.validation-badge {
  position: absolute;
  top: -6px; right: -6px;
  font-size: 10px;
  min-width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}
.badge-error-bg { background: #ef4444; }
.badge-warning-bg { background: #f59e0b; }

.validation-summary-badge {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 4px 10px;
  border-radius: 6px; font-weight: 600;
}
.validation-summary-badge.badge-error { background: #fef2f2; color: #ef4444; }
.validation-summary-badge.badge-warning { background: #fffbeb; color: #f59e0b; }
.validation-summary-badge.badge-tip { background: #f0fdf4; color: #22c55e; }
.validation-summary-badge.badge-field { background: #f5f3ff; color: #8b5cf6; }
.badge-count { font-size: 14px; font-weight: 700; }

.validation-section { border-left: 3px solid; padding-left: 12px; margin-bottom: 16px; }

.validation-item {
  padding: 8px 12px; margin-bottom: 6px;
  background: var(--surface); border-radius: 6px;
  border: 1px solid #e2e8f0;
  transition: background .15s;
}
.validation-item:hover { background: #f8fafc; }
.validation-item-message { font-size: 13px; font-weight: 600; }
.validation-item-detail { font-size: 11px; color: #64748b; margin-top: 2px; }

.node-validation-highlight {
  animation: validationPulse 0.5s ease-in-out 3;
}
@keyframes validationPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,.3); }
}

/* ── Custom Fields D&D ── */
.drag-handle { cursor: grab; color: #94a3b8; margin-right: 4px; font-size: 14px; }
.custom-field-row { transition: background .15s, border-top .15s; border-top: 2px solid transparent; }
.custom-field-row.dragging { opacity: 0.4; background: #e0e7ff; }
.custom-field-row.drag-over { border-top: 2px solid var(--primary); }

.cf-delete-btn {
  opacity: 0; border: none; background: none; color: #ef4444;
  cursor: pointer; padding: 2px 4px; font-size: 12px; transition: opacity .15s;
  flex-shrink: 0;
}
.info-row:hover .cf-delete-btn { opacity: 0.7; }
.cf-delete-btn:hover { opacity: 1 !important; }

#addFieldForm {
  background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 10px; margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 1100px) {
  .constructor-page { grid-template-columns: 180px 1fr 280px; }
}
@media (max-width: 800px) {
  .constructor-page { grid-template-columns: 1fr; height: auto; }
  .constructor-left, .constructor-right { border: none; }
}

/* ── FAB: Create Lead ── */
.fab-create-lead {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #22c55e;
  color: white;
  border: none;
  box-shadow: 0 4px 14px rgba(34,197,94,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab-create-lead:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(34,197,94,0.5);
}
.fab-create-lead:active {
  transform: scale(0.95);
}
@media (max-width: 768px) {
  .fab-create-lead {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
    font-size: 22px;
  }
}
/* Modal overlay for create lead */
#createLeadModal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Lead History Timeline ───────────────────────────────── */
.lead-history-timeline {
  padding: 8px 0;
  max-height: 300px;
  overflow-y: auto;
}
.history-item {
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  position: relative;
}
.history-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 17px;
  top: 22px;
  bottom: -6px;
  width: 2px;
  background: #e2e8f0;
}
.history-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  margin-top: 6px;
  flex-shrink: 0;
}
.history-content {
  flex: 1;
  min-width: 0;
}
.history-action {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}
.history-action i {
  margin-right: 4px;
}
.history-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 1px;
}

/* ── Phone duplicate warning ─────────────────────────────── */
.phone-dup-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 13px;
  color: #92400e;
}
.phone-dup-warning .dup-lead-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #d97706;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.phone-dup-warning .dup-lead-link:hover {
  color: #b45309;
}

/* ── Manager role badges ─────────────────────────────────── */
.role-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}
.role-badge.role-admin { background: #dbeafe; color: #1e40af; }
.role-badge.role-social_manager { background: #fce7f3; color: #9d174d; }
.role-badge.role-showroom_manager { background: #d1fae5; color: #065f46; }

/* ── Showroom page ───────────────────────────────────────── */
.showroom-page { max-width: 960px; }
.showroom-page h2, .showroom-page h3 { color: var(--text-primary); font-weight: 700; }
.showroom-page h2 { font-size: 22px; }
.showroom-page h3 { font-size: 18px; }
.showroom-page .table { color: var(--text-primary); }
.showroom-page .table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.showroom-page .table td { vertical-align: middle; }
.showroom-page .sr-phone-prefix { color: var(--text-primary); }

/* Phone auto-check status */
.sr-phone-found {
  font-size: 13px; padding: 6px 12px; border-radius: 6px;
  background: var(--accent-bg, #dcfce7); color: #15803d;
  border: 1px solid #bbf7d0;
}
.sr-phone-new {
  font-size: 13px; padding: 6px 12px; border-radius: 6px;
  background: var(--warning-bg, #fef9c3); color: #a16207;
  border: 1px solid #fde68a;
}
body.dark .sr-phone-found { background: rgba(34,197,94,.15); color: #4ade80; border-color: rgba(34,197,94,.3); }
body.dark .sr-phone-new { background: rgba(234,179,8,.15); color: #facc15; border-color: rgba(234,179,8,.3); }

/* Form card */
.sr-form-card { max-width: 700px; }

/* Filters row */
.sr-filters-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
}
.sr-filter-item { flex: 1; min-width: 120px; }
.sr-filter-btn { flex: 0 0 auto; align-self: flex-end; }

/* History mobile cards */
.sr-hist-card {
  display: block; padding: 10px 14px; margin-bottom: 8px;
  background: var(--card-bg, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px; text-decoration: none; color: var(--text-primary);
  transition: box-shadow .15s;
}
.sr-hist-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.sr-hist-card-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.sr-hist-card-info {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-muted);
}
.sr-hist-card-info i { font-size: 11px; }

/* Autocomplete dropdown */
.sr-ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1050;
  max-height: 240px; overflow-y: auto;
  background: var(--card-bg, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  margin-top: 4px;
}
.sr-ac-item {
  padding: 8px 14px; cursor: pointer; font-size: 14px;
  color: var(--text-primary); transition: background .1s;
}
.sr-ac-item:hover, .sr-ac-item.sr-ac-active {
  background: var(--accent-bg, #eff6ff);
}
.sr-ac-item b { color: var(--accent, #6366f1); font-weight: 700; }
.sr-ac-empty {
  padding: 12px 14px; font-size: 13px; color: var(--text-muted);
  text-align: center;
}

/* ── Showroom Mobile ── */
@media (max-width: 767px) {
  .showroom-page { padding: 0; }
  .showroom-page h2 { font-size: 18px; margin-bottom: 12px !important; }
  .showroom-page h3 { font-size: 15px; }
  .sr-form-card { max-width: 100%; padding: 12px !important; }
  .sr-form-card .info-section-title { font-size: 13px; }
  .sr-form-card .row.g-2 > .col-6 { flex: 0 0 100%; max-width: 100%; }
  .sr-form-card .form-label { font-size: 12px !important; margin-bottom: 2px !important; }
  .sr-form-card .form-control,
  .sr-form-card .form-select { font-size: 14px; padding: 6px 10px; }
  .sr-form-card .input-group .form-control { font-size: 15px !important; }
  .sr-form-card .btn-success { width: 100%; }
  .sr-form-card .btn-outline-secondary { width: 100%; }
  .sr-form-card .d-flex.gap-2 { flex-direction: column; }
  .sr-filters-row { gap: 6px; }
  .sr-filter-item { min-width: 0; flex: 1 1 45%; }
  .sr-filter-btn { flex: 1 1 100%; }
  .sr-ac-dropdown { max-height: 180px; }
  .sr-ac-item { padding: 10px 12px; font-size: 13px; }
  .sr-phone-found, .sr-phone-new { font-size: 12px; padding: 5px 10px; }
}

/* ── Dropdown Editor (admin) ─────────────────────────────── */
.sr-dd-edit-btn {
  cursor: pointer;
  font-size: 11px;
  color: var(--primary, #6366f1);
  opacity: 0.6;
  transition: opacity .2s;
}
.sr-dd-edit-btn:hover { opacity: 1; }

.sr-dd-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sr-dd-editor {
  background: var(--card-bg, #fff);
  border-radius: 12px;
  width: 380px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}

.sr-dd-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  font-size: 14px;
}

.sr-dd-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  max-height: 300px;
}

.sr-dd-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  color: var(--text-primary);
}
.sr-dd-item:last-child { border-bottom: none; }

.sr-dd-item-text { flex: 1; }

.sr-dd-item-actions {
  display: flex;
  gap: 8px;
  font-size: 13px;
}
.sr-dd-item-actions i {
  cursor: pointer;
  opacity: 0.6;
  transition: opacity .2s;
}
.sr-dd-item-actions i:hover { opacity: 1; }

.sr-dd-editor-add {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border, #e2e8f0);
}
.sr-dd-editor-add input { flex: 1; }

.sr-dd-editor-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border, #e2e8f0);
  justify-content: flex-end;
}

body.dark .sr-dd-editor { background: var(--card-bg, #1e293b); }
body.dark .sr-dd-editor-header .btn-close-white { filter: none; }

/* ── Analytics page ──────────────────────────────────────── */
.analytics-page h2 { color: var(--text-primary); font-size: 22px; font-weight: 700; }
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 768px) {
  .analytics-grid { grid-template-columns: 1fr; }
}
.chart-bars { padding: 8px 0; }
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
}
.bar-label {
  width: 100px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
  text-align: right;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  min-width: 2px;
}
.bar-value {
  width: 45px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
  flex-shrink: 0;
}
.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.analytics-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}
.analytics-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.analytics-table tr:hover td {
  background: var(--bg-hover);
}
.conv-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: #dcfce7;
  color: #16a34a;
  font-weight: 700;
  font-size: 12px;
}
.conv-bar-wrap {
  position: relative;
  height: 22px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
  min-width: 80px;
}
.conv-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 4px;
  transition: width 0.6s ease;
}
.conv-bar-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Kanban overdue badge */
.kanban-overdue-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #ef4444;
  border-radius: 8px;
  padding: 1px 5px;
  margin-left: 4px;
  line-height: 1.2;
  vertical-align: middle;
  min-width: 20px;
  animation: overdue-pulse 2s infinite;
}
@keyframes overdue-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
body.dark .kanban-overdue-badge {
  background: #dc2626;
}

/* ── Unified timeline: note & task bubbles ── */
.note-bubble {
  background: #fffbeb !important;
  border: 1.5px solid #fbbf24 !important;
  border-radius: 10px !important;
  margin: 6px 24px !important;
  max-width: none !important;
  float: none !important;
  clear: both !important;
}
.note-bubble-header {
  font-size: 11px;
  font-weight: 700;
  color: #d97706;
  padding: 6px 12px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-bubble-author {
  font-weight: 400;
  color: #92400e;
  margin-left: auto;
  font-size: 10px;
}
.note-bubble .bubble-content {
  padding: 4px 12px 2px;
  font-size: 13px;
  color: #78350f;
  white-space: pre-wrap;
}
.note-bubble .bubble-time {
  padding: 0 12px 6px;
  font-size: 10px;
  color: #b45309;
}

.task-bubble {
  background: #f0fdf4 !important;
  border: 1.5px solid #86efac !important;
  border-radius: 10px !important;
  margin: 6px 24px !important;
  max-width: none !important;
  float: none !important;
  clear: both !important;
}
.task-completed {
  opacity: 0.6;
}
.task-completed .bubble-content {
  text-decoration: line-through;
}
.task-high {
  border-color: #fca5a5 !important;
  background: #fef2f2 !important;
}
.task-bubble-header {
  font-size: 11px;
  font-weight: 700;
  color: #16a34a;
  padding: 6px 12px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.task-high .task-bubble-header { color: #dc2626; }
.task-bubble-author {
  font-weight: 400;
  color: #166534;
  margin-left: auto;
  font-size: 10px;
}
.task-high .task-bubble-author { color: #991b1b; }
.task-bubble .bubble-content {
  padding: 4px 12px 2px;
  font-size: 13px;
  color: #14532d;
}
.task-high .bubble-content { color: #7f1d1d; }
.task-bubble-desc {
  padding: 2px 12px;
  font-size: 11px;
  color: #4ade80;
  font-style: italic;
}
.task-bubble-due {
  padding: 2px 12px;
  font-size: 11px;
  color: #15803d;
  font-weight: 600;
}
.task-bubble-due.overdue { color: #dc2626; font-weight: 700; }
.task-bubble-due.today { color: #d97706; }
.task-overdue-label {
  font-size: 9px;
  background: #fecaca;
  color: #dc2626;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
}
.task-bubble .bubble-time {
  padding: 0 12px 6px;
  font-size: 10px;
  color: #16a34a;
}

/* ── Chat type selector (amoCRM style) ── */
.chat-type-selector {
  padding: 4px 8px 0;
}
.chat-type-select {
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
  outline: none;
}
.chat-type-select option {
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
}
.chat-task-fields {
  display: flex;
  gap: 8px;
  padding: 4px 8px;
  align-items: center;
}
.chat-send-row {
  display: flex;
  gap: 8px;
  padding: 8px;
  align-items: flex-end;
}
.chat-send-row .chat-send-input {
  flex: 1;
}

/* ── Dark mode for note & task bubbles ── */
body.dark .note-bubble {
  background: #422006 !important;
  border-color: #92400e !important;
}
body.dark .note-bubble-header { color: #fbbf24; }
body.dark .note-bubble-author { color: #fcd34d; }
body.dark .note-bubble .bubble-content { color: #fef3c7; }
body.dark .note-bubble .bubble-time { color: #f59e0b; }

body.dark .task-bubble {
  background: #052e16 !important;
  border-color: #166534 !important;
}
body.dark .task-high {
  background: #450a0a !important;
  border-color: #991b1b !important;
}
body.dark .task-bubble-header { color: #4ade80; }
body.dark .task-high .task-bubble-header { color: #fca5a5; }
body.dark .task-bubble-author { color: #86efac; }
body.dark .task-high .task-bubble-author { color: #fecaca; }
body.dark .task-bubble .bubble-content { color: #dcfce7; }
body.dark .task-high .bubble-content { color: #fee2e2; }
body.dark .task-bubble-due { color: #4ade80; }
body.dark .task-bubble-due.overdue { color: #f87171; }
body.dark .task-bubble .bubble-time { color: #22c55e; }

body.dark .chat-type-select { color: var(--accent); }

/* Dark mode: readable manager name in chat bubbles */
body.dark .bubble-sender {
  color: #93c5fd;
}

/* Recording bubbles */
.recording-bubble {
  background: linear-gradient(135deg, #fef2f2, #fff1f2) !important;
  border: 1.5px solid #fca5a5 !important;
  border-radius: 12px;
  margin: 8px 20px;
}
body.dark .recording-bubble {
  background: linear-gradient(135deg, #1c1017, #1a0f14) !important;
  border-color: #7f1d1d !important;
}
.recording-bubble-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px 4px; font-size: 13px; font-weight: 600;
  color: #dc2626;
}
body.dark .recording-bubble-header { color: #f87171; }
.recording-bubble-author {
  font-weight: 400; color: #64748b; font-size: 12px;
}
body.dark .recording-bubble-author { color: #94a3b8; }
.recording-bubble-duration {
  font-size: 11px; background: #fee2e2; color: #dc2626;
  padding: 1px 6px; border-radius: 6px; font-weight: 600;
  margin-left: auto;
}
body.dark .recording-bubble-duration {
  background: #450a0a; color: #fca5a5;
}
.recording-player { padding: 4px 12px 8px; }
.recording-audio-player {
  width: 100%; height: 36px; border-radius: 8px;
  filter: invert(0);
}
body.dark .recording-audio-player,
body.dark .call-audio-player {
  filter: invert(0.92) hue-rotate(180deg) saturate(0.85);
  border-radius: 8px;
}
body.dark .recording-audio-player::-webkit-media-controls-panel,
body.dark .call-audio-player::-webkit-media-controls-panel {
  background: #f1f5f9;
}
.recording-transcription-area { padding: 0 12px 8px; }
.recording-transcription-text {
  font-size: 12px; color: #64748b; padding: 6px 8px;
  background: #fafafa; border-radius: 6px; line-height: 1.5;
}
body.dark .recording-transcription-text {
  background: #1e1e2e; color: #94a3b8;
}

/* Record button active state */
.recording-active {
  background: #ef4444 !important;
  border-color: #ef4444 !important;
  color: white !important;
  animation: record-pulse 1s infinite;
}
@keyframes record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* Showroom recording bar */
.sr-recording-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(135deg, #fef2f2, #fff1f2);
  border: 1.5px solid #fca5a5;
  border-radius: 10px;
  margin-top: 12px;
  animation: sr-rec-fade-in 0.3s ease;
}
body.dark .sr-recording-bar {
  background: linear-gradient(135deg, #1c1017, #1a0f14);
  border-color: #7f1d1d;
}
@keyframes sr-rec-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.sr-rec-dot {
  width: 10px; height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: sr-rec-blink 1s infinite;
}
@keyframes sr-rec-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.sr-rec-label {
  font-size: 13px;
  color: #dc2626;
  font-weight: 500;
}
body.dark .sr-rec-label { color: #f87171; }
#srRecTimer {
  font-size: 14px;
  font-weight: 700;
  color: #dc2626;
  font-variant-numeric: tabular-nums;
}
body.dark #srRecTimer { color: #f87171; }

/* Calls page stat cards */
.calls-stat-card {
  flex: 1; min-width: 100px; padding: 10px 14px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 10px; text-align: center;
}
.calls-stat-num { font-size: 22px; font-weight: 700; color: var(--text); }
.calls-stat-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.calls-stat-success { border-color: #10b981; }
.calls-stat-success .calls-stat-num { color: #10b981; }
.calls-stat-danger { border-color: #ef4444; }
.calls-stat-danger .calls-stat-num { color: #ef4444; }
.calls-stat-info { border-color: #3b82f6; }
.calls-stat-info .calls-stat-num { color: #3b82f6; }
.calls-stat-warning { border-color: #f59e0b; }
.calls-stat-warning .calls-stat-num { color: #f59e0b; }

/* Unread calls - bold */
.call-unread td { font-weight: 700 !important; }
.call-unread td a { font-weight: 700 !important; }

/* Instagram page cards */
.ig-card {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background .15s;
}
.ig-card:hover { background: var(--hover, #f8fafc); }
body.dark .ig-card:hover { background: #1a2236; }
.ig-card-unread { background: #eff6ff; }
body.dark .ig-card-unread { background: #1a1a2e; }
.ig-card-avatar {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  flex-shrink: 0;
}
.ig-card-avatar i { color: white !important; font-size: 20px !important; }
.ig-card-body { flex: 1; min-width: 0; }
.ig-card-top {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 2px;
}
.ig-card-username { font-size: 12px; color: #E1306C; }
.ig-card-time { margin-left: auto; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.ig-card-preview {
  display: flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ig-card-meta {
  display: flex; gap: 12px; margin-top: 4px;
  font-size: 11px; color: var(--text-muted);
}
.ig-card-stage {
  font-size: 10px; background: #e2e8f0; color: #475569;
  padding: 1px 6px; border-radius: 4px;
}
body.dark .ig-card-stage { background: #334155; color: #94a3b8; }
.ig-unread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  background: #E1306C; color: white;
  border-radius: 9px; font-size: 10px; font-weight: 700;
  padding: 0 5px;
}

/* Instagram source badges */
.ig-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 4px;
}
.ig-source-dm {
  background: #fce4ec;
  color: #E1306C;
}
.ig-source-comment {
  background: #fff8e1;
  color: #f59e0b;
}
body.dark .ig-source-dm {
  background: #3b1028;
  color: #f472b6;
}
body.dark .ig-source-comment {
  background: #3b2e10;
  color: #fbbf24;
}
.ig-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 0 4px;
  border-radius: 4px;
}
.ig-count-dm {
  color: #E1306C;
}
.ig-count-comment {
  color: #f59e0b;
}
body.dark .ig-count-dm { color: #f472b6; }
body.dark .ig-count-comment { color: #fbbf24; }

/* No callback highlight */
.call-no-callback {
  background: rgba(127,29,29,0.15) !important;
  border-left: 3px solid #dc2626;
}
.call-no-callback td { color: #fca5a5 !important; }
body.dark .call-no-callback { background: rgba(127,29,29,0.25) !important; }
@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Owner tabs (My / All) */
.owner-tabs {
  display: flex;
  gap: 2px;
  background: var(--border);
  border-radius: 8px;
  padding: 2px;
}
.owner-tab {
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.owner-tab:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}
.owner-tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Stage hints */
.kanban-col-stage-hint {
  white-space: pre-line;
  font-size: 11px;
  color: #06b6d4;
  padding: 2px 8px 4px;
  line-height: 1.3;
  border-top: 1px dashed rgba(6,182,212,0.2);
  background: rgba(6,182,212,0.04);
}
.kanban-col-stage-hint i { margin-right: 3px; }
body.dark .kanban-col-stage-hint {
  white-space: pre-line;
  color: #22d3ee;
  border-top-color: rgba(34,211,238,0.15);
  background: rgba(34,211,238,0.05);
}
#btnHints.active {
  background: #06b6d4 !important;
  border-color: #06b6d4 !important;
  color: white !important;
}

/* Stage edit textareas */
.at-textarea {
  width: 100%;
  resize: vertical;
  min-height: 40px;
  font-size: 11px;
  line-height: 1.3;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.at-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

/* ═══════════════════════════════════════════════════════════════
   Stage Gates — progress bar, side panel, gate check modal
   ═══════════════════════════════════════════════════════════════ */

/* Progress bar on kanban cards */
.gate-progress-bar {
  height: 3px;
  border-radius: 0 0 6px 6px;
  margin-top: auto;
  transition: background .3s;
}
.gate-progress-bar.gate-ok { background: linear-gradient(90deg, #22c55e, #16a34a); }
.gate-progress-bar.gate-partial { background: linear-gradient(90deg, #f59e0b, #eab308); }
.gate-progress-bar.gate-none { background: linear-gradient(90deg, #ef4444, #dc2626); }
.gate-progress-bar.gate-empty { background: transparent; height: 0; }

/* Gate badge on card */
.gate-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 600;
  line-height: 1;
}
.gate-badge.ok { background: #dcfce7; color: #166534; }
.gate-badge.partial { background: #fef9c3; color: #854d0e; }
.gate-badge.blocked { background: #fee2e2; color: #991b1b; }

/* Gate check modal items */
.gate-check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.gate-check-item:last-child { border-bottom: none; }
.gate-check-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}
.gate-check-icon.passed { background: #dcfce7; color: #166534; }
.gate-check-icon.failed { background: #fee2e2; color: #991b1b; }
.gate-check-info { flex: 1; min-width: 0; }
.gate-check-label { font-weight: 600; font-size: 13px; }
.gate-check-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.gate-check-meta { font-size: 11px; color: #16a34a; margin-top: 2px; }
.gate-check-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 13px;
}
.gate-check-summary.ok { background: #dcfce7; color: #166534; }
.gate-check-summary.blocked { background: #fee2e2; color: #991b1b; }
.gate-check-summary.warning { background: #fef9c3; color: #854d0e; }

/* Side panel for stage gate configuration */
.gate-side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 90vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,.12);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  animation: slideInRight .2s ease-out;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.gate-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.gate-panel-header h5 { margin: 0; font-size: 15px; }
.gate-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.gate-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Gate config card in side panel */
.gate-config-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.gate-config-card .gate-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.gate-config-card .gate-type-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}
.gate-config-card .gate-config-actions {
  display: flex;
  gap: 4px;
}
.gate-config-card .gate-config-actions button {
  padding: 2px 6px;
  font-size: 12px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
}
.gate-config-card .gate-config-actions button:hover { color: var(--text); }

/* Stage column settings button */
.kanban-col-settings {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
}
.kanban-col-head:hover .kanban-col-settings { opacity: 1; }
.kanban-col-settings:hover { background: var(--border); color: var(--text); }
