: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; }
