:root {
  --bg: #f4f6f5; --card: #fff; --text: #1d2521; --muted: #6b7671; --line: #e2e6e4;
  --accent: #128c4a; --accent-soft: #e5f4ec; --danger: #c43c3c; --warn: #b7791f;
  --in: #fff; --out: #dcf5e4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614; --card: #1a201d; --text: #e6ebe8; --muted: #8e9993; --line: #2b332f;
    --accent: #2fbf6b; --accent-soft: #1d3327; --danger: #e26464; --warn: #e0a64a;
    --in: #222a26; --out: #1f3a2a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 16px; }
nav { display: flex; gap: 4px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
nav button { border: 0; background: none; padding: 12px 14px; color: var(--muted); font: inherit; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
nav button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; }
h2 { margin: 0 0 12px; font-size: 18px; }
h3 { margin: 0 0 8px; font-size: 15px; }
.tab { display: none; } .tab.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); } .pad { padding: 20px; } .hidden { display: none !important; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox], .row input[type=checkbox] { width: auto; flex: none; min-width: 0; }
.row input { flex: 1; min-width: 160px; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
label.inline { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
button, .button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 7px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.danger { color: var(--danger); }
.small { padding: 4px 9px; font-size: 12.5px; }
.pill { padding: 4px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--line); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: #fbe9e9; color: var(--danger); }
.qr { display: block; margin: 14px 0; background: #fff; padding: 8px; border-radius: 8px; width: 316px; max-width: 100%; }
ol.steps-help { padding-left: 18px; color: var(--muted); }
.trigger { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.trigger .kw { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 99px; font-size: 12.5px; }
.off { opacity: .55; }
.step { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 10px 0; background: var(--bg); }
.step-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.step-head .row { flex-wrap: nowrap; }
.step-num { font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.file-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.file-row:last-child { border-bottom: 0; }
.inbox { display: grid; grid-template-columns: 300px 1fr; gap: 14px; min-height: 520px; }
@media (max-width: 760px) { .inbox { grid-template-columns: 1fr; } }
.contact-list { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow-y: auto; max-height: 640px; }
.contact { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.contact.active { background: var(--accent-soft); }
.contact .name { font-weight: 600; }
.contact .last { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; max-height: 640px; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 75%; padding: 7px 11px; border-radius: 9px; white-space: pre-wrap; word-wrap: break-word; border: 1px solid var(--line); }
.bubble.in { background: var(--in); align-self: flex-start; }
.bubble.out { background: var(--out); align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-send { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.paused { color: var(--warn); font-weight: 600; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
.ai-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .ai-layout { grid-template-columns: 1fr; } }
.ai-test { position: sticky; top: 12px; }
.ai-test .chat-msgs { padding: 0; max-height: 420px; }
textarea.tall { min-height: 260px; }
.badge-human { background: #fdf0dc; color: #9a5b00; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.stat { display: flex; gap: 18px; flex-wrap: wrap; margin: 4px 0 6px; }
.error-box { color: var(--danger); font-size: 13px; }
a { color: var(--accent); }
.attach-chip { display: flex; align-items: center; gap: 8px; margin: 0 10px; padding: 6px 10px; border: 1px dashed var(--accent); border-radius: 8px; background: var(--accent-soft); }
.attach-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-btn { padding: 8px 11px; margin: 0; font-weight: 400; }
.attach-lib { width: auto; max-width: 130px; }
/* Inbox fills the window so the reply box is always visible */
.inbox { min-height: 0; }
.chat, .contact-list { height: calc(100vh - 205px); min-height: 420px; max-height: none; }
.chat-msgs { min-height: 120px; }
#chat .chat-head .grid2 label { margin-top: 4px; }
.ai-switch { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 400; cursor: pointer; }
.ai-switch input { display: none; }
.ai-switch .track { width: 40px; height: 22px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.ai-switch .knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.ai-switch input:checked + .track { background: var(--accent); }
.ai-switch input:checked + .track .knob { left: 21px; }
.ai-switch .hint { font-size: 12px; }
.chat-switches { display: flex; gap: 18px; flex-wrap: wrap; }
.learn-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.learn-row .learn-text { flex: 1; }
.learn-kind { font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--muted); }
.learn-example { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; background: var(--bg); }
#ai-learning h4 { margin: 16px 0 4px; font-size: 14px; }
.rate { margin-left: 6px; }
.rate-btn { border: 0; background: none; padding: 0 2px; cursor: pointer; opacity: .45; font-size: 13px; }
.rate-btn:hover, .rate-btn.on { opacity: 1; }
textarea.ai-note { min-height: 52px; border-color: var(--accent); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal.hidden { display: none !important; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(720px, 100%); max-height: 90vh; overflow: auto; }
.fb-text { min-height: 110px; }
.fb-understood { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.fb-lesson { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.fb-lesson input[type=text] { flex: 1; }
.fb-history { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; background: var(--bg); }
.modal-card h4 { margin: 16px 0 6px; font-size: 14px; }
.badge { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: 4px; }
.badge.hidden { display: none !important; }
.fu-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 10px 0; }
.fu-card.queued { border-color: var(--accent); }
.fu-card.done { opacity: .8; }
.fu-head { margin-bottom: 6px; }
.fu-context { background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin: 6px 0; max-height: 120px; overflow: auto; }
.fu-skip { background: #fdf0dc; color: #7a4a00; border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; }
.fu-draft { min-height: 74px; margin: 6px 0; }
.fu-instr { flex: 1; }
.fu-sent { font-size: 13px; margin: 4px 0; }
label.nofu { display: inline-flex; font-size: 12px; margin: 0 6px 0 4px; font-weight: 400; }
input.secret { -webkit-text-security: disc; text-security: disc; }

#reply-text { flex: 1; resize: none; min-height: 38px; max-height: 260px; overflow-y: auto; font: inherit; line-height: 1.4; white-space: pre-wrap; }

.incoming-media { margin-top: 8px; white-space: normal; }
.incoming-media img, .incoming-media video { display: block; max-width: min(100%, 340px); max-height: 300px; border-radius: 8px; margin-bottom: 6px; }
.incoming-media audio { display: block; width: min(100%, 300px); margin-bottom: 6px; }

.voice-recorder { max-width: 460px; }
.voice-recorder audio { display: block; width: 100%; margin-top: 14px; }
.voice-recorder .voice-status { min-height: 38px; }
@media(max-width:640px){ .chat-send { flex-wrap:wrap; } .chat-send #reply-text { min-width: 45%; flex:1; } }

.crm-filters { flex-wrap: wrap; } .crm-filters select { width:auto; max-width:260px; } .crm-filters input { flex:1; min-width:180px; }
.crm-summary { display:flex; gap:12px; flex-wrap:wrap; margin:18px 0; } .crm-stat,.crm-unique { display:flex; flex-direction:column; padding:12px 20px; border:1px solid var(--line); border-radius:12px; background:var(--card); } .crm-stat strong,.crm-unique strong { font-size:24px; } .crm-stat.active { background:var(--accent-soft); }
.crm-board { display:flex; gap:16px; overflow-x:auto; align-items:flex-start; padding-bottom:12px; } .crm-column { flex:1; min-width:280px; padding:12px; border-radius:12px; border:1px solid var(--line); background:var(--bg); } .crm-column h3 { margin:4px 4px 12px; } .crm-card { border:1px solid var(--line); border-radius:10px; background:var(--card); padding:14px; margin-bottom:12px; cursor:grab; } .crm-card small { color:var(--muted); } .crm-card .row { margin-top:12px; flex-wrap:wrap; } .crm-tag-options { display:flex; flex-wrap:wrap; gap:10px; max-height:200px; overflow-y:auto; }

.notification-controls{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 16px;border-bottom:1px solid var(--line);background:var(--card)}.notification-controls button{font-size:12px;padding:6px 10px}

.campaign-filters { margin-top:12px; }
.campaign-filters > .row { flex-wrap:wrap; }
.campaign-filters select { width:auto; max-width:280px; }
.campaign-tag-filter { align-items:flex-start; margin-top:12px; }
.campaign-tag-filter > b { padding:7px 4px 0 0; }
#campaign-tag-options { flex:1; }
.campaign-recipient-list { display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); gap:8px; max-height:390px; overflow:auto; margin-top:12px; }
.campaign-recipient { display:flex; align-items:flex-start; gap:10px; border:1px solid var(--line); border-radius:9px; padding:10px; margin:0; background:var(--bg); cursor:pointer; }
.campaign-recipient input { width:auto; margin:3px 0 0; }
.campaign-recipient span { display:grid; gap:2px; min-width:0; }
.campaign-recipient small { color:var(--muted); overflow-wrap:anywhere; }
.campaign-recipient.unavailable { opacity:.55; cursor:not-allowed; }
.campaign-rule { border:1px solid var(--line); border-radius:9px; padding:10px; margin-top:10px; }
.campaign-rule select { width:auto; min-width:180px; }
.campaign-rule textarea { margin-top:8px; }
.campaign-preview-list { display:grid; gap:8px; margin-top:12px; max-height:480px; overflow:auto; }
.campaign-preview { padding:10px 12px; border:1px solid var(--line); border-radius:9px; white-space:pre-wrap; overflow-wrap:anywhere; }
.campaign-preview .row-between { margin-bottom:6px; }
@media(max-width:640px){.campaign-recipient-list{grid-template-columns:1fr}.campaign-filters select{max-width:100%;flex:1}}
.contact.unread { background:var(--accent-soft); border-left:4px solid var(--accent); padding-left:10px; }
.contact.unread .name,.contact.unread .last { font-weight:700; }
.badge-unread { display:inline-block; background:var(--accent); color:#fff; border-radius:99px; padding:2px 7px; font-size:10px; font-weight:700; vertical-align:middle; }

/* Inbox: filter contacts by tag */
.inbox-tag-filter { margin: 8px 0 10px; }
.inbox-tag-filter [data-toggle].active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.inbox-tag-panel { margin-top: 6px; padding: 10px 12px; max-height: 280px; overflow: auto; }
.inbox-tag-list { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.inbox-tag-list label { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.filter-chip button { border: 0; background: none; padding: 0 2px; cursor: pointer; color: inherit; font-size: 14px; line-height: 1; }
.linklike { border: 0; background: none; color: var(--accent); padding: 0; cursor: pointer; font: inherit; }
