/* TaxDesk CRM — ledger-inspired UI */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --line: #e3e0d7;
  --line-strong: #cfcabd;
  --ink: #1d2320;
  --ink-2: #4b524d;
  --ink-3: #7a807b;
  --accent: #1f5c46;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe9;
  --amber: #a86412;
  --amber-soft: #fbf0dc;
  --red: #a3322a;
  --red-soft: #f9e5e2;
  --blue: #2b5c9e;
  --blue-soft: #e5edf8;
  --violet: #6146a3;
  --violet-soft: #eee9f8;
  --teal: #1c7480;
  --teal-soft: #e0f1f2;
  --green: #2f7a3e;
  --green-soft: #e3f2e5;
  --sidebar: #17201c;
  --sidebar-ink: #c9d2cc;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(29, 35, 32, .06), 0 2px 8px rgba(29, 35, 32, .04);
  --font: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.icon { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 248px; flex: none; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: #2e7a5d; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .5px; }
.brand-mark.lg { width: 48px; height: 48px; font-size: 17px; margin: 0 auto 12px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { color: #fff; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 11.5px; color: #8d988f; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7c877f; padding: 14px 8px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--sidebar-ink); font-weight: 500; }
.nav-link:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav-link.active { background: rgba(110, 196, 158, .14); color: #fff; }
.nav-link.active .icon { color: #7fd0aa; }
.nav-link span { flex: 1; }
.pill { background: #e0a43a; color: #241a06; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding: 12px; display: flex; align-items: center; gap: 8px; }
.sidebar-foot form { margin: 0; }
.me { display: flex; gap: 10px; align-items: center; flex: 1; color: var(--sidebar-ink); min-width: 0; }
.me:hover { text-decoration: none; }
.me strong { display: block; color: #fff; font-size: 13px; }
.me small { color: #8d988f; }
.sidebar .icon-btn { color: var(--sidebar-ink); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.sidebar .avatar { background: #2b3a33; color: #cfe7da; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: rgba(246, 245, 241, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 520px; position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 11px; color: var(--ink-3); }
.search input[type=search] { padding-left: 36px; background: var(--surface); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar .menu-btn { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; }
.scrim { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--ink-3); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: 12.5px; color: var(--ink-3); margin-bottom: 4px; }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .split > .card + .card, .grid > .card, .split > * { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.split-left { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.stat { padding: 16px; }
.stat .label { font-size: 12.5px; color: var(--ink-3); }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.stat.accent { border-top: 3px solid var(--accent); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid #3d8f6c; outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: #18493a; }
.btn-wa { background: #1f8f53; border-color: #1f8f53; color: #fff; }
.btn-wa:hover { background: #187344; }
.btn-danger { color: var(--red); border-color: #e4bdb8; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 6px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
form.inline { display: inline; margin: 0; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 500; font-size: 13px; color: var(--ink-2); }
label .hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=tel], input[type=search], input[type=url], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 4px; height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink); font: 14px var(--font);
}
textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: #3d8f6c; outline: none; box-shadow: 0 0 0 3px rgba(61, 143, 108, .15); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); vertical-align: -3px; margin: 0 6px 0 0; }
.check { display: flex; align-items: flex-start; gap: 4px; font-weight: 400; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2, .span-2 { grid-column: 1 / -1; }
.form-grid h3 { margin: 8px 0 -4px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; }
.required::after { content: " *"; color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fbfaf7; white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfaf6; }
td .sub { display: block; font-size: 12.5px; color: var(--ink-3); }
.t-right { text-align: right; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-teal { background: var(--teal-soft); color: var(--teal); }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: var(--green-soft); border-color: #bfdcc4; color: #1f5a2b; }
.alert-error { background: var(--red-soft); border-color: #ebc3bd; color: #7d241d; }
.alert-info { background: var(--blue-soft); border-color: #c6d6ee; color: #23497d; }
.alert-warning { background: var(--amber-soft); border-color: #ecd3a6; color: #6f420b; }

/* ---------- Tabs ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a, .tabs button { padding: 9px 14px; color: var(--ink-2); font-weight: 500; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; font: 500 13.5px var(--font); white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs .active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 150px; }
.filters input, .filters select { height: 34px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--ink-2); font-weight: 500; font-size: 13px; }
.seg a + a { border-left: 1px solid var(--line-strong); }
.seg a.active { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }

/* ---------- Pipeline board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.column.drag-over { outline: 2px dashed var(--accent); }
.column-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 13px; }
.lead-card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.lead-card:active { cursor: grabbing; }
.lead-card strong { display: block; }
.lead-card .meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Profile ---------- */
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-head .avatar { width: 52px; height: 52px; font-size: 17px; }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
dl.kv dt { color: var(--ink-3); font-size: 13px; }
dl.kv dd { margin: 0; word-break: break-word; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.timeline li { position: relative; display: flex; gap: 12px; padding: 0 0 16px; }
.t-dot { width: 31px; height: 31px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-2); flex: none; z-index: 1; }
.t-dot .icon { width: 15px; height: 15px; }
.t-dot.whatsapp { color: #1f8f53; } .t-dot.call { color: var(--blue); } .t-dot.stage { color: var(--violet); }
.t-dot.document { color: var(--amber); } .t-dot.ai { color: var(--teal); } .t-dot.intake { color: var(--accent); }
.t-body { flex: 1; min-width: 0; padding-top: 5px; }
.t-body .t-title { font-weight: 500; }
.t-body .t-meta { font-size: 12px; color: var(--ink-3); }
.t-body .t-text { margin-top: 4px; white-space: pre-wrap; color: var(--ink-2); background: var(--surface-2); padding: 8px 10px; border-radius: 6px; font-size: 13px; }

/* ---------- Notes ---------- */
.note { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; background: #fffdf6; }
.note.pinned { border-color: #e7cf94; background: #fff8e4; }
.note + .note { margin-top: 8px; }
.note-meta { font-size: 12px; color: var(--ink-3); display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.note-body { white-space: pre-wrap; }

/* ---------- Progress & checklists ---------- */
.progress { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist li.done .c-title { color: var(--ink-3); text-decoration: line-through; }
.checklist .c-title { flex: 1; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.step-num { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; color: var(--ink-2); }
.steps li.done .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps li.in_progress .step-num { border-color: var(--amber); color: var(--amber); }

/* ---------- Repeater (service editor) ---------- */
.repeater-row { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.repeater-row.three { grid-template-columns: 24px minmax(0, 1.2fr) minmax(0, 1fr) auto auto; }
.repeater-row input { margin-top: 0; }
.drag-handle { color: var(--ink-3); cursor: grab; text-align: center; user-select: none; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 150px); min-height: 480px; }
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; }
.inbox-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.inbox-item:hover { background: var(--surface-2); text-decoration: none; }
.inbox-item.active { background: var(--accent-soft); }
.inbox-item .preview { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item .unread { width: 8px; height: 8px; border-radius: 50%; background: #1f8f53; margin-top: 6px; flex: none; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 16px; background: #f3f1ea; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 72%; padding: 8px 11px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: #dcf1e3; }
.bubble.ai { background: #e2f0f1; }
.bubble .b-meta { font-size: 11px; color: var(--ink-3); margin-top: 3px; text-align: right; }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 40px; height: 40px; margin: 0; }

/* ---------- Bars (stats without a chart lib) ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) 60px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.chart-box { position: relative; height: 260px; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty h1, .empty h3 { color: var(--ink); }
.empty .btn { margin-top: 8px; }

/* ---------- Auth & public pages ---------- */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; background: radial-gradient(1200px 500px at 50% -10%, #e1ece5, var(--bg)); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: 0 10px 30px rgba(29, 35, 32, .08); text-align: left; }
.auth-card > h1, .auth-card > .muted { text-align: center; }
.auth-card.wide { max-width: 640px; }
.auth-flash { max-width: 400px; width: 100%; }
.public-page { width: 100%; max-width: 720px; }
.public-head { text-align: center; margin-bottom: 18px; }
.upload-item { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--surface); }
.upload-item + .upload-item { margin-top: 10px; }
.file-chip { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font-size: 12.5px; margin: 4px 6px 0 0; }

/* ---------- Copy field ---------- */
.copy-field { display: flex; gap: 6px; }
.copy-field input { margin: 0; font-family: var(--mono); font-size: 12.5px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split-left { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
  .topbar .menu-btn { display: inline-grid; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar-actions .btn span { display: none; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; }
  .inbox-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .messages { min-height: 360px; }
  .bubble { max-width: 88%; }
  dl.kv { grid-template-columns: 100px 1fr; }
  .bar-row { grid-template-columns: 100px minmax(0, 1fr) 48px; }
  .repeater-row.three { grid-template-columns: 20px minmax(0, 1fr) auto; }
  .repeater-row.three .doc-desc { grid-column: 2 / 3; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .page-head .actions { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
