/* OrangeCRM default palette — black surfaces, orange accent. Light mode is
   available via the toggle ([data-theme="light"] below) but black/orange is
   what loads first, so this brand never gets mistaken for the original. */
:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface2: #212121;
  --border: #303030;
  --accent: #ff7a1a;
  --accent2: #ffb347;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --orange: #ff7a1a;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --radius: 8px;
  --shadow: none;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --border: #e2e8f0;
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --orange: #ea580c;
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* NAV */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo { font-weight: 700; font-size: 16px; color: var(--accent); letter-spacing: 0.5px; }
.topbar-right { display: flex; gap: 4px; align-items: center; }
.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  margin-left: 8px;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--accent); background: rgba(255,122,26,0.12); }

/* TABS */
.tab { display: none; padding: 24px; max-width: 1400px; margin: 0 auto; }
.tab.active { display: block; }
.tab-full { max-width: none; }
.clicks-frame-card { padding: 0; overflow: hidden; }
.clicks-frame-card iframe {
  display: block;
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 500px;
  border: 0;
  background: #fff;
}

/* SECTION HEADER */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-header h2 { font-size: 20px; font-weight: 600; }
.btn-refresh {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.btn-refresh:hover { color: var(--text); }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--muted); }

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* SALES REPORT TABLES */
.card h3.report-title { padding: 18px 18px 14px; margin-bottom: 0; }
.sales-table th:not(:first-child),
.sales-table td:not(:first-child) { text-align: right; }
.sales-table td { font-variant-numeric: tabular-nums; }
.sales-table td.zero { color: var(--muted); }
.sales-table .row-hint { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 8px; }
.sales-table .totals-row td { font-weight: 700; background: var(--surface2); }
.sales-table .totals-row:hover td { background: var(--surface2); }

/* CHARTS ROW */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 768px) { .charts-row { grid-template-columns: 1fr; } }
.chart-card { margin-bottom: 0; }

/* FUNNEL */
.funnel-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.funnel-bar .f-label { width: 160px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.funnel-bar .f-track { flex: 1; background: var(--surface2); border-radius: 4px; height: 22px; position: relative; overflow: hidden; }
.funnel-bar .f-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; display: flex; align-items: center; padding-left: 8px; font-size: 11px; font-weight: 600; }
.funnel-bar .f-count { width: 40px; text-align: right; font-size: 12px; font-weight: 600; }

/* SOURCE BARS */
.source-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.source-bar .s-label { width: 100px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-bar .s-track { flex: 1; background: var(--surface2); border-radius: 4px; height: 18px; overflow: hidden; }
.source-bar .s-fill { height: 100%; background: var(--accent2); border-radius: 4px; transition: width 0.4s; }
.source-bar .s-count { width: 30px; text-align: right; font-size: 12px; }

/* DAILY CHART */
.bar-chart-wrap { display: flex; align-items: flex-end; gap: 4px; height: 80px; padding-top: 8px; overflow-x: auto; }
.daily-bar { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; min-width: 24px; }
.daily-bar .d-bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; transition: height 0.3s; }
.daily-bar .d-label { font-size: 9px; color: var(--muted); white-space: nowrap; }

