:root {
  --bg: #f5f6f8; --panel: #ffffff; --rail: #f0f2f5; --line: #e4e7eb; --text: #1b1f24; --muted: #6b7380;
  --accent: #2563eb; --accent-soft: #e8efff; --mine: #dff3e7; --theirs: #ffffff; --danger: #c62828; --hover: #eef1f5;
  --c-wa-youtomatic: #15803d; --c-wa-smartify: #0e7490; --c-slack: #7e22ce; --c-zoho-mail: #c2410c; --c-claude: #2563eb; --c-unread: #2563eb;
  --on-accent: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #15181d; --rail: #111317; --line: #262a31; --text: #e7e9ed; --muted: #9aa3af;
    --accent: #5b8cff; --accent-soft: #1b2640; --mine: #173628; --theirs: #1c2027; --danger: #ff6b6b; --hover: #1b1f25;
    --c-wa-youtomatic: #4ade80; --c-wa-smartify: #38bdf8; --c-slack: #c084fc; --c-zoho-mail: #fb923c; --c-claude: #7aa2ff; --c-unread: #7aa2ff;
    --on-accent: #0f1115; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font-size: 15px; line-height: 1.4; }
button { font: inherit; cursor: pointer; color: inherit; }
input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); }

/* login */
.login-page { display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 10px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.login-card button { padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* three columns: channels | conversations | conversation */
.app { display: grid; grid-template-columns: 236px minmax(0, 380px) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }

/* channel rail */
.brand { font-weight: 700; font-size: 18px; padding: 16px 18px 6px; }
.nav { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.nav-sec { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left; padding: 8px 10px; border-radius: 8px; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
.nav-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c); }
.nav-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 24px; text-align: center; padding: 1px 7px; border-radius: 999px; background: var(--c); color: var(--on-accent); }
.nav-item .count.quiet { background: transparent; color: var(--muted); font-weight: 500; }
.nav-item.sub { padding: 5px 10px 5px 30px; font-size: 14px; color: var(--muted); }
.nav-item.sub.active { color: var(--text); }
.rail-foot { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.rail-btn { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px; font-size: 13px; }

/* list */
.pane-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 10px; min-height: 58px; }
.pane-title { flex: 1; min-width: 0; }
.pane-title h2 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-title span { display: block; font-size: 12px; color: var(--muted); }
.back { display: none; border: 0; background: transparent; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); }
.icon-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 8px; width: 34px; height: 34px; font-size: 16px; flex: none; }
.search-wrap { padding: 0 14px 10px; }
.search { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.banner { margin: 0 14px 8px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 13px; }
.banner.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.list { overflow-y: auto; overflow-x: hidden; flex: 1; border-top: 1px solid var(--line); }
.item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; column-gap: 10px; row-gap: 1px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--accent-soft); }
.avatar { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent); }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .title { font-weight: 700; }
.item .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.item.unread .time { color: var(--accent); font-weight: 600; }
.item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .preview { color: var(--text); }
.item .src { color: var(--c); font-weight: 600; }
.item .badges { display: flex; gap: 4px; justify-content: flex-end; min-height: 18px; }
.pill { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-variant-numeric: tabular-nums; }
.pill.ai { background: var(--accent-soft); color: var(--accent); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* conversation */
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: 58px; border-bottom: 1px solid var(--line); background: var(--panel); }
.thread-head .avatar { grid-row: auto; width: 36px; height: 36px; font-size: 13px; flex: none; }
.thread-head .t { flex: 1; min-width: 0; }
.thread-head .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .t span { font-size: 12px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head a { font-size: 13px; color: var(--accent); white-space: nowrap; text-decoration: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 10px 0 2px; }
.msg { max-width: min(620px, 80%); padding: 7px 11px 5px; border-radius: 12px; background: var(--theirs); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--accent); }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg.failed { border: 1px solid var(--danger); }
.msg .media a { font-size: 13px; color: var(--accent); }
.mail-frame { flex: 1; border: 0; width: 100%; background: #fff; }
.placeholder { margin: auto; color: var(--muted); text-align: center; padding: 20px; }

/* composer */
.composer { border-top: 1px solid var(--line); background: var(--panel); }
.reply { display: flex; gap: 8px; padding: 10px 12px; align-items: flex-end; }
.reply textarea { flex: 1; min-width: 0; resize: none; min-height: 42px; max-height: 160px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.btn { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 9px 14px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.ai { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-weight: 600; }
.btn.ai[aria-pressed="true"] { background: var(--accent-soft); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; }
.note { font-size: 12px; color: var(--muted); padding: 0 14px 8px; }

/* Ask Claude drawer */
.claude { border-bottom: 1px solid var(--line); max-height: 50vh; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: color-mix(in srgb, var(--accent-soft) 45%, var(--panel)); }
.claude[hidden] { display: none; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--panel); display: grid; gap: 6px; }
.card.draft { border-color: var(--accent); }
.card .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.card .instr { white-space: pre-wrap; }
.card .answer { white-space: pre-wrap; border-left: 3px solid var(--accent); padding-left: 8px; }
.card.ask.running .label, .card.ask.queued .label { color: var(--accent); }
.card textarea, .ask-form textarea { width: 100%; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ask-form { display: grid; gap: 8px; }
.ask-form .row { justify-content: space-between; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.link { border: 0; background: transparent; color: var(--muted); font-size: 12px; text-decoration: underline; justify-self: start; padding: 0; }
.history summary { font-size: 12px; color: var(--muted); cursor: pointer; padding: 2px 0; }
.history[open] summary { margin-bottom: 6px; }
.history .card { margin-bottom: 6px; }

/* settings */
.settings { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.check { display: flex; gap: 8px; align-items: center; padding: 4px 0; }

/* medium screens: channels + one pane */
@media (max-width: 1099px) {
  .app { grid-template-columns: 210px minmax(0, 1fr); }
  .app[data-view="list"] .thread-pane, .app[data-view="channels"] .thread-pane { display: none; }
  .app[data-view="thread"] .list-pane { display: none; }
  .thread-head .back { display: inline-block; }
}
/* phones: one screen at a time, channels first */
@media (max-width: 759px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="channels"] .list-pane, .app[data-view="channels"] .thread-pane { display: none; }
  .app[data-view="list"] .rail, .app[data-view="thread"] .rail { display: none; }
  .back { display: inline-block; }
  .msg { max-width: 88%; }
  .nav-item { padding: 12px; font-size: 16px; }
  .nav-item.sub { padding: 9px 12px 9px 34px; font-size: 15px; }
  .rail { border-right: 0; }
  .reply { padding: 8px; gap: 6px; }
  .btn { padding: 9px 11px; }
}

/* suggestions, scheduling */
.row.between { justify-content: space-between; }
.suggest { display: grid; gap: 8px; }
.suggest > .row .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.thinking { color: var(--accent); font-size: 14px; padding: 6px 0; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.opt { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--panel); display: grid; gap: 4px; }
.opt .row b { flex: 1; min-width: 0; }
.opt-text { white-space: pre-wrap; font-size: 14px; background: var(--bg); border-radius: 8px; padding: 7px 9px; }
.opt .when { color: var(--accent); font-weight: 600; }
.sched-strip { display: grid; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.sched-strip[hidden] { display: none; }
.sched-item { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.sched-item .when { color: var(--accent); font-weight: 600; white-space: nowrap; }
.sched-item .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.sched-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px 0; }
.sched-row[hidden] { display: none; }
.sched-row input[type=datetime-local] { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color-scheme: light dark; }
.sched-row .check { padding: 0; }
@media (max-width: 759px) { .sched-item .btn { padding: 4px 8px; } }
.sched-strip > * { min-width: 0; }
.sched-item { min-width: 0; width: 100%; }
@media (max-width: 759px) { .sched-item .when { font-size: 12px; } .reply textarea { min-width: 120px; } }
