:root {
  --bg: #f4f3ee; --surface: #fff; --surface-2: #f8f7f3; --line: #e3e1d8; --ink: #17211e; --ink-2: #56615c; --ink-3: #6f7a75;
  --side: #14201d; --side-2: #21302c; --side-ink: #dfe7e3; --side-mute: #93a39d; --lime: #c8f169;
  --brand: #1c6b50; --brand-soft: #e2f0e9; --danger: #bd3a2c; --danger-soft: #fbe9e6; --warn: #9a6400; --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgb(20 32 29 / .06), 0 8px 24px rgb(20 32 29 / .06);
  --radius: 12px;
  font-family: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); font-size: 14px; line-height: 1.45; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2a3833; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 0 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, select.input, textarea.input { width: 100%; min-height: 36px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
textarea.input { resize: vertical; min-height: 72px; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.check { display: flex; gap: 9px; align-items: flex-start; font-weight: 500; color: var(--ink); }
.check input { margin-top: 3px; accent-color: var(--brand); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { font-size: 15px; }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-2); }
.code { display: block; padding: 9px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }

/* Auth */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--side); }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 16px; padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { font-size: 23px; letter-spacing: -.02em; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.logo svg { width: 28px; height: 28px; }
.error { color: var(--danger); font-size: 13px; }

/* Layout */
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.sidebar .logo { padding: 0 8px; color: #fff; }
.account-select { width: 100%; min-height: 38px; padding: 6px 9px; background: var(--side-2); color: #fff; border: 1px solid #33443f; border-radius: 9px; }
.account-name { padding: 9px 10px; background: var(--side-2); border-radius: 9px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; color: var(--side-mute); text-decoration: none; border-radius: 8px; font-weight: 600; }
.nav a:hover { color: #fff; background: var(--side-2); }
.nav a.active { background: var(--lime); color: var(--side); }
.nav svg, .icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; display: grid; gap: 8px; font-size: 13px; color: var(--side-mute); }
.side-foot .who { padding: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot button { background: none; border: 0; text-align: left; color: var(--side-mute); padding: 4px 10px; cursor: pointer; }
.side-foot button:hover { color: #fff; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--bg); }
.topbar h1 { font-size: 20px; letter-spacing: -.02em; }
.content { flex: 1; overflow: auto; padding: 20px 24px 40px; min-height: 0; }
.bell { position: relative; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.popover { position: absolute; z-index: 40; right: 24px; top: 58px; width: min(370px, calc(100vw - 32px)); max-height: 440px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.notif { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--brand-soft); }
.notif b { display: block; font-weight: 600; }

/* KPIs & charts */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 27px; font-weight: 700; letter-spacing: -.03em; margin-top: 2px; }
.kpi .hint { color: var(--ink-3); font-size: 12px; }
.dash { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; }
.dash .wide { grid-column: 1 / -1; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 170px; margin-top: 16px; border-bottom: 1px solid var(--line); }
.bars .slot { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; }
.bars .bar { width: 100%; min-height: 0; max-width: 22px; margin: 0 auto; background: var(--brand); border-radius: 4px 4px 0 0; }
.bars .slot:hover .bar { background: #2a8d6a; }
.axis { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 12px; margin-top: 6px; }
.funnel { display: grid; gap: 11px; margin-top: 14px; }
.funnel-row .row { justify-content: space-between; flex-wrap: nowrap; font-size: 13px; }
.track { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.track i { display: block; height: 100%; border-radius: 4px; }

/* Tables */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar .input { width: auto; min-width: 130px; flex: 0 1 170px; }
.toolbar .search { flex: 1 1 220px; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; background: var(--brand-soft); border-radius: 9px; margin-bottom: 10px; font-weight: 600; }
.bulkbar .input { width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
th.sortable { cursor: pointer; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-2); font-size: 12.5px; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill .dot, .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; background: var(--warn-soft); color: var(--warn); border-radius: 6px; font-size: 12px; font-weight: 600; }
.tag button { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; }
.stage-select { min-width: 150px; max-width: 190px; font-size: 13px; font-weight: 600; min-height: 32px; padding: 3px 7px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }

/* Board */
.board { display: flex; gap: 12px; align-items: stretch; height: 100%; min-height: 420px; overflow-x: auto; padding-bottom: 8px; }
.column { flex: 0 0 272px; display: flex; flex-direction: column; background: #eae8e0; border-radius: var(--radius); min-height: 0; }
.column.over { outline: 2px solid var(--brand); }
.column header { padding: 11px 12px 8px; }
.column header .row { flex-wrap: nowrap; justify-content: space-between; font-weight: 700; }
.column-list { flex: 1; overflow-y: auto; padding: 2px 8px 8px; display: grid; gap: 8px; align-content: start; }
.lead-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; cursor: grab; }
.lead-card:hover { box-shadow: var(--shadow); }
.lead-card.dragging { opacity: .45; }

/* Drawer & modal */
.scrim { position: fixed; inset: 0; background: rgb(20 32 29 / .38); z-index: 50; }
.drawer { position: fixed; z-index: 51; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--bg); display: flex; flex-direction: column; box-shadow: -8px 0 32px rgb(20 32 29 / .18); }
.drawer-head { padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.drawer-head h2 { font-size: 20px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 32px; display: grid; gap: 12px; align-content: start; }
.stages-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-chip { border: 1px solid var(--line); background: var(--surface); padding: 5px 10px; border-radius: 99px; font-weight: 600; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.stage-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 10px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { display: grid; gap: 10px; }
.timeline .item { border-left: 2px solid var(--line); padding-left: 11px; }
.timeline .item.note { border-color: var(--brand); }
.task-line { display: flex; gap: 9px; align-items: flex-start; padding: 6px 0; }
.task-line input { margin-top: 3px; accent-color: var(--brand); width: 16px; height: 16px; }
.task-line.done .t { text-decoration: line-through; color: var(--ink-3); }
.late { color: var(--danger); font-weight: 600; }
.modal { position: fixed; z-index: 61; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 14px; padding: 20px; display: grid; gap: 12px; }
.modal h2 { font-size: 18px; }
.scrim.top { z-index: 60; }

/* Settings */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 7px 12px; border-radius: 8px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--ink); color: #fff; }
.settings { max-width: 860px; display: grid; gap: 14px; }
.stage-row { display: grid; grid-template-columns: 52px 34px minmax(120px, 1fr) 76px 112px auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stage-row:last-of-type { border-bottom: 0; }
.stage-row input[type=color] { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: none; }
.icon-btn { width: 24px; height: 24px; border: 0; background: none; cursor: pointer; padding: 0; color: var(--ink-2); }
.icon-btn:disabled { opacity: .3; }
.map-row { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 10px; align-items: center; padding: 6px 0; }

/* Toasts & tooltips */
#toasts { position: fixed; z-index: 90; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(340px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); cursor: default; }
.toast.err { background: var(--danger); }
.toast a { color: var(--lime); font-weight: 600; }
#tip { position: fixed; z-index: 95; pointer-events: none; display: none; background: var(--ink); color: #fff; padding: 5px 9px; border-radius: 7px; font-size: 12.5px; white-space: nowrap; }

.comment-cell { max-width: 260px; font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.comment-btn { min-width: 32px; padding: 0 7px; }
.comment-m { display: none !important; }
.access-row { flex-wrap: nowrap; padding: 8px 0; border-top: 1px solid var(--line); }
.access-row .cell-sub { overflow-wrap: anywhere; }
.phrases { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.phrase { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); border-radius: 99px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.phrase:hover { background: var(--brand-soft); color: var(--brand); border-color: #bcdccd; }
.attempts { display: inline-block; margin-top: 3px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.protocol { border-color: #f3c9a8; background: #fffaf5; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 9px; align-items: center; font-size: 13.5px; padding: 5px 6px; border-radius: 8px; }
.steps li.done { color: var(--ink-3); }
.steps li.done .step-text { text-decoration: line-through; }
.steps li.current { background: #fff; outline: 1px solid #f3c9a8; }
.check-mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); }
.steps li.done .check-mark { background: var(--brand); border-color: var(--brand); color: #fff; }
.timeline .reason { margin-top: 3px; padding: 6px 9px; background: var(--brand-soft); border-radius: 7px; font-size: 13px; }
.report-head { margin-bottom: 14px; display: grid; gap: 4px; }
.report-head h2 { font-size: 20px; letter-spacing: -.02em; }
.report-table td { vertical-align: top; }
.report-foot { margin-top: 10px; }

@media print {
  body, html { background: #fff; height: auto; }
  .sidebar, .topbar, #toasts, #tip, #popover, .scrim, .drawer { display: none !important; }
  .shell { display: block; height: auto; }
  .content { overflow: visible; padding: 0; }
  .table-wrap { border: 0; overflow: visible; }
  th { background: #fff; }
  tr { break-inside: avoid; }
  @page { margin: 14mm; }
}

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
  .sidebar { display: contents; }
  .sidebar .logo, .side-foot { display: none; }
  .account-select, .account-name { grid-row: 1; margin: 8px 16px 0; width: calc(100% - 32px); background: var(--side); }
  .sidebar > .account-box { grid-row: 1; background: var(--bg); }
  .main { grid-row: 2; }
  .nav { grid-row: 3; display: flex; justify-content: space-around; background: var(--side); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .nav a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: 11px; padding: 4px 2px; min-height: 46px; }
  .topbar { padding: 10px 16px; }
  .content { padding: 14px 16px 28px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .popover { right: 16px; }
  .toolbar .input { flex: 1 1 42%; }
  .hide-m { display: none; }
  .comment-m { display: -webkit-box !important; margin-top: 4px; max-width: 160px; }
  .stage-select { min-width: 0; max-width: 128px; }
  td { padding: 10px 8px; }
  .column { flex-basis: 82vw; }
  .stage-row { grid-template-columns: 52px 34px minmax(0, 1fr); }
  .stage-row > .stage-extra { grid-column: span 1; }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
  .map-row { grid-template-columns: minmax(0, 1fr); }
}
