:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e1dc;
  --accent: #1f5fae; --accent-text: #ffffff; --user: #eaf1fb; --err: #b3261e; --warn: #8a5a00;
  --side: #efeeea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181a; --panel: #212124; --text: #ececea; --muted: #a0a09a; --line: #34343a;
    --accent: #6fa3e6; --accent-text: #0e1a2b; --user: #23324a; --err: #ff8a80; --warn: #e0b060;
    --side: #1d1d20;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-text); cursor: pointer; }
button.ghost { background: transparent; color: var(--text); text-align: left; }
button.ghost:hover { background: var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
label { display: block; margin: 10px 0; }
label input { display: block; width: 100%; margin-top: 4px; }
label.inline { display: inline-block; margin-right: 12px; }
label.inline input[type=radio] { display: inline; width: auto; }
label.inline input:not([type=radio]) { display: inline-block; width: auto; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--err); min-height: 1em; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 16px; }
.narrow { width: min(380px, calc(100vw - 32px)); }
.center { min-height: 100%; display: grid; place-items: center; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }

#app-view { display: flex; height: 100vh; }
#sidebar { width: 260px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px; gap: 8px; }
#conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
#conv-list .conv { display: flex; align-items: center; border-radius: 8px; }
#conv-list .conv.active { background: var(--line); }
#conv-list .conv button.title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#conv-list .conv button.del { padding: 4px 8px; color: var(--muted); }
.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }

.tab { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
#menu { display: none; }
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user .bubble { background: var(--user); border-radius: 12px; padding: 10px 14px; white-space: pre-wrap; margin-left: auto; width: fit-content; max-width: 85%; }
.msg.assistant .bubble { padding: 4px 2px; }
.bubble table { border-collapse: collapse; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; }
.bubble pre { overflow-x: auto; background: var(--panel); padding: 10px; border-radius: 8px; }
details.sources { margin-top: 6px; font-size: 13px; }
details.sources li { margin: 4px 0; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.snippet { color: var(--muted); }
.empty { color: var(--muted); text-align: center; margin-top: 20vh; }
#ask-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); max-width: 892px; width: 100%; margin: 0 auto; }
#ask { flex: 1; resize: vertical; min-height: 44px; }
table { border-collapse: collapse; margin: 0 16px 16px; font-size: 14px; }
table th, table td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.user-pw { font-family: ui-monospace, monospace; background: var(--user); padding: 2px 6px; border-radius: 6px; }

@media (max-width: 760px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .15s; }
  #sidebar.open { transform: none; }
  #menu { display: inline-block; }
  table { display: block; overflow-x: auto; margin: 0 16px 16px; }
}
