:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c1e21; --muted: #65676b; --line: #e4e6eb;
  --accent: #7d1d1d; --accent-ink: #fff; --soft: #f7eeee; --danger: #c0392b; --ok: #1f8f4e; --warn: #b7791f;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }
code { background: var(--soft); padding: 0 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 2rem 1rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; margin-right: 8px; }
.logo { height: 66px; width: auto; display: block; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--ink); font-weight: 600; }
.tabs a.active { background: var(--soft); color: var(--accent); }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 12px; line-height: 18px; text-align: center; margin-left: 4px; }
.pill:empty { display: none; }
.top-right { display: flex; align-items: center; gap: 8px; }
.top-right form { margin: 0; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--line); }
.banner { background: #fff4e5; color: #7a4a00; padding: 10px 16px; border-bottom: 1px solid #f3d9a4; }
.banner a { font-weight: 600; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #641717; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn-wide { display: block; text-align: center; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .count:not(:empty)::before { content: " · "; }

/* layout */
main { max-width: 1280px; margin: 0 auto; padding: 12px 16px; }
.split { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 12px; align-items: start; }
.list-pane, .detail-pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.list-pane { padding: 10px; position: sticky; top: 60px; max-height: calc(100vh - 80px); display: flex; flex-direction: column; }
.detail-pane { padding: 16px; min-height: 300px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.comment-list, .lead-list, ul.plain { list-style: none; margin: 0; padding: 0; overflow: auto; }
.comment-list li, .lead-list li { padding: 10px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.comment-list li:hover, .lead-list li:hover { background: var(--bg); }
.comment-list li.active, .lead-list li.active { background: var(--soft); }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.user { font-weight: 600; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.snippet { margin: 2px 0 0; color: #333; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-size: 12px; color: var(--muted); }
.tag { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.tag.q { color: var(--accent); border-color: #e2c9c9; background: var(--soft); }
.tag.lead { color: var(--ok); border-color: #bfe3cd; background: #ecf8f0; }
.tag.dm { color: var(--warn); }
.tag.cat-question { color: var(--accent); border-color: #e2c9c9; background: var(--soft); }
.tag.cat-interested { color: var(--ok); border-color: #bfe3cd; background: #ecf8f0; }
.tag.cat-cta { color: #555; }
.tag.cat-spam { color: var(--danger); }

/* selection mode + bulk */
.select-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 6px; }
.select-bar #list-count { margin-left: auto; }
.comment-list li .pick { display: none; margin-right: 8px; vertical-align: middle; }
.comment-list.selecting li { display: flex; gap: 8px; align-items: flex-start; }
.comment-list.selecting li .pick { display: inline-block; margin-top: 3px; width: 16px; height: 16px; flex: none; }
.comment-list.selecting li .body { flex: 1; min-width: 0; }
.comment-list li.picked { background: var(--soft); }
.progress { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.sample { border-left: 3px solid var(--line); padding-left: 10px; margin: 8px 0; font-size: 13px; }
.sample .reply { white-space: pre-wrap; color: #333; margin-top: 4px; }
.job-log { max-height: 180px; overflow: auto; font-size: 12px; color: var(--muted); margin-top: 8px; }

/* detail */
.detail-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.detail-head .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--bg); flex: none; }
.detail-text { font-size: 16px; margin: 6px 0 10px; white-space: pre-wrap; }
.thread { border-left: 3px solid var(--line); margin: 8px 0 12px; padding-left: 10px; }
.thread p { margin: 4px 0; }
.thread .own { color: var(--accent); }
.saved-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
textarea.reply { width: 100%; min-height: 120px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.actions .spacer { flex: 1; }
.history { margin-top: 16px; }
.history li { margin: 4px 0; font-size: 13px; }
.status-line { font-size: 13px; color: var(--muted); margin-top: 8px; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

/* leads */
.leads-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.stage-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.leads-tools { display: flex; gap: 10px; align-items: center; }
.leads-tools select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; }
.lead-list .stage { font-size: 12px; color: var(--muted); }
.due { color: var(--danger); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid label, .settings label, .form-grid .full { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea, .settings input, .settings select, .settings textarea {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff; }
.events { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.events li { font-size: 13px; margin: 6px 0; }
.events .who { color: var(--muted); }
.stage-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--soft); color: var(--accent); }

/* settings */
.settings { display: grid; gap: 12px; max-width: 820px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.settings label { margin: 10px 0; }
.saved-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.saved-item .row strong { font-size: 15px; }
.saved-item pre { white-space: pre-wrap; font: inherit; margin: 6px 0; color: #333; }
.saved-edit textarea { min-height: 70px; }
.saved-edit label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.saved-edit label.inline input[type=checkbox] { width: 16px; height: 16px; margin: 0; }
.saved-edit .variants textarea { min-height: 50px; }

/* login */
.login-body { display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(380px, 92vw); text-align: center; }
.login-logo { width: min(300px, 80%); height: auto; margin: 0 auto 16px; display: block; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .btn-wide { margin: 20px 0 12px; padding: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }
.toast.err { background: var(--danger); }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
  .list-pane { position: static; max-height: none; }
  .split.showing-detail .list-pane { display: none; }
  .split:not(.showing-detail) .detail-pane { display: none; }
  .back { display: inline-block !important; margin-bottom: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
  .logo { height: 44px; }
}
.back { display: none; }
