:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #fafafb;
  --border: #e4e4e9;
  --text: #1d1d22;
  --muted: #6b6b76;
  --accent: #5b5fc7;
  --accent-soft: #ececfb;
  --hermes: #0f766e;
  --hermes-soft: #e6f4f2;
  --danger: #c4314b;
  --mention: #fff4ce;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171b;
    --panel: #1f1f24;
    --panel-2: #24242a;
    --border: #33333b;
    --text: #ececf1;
    --muted: #9a9aa6;
    --accent: #8b8ef0;
    --accent-soft: #2c2d4a;
    --hermes: #5eead4;
    --hermes-soft: #173431;
    --danger: #f87185;
    --mention: #3d3620;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--hermes)); color: #fff; display: grid; place-items: center; font-weight: 700; }
label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 14px; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.block { width: 100%; padding: 11px; font-weight: 600; }
.btn.danger { color: var(--danger); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 10px; }

/* ---------- app layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr 340px; height: 100%; }
.app.no-side .side-right { display: none; }
.app.no-side { grid-template-columns: 260px 1fr; }
.side-left { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-left header { padding: 16px; border-bottom: 1px solid var(--border); }
.room-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.section-label { font-size: 12px; color: var(--muted); padding: 14px 16px 6px; display: flex; justify-content: space-between; align-items: center; }
.member-list { overflow-y: auto; flex: 1; padding: 0 8px 8px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.member:hover { background: var(--panel-2); }
.member .meta { min-width: 0; flex: 1; }
.member .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .role { font-size: 11px; color: var(--muted); }
.member .kick { opacity: 0; border: 0; background: none; color: var(--muted); padding: 2px 6px; }
.member:hover .kick { opacity: 1; }
.side-left footer { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: center; }
.side-left footer .me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px; border-radius: 8px; text-align: left; }
.side-left footer .me:hover { background: var(--panel-2); }

.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; position: relative; object-fit: cover; background: var(--accent); }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar.hermes { background: linear-gradient(135deg, #14b8a6, #0f766e); border-radius: 9px; }
.avatar-wrap { position: relative; flex: none; }
.dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); background: #9ca3af; }
.dot.on { background: #22c55e; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.main-head .title { font-weight: 700; flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.status-pill { font-size: 12px; font-weight: 500; color: var(--hermes); background: var(--hermes-soft); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.icon-btn { border: 1px solid transparent; background: none; border-radius: 8px; padding: 6px 8px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.only-mobile { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 12px 0 8px; min-height: 0; }
.load-more { display: block; margin: 4px auto 12px; }
.day-sep { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 6px; }
.msg { display: flex; gap: 12px; padding: 6px 20px; position: relative; }
.msg:hover { background: color-mix(in srgb, var(--panel) 60%, transparent); }
.msg.grouped { padding-top: 1px; }
.msg.grouped .avatar-col { visibility: hidden; height: 0; }
.msg .avatar-col { width: 32px; flex: none; }
.msg .body { min-width: 0; flex: 1; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 600; }
.msg.hermes .author { color: var(--hermes); }
.msg .time { color: var(--muted); font-size: 12px; }
.msg .edited { color: var(--muted); font-size: 12px; }
.msg .text { word-wrap: break-word; overflow-wrap: anywhere; }
.msg .text p { margin: 0 0 6px; }
.msg .text p:last-child { margin-bottom: 0; }
.msg .text pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; }
.msg .text code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.msg .text pre code { border: 0; padding: 0; background: none; }
.msg .text ul, .msg .text ol { margin: 4px 0; padding-left: 22px; }
.msg .text h1, .msg .text h2, .msg .text h3 { font-size: 15px; margin: 8px 0 4px; }
.msg .text blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.msg.deleted .text { color: var(--muted); font-style: italic; }
.msg.mentions-me { background: var(--mention); }
.mention { color: var(--accent); font-weight: 600; background: var(--accent-soft); border-radius: 4px; padding: 0 3px; }
.mention.hermes { color: var(--hermes); background: var(--hermes-soft); }
.hermes-bubble { background: var(--hermes-soft); border-radius: 10px; padding: 8px 12px; display: inline-block; max-width: 100%; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--hermes); }
@keyframes blink { 50% { opacity: 0; } }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.tool-chip { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; background: var(--panel); }
.thinking { color: var(--muted); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.att-img { max-width: 260px; max-height: 200px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.att-file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); text-decoration: none; color: var(--text); max-width: 280px; }
.att-file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file .fsize { color: var(--muted); font-size: 12px; flex: none; }
.reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.reaction { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 0 8px; font-size: 13px; line-height: 24px; }
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); }
.thread-link { margin-top: 4px; border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; font-size: 13px; }
.actions { position: absolute; right: 16px; top: -12px; display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 2px; z-index: 2; }
.msg:hover .actions, .msg:focus-within .actions { display: flex; }
.actions button { border: 0; background: none; padding: 4px 7px; border-radius: 6px; font-size: 14px; }
.actions button:hover { background: var(--panel-2); }
.picker { position: absolute; display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; z-index: 20; }
.picker button { border: 0; background: none; font-size: 18px; padding: 4px 6px; border-radius: 6px; }
.picker button:hover { background: var(--panel-2); }
.edit-box textarea { width: 100%; min-height: 60px; }
.edit-box .row { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }

.typing { height: 20px; padding: 0 20px; font-size: 12px; color: var(--muted); }
.composer { padding: 0 16px 16px; flex: none; }
.composer-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); position: relative; }
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; padding: 12px 14px 4px; max-height: 200px; min-height: 44px; display: block; }
.composer .bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px 8px; }
.composer .hint { color: var(--muted); font-size: 12px; flex: 1; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.pending .chip { font-size: 12px; border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; display: inline-flex; gap: 6px; align-items: center; background: var(--panel-2); }
.pending .chip button { border: 0; background: none; color: var(--muted); }
.mention-menu { position: absolute; bottom: 100%; left: 8px; margin-bottom: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); min-width: 220px; padding: 4px; z-index: 10; }
.mention-menu button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 6px; }
.mention-menu button.active, .mention-menu button:hover { background: var(--accent-soft); }

.side-right { background: var(--panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.side-right .panel-head { height: 56px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.panel-body { overflow-y: auto; flex: 1; padding: 12px 16px; min-height: 0; }
.digest .text h2 { font-size: 14px; margin: 14px 0 6px; color: var(--hermes); }
.digest .text ul { padding-left: 18px; margin: 4px 0; }
.digest .text p { margin: 4px 0; }
.digest .updated { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.thread-panel .msg { padding: 6px 4px; }
.thread-panel .actions { right: 4px; }
.thread-panel .composer { padding: 8px 12px 12px; }
.thread-root { border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 8px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 420px; padding: 22px; border: 1px solid var(--border); }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.copy-row { display: flex; gap: 6px; }
.copy-row .input { font-size: 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 60; font-size: 13px; }
.drop-hint { position: absolute; inset: 0; border: 2px dashed var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--accent-soft) 70%, transparent); display: grid; place-items: center; font-weight: 600; color: var(--accent); pointer-events: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .app, .app.no-side { grid-template-columns: 240px 1fr; }
  .side-right { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100%); z-index: 30; box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .app, .app.no-side { grid-template-columns: 1fr; }
  .side-left { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 85%); z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side-left.open { transform: none; }
  .only-mobile { display: inline-block; }
  .msg { padding: 6px 12px; }
  .composer { padding: 0 8px 8px; }
  .composer .hint { display: none; }
  .att-img { max-width: 100%; }
}
