:root {
  --bg: #f6f5f2; --panel: #ffffff; --panel-2: #f0eee9; --line: #e4e1da;
  --text: #1d1d1f; --muted: #6e6b66; --accent: #c8912e; --accent-ink: #ffffff; --accent-soft: #f6ead3;
  --mine: #f3e2bf; --danger: #d0453a; --ok: #2f9e5b; --radius: 12px; --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a; --panel: #1f2024; --panel-2: #26272c; --line: #33343a;
    --text: #ececef; --muted: #9a9aa2; --accent: #d9a441; --accent-ink: #1a1a1a; --accent-soft: #3a3020; --mine: #4a3d22;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16171a; --panel: #1f2024; --panel-2: #26272c; --line: #33343a;
  --text: #ececef; --muted: #9a9aa2; --accent: #d9a441; --accent-ink: #1a1a1a; --accent-soft: #3a3020; --mine: #4a3d22;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* buttons & fields */
.btn { min-height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.btn:hover { background: var(--panel-2); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.dan { color: var(--danger); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.field { display: block; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); outline: none; }
.field:focus { border-color: var(--accent); }
label.lb { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.icon-btn { width: var(--tap); height: var(--tap); display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 10px; }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* auth */
.madeby { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0 0; }
.auth { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card p { margin: 0 0 8px; color: var(--muted); }
.auth-card .btn.pri { width: 100%; margin-top: 18px; min-height: 44px; }
.auth-switch { margin-top: 14px; text-align: center; font-size: 14px; }
.auth-switch button { border: 0; background: none; color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; overflow-wrap: anywhere; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* shell */
.shell { display: grid; grid-template-columns: 68px 300px 1fr; height: 100%; height: 100dvh; }
.rail { background: var(--panel-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px; }
.rail .tab { width: 52px; height: 52px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); display: grid; place-items: center; position: relative; }
.rail .tab.on { background: var(--accent-soft); color: var(--accent); }
.rail .tab svg { width: 24px; height: 24px; }
.badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.list-head { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); }
.list-head h2 { font-size: 17px; margin: 0; }
.list-body { overflow-y: auto; flex: 1; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 0; background: none; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.row:hover { background: var(--panel-2); }
.row.on { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; flex: none; border-radius: 10px; display: grid; place-items: center; font-weight: 600; color: #fff; font-size: 15px; }
.avatar.ai { border-radius: 50%; }
.row-main { min-width: 0; flex: 1; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { color: var(--muted); font-size: 12px; flex: none; }
.row-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .badge { position: static; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-left: 6px; }
.dot.on { background: var(--ok); }

.shell.tab-page { grid-template-columns: 68px 1fr; }
.shell.tab-page .list { display: none; }

/* chat */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head { height: 56px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head h2 { font-size: 17px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 8px; max-width: 880px; }
.msg.mine { flex-direction: row-reverse; align-self: flex-end; }
.msg .avatar { width: 36px; height: 36px; font-size: 13px; }
.bubble-wrap { min-width: 0; max-width: min(640px, 78vw); }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 4px 2px; }
.msg.mine .who { text-align: right; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; white-space: pre-wrap; word-break: break-word; position: relative; }
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
.bubble .mention { color: var(--accent); font-weight: 600; }
.bubble.recalled { color: var(--muted); font-style: italic; background: transparent; }
.quote { font-size: 12px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; margin-bottom: 6px; cursor: pointer; }
.att { margin-top: 6px; }
.att img, .att video { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; cursor: zoom-in; }
.att .file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); text-decoration: none; color: var(--text); }
.msg-more { opacity: 0; border: 0; background: none; color: var(--muted); align-self: flex-end; padding: 2px 6px; border-radius: 6px; }
.msg:hover .msg-more, .msg-more:focus { opacity: 1; }
.sys { align-self: center; font-size: 12px; color: var(--muted); }
.compose { flex: none; border-top: 1px solid var(--line); background: var(--panel); padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.compose-row { display: flex; align-items: flex-end; gap: 6px; }
.compose textarea { flex: 1; resize: none; max-height: 160px; min-height: 40px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; }
.compose textarea:focus { border-color: var(--accent); }
.replying { font-size: 12px; color: var(--muted); padding: 2px 6px 6px; display: flex; justify-content: space-between; }
.pending-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 8px; background: var(--panel-2); }
.mention-pop { position: absolute; bottom: 64px; left: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 220px; overflow: auto; min-width: 200px; z-index: 5; }
.mention-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; }
.mention-pop button.on, .mention-pop button:hover { background: var(--accent-soft); }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 24px; }

/* pages (todos, members, me) */
.page { flex: 1; overflow-y: auto; padding: 16px; }
.page-inner { max-width: 880px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.todo { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.todo:last-child { border-bottom: 0; }
.todo-title { flex: 1; min-width: 0; word-break: break-word; }
.todo-title small { display: block; color: var(--muted); }
.st { font-size: 12px; padding: 1px 8px; border-radius: 8px; flex: none; margin-top: 2px; }
.st.todo { background: var(--panel-2); color: var(--muted); }
.st.doing { background: var(--accent-soft); color: var(--accent); }
.st.blocked { background: #f8dcd9; color: var(--danger); }
.st.done { background: #dcefe3; color: var(--ok); }
.todo.done .todo-title { color: var(--muted); text-decoration: line-through; }
.todo-acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.keybox { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--panel-2); border-radius: 8px; padding: 10px; word-break: break-all; user-select: all; }
pre.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--panel-2); border-radius: 8px; padding: 10px; white-space: pre-wrap; word-break: break-all; }

/* side panel (group info / files) */
.side { position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 100%; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.08); display: flex; flex-direction: column; z-index: 20; }
.side .page { padding: 12px 16px; }

/* dialog */
.dlg-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dlg { background: var(--panel); border-radius: 16px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; padding: 20px; }
.dlg h3 { margin: 0 0 8px; }
.dlg-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pick input { width: 18px; height: 18px; accent-color: var(--accent); }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.viewer img { max-width: 96vw; max-height: 96vh; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; }

/* phones */
.bottom-bar { display: none; }
@media (max-width: 760px) {
  .shell, .shell.tab-page { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { display: none; }
  .list, .main { grid-column: 1; grid-row: 1; border-right: 0; min-height: 0; }
  .shell.in-chat .list { display: none; }
  .shell:not(.in-chat) .main.chat-mode { display: none; }
  .shell.in-chat .bottom-bar { display: none; }
  .back { display: inline-grid; }
  .bottom-bar { display: flex; grid-row: 2; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-bar .tab { flex: 1; height: 56px; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; position: relative; }
  .bottom-bar .tab.on { color: var(--accent); }
  .bottom-bar .tab svg { width: 24px; height: 24px; }
  .bottom-bar .badge { top: 4px; right: calc(50% - 22px); }
  .msg-more { opacity: 1; }
  .side { width: 100%; }
}

/* update banner (owner / admins) */
.upd { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; padding: 10px 14px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13px; }
.upd b { margin-right: 4px; }
.upd .btn { margin-left: auto; }
.upd.sec { background: #f8dcd9; color: var(--danger); }
.upd.sec a { color: var(--danger); font-weight: 600; }
