/* Palette/type carried over from the mockup (docs/mockup-team-chat.html) and
   originally from v1's styles.css — iOS system palette + system font stack.
   This is a real full-viewport app now, not a phone-frame demo. */
:root {
  /* --canvas (page ground) must read as distinct from --surface-2 (card/bubble
     ground) or every card and chat bubble silently disappears into the page —
     found by actually looking at the rendered dashboard, not in the CSS. */
  --bg: #ffffff; --canvas: #eef0f3; --surface-2: #f5f5f7; --surface-3: #e5e5ea;
  --text: #111111; --text-muted: #8e8e93; --border: #d9d9de;
  --accent: #007aff; --accent-contrast: #ffffff;
  --success: #34c759; --warning: #ff9500; --danger: #d70015; --drive-green: #0f9d58;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --canvas: #000000; --surface-2: #1c1c1e; --surface-3: #2c2c2e;
    --text: #f2f2f7; --text-muted: #98989d; --border: #38383a;
    --accent: #0a84ff; --success: #30d158; --warning: #ff9f0a; --danger: #ff453a; --drive-green: #34a853;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --canvas: #000000; --surface-2: #1c1c1e; --surface-3: #2c2c2e;
  --text: #f2f2f7; --text-muted: #98989d; --border: #38383a;
  --accent: #0a84ff; --success: #30d158; --warning: #ff9f0a; --danger: #ff453a; --drive-green: #34a853;
}
* { box-sizing: border-box; }
/* Several elements below set their own `display` (grid/flex) as part of an ID
   or class rule, which outranks the browser's default `[hidden] { display:
   none }` (an attribute selector has lower specificity than an ID/class rule
   with the same or higher weight) — so toggling the `hidden` attribute from JS
   silently did nothing. Force it, globally, once. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Pretendard, "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.eyebrow { font-size: 10px; font-weight: 750; letter-spacing: .14em; color: var(--text-muted); text-transform: uppercase; }

/* auth */
#auth-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--canvas); z-index: 50; }
#auth-form { width: min(360px, 100%); display: grid; gap: 12px; padding: 30px; border-radius: 22px; background: var(--bg); box-shadow: 0 12px 40px rgba(0,0,0,.12); }
#auth-form h1 { margin: 4px 0; font-size: 22px; }
#auth-form p { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; line-height: 1.5; }
#auth-form input { border: 1px solid var(--border); border-radius: 12px; padding: 12px; outline: none; background: var(--bg); color: var(--text); }
#auth-form button { border: 0; border-radius: 12px; padding: 12px; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; }
#auth-error { min-height: 16px; color: var(--danger); font-size: 12px; }

/* app shell */
#app { height: 100dvh; display: flex; flex-direction: column; }
#room-content { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#room-content[hidden] { display: none; }
#room-placeholder { display: none; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 13.5px; }

/* Wide viewport: v1 filled the full browser window edge-to-edge (a real
   desktop app shell — sidebar + main, like any desktop chat app), never a
   bordered card floating on a colored background. An earlier version of this
   put #app in a shadowed, rounded, centered "phone frame" here instead —
   on an actual desktop monitor that reads as a toy floating in empty gray
   space, not a real page ("창 안에 또 창을 만들었다" — user feedback). Full-
   bleed two-pane layout instead, matching v1's actual proportions. */
@media (min-width: 760px) {
  #app { flex-direction: row; }
  #screen-home { display: flex !important; width: 330px; flex: 0 0 330px; border-right: 1px solid var(--border); }
  #screen-room { display: flex !important; flex: 1; min-width: 0; }
  .proj-card.active-room { background: var(--surface-3); }
  #room-placeholder { display: flex; }
  #back-btn { display: none; } /* sidebar is always visible here, no need to navigate back to it */
}
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#screen-room { background: var(--bg); } /* right pane reads as the "paper", left sidebar keeps the canvas tone */

