:root {
  --bg: #17171c; --panel: #1f1f26; --panel2: #262630; --line: #33333f;
  --text: #ececf1; --muted: #9a9aa8; --accent: #d97757; --accent2: #b85f41;
  --user: #2f3a55; --danger: #b3463f; --ok: #3f8f5a; --warn: #b88a2a;
  --radius: 12px; font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:disabled { opacity: .5; cursor: default; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:disabled { opacity: .35; cursor: default; }
button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: .9rem; }
button.icon { padding: 6px 10px; font-size: 1.2rem; display: none; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: #ff9b94; min-height: 1.2em; }

#login { height: 100%; display: grid; place-items: center; padding: 16px; }
#login form { width: min(360px, 100%); display: grid; gap: 12px; background: var(--panel); padding: 28px 24px; border-radius: 16px; border: 1px solid var(--line); }
#login h1 { margin: 0; font-size: 1.5rem; }

#app { height: 100%; width: 100%; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
#scrim { display: none; }
#sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#sidebar header, #sidebar footer { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; gap: 8px; }
#sidebar footer { border-top: 1px solid var(--line); }
#convList { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; }
#convList li { padding: 10px 10px; border-radius: 10px; cursor: pointer; display: grid; gap: 3px; }
#convList li:hover { background: var(--panel2); }
#convList li.active { background: var(--panel2); outline: 1px solid var(--line); }
#convList .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#convList .sub { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .8rem; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }

#main { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; min-height: 0; min-width: 0; height: 100%; }
#topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
#convHead { flex: 1; min-width: 0; }
#convTitle.title { background: none; border: none; padding: 0; font-weight: 600; font-size: 1.05rem; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#convMeta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: .78rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.badge.idle { color: var(--muted); }
.badge.running { background: #2b3f6b; border-color: #3e5a93; }
.badge.waiting { background: #5a4a1e; border-color: var(--warn); }

#messages { overflow-y: auto; overflow-x: hidden; min-width: 0; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { max-width: min(860px, 100%); min-width: 0; padding: 10px 14px; border-radius: var(--radius); line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.assistant.live { border-style: dashed; }
.msg p { margin: 0 0 .6em; } .msg p:last-child { margin-bottom: 0; }
.msg pre { background: #101014; border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: .86rem; margin: .5em 0; white-space: pre-wrap; }
.msg code { background: #101014; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.msg pre code { background: none; padding: 0; }
.msg ul { margin: .3em 0 .6em 1.2em; padding: 0; }
.msg a { color: #8ab4ff; }
.tool { align-self: flex-start; max-width: min(860px, 100%); min-width: 0; width: 100%; font-size: .85rem; color: var(--muted); }
.tool summary { cursor: pointer; list-style: none; display: flex; gap: 6px; align-items: center; min-width: 0; }
.tool summary .label { white-space: nowrap; }
.tool summary .muted { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool summary::before { content: "▸"; } .tool[open] summary::before { content: "▾"; }
.tool pre { margin: 6px 0 0; background: #101014; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: .8rem; white-space: pre-wrap; max-height: 320px; overflow: auto; }
.tool.err summary { color: #ff9b94; }
.note { align-self: center; max-width: 100%; overflow-wrap: anywhere; color: var(--muted); font-size: .8rem; text-align: center; padding: 2px 8px; }
.note.warning { color: #ffd27f; }
.card { align-self: stretch; max-width: 860px; min-width: 0; background: #2a2418; border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.card.done { opacity: .6; border-color: var(--line); background: var(--panel); }
.card h4 { margin: 0; font-size: .95rem; }
.card pre { margin: 0; background: #101014; border-radius: 8px; padding: 8px; font-size: .82rem; white-space: pre-wrap; max-height: 260px; overflow: auto; }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.card .q { display: grid; gap: 6px; }
.card .opt { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.card .opt small { display: block; color: var(--muted); }

#composer { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); display: grid; gap: 6px; }
#liveStatus { min-height: 1.1em; }
.composerRow { display: flex; gap: 8px; align-items: stretch; }
#input { flex: 1; resize: none; max-height: 40vh; min-height: 44px; }
.composerButtons { display: flex; flex-direction: column; gap: 6px; }
.composerTools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.composerTools select { padding: 4px 8px; font-size: .85rem; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; width: min(420px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
dialog h2 { margin: 0; font-size: 1.2rem; }
.dialogButtons { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 800px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  #sidebar.open { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; z-index: 10; }
  #scrim.open { display: block; }
  button.icon { display: inline-block; }
  .composerButtons { flex-direction: row; }
  .composerRow { flex-wrap: wrap; }
  #input { width: 100%; flex-basis: 100%; }
}
