:root {
  --brand: #2258C3; --brand-600: #1c4aa6; --brand-50: #eef3fc; --brand-100: #dce6f8;
  --ink: #14181f; --body: #3b4250; --muted: #6b7280; --line: #e3e6ec; --bg: #f5f6f8; --card: #fff;
  --green: #1f9d6b; --amber: #b86e00; --red: #c42b2b; --purple: #6b21a8;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--body); font-size: 14.5px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { color: var(--ink); margin: 0; line-height: 1.25; }
a { color: var(--brand); text-decoration: none; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 8px 14px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-outline { background: #fff; color: var(--ink); border-color: #d3d8e0; }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--body); }
.btn-ghost:hover { background: #eceef2; }
.btn-danger { background: #fff; color: var(--red); border-color: #f0c9c9; }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid #d3d8e0; border-radius: 8px; padding: 8px 11px; font-size: 14px; color: var(--ink); background: #fff; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(34, 88, 195, .14); }
textarea.input { resize: vertical; min-height: 90px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(180deg, #eef3fc 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; box-shadow: 0 18px 40px -16px rgba(20, 24, 31, .2); }
.login-card img { height: 34px; margin-bottom: 22px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.login-err { background: #fdecec; color: #9b1c1c; border: 1px solid #f5c6c6; border-radius: 8px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 14px; }

/* Shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: #0f1522; color: #a5adbb; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.side .logo { padding: 6px 10px 22px; }
.side .logo img { height: 28px; }
.side nav { display: grid; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #a5adbb; font-weight: 500; }
.side nav a:hover { background: #18202f; color: #fff; }
.side nav a.active { background: #1c2740; color: #fff; }
.side nav a .count { margin-left: auto; background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.side-foot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid #222b3b; font-size: 13px; }
.side-foot strong { color: #fff; display: block; font-weight: 600; }
.side-foot .row { display: flex; gap: 8px; margin-top: 10px; }
.side-foot a, .side-foot button { color: #a5adbb; background: none; border: 0; padding: 0; cursor: pointer; font-size: 13px; }
.side-foot a:hover, .side-foot button:hover { color: #fff; }
.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 28px 32px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.back:hover { color: var(--brand); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); gap: 12px; }
.card-head h2, .card-head h3 { font-size: 15px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { padding: 18px 20px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi .delta { font-size: 12.5px; color: var(--muted); }
.kpi .delta.up { color: var(--green); }
.kpi .delta.down { color: var(--red); }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-2e { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* Chart */
.chart { padding: 18px 20px 14px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; border-bottom: 1px solid var(--line); }
.bars .b { flex: 1; background: var(--brand-100); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; transition: background .12s; }
.bars .b:hover { background: var(--brand); }
.bars .b.today { background: var(--brand); }
.bars .b[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 3px 7px; border-radius: 5px; white-space: nowrap; z-index: 2; }
.axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.funnel { padding: 8px 20px 18px; }
.funnel .fr { display: grid; grid-template-columns: 96px 1fr 34px; align-items: center; gap: 10px; margin: 10px 0; font-size: 13.5px; }
.funnel .track { height: 10px; background: #eef0f3; border-radius: 99px; overflow: hidden; }
.funnel .fill { height: 100%; background: var(--brand); border-radius: 99px; }
.funnel .fr b { text-align: right; color: var(--ink); }

/* Tables */
.toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .input { width: auto; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 360px; }
.seg { display: inline-flex; background: #eef0f3; border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--body); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.seg button .n { color: var(--muted); font-weight: 500; margin-left: 4px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
td { padding: 12px 16px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fb; }
tbody tr:last-child td { border-bottom: 0; }
td .who strong { display: block; color: var(--ink); font-weight: 600; }
td .who span { color: var(--muted); font-size: 13px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; color: #c3c9d3; margin-bottom: 10px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid #eef0f3; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #f8f9fb; }
.list-row .who strong { display: block; color: var(--ink); font-weight: 600; font-size: 14px; }
.list-row .who span { color: var(--muted); font-size: 13px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.s-new, .s-open { background: #e8effc; color: var(--brand); }
.s-contacted, .s-in_progress { background: #fff4e0; color: var(--amber); }
.s-demo_sent, .s-awaiting_customer { background: #f3e8ff; color: var(--purple); }
.s-proposal { background: #e0f2fe; color: #075985; }
.s-won, .s-resolved, .s-sent { background: #e7f6ef; color: #12603f; }
.s-lost, .s-closed { background: #eef0f3; color: #4b5563; }
.s-failed { background: #fdecec; color: var(--red); }
.s-logged { background: #fff4e0; color: var(--amber); }
.p-urgent { background: #fdecec; color: var(--red); }
.p-high { background: #fff1e6; color: #c2410c; }
.p-medium { background: #eef0f3; color: #4b5563; }
.p-low { background: #f5f6f8; color: var(--muted); }
.p-urgent::before, .p-high::before, .p-medium::before, .p-low::before { display: none; }

/* Detail */
.detail { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); word-break: break-word; }
.message-box { background: #f8f9fb; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; white-space: pre-wrap; color: var(--ink); }
.stage { display: flex; gap: 4px; margin: 4px 0 2px; flex-wrap: wrap; }
.stage button { flex: 1 1 auto; border: 1px solid var(--line); background: #fff; padding: 7px 8px; font-size: 12.5px; font-weight: 600; color: var(--body); cursor: pointer; border-radius: 7px; white-space: nowrap; }
.stage button:hover { border-color: var(--brand); color: var(--brand); }
.stage button.done { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand); }
.stage button.current { background: var(--brand); border-color: var(--brand); color: #fff; }
.stage button.lost.current { background: #4b5563; border-color: #4b5563; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--body); margin-top: 10px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.timeline { list-style: none; margin: 0; padding: 4px 20px 16px; }
.timeline li { position: relative; padding: 12px 0 12px 26px; border-bottom: 1px solid #f0f1f4; }
.timeline li:last-child { border-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: #c3c9d3; }
.timeline li.note::before { background: #f5a524; }
.timeline li.email::before { background: var(--brand); }
.timeline li.status::before { background: var(--green); }
.timeline .meta { font-size: 12.5px; color: var(--muted); }
.timeline .body { white-space: pre-wrap; color: var(--ink); margin-top: 2px; }
.compose { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.compose .tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.compose .tabs button { border: 0; background: none; padding: 6px 10px; border-radius: 6px; font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.compose .tabs button.on { background: var(--brand-50); color: var(--brand); }
.compose .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.thread { padding: 16px 20px; display: grid; gap: 12px; }
.bubble { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; max-width: 88%; }
.bubble.staff { background: var(--brand-50); border-color: var(--brand-100); margin-left: auto; }
.bubble.internal { background: #fff8e6; border-color: #f6e2b0; margin-left: auto; }
.bubble.system { background: transparent; border: 0; padding: 0; max-width: 100%; text-align: center; color: var(--muted); font-size: 12.5px; }
.bubble .meta { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.bubble .body { white-space: pre-wrap; color: var(--ink); }

/* Email preview */
.email-frame { width: 100%; height: 640px; border: 0; background: #f3f4f6; border-radius: 0 0 12px 12px; }
.err-box { background: #fdecec; color: #9b1c1c; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid #f5c6c6; }

/* Settings */
.settings { display: grid; gap: 20px; max-width: 880px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid #eef0f3; }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row strong { display: block; color: var(--ink); font-weight: 600; }
.toggle-row span { color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #d3d8e0; border-radius: 99px; transition: background .15s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }
.transport { display: flex; gap: 14px; align-items: flex-start; padding: 16px 20px; }
.transport .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.transport .dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(31, 157, 107, .15); }
.transport .dot.log { background: #f5a524; box-shadow: 0 0 0 4px rgba(245, 165, 36, .18); }
.callout { background: #fffaf0; border: 1px solid #f6e2b0; color: #7a4a00; border-radius: 10px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 20px; display: flex; gap: 10px; align-items: flex-start; }
.callout code { background: rgba(0, 0, 0, .05); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* Modal */
dialog.m { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .35); }
dialog.m::backdrop { background: rgba(15, 21, 34, .5); }
dialog.m form { padding: 22px; }
dialog.m h3 { font-size: 18px; margin-bottom: 16px; }
dialog.m .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--red); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2e, .detail { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 21, 34, .45); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
  .topbar img { height: 26px; }
  .topbar button { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; }
  .page { padding: 20px 16px 40px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 23px; }
  .hide-sm { display: none; }
  .toolbar .search { max-width: none; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 100px 1fr; }
  td, th { padding: 10px 12px; }
}

/* Inbox */
.inbox { display: grid; grid-template-columns: 360px 1fr; min-height: calc(100vh - 210px); overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.inbox-list .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
.inbox-list .seg button { padding: 5px 8px; font-size: 12.5px; }
.threads { overflow-y: auto; flex: 1; max-height: calc(100vh - 300px); }
.thread-row { display: block; padding: 12px 16px; border-bottom: 1px solid #eef0f3; color: inherit; }
.thread-row:hover { background: #f8f9fb; }
.thread-row.sel { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand); }
.tr-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tr-name { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.thread-row.unread .tr-name { font-weight: 700; }
.tr-name .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; }
.tr-time { font-size: 12px; color: var(--muted); flex: none; }
.tr-sub { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink); margin-top: 2px; overflow: hidden; }
.tr-sub span:last-child:not(.ch) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-snip { font-size: 13px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tr-rel { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--brand); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-rel svg { width: 13px; height: 13px; }
.tr-rel.none { color: var(--amber); }
.ch { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; flex: none; margin-right: 2px; }
.ch svg { width: 12px; height: 12px; }
.ch.wa { background: #e7f8ee; color: #128c4a; }
.ch.em { background: var(--brand-50); color: var(--brand); }
.inbox-pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.pane-head h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pane-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.back-sm { display: none; }
.pane-msgs { flex: 1; overflow-y: auto; padding: 18px 20px; display: grid; gap: 12px; align-content: start; max-height: calc(100vh - 420px); min-height: 240px; background: #fafbfc; }
.pane-msgs .bubble { max-width: 80%; }
.bubble .meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bubble .subj { font-weight: 600; color: var(--ink); font-size: 13.5px; margin-bottom: 4px; }
.bubble.auto { opacity: .7; }
.bubble .fail { color: var(--red); font-weight: 600; }
.quoted { margin-top: 8px; font-size: 12.5px; }
.quoted summary { cursor: pointer; color: var(--muted); }
.quoted pre { white-space: pre-wrap; font-family: inherit; color: var(--muted); max-height: 260px; overflow: auto; margin: 6px 0 0; padding: 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.pane-compose { border-top: 1px solid var(--line); border-bottom: 0 !important; background: #fff; }
.pane-compose .tabs button { display: inline-flex; align-items: center; gap: 4px; }
.pane-compose .tabs button svg { width: 14px; height: 14px; }
.pane-compose .tabs button[disabled] { opacity: .45; cursor: not-allowed; }
.timeline li.email_in::before { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
.timeline li.whatsapp_in::before, .timeline li.whatsapp_out::before { background: #25d366; }
.steps { margin: 8px 0 0; padding-left: 18px; color: var(--body); display: grid; gap: 6px; }
.copy { cursor: pointer; background: #eef0f3; padding: 1px 6px; border-radius: 4px; word-break: break-all; }
.copy:hover { background: var(--brand-50); color: var(--brand); }
@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } }
@media (max-width: 820px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox-list.has-open { display: none; }
  .inbox-list:not(.has-open) + .inbox-pane { display: none; }
  .back-sm { display: inline-flex; }
  .threads, .pane-msgs { max-height: none; }
  .pane-msgs .bubble { max-width: 92%; }
}