/* PIPELINE BOARD */
.pipeline-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 16px;
}
.pipeline-col {
  flex: 0 0 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.pipeline-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.pipeline-col-header .col-title { font-size: 12px; font-weight: 600; }
.pipeline-col-header .col-count {
  background: var(--surface2);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--muted);
}
.pipeline-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.pipeline-card:hover { border-color: var(--accent); }
.pipeline-card .pc-name { font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.pipeline-card .pc-email { font-size: 11px; color: var(--muted); margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pipeline-card .pc-meta { font-size: 10px; color: var(--muted); }
.pipeline-card .pc-bar { height: 3px; background: var(--surface); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.pipeline-card .pc-bar-fill { height: 100%; background: var(--green); border-radius: 2px; }

/* FILTERS */
.filters-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filters-bar input[type="text"],
.filters-bar select,
.filters-bar input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
}
.filters-bar input[type="text"] { width: 220px; }
.filters-bar input[type="text"]:focus,
.filters-bar select:focus { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

/* TABLE */
.table-card { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface2); }
th { padding: 14px 18px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
td { padding: 15px 18px; border-top: 1px solid var(--border); font-size: 15px; vertical-align: middle; }
tr:hover td { background: var(--surface2); }
.td-name { font-weight: 600; font-size: 15px; }
.td-email { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* STAGE BADGES */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-0 { background: rgba(100,116,139,0.2); color: #94a3b8; }
.badge-1 { background: rgba(234,179,8,0.15); color: #eab308; }
.badge-2 { background: rgba(255,122,26,0.15); color: #ffb347; }
.badge-3 { background: rgba(249,115,22,0.15); color: #f97316; }
.badge-4 { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge-5 { background: rgba(239,68,68,0.25); color: #f87171; }
.badge-6 { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge-7 { background: rgba(14,165,233,0.15); color: #38bdf8; }
.badge-8 { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge-9 { background: rgba(21,128,61,0.2); color: #4ade80; }
.badge-10 { background: rgba(190,18,60,0.2); color: #fb7185; }
.badge-11 { background: rgba(219,39,119,0.2); color: #f472b6; }

[data-theme="light"] .badge-0 { background: #f1f5f9; color: #475569; }
[data-theme="light"] .badge-1 { background: #fef9c3; color: #854d0e; }
[data-theme="light"] .badge-2 { background: #ffedd5; color: #9a3412; }
[data-theme="light"] .badge-3 { background: #ffedd5; color: #9a3412; }
[data-theme="light"] .badge-4 { background: #fee2e2; color: #991b1b; }
[data-theme="light"] .badge-5 { background: #fecaca; color: #991b1b; }
[data-theme="light"] .badge-6 { background: #dcfce7; color: #166534; }
[data-theme="light"] .badge-7 { background: #e0f2fe; color: #075985; }
[data-theme="light"] .badge-8 { background: #fef3c7; color: #92400e; }
[data-theme="light"] .badge-9 { background: #bbf7d0; color: #14532d; }
[data-theme="light"] .badge-10 { background: #ffe4e6; color: #9f1239; }
[data-theme="light"] .badge-11 { background: #fce7f3; color: #9d174d; }

/* FORM % BAR */
.pct-bar { display: flex; align-items: center; gap: 8px; }
.pct-track { width: 64px; height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.pct-fill { height: 100%; background: var(--green); border-radius: 3px; }
.pct-text { font-size: 13px; color: var(--muted); }

/* PAGINATION */
.pagination {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  align-items: center;
}
.page-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-info { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ACTION BTNS */
.btn-view, .btn-del {
  border: none;
  border-radius: 5px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-right: 4px;
}
.btn-view { background: rgba(255,122,26,0.15); color: var(--accent); }
.btn-del  { background: rgba(239,68,68,0.1); color: var(--red); }
.btn-view:hover { background: rgba(255,122,26,0.3); }
.btn-del:hover  { background: rgba(239,68,68,0.25); }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 680px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 4px;
}
.modal-body { padding: 24px; }

/* LOGIN — full-screen branded gate, deliberately not a reused modal so this
   deployment reads as its own product from the very first screen. */
.login-page {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 300;
  background:
    radial-gradient(circle at 18% 18%, rgba(255,122,26,0.16), transparent 42%),
    radial-gradient(circle at 84% 88%, rgba(255,138,42,0.10), transparent 46%),
    #060606;
}
.login-page.hidden { display: none; }

.login-card {
  width: 380px;
  max-width: 100%;
  background: #121212;
  border: 1px solid #2c2c2c;
  border-radius: 18px;
  padding: 42px 32px 30px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(255,122,26,0.06), 0 30px 80px rgba(0,0,0,0.55), 0 0 70px rgba(255,122,26,0.05);
}

.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 10px;
}
.login-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ffa64d, #ff5f0a);
  color: #170d00;
  font-weight: 800;
  font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(255,111,10,0.35);
}
.login-wordmark { font-size: 21px; font-weight: 600; color: #f2f2f2; letter-spacing: 0.2px; }
.login-wordmark b { color: #ff7a1a; font-weight: 800; }

.login-tagline { color: #8c8c8c; font-size: 13px; margin-bottom: 26px; }

.login-error { color: #ef4444; font-size: 13px; min-height: 18px; margin-bottom: 2px; }

.login-form { display: grid; gap: 14px; text-align: left; }
.login-form .field-label { color: #7f7f7f; }
.login-form .field-input:focus {
  border-color: #ff7a1a;
  box-shadow: 0 0 0 3px rgba(255,122,26,0.18);
}

.login-btn {
  width: 100%;
  padding: 11px;
  margin-top: 6px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #ff9a3c, #ff5f0a);
  color: #170d00;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s;
}
.login-btn:hover { filter: brightness(1.08); }
.login-btn:active { transform: translateY(1px); }

.login-footer {
  margin-top: 24px;
  font-size: 11px;
  color: #565656;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.detail-field { display: flex; flex-direction: column; gap: 3px; }
.detail-field .df-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.detail-field .df-value { font-size: 13px; }

.stage-change-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.stage-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius);
  flex: 1;
  outline: none;
}
.btn-update-stage {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.history-list { margin-top: 16px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.history-item:last-child { border-bottom: none; }
.history-arrow { color: var(--accent); }

/* EMAIL TAB */
.email-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .email-two-col { grid-template-columns: 1fr; } }

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel-title { font-size: 15px; font-weight: 600; }

.tpl-row, .auto-row, .log-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.tpl-row:last-child, .auto-row:last-child, .log-row:last-child { border-bottom: none; }
.tpl-row:hover, .auto-row:hover, .log-row:hover { background: var(--surface2); }

.tpl-name, .auto-name { font-weight: 600; flex: 1; }
.tpl-subject, .auto-meta { font-size: 12px; color: var(--muted); flex: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auto-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: rgba(255,122,26,0.12); color: var(--accent); white-space: nowrap; }
.auto-toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.auto-toggle input { opacity: 0; width: 0; height: 0; }
.auto-toggle .slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 20px; cursor: pointer; transition: 0.2s;
}
.auto-toggle input:checked + .slider { background: var(--accent); }
.auto-toggle .slider:before {
  content: ''; position: absolute; width: 14px; height: 14px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.auto-toggle input:checked + .slider:before { transform: translateX(16px); }

/* Share of a product's checkouts a gateway takes, drawn from its weight */
.weight-bar {
  height: 6px; border-radius: 3px; background: var(--surface2);
  border: 1px solid var(--border); overflow: hidden;
}
.weight-bar span { display: block; height: 100%; background: var(--accent); }

.log-status-sent   { color: var(--green); font-weight: 600; font-size: 11px; }
.log-status-failed { color: var(--red);   font-weight: 600; font-size: 11px; }

/* FORM FIELDS (email modals) */
.field-label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 5px; }
.field-input {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: var(--radius);
  font-size: 13px; outline: none;
}
.field-input:focus { border-color: var(--accent); }
.field-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: var(--radius);
  font-size: 13px; font-family: monospace; outline: none; resize: vertical;
}
.field-textarea:focus { border-color: var(--accent); }

.var-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.var-chips span {
  font-size: 11px; font-family: monospace;
  background: rgba(255,122,26,0.12); color: var(--accent);
  padding: 2px 8px; border-radius: 4px; cursor: pointer;
}
.var-chips span:hover { background: rgba(255,122,26,0.25); }

/* API DOCS */
.api-doc code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; }
.api-doc pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  font-family: monospace;
  font-size: 12px;
  margin: 12px 0;
  line-height: 1.6;
}
.endpoint-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
  font-family: monospace;
}
.api-doc h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.api-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.api-table th { background: var(--surface2); padding: 8px 12px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.api-table td { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12px; }
.api-table td:first-child { font-family: monospace; color: var(--accent); }

.method {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
}
.method.post { background: rgba(34,197,94,0.15); color: #22c55e; }
.method.get  { background: rgba(255,122,26,0.15); color: #ffb347; }
.method.put  { background: rgba(234,179,8,0.15); color: #eab308; }
.method.del  { background: rgba(239,68,68,0.15); color: #ef4444; }

.stages-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.stages-list .badge { font-size: 12px; padding: 4px 12px; }

.api-doc p { color: var(--muted); margin: 8px 0; line-height: 1.6; }

/* ── MOBILE / INSTALLED-APP LAYOUT ──────────────────────────────────────────
   Keeps the dashboard usable on a phone: the nav tabs scroll horizontally
   instead of overflowing, wide tables scroll sideways instead of being
   clipped, and filters/stats stack. */
@media (max-width: 640px) {
  .topbar { padding: 0 10px; height: 48px; }
  .logo { font-size: 14px; }
  .topbar-right {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar-right::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 8px 11px; white-space: nowrap; }
  .theme-toggle { flex: 0 0 auto; }

  .tab { padding: 14px; }
  .section-header { flex-wrap: wrap; gap: 8px; }

  /* Wide tables: scroll horizontally within the card rather than clip. */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; }
  th { padding: 10px 12px; }
  td { padding: 12px; font-size: 14px; }

  /* Filters stack and fill the width. */
  .filters-bar { gap: 6px; }
  .filters-bar input[type="text"] { width: 100%; flex: 1 1 100%; }
  .filters-bar select,
  .filters-bar input[type="date"] { flex: 1 1 44%; }
  .filters-bar .btn-primary,
  .filters-bar .btn-secondary { flex: 1 1 auto; }

  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 22px; }

  .modal { width: 94vw; max-width: 94vw; }
}

/* Respect notch / home-indicator safe areas when launched as an installed app. */
@media (display-mode: standalone) {
  .topbar {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
  }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ─── Lead documents & customer download link ──────────────────────────────── */
.attach-panel {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.attach-head {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--muted);
}

.attach-loading,
.attach-empty {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface2);
  border-radius: 6px;
  padding: 12px;
  line-height: 1.5;
}

.attach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 6px;
}

.attach-row.attach-missing { border-color: var(--red); }
.attach-ic { font-size: 17px; line-height: 1; }

.attach-name { flex: 1; min-width: 0; }
.attach-name strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}
.attach-name > span {
  font-size: 11px;
  color: var(--muted);
}

.attach-tag {
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 5px;
}
.attach-tag-muted { background: var(--muted); }
.attach-tag-warn { background: var(--red); }

.attach-actions { display: flex; gap: 4px; flex-shrink: 0; }
.attach-actions button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}
.attach-actions button:hover { color: var(--text); border-color: var(--accent); }
.attach-actions .attach-del:hover { color: var(--red); border-color: var(--red); }

.attach-upload {
  display: block;
  margin-top: 10px;
  padding: 11px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 7px;
  cursor: pointer;
}
.attach-upload:hover { color: var(--accent); border-color: var(--accent); }
.attach-upload input { display: none; }

.attach-status {
  font-size: 12px;
  min-height: 16px;
  margin-top: 6px;
  text-align: center;
  word-break: break-word;
}

.attach-full { width: 100%; padding: 9px; font-size: 13px; }

.share-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 12px;
}
.share-box.share-revoked { border-color: var(--red); }

.share-url {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.share-meta { font-size: 11px; color: var(--muted); margin: 8px 0; }

.share-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.share-actions button {
  flex: 1 1 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.share-actions button:hover { color: var(--text); border-color: var(--accent); }

/* ─── DASHBOARD V2 — state performance ──────────────────────────────────────
   Everything here is namespaced .dv2-* so this view can be restyled (or
   dropped) without touching the rest of the CRM. Colours come from the theme
   variables, so it reads correctly in both light and dark mode. */
.dv2-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.dv2-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.dv2-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.dv2-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dv2-controls input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
}
.dv2-controls input[type="date"]:focus { border-color: var(--accent); }

.dv2-notice {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 18px;
}
.dv2-notice strong { color: var(--text); display: block; margin-bottom: 4px; }
.dv2-notice code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}
.dv2-notice-count { font-size: 11px; opacity: 0.7; }

.dv2-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
/* All eight figures on one row once there is room, so the KPI strip reads as a
   single band rather than an orphaned last card. */
@media (min-width: 1180px) {
  .dv2-kpis { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
.dv2-kpis .stat-card { padding: 14px; }
.dv2-kpis .stat-card .label { font-size: 11px; letter-spacing: 0.3px; text-transform: none; }
.dv2-kpis .stat-card .value { font-size: 26px; }

.dv2-panel { padding: 16px 18px; }
.dv2-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

/* Funnel: step boxes joined by connectors carrying the conversion + drop-off */
.dv2-funnel {
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.dv2-step {
  flex: 1 1 0;
  min-width: 132px;
  background: color-mix(in srgb, var(--step) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--step) 45%, transparent);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.dv2-step-label { font-size: 12px; font-weight: 600; color: var(--step); }
.dv2-step-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.dv2-conn {
  flex: 0 1 120px;
  min-width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 2px;
}
.dv2-conn-rate { font-size: 12px; font-weight: 700; }
.dv2-conn-line {
  width: 100%;
  height: 1px;
  background: var(--border);
  position: relative;
  margin: 3px 0;
}
.dv2-conn-arrow {
  position: absolute;
  right: -2px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  color: var(--muted);
  line-height: 1;
}
.dv2-conn-sub { font-size: 10px; color: var(--muted); text-align: center; line-height: 1.3; }
.dv2-drop {
  font-size: 10px;
  font-weight: 600;
  color: var(--red);
  background: rgba(239, 68, 68, 0.12);
  border-radius: 10px;
  padding: 1px 7px;
  margin-top: 3px;
  white-space: nowrap;
}

/* Table on the left, charts + insights stacked on the right */
.dv2-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.dv2-side { display: grid; gap: 16px; }
.dv2-grid .dv2-panel, .dv2-side .dv2-panel { margin-bottom: 0; }
/* minmax(0,…) rather than 1fr: the breakdown table is deliberately wider than a
   phone, and an auto-sized track would stretch the whole page instead of
   letting the table scroll inside its own card. */
@media (max-width: 1024px) { .dv2-grid { grid-template-columns: minmax(0, 1fr); } }

.dv2-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dv2-table { width: 100%; border-collapse: collapse; min-width: 620px; }
.dv2-table th {
  padding: 8px 8px;
  font-size: 10px;
  letter-spacing: 0.3px;
  background: transparent;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: normal;
  line-height: 1.25;
}
.dv2-table th:nth-child(-n+2) { text-align: left; }
.dv2-table td {
  padding: 7px 8px;
  font-size: 12px;
  text-align: right;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.dv2-table td.zero { color: var(--muted); opacity: 0.55; }
.dv2-table tr:hover td { background: var(--surface2); }
.dv2-rank { text-align: left !important; color: var(--muted); width: 34px; }
.dv2-state { text-align: left !important; font-weight: 700; letter-spacing: 0.03em; }
.dv2-heat {
  background: hsla(var(--heat-h), 70%, 45%, 0.15);
  color: hsl(var(--heat-h), 72%, 34%);
  font-weight: 700;
}
[data-theme="dark"] .dv2-heat {
  background: hsla(var(--heat-h), 70%, 45%, 0.22);
  color: hsl(var(--heat-h), 75%, 62%);
}
.dv2-table tr:hover .dv2-heat { background: hsla(var(--heat-h), 70%, 45%, 0.28); }
.dv2-totals td { font-weight: 700; background: var(--surface2); border-top: 2px solid var(--border); }
.dv2-totals:hover td { background: var(--surface2); }
.dv2-empty { color: var(--muted); font-size: 13px; padding: 14px 0; text-align: center; }
td.dv2-empty { text-align: center; }

/* Horizontal bar charts */
.dv2-bars { display: grid; gap: 3px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.dv2-bar-row { display: flex; align-items: center; gap: 8px; }
.dv2-bar-label {
  width: 26px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}
.dv2-bar-track { flex: 1; height: 12px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.dv2-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.dv2-bar-net { background: linear-gradient(90deg, #16a34a, #4ade80); }
.dv2-bar-abandon { background: linear-gradient(90deg, #ea580c, #fb923c); }
.dv2-bar-value {
  width: 26px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.dv2-bar-value.zero { color: var(--muted); opacity: 0.5; }

/* Quick insights */
.dv2-insight {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.dv2-insight:first-child { border-top: 0; padding-top: 0; }
.dv2-insight b { font-weight: 700; }
.dv2-insight-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  margin-top: 1px;
}
.dv2-tone-blue { background: rgba(56, 189, 248, 0.18); color: #0284c7; }
.dv2-tone-green { background: rgba(34, 197, 94, 0.18); color: #16a34a; }
.dv2-tone-orange { background: rgba(249, 115, 22, 0.18); color: #ea580c; }
.dv2-tone-purple { background: rgba(168, 85, 247, 0.18); color: #9333ea; }
.dv2-tone-red { background: rgba(239, 68, 68, 0.18); color: #dc2626; }
[data-theme="dark"] .dv2-tone-blue { color: #38bdf8; }
[data-theme="dark"] .dv2-tone-green { color: #4ade80; }
[data-theme="dark"] .dv2-tone-orange { color: #fb923c; }
[data-theme="dark"] .dv2-tone-purple { color: #c084fc; }
[data-theme="dark"] .dv2-tone-red { color: #f87171; }

.dv2-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 16px;
}

@media (max-width: 640px) {
  .dv2-title { font-size: 18px; }
  .dv2-controls input[type="date"] { flex: 1 1 44%; }
  .dv2-kpis { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; }
  .dv2-kpis .stat-card .value { font-size: 22px; }
  .dv2-funnel { flex-direction: column; }
  .dv2-conn { flex-basis: auto; padding: 4px 0; }
  .dv2-conn-line { width: 1px; height: 14px; }
  .dv2-conn-arrow { right: 50%; top: auto; bottom: -4px; transform: translateX(50%) rotate(90deg); }
  .dv2-bars { max-height: none; }
}
