:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #14181f; --muted: #5d6675; --line: #e3e6ea; --hover: #f0f2f5;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e6f4f2;
  --in: #eef0f3; --out: #0f766e; --out-ink: #fff;
  --note: #fff7e0; --note-line: #f2d48a; --ok: #16a34a; --warn: #b45309; --bad: #dc2626;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #171b21; --ink: #e8ebef; --muted: #9aa4b2; --line: #262c34; --hover: #1e242b;
    --brand: #2dd4bf; --brand-ink: #062320; --brand-soft: #123532;
    --in: #232a32; --out: #115e57; --out-ink: #eafffb; --note: #2b2615; --note-line: #5c4d1e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.primary { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.primary.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; text-align: left; }
.icon-btn { background: none; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--hover); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=email], input[type=password], input[type=search], select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 360px 1fr; height: 100vh; height: 100dvh; }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; }
.nav-head { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 700; }
#folders { display: grid; gap: 2px; }
.folder { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 10px; cursor: pointer; text-align: left; }
.folder:hover { background: var(--hover); }
.folder[aria-current="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.count { font-size: 12px; font-weight: 700; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--line); color: var(--ink); text-align: center; }
.count.hot { background: var(--brand); color: var(--brand-ink); }
.nav-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }

.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.status-bar { font-size: 13px; padding: 8px 14px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.status-bar .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-bar.ok .dot { background: var(--ok); } .status-bar.warn { background: #fff4e5; color: var(--warn); } .status-bar.warn .dot { background: var(--warn); }
.status-bar.bad { background: #fdecec; color: var(--bad); } .status-bar.bad .dot { background: var(--bad); }
@media (prefers-color-scheme: dark) { .status-bar.warn { background: #2e230f; } .status-bar.bad { background: #331617; } }
.list-head { padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 18px; }
.list-head input { grid-column: 1 / -1; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.conv:hover { background: var(--hover); }
.conv[aria-current="true"] { background: var(--brand-soft); }
.conv.unread .c-name, .conv.unread .c-snippet { font-weight: 700; color: var(--ink); }
.conv.unread::before { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--brand); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; flex: none; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.c-main { min-width: 0; }
.c-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-snippet { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); }
.chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--ink); white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.chip.mine { background: var(--brand); color: var(--brand-ink); }
.chip.done { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.chip.ping { background: #fde68a; color: #713f12; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }

.thread-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty-thread { margin: auto; text-align: center; max-width: 340px; padding: 20px; }
#thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.who { flex: 1; min-width: 140px; }
.who h2 { margin: 0; font-size: 17px; }
.thread-actions { display: flex; gap: 8px; align-items: center; }
.assign select { min-width: 150px; padding: 8px 10px; }
.timeline { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.msg { max-width: min(72%, 560px); display: flex; flex-direction: column; }
.msg .bubble { padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg .time { font-size: 11px; color: var(--muted); margin: 2px 8px 0; }
.msg.in { align-self: flex-start; } .msg.in .bubble { background: var(--in); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; align-items: flex-end; } .msg.out .bubble { background: var(--out); color: var(--out-ink); border-bottom-right-radius: 6px; }
.note { align-self: center; width: min(92%, 620px); background: var(--note); border: 1px solid var(--note-line); border-radius: 12px; padding: 8px 12px; font-size: 14px; margin: 6px 0; }
.note .n-head { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.note .n-head b { color: var(--ink); }
.note .mention { background: var(--brand-soft); color: var(--brand); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.event { align-self: center; font-size: 12px; color: var(--muted); margin: 6px 0; text-align: center; }

.composer { border-top: 1px solid var(--line); padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--panel); }
.composer-hint { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.composer-hint a { color: var(--brand); font-weight: 600; text-decoration: none; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.note-wrap { position: relative; flex: 1; }
textarea { resize: none; max-height: 160px; display: block; }
.mention-menu { position: absolute; bottom: calc(100% + 6px); left: 0; list-style: none; margin: 0; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 200px; z-index: 5; }
.mention-menu li { padding: 7px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.mention-menu li[aria-selected="true"], .mention-menu li:hover { background: var(--hover); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 20; }
.mobile-only { display: none; }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) { .app { grid-template-columns: 64px 320px 1fr; } .nav .brand-name, .folder .label, .nav-foot .link, .me span { display: none; } .folder { justify-content: center; position: relative; } .folder .count { position: absolute; top: 2px; right: 2px; font-size: 10px; min-width: 18px; padding: 0 5px; } .folder .ico { font-size: 18px; } }
.folder .ico { width: 20px; text-align: center; }
.folder .lbl-wrap { display: flex; gap: 10px; align-items: center; }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; place-items: center; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .nav .brand-name, .folder .label, .nav-foot .link, .me span { display: initial; }
  .folder { justify-content: space-between; } .folder .count { position: static; font-size: 12px; }
  .app.nav-open .nav { transform: none; }
  .list-head { grid-template-columns: auto 1fr; padding: 10px 16px; }
  .conv { padding: 12px 16px; }
  .thread-pane { position: fixed; inset: 0; background: var(--bg); z-index: 8; transform: translateX(100%); transition: transform .2s; }
  .app.show-thread .thread-pane { transform: none; }
  .thread-head { padding: 8px 12px; gap: 8px; }
  .thread-actions { width: 100%; }
  .assign { flex: 1; } .assign select { width: 100%; min-width: 0; }
  .timeline { padding: 14px 12px; }
  .msg { max-width: 85%; }
  .composer { padding-left: 12px; padding-right: 12px; }
}