/* home */
.home-head { padding: max(18px, env(safe-area-inset-top)) 18px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.wordmark { font-size: 19px; letter-spacing: -.02em; display: block; }
.home-head small { color: var(--text-muted); font-size: 12px; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-3); color: var(--accent); font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.home-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 16px 32px; display: grid; align-content: start; gap: 12px; max-width: 640px; width: 100%; margin: 0 auto; }
.dash-label { font-size: 14px; font-weight: 750; color: var(--text); letter-spacing: -.01em; margin: 0 0 6px 2px; }
.dash-label-row { display: flex; align-items: center; justify-content: space-between; margin: 0 0 2px; }
.dash-label-row .dash-label { margin: 0; }
.dash-label-row .icon-btn { width: 28px; height: 28px; font-size: 15px; }
.live-strip { display: flex; gap: 6px; overflow-x: auto; }
.live-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border)); color: var(--text); font-size: 12px; font-weight: 600; padding: 8px 13px; border-radius: 999px; white-space: nowrap; }
.live-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-chip .dot { animation: none; } }

.proj-list { display: grid; gap: 5px; }
.proj-card-row { display: flex; align-items: stretch; gap: 4px; min-width: 0; }
.proj-card { display: flex; align-items: center; gap: 11px; background: var(--surface-2); border-radius: 14px; padding: 9px 14px; cursor: pointer; border: 0; text-align: left; width: 100%; flex: 1 1 0; min-width: 0; overflow: hidden; }
.proj-card:hover { background: var(--surface-3); }
.proj-delete {
  flex: 0 0 auto; width: 34px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--danger);
  display: grid; place-items: center; cursor: pointer; opacity: .55; transition: opacity .15s ease, background .15s ease;
}
.proj-delete:hover { opacity: 1; background: color-mix(in srgb, var(--danger) 12%, var(--surface-2)); }
.proj-state { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--surface-3); }
.proj-state.active { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }
.proj-state.blocked { background: var(--danger); }
.proj-state.idle, .proj-state.completed { background: var(--text-muted); opacity: .5; }
.proj-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(145deg,#c5c5ca,#8e8e93); flex: 0 0 auto; }
.avatar-sm { border-radius: 50%; flex: 0 0 auto; object-fit: cover; display: block; cursor: pointer; }
.avatar-sm--blank { background: linear-gradient(145deg,#c5c5ca,#8e8e93); }

/* persona popup */
.persona-card { position: relative; text-align: center; max-height: 82vh; overflow-y: auto; }
.persona-close { position: absolute; top: 8px; right: 8px; }
.persona-photo { width: 192px; height: 192px; border-radius: 50%; object-fit: cover; margin: 4px auto 10px; display: block; }
.persona-name { font-size: 17px; font-weight: 750; }
.persona-role { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.5; }
.persona-section-label { font-size: 10.5px; font-weight: 750; color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase; margin: 16px 0 6px; text-align: left; }
.persona-model { text-align: left; font-size: 13px; background: var(--surface-2); border-radius: 10px; padding: 8px 11px; }
.persona-tasks { display: grid; gap: 5px; text-align: left; }
.persona-task-row { background: var(--surface-2); border-radius: 10px; padding: 7px 11px; font-size: 12px; line-height: 1.4; }
.persona-task-row .t-room { font-weight: 650; }
.persona-task-row .t-role { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; margin-right: 5px; }
.persona-empty { font-size: 12px; color: var(--text-muted); text-align: left; padding: 4px 2px; }
.proj-meta { min-width: 0; flex: 1; }
.proj-name { display: block; font-size: 14px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-sub { display: block; font-size: 12px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj-card .chev { color: var(--text-muted); font-size: 16px; flex: 0 0 auto; }
.empty-note { color: var(--text-muted); font-size: 12.5px; padding: 8px 2px; }

/* modal */
.modal-form { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-card { width: min(360px, 100%); background: var(--bg); border-radius: 18px; padding: 20px; display: grid; gap: 12px; }
.modal-card h2 { margin: 0; font-size: 17px; }
.modal-card input { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--bg); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button { border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.modal-actions button[data-cancel] { background: var(--surface-3); color: var(--text); }
.modal-actions button[type="submit"] { background: var(--accent); color: #fff; font-weight: 650; }
.confirm-text { margin: 4px 2px 0; font-size: 13.5px; line-height: 1.5; }
.confirm-danger { background: var(--danger); color: #fff; font-weight: 650; }

/* room */
.chat-head { padding: max(14px, env(safe-area-inset-top)) 10px 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.room-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.room-meta { min-width: 0; flex: 1; }
.room-meta strong { font-size: 15px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta small { color: var(--text-muted); font-size: 11.5px; display: flex; align-items: center; }
.drive-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--drive-green); display: inline-block; margin-right: 5px; }
.thread { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 14px; display: flex; flex-direction: column; gap: 8px; max-width: 720px; width: 100%; margin: 0 auto; }
.from-user { min-width: 0; max-width: 100%; background: var(--accent); color: var(--accent-contrast); padding: 7px 12px; border-radius: 18px 18px 4px 18px; font-size: 14px; line-height: 1.4; }
/* A file-only message has no text — the file card itself should be the whole
   bubble (like an iMessage image attachment), not a card floating inside
   another colored box with its own padding on top. */
.from-user.file-only { background: none; padding: 0; border-radius: 11px; }
.from-user.file-only .file-card { margin-top: 0; }

/* iMessage-style rows: avatar to the left, name shown once per consecutive
   group, tight spacing within a group and a bit more air between speakers. */
.msg-row { display: flex; align-items: flex-start; gap: 6px; max-width: 88%; align-self: flex-start; margin-top: 4px; }
.msg-row.grouped { margin-top: -2px; }
.msg-row.user-row { align-self: flex-end; max-width: 78%; }
.msg-avatar-slot { width: 40px; flex: 0 0 auto; }
.msg-col { min-width: 0; display: flex; flex-direction: column; }
.msg-col.user-col { align-items: flex-end; }
.msg-row .who { font-size: 11px; font-weight: 750; color: var(--text-muted); letter-spacing: .02em; margin: 0 0 3px 3px; }
/* v1's pattern: a "삭제" text link stays invisible until you hover/focus the
   message, sitting next to its timestamp below the bubble — quieter than an
   always-visible icon on a UI that's mostly text. */
.msg-footer { display: flex; align-items: center; gap: 6px; margin: 2px 3px 0; font-size: 10.5px; color: var(--text-muted); }
.msg-delete { border: 0; background: none; padding: 0; color: var(--text-muted); font-size: 10.5px; cursor: pointer; opacity: 0; transition: opacity .15s ease; }
.msg-row:hover .msg-delete, .msg-row:focus-within .msg-delete { opacity: .75; }
.msg-delete:hover { color: var(--danger); }
@media (max-width: 759px) { .msg-delete { opacity: .45; } } /* no hover on touch — keep it faintly visible instead */
.bubble { min-width: 0; background: var(--surface-2); border-radius: 4px 16px 16px 16px; padding: 7px 12px; font-size: 14px; line-height: 1.4; }
/* white-space:pre-wrap lives on .msg-text, not the bubble itself — the
   bubble's innerHTML is built from a multi-line JS template literal, and
   putting pre-wrap on the bubble made that template's own indentation
   whitespace render as real blank lines around the text (the actual cause
   of "too much padding" reports — it was never the CSS padding value). */
.msg-text { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg-row.grouped .bubble { border-radius: 16px; }
.bubble.failure { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); }
.note-row { align-self: stretch; text-align: center; font-size: 11.5px; color: var(--text-muted); padding: 2px 10px; }

.expand-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.expand-chip {
  appearance: none; -webkit-appearance: none; border: none; margin: 0; font: inherit;
  font-size: 11.5px; font-weight: 600; color: var(--accent); white-space: nowrap;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  height: 28px; padding: 0 12px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; cursor: pointer;
}

.file-card { margin-top: 10px; display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; text-decoration: none; color: var(--text); }
.file-card .file-ico { width: 34px; height: 34px; border-radius: 8px; background: #ff3b30; color: #fff; display: grid; place-items: center; font-size: 9px; font-weight: 800; letter-spacing: .02em; flex: 0 0 auto; }
.file-card .file-meta { min-width: 0; flex: 1; }
.file-card .file-name { display: block; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .file-sub { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; display: flex; align-items: center; }
.file-card .open-btn { font-size: 11px; font-weight: 700; color: var(--accent); flex: 0 0 auto; }

.status-chip { align-self: center; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; font-size: 12.5px; color: var(--text); }
.status-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .status-chip .dot { animation: none; } }
.chip-actions { display: flex; gap: 4px; margin-left: 2px; }
.chip-actions button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 11.5px; color: var(--text); cursor: pointer; }
.chip-actions button:hover { background: var(--surface-3); }
.chip-actions button.chip-danger { color: var(--danger); }

/* v1-style "..." bubble while a 1:1 persona is composing */
.typing-bubble { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: typing-dot 1.2s ease-in-out infinite; }
.typing-bubble span:nth-child(2) { animation-delay: .2s; }
.typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .typing-bubble span { animation: none; opacity: .6; } }

.composer { flex: 0 0 auto; padding: 10px 14px 4px; display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--border); max-width: 720px; width: 100%; margin: 0 auto; }
.composer input { flex: 1; background: var(--surface-2); border: 0; border-radius: 999px; padding: 11px 16px; font-size: 16px; color: var(--text); outline: none; }
.composer button[type="submit"] { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; display: grid; place-items: center; font-size: 16px; flex: 0 0 auto; cursor: pointer; }
.composer button:disabled { opacity: .5; }
.composer .attach-btn { width: 34px; height: 34px; font-size: 20px; flex: 0 0 auto; }
.clear-history-btn {
  display: block; margin: 0 auto max(8px, env(safe-area-inset-bottom)); border: 0; background: none; color: var(--text-muted);
  font-size: 11.5px; cursor: pointer; padding: 2px 8px;
}
.clear-history-btn:hover { color: var(--danger); }
.attach-preview {
  max-width: 720px; width: calc(100% - 28px); margin: 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 12px; background: var(--surface-2); border-radius: 12px 12px 0 0; font-size: 12.5px; color: var(--text-muted);
}
.attach-preview button { border: 0; background: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 0 4px; }

/* deliberation panel */
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; }
#deliberation-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100%); background: var(--bg);
  z-index: 61; transform: translateX(100%); transition: transform .2s ease; display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.15);
}
#deliberation-panel.open { transform: translateX(0); }
#deliberation-panel header { padding: max(16px, env(safe-area-inset-top)) 16px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; }
#deliberation-body { flex: 1; overflow-y: auto; padding: 12px; }
.delib-step { display: flex; gap: 10px; padding: 10px; position: relative; }
.delib-step:not(:last-child)::after { content: ""; position: absolute; left: 20px; top: 34px; bottom: -4px; width: 1.5px; background: var(--border); }
.delib-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 3px; flex: 0 0 auto; background: var(--accent); z-index: 1; }
.delib-dot.reviewer, .delib-dot.review { background: var(--warning); }
.delib-body .step-label { font-size: 10px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.delib-body .step-who { font-size: 12.5px; font-weight: 650; margin: 1px 0 3px; }
.delib-body .step-text { font-size: 12.5px; line-height: 1.5; color: var(--text); }

#toast { position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; translate: -50% 0; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 12.5px; z-index: 80; max-width: 90vw; text-align: center; }

/* PWA(홈 화면 설치) 안전영역: 아이폰 노치·홈 인디케이터와 겹침 방지 */
#app { padding-top: env(safe-area-inset-top); }
.composer { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }

/* iOS 자동 확대 방지: 입력창 글자가 16px 미만이면 사파리가 탭 시 화면을
   확대해 좌우가 잘린다(대표님 실사용 보고). 모든 입력창 16px 보장. */
input, textarea, select { font-size: 16px; }

/* 모바일 상태창: 버튼이 눌려 글자가 세로로 꺾이던 문제(대표님 실사용
   보고) — 버튼은 절대 줄바꿈·축소 금지, 안내 문구만 접히게. */
.status-chip { flex-wrap: wrap; row-gap: 6px; max-width: 92%; }
.status-chip .text { min-width: 0; }
.chip-actions { flex: 0 0 auto; }
.chip-actions button { white-space: nowrap; flex: 0 0 auto; }

/* 파일 카드의 Drive 보조 링크 */
.file-sub .drive-link { color: var(--text-muted); text-decoration: underline; display: inline-flex; align-items: center; gap: 3px; }
