:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1d2330;
  --muted: #6b7382;
  --accent: #128c7e;
  --accent-dark: #0d6e63;
  --out: #dcf5e8;
  --in: #ffffff;
  --chat-bg: #efeae2;
  --new: #2563eb;
  --qualified: #b7791f;
  --converted: #15803d;
  --failed: #c2410c;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent-dark); }
h1 { font-size: 22px; margin: 0 0 20px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 14px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; }

/* shell */
.shell { display: flex; min-height: 100vh; background: linear-gradient(to right, #1f2a37 210px, var(--bg) 210px); }
.sidebar { width: 210px; flex: none; background: #1f2a37; color: #cfd6df; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { color: #cfd6df; text-decoration: none; padding: 9px 10px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.logout button { background: none; border: 0; color: #9aa4b1; cursor: pointer; padding: 9px 10px; font: inherit; }
.logout button:hover { color: #fff; }
.main { flex: 1; padding: 28px 32px; min-width: 0; }
.inbox-page .main { padding: 0; }

/* bits */
.pill { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; letter-spacing: .02em; }
.st-new { color: var(--new); background: #e7efff; }
.st-qualified { color: var(--qualified); background: #fdf3dc; }
.st-converted { color: var(--converted); background: #e2f6e9; }
.capi-sent { color: var(--converted); background: #e2f6e9; }
.capi-failed { color: var(--failed); background: #feebe2; }
.capi-pending { color: var(--muted); background: #eef0f3; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: #c9ced6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 18px; white-space: pre-line; background: #e2f6e9; color: #14532d; border: 1px solid #bfe6cc; }
.flash.err { background: #feebe2; color: #7c2d12; border-color: #f7c9b4; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2a37; color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 50; max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: #9a3412; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(18,140,126,.25); border-color: var(--accent); }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.field small { display: block; margin-top: 4px; font-size: 12px; }
.field small.help { color: var(--muted); }
.field small.ok { color: var(--converted); }
.field small.warn { color: var(--failed); }
.field.compact { margin-bottom: 10px; }
.field.compact > span { font-weight: 500; color: var(--muted); font-size: 12px; }
.filters { display: flex; gap: 4px; }
.filters a { padding: 4px 10px; border-radius: 14px; font-size: 12px; cursor: pointer; color: var(--muted); text-decoration: none; }
.filters a.on { background: #e6f4f1; color: var(--accent-dark); font-weight: 600; }

/* auth */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { width: 360px; }
.auth-card h1 { text-align: center; }
.auth-card label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
.auth-card input { margin-top: 5px; }
.auth-card .btn { width: 100%; }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 16px; max-width: 900px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 6px; border-top: 3px solid #cfd6df; }
.tile:hover { border-color: #c9ced6; }
.tile.st-new, .tile.st-qualified, .tile.st-converted, .tile.capi-sent, .tile.capi-failed { background: var(--panel); }
.tile.st-new { border-top-color: var(--new); }
.tile.st-qualified { border-top-color: var(--qualified); }
.tile.st-converted, .tile.capi-sent { border-top-color: var(--converted); }
.tile.capi-failed { border-top-color: var(--failed); }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-num { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* conversions */
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table td.right { white-space: nowrap; }
form.inline { display: inline; }
details.payload { display: inline-block; margin-left: 8px; text-align: left; }
details.payload summary { cursor: pointer; color: var(--accent-dark); font-size: 12px; }
.payload-body { position: absolute; right: 40px; width: 560px; max-width: calc(100vw - 280px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 5; white-space: normal; }
.payload-body pre { background: #f6f7f9; padding: 10px; border-radius: 6px; max-height: 240px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

/* settings */
.settings { max-width: 720px; display: flex; flex-direction: column; gap: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 10px; }
input[readonly] { background: #f6f7f9; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; height: 100vh; }
.pane { background: var(--panel); min-height: 0; }
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.list-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.lead-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.lead-list .pad { padding: 20px; }
.lead { padding: 11px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.lead:hover { background: #f7f8f9; }
.lead.active { background: #e9f5f2; }
.lead-top, .lead-bottom { display: flex; align-items: center; gap: 8px; }
.lead-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-time { font-size: 11px; color: var(--muted); }
.lead-bottom { margin-top: 3px; }
.lead-preview { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead.unread .lead-preview { color: var(--text); font-weight: 500; }
.lead .badge { font-size: 10px; padding: 1px 6px; }

.chat-pane { display: flex; flex-direction: column; background: var(--chat-bg); }
.chat-pane .empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { background: var(--panel); padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.messages { flex: 1; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: #fff; color: var(--muted); font-size: 11px; padding: 3px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble { max-width: 65%; padding: 6px 9px 4px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; }
.bubble.in { align-self: flex-start; background: var(--in); }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; justify-content: flex-end; gap: 4px; }
.bubble .media { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; }
.bubble audio { width: 260px; }
.tpl-tag { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.tick.read { color: #34b7f1; }
.tick.failed { color: var(--failed); font-weight: 600; }
.window-note { background: #fff8e6; color: #7a5b0d; font-size: 13px; padding: 10px 18px; border-top: 1px solid #f1e2b5; }
.composer { display: flex; gap: 8px; padding: 12px 16px; background: #f0f2f5; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }
.template-form { padding: 12px 16px; background: #f0f2f5; border-top: 1px solid var(--line); }
.template-form select { flex: 1; }
.tpl-preview { white-space: pre-wrap; font-size: 13px; color: var(--muted); margin: 8px 0; max-height: 120px; overflow: auto; }
.tpl-preview:empty { display: none; }

.info-pane { border-left: 1px solid var(--line); padding: 4px 18px 18px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 10px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.status-buttons { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.status-buttons button { flex: 1; font: inherit; font-size: 12px; font-weight: 600; background: #fff; border: 0; border-right: 1px solid var(--line); padding: 8px 4px; cursor: pointer; color: var(--muted); }
.status-buttons button:last-child { border-right: 0; }
.status-buttons button:hover { background: #f7f8f9; }
.status-buttons button.on[data-s=NEW] { background: var(--new); color: #fff; }
.status-buttons button.on[data-s=QUALIFIED] { background: var(--qualified); color: #fff; }
.status-buttons button.on[data-s=CONVERTED] { background: var(--converted); color: #fff; }
.convert-box { margin-top: 12px; padding: 12px; border: 1px solid #bfe6cc; background: #f3fbf6; border-radius: 6px; font-size: 13px; }
.convert-box p { margin: 0 0 10px; }
.conversion { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; font-size: 12px; }
.cv-row { display: flex; flex-direction: column; gap: 4px; }
.small-link { font-size: 12px; }
.history { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.history li { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
#find-dataset { margin: -6px 0 16px; }

/* Security page */
.security { max-width: 640px; }
.security .steps { padding-left: 20px; margin: 10px 0; }
.security .qr { margin: 8px 0 12px; }
.security .qr img { display: block; border: 1px solid var(--line, #e5e7eb); border-radius: 6px; }
.security .setup-key { font-family: ui-monospace, Menlo, monospace; background: #f3f4f6; padding: 2px 6px; border-radius: 4px; letter-spacing: 1px; }
.security .st-on { color: #166534; font-weight: 600; }
.security .inline-form .btn { margin-right: 8px; }
.backup-codes { columns: 2; list-style: none; padding: 12px 16px; background: #f9fafb; border: 1px dashed #d1d5db; border-radius: 6px; font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
.backup-codes li { padding: 3px 0; }
.btn.danger { color: #b91c1c; border-color: #fca5a5; }
.auth-note { margin: 14px 0 0; font-size: 13px; color: var(--muted, #6b7280); text-align: center; }
