:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1b2430; --muted: #6b7785; --line: #dde3ea;
  --brand: #1f4e79; --brand-ink: #ffffff; --me: #dcebf9; --danger: #c0392b; --rec: #d63031;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d; --panel: #1b222b; --ink: #e6ebf1; --muted: #93a0ae; --line: #2c3642;
    --brand: #2f6da6; --brand-ink: #ffffff; --me: #23405c; --danger: #ff7b6b; --rec: #ff5a52;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Pretendard", "Malgun Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

/* 로그인 */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; display: grid; gap: 12px; justify-items: center;
}
.login-card h1 { margin: 0 0 8px; font-size: 20px; }
.login-card input, .login-card button { width: 100%; padding: 12px 14px; border-radius: 10px; font: inherit; }
.login-card input { border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.login-card button { border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.error { color: var(--danger); margin: 0; min-height: 1.4em; font-size: 14px; }

/* 채팅 골격 */
#chat { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; max-width: 860px; margin: 0 auto; position: relative; }
header {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
header h1 { flex: 1; margin: 0 6px; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { border: 0; background: transparent; color: inherit; font-size: 20px; width: 40px; height: 40px; border-radius: 10px; }
.icon:hover, .icon:focus-visible { background: rgba(255,255,255,.16); outline: none; }
.icon[aria-pressed="true"] { background: rgba(255,255,255,.28); }

#drawer {
  position: absolute; top: 56px; left: 8px; z-index: 5; width: min(320px, calc(100% - 16px)); max-height: 70dvh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.25); padding: 6px;
}
#roomList { list-style: none; margin: 0; padding: 0; }
#roomList li { display: flex; align-items: center; }
#roomList button.room { flex: 1; text-align: left; border: 0; background: transparent; color: var(--ink); padding: 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#roomList button.room.active { background: var(--me); }
#roomList button.del { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; }
.text { border: 0; background: transparent; color: var(--muted); padding: 10px; width: 100%; text-align: left; border-top: 1px solid var(--line); margin-top: 4px; }

/* 메시지 */
#messages { overflow-y: auto; padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 8px 14px; font-size: 14px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant p { margin: 0 0 .6em; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: .2em 0 .6em; padding-left: 1.3em; }
.msg.assistant h3 { margin: .5em 0 .3em; font-size: 1em; }
.msg pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; position: relative; }
.msg code { font-family: Consolas, "D2Coding", monospace; font-size: .92em; }
.msg .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 6px; padding: 2px 8px; }
.msg .tools { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.msg .replay { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 4px 0 0; }
.msg.error { border-color: var(--danger); color: var(--danger); }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

/* 입력 */
footer { padding: 6px 10px max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.status { font-size: 13px; color: var(--muted); padding: 2px 6px 6px; }
.status.rec { color: var(--rec); font-weight: 600; }
#composer { display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 6px; }
#input { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); font: inherit; padding: 8px 4px; max-height: 160px; }
.mic, .send { border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 18px; flex: none; }
.mic { background: var(--bg); color: var(--ink); }
.mic.rec { background: var(--rec); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(214,48,49,.18); } }
.send { background: var(--brand); color: var(--brand-ink); }
.send:disabled, .mic:disabled { opacity: .45; cursor: default; }
@media (prefers-reduced-motion: reduce) { .mic.rec, .typing::after { animation: none; } }

/* 확인 후 실행 카드 */
#pending { display: grid; gap: 8px; padding-bottom: 6px; max-height: 45dvh; overflow-y: auto; }
.pcard { background: var(--panel); border: 1px solid var(--brand); border-left-width: 5px; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.pcard h4 { margin: 0 0 4px; font-size: 14px; }
.pcard dl { margin: 6px 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.pcard dt { color: var(--muted); } .pcard dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.pcard .btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.pcard button { border-radius: 8px; padding: 8px 16px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.pcard button.go { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.pcard button:disabled { opacity: .5; }
.pcard .result { margin-top: 6px; font-weight: 600; } .pcard .result.fail { color: var(--danger); }
