:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --line: #dfe5e3;
  --text: #17201e;
  --muted: #5f6b68;
  --brand: #0f5f58;
  --brand-ink: #ffffff;
  --brand-soft: #e1efed;
  --user-bubble: #0f5f58;
  --user-ink: #ffffff;
  --manual: #0f5f58;
  --manual-soft: #e1efed;
  --web: #3a5ba0;
  --web-soft: #e6ecf8;
  --warn: #9a5b00;
  --warn-soft: #fbf0dd;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --surface: #182120;
    --surface-2: #1f2a28;
    --line: #2b3735;
    --text: #e6ecea;
    --muted: #9aa8a5;
    --brand: #4fb3a8;
    --brand-ink: #062320;
    --brand-soft: #1d3633;
    --user-bubble: #2a6f68;
    --user-ink: #f2fbf9;
    --manual: #6cc4b9;
    --manual-soft: #1d3633;
    --web: #8fb0ef;
    --web-soft: #1f2a40;
    --warn: #f0b75a;
    --warn-soft: #3a2c12;
    --danger: #f2877f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 14px; min-height: 44px; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 10px; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.link-btn { border: 0; background: none; padding: 10px 0; text-align: left; color: var(--muted); font-size: 15px; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
input {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0 0 12px; }

/* 로그인 */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-icon { width: 56px; height: 56px; border-radius: 14px; display: block; }
.login h1 { font-size: 24px; margin: 18px 0 4px; letter-spacing: -.02em; }
.login-sub { margin: 0 0 28px; color: var(--muted); }
.login-help { margin-top: 18px; font-size: 13px; color: var(--muted); }

/* 메인 */
.main { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-t)) 6px 6px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; }

.thread { flex: 1; overflow-y: auto; padding: 16px 16px 8px; -webkit-overflow-scrolling: touch; }
.thread-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

.empty { padding: 28px 4px 8px; }
.empty h2 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.how { display: grid; gap: 10px; margin-bottom: 24px; }
.how div { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
.how b { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 13px; }
.examples { display: flex; flex-direction: column; gap: 8px; }
.example {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; font-size: 15px;
}
.example:active { background: var(--surface-2); }

.msg-user {
  align-self: flex-end; max-width: 85%; background: var(--user-bubble); color: var(--user-ink);
  padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap;
}
.msg-bot {
  align-self: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.msg-bot.error { border-color: var(--danger); }
.msg-bot.error .answer { color: var(--danger); }

.basis { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; margin-bottom: 8px; }
.basis.manual { background: var(--manual-soft); color: var(--manual); }
.basis.web { background: var(--web-soft); color: var(--web); }
.basis.mixed { background: linear-gradient(90deg, var(--manual-soft), var(--web-soft)); color: var(--text); }
.basis.none { background: var(--warn-soft); color: var(--warn); }

.answer p { margin: 0 0 10px; }
.answer h4 { margin: 14px 0 6px; font-size: 16px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.answer a { color: var(--web); }
.answer > :last-child { margin-bottom: 0; }

.cite {
  display: inline-block; border: 0; font-size: 11px; font-weight: 700; line-height: 1;
  padding: 4px 6px; border-radius: 6px; margin: 0 1px; vertical-align: 2px;
}
.cite.m { background: var(--manual-soft); color: var(--manual); }
.cite.w { background: var(--web-soft); color: var(--web); }

.sources { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.sources-label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.src {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px;
  text-decoration: none; color: inherit;
}
.src:active { background: var(--surface-2); }
.src-tag { flex: none; font-size: 11px; font-weight: 800; padding: 3px 6px; border-radius: 6px; margin-top: 2px; }
.src.m .src-tag { background: var(--manual-soft); color: var(--manual); }
.src.w .src-tag { background: var(--web-soft); color: var(--web); }
.src-body { min-width: 0; flex: 1; }
.src-title { font-weight: 600; font-size: 14px; }
.src-sub { font-size: 12px; color: var(--muted); }
.src-quote { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.meta-line { margin-top: 10px; font-size: 12px; color: var(--muted); }
details.steps-done summary { cursor: pointer; }
details.steps-done ul { margin: 6px 0 0; padding-left: 18px; }

.progress { display: grid; gap: 6px; }
.progress-head { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.step { font-size: 14px; color: var(--muted); display: flex; gap: 8px; }
.step::before { content: "·"; font-weight: 800; }
.step.web { color: var(--web); }
.progress-time { font-size: 12px; color: var(--muted); }

.composer-wrap { flex: none; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px calc(8px + var(--safe-b)); }
.composer { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px; padding: 11px 16px;
  background: var(--bg); font-size: 16px; line-height: 1.4; max-height: 140px;
}
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.send:disabled { opacity: .4; }
.notice { max-width: 720px; margin: 6px auto 0; font-size: 11.5px; color: var(--muted); text-align: center; }

/* 메뉴 */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); z-index: 21; background: var(--surface);
  display: flex; flex-direction: column; padding: calc(10px + var(--safe-t)) 16px calc(12px + var(--safe-b));
  box-shadow: 4px 0 24px rgba(0, 0, 0, .15);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.drawer-user { font-weight: 700; }
.drawer-app { font-size: 13px; color: var(--muted); }
.drawer-label { font-size: 12px; font-weight: 700; color: var(--muted); margin: 18px 0 6px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; border-radius: 10px; }
.conv.active { background: var(--brand-soft); }
.conv-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 10px 8px; }
.conv-title { font-size: 15px; }
.conv-date { font-size: 12px; color: var(--muted); }
.conv-del { width: 36px; height: 36px; border: 0; background: none; color: var(--muted); border-radius: 8px; }
.drawer-foot { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; }

/* 시트 */
.sheet {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
.sheet.small-sheet { inset: auto 0 0 0; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 32px rgba(0, 0, 0, .2); padding-bottom: var(--safe-b); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet-title { flex: 1; min-width: 0; font-weight: 700; }
.pad { padding: 16px; }
.viewer-quote { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; padding: 10px 16px; font-size: 13px; background: var(--manual-soft); color: var(--text); border-bottom: 1px solid var(--line); }
.viewer-body { flex: 1; overflow: auto; background: #6b7472; -webkit-overflow-scrolling: touch; }
.viewer-body img { display: block; width: 100%; height: auto; background: #fff; }
.viewer-body pre { margin: 0; padding: 16px; white-space: pre-wrap; background: var(--surface); color: var(--text); font-size: 14px; min-height: 100%; }
.viewer-loading { color: #fff; padding: 40px 16px; text-align: center; }
.viewer-nav { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-top: 1px solid var(--line); }
.viewer-nav .btn { flex: none; }
.page-label { flex: 1; text-align: center; font-size: 14px; color: var(--muted); }
.viewer-links { display: flex; justify-content: center; gap: 24px; padding: 8px 0 calc(10px + var(--safe-b)); background: var(--surface); }
.viewer-file { display: block; text-align: center; color: var(--brand); font-size: 14px; padding: 4px 0; }
.excerpt {
  display: flex; gap: 12px; align-items: center; margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--brand); color: var(--brand-ink); text-decoration: none;
}
.excerpt .src-sub { display: block; color: inherit; opacity: .85; }
.excerpt-icon { flex: none; width: 36px; height: 36px; border-radius: 50%; background: rgba(255, 255, 255, .18); display: grid; place-items: center; }
.excerpt-link { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--brand); font-weight: 600; }

/* 관리자 */
.tabs { display: flex; gap: 4px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab.active { background: var(--brand-soft); color: var(--brand); }
.admin-body { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: calc(24px + var(--safe-b)); }
.admin-body > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .v.ok { color: var(--manual); }
.card .v.bad { color: var(--danger); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 8px; font-size: 15px; }
.panel p { margin: 0 0 8px; font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.list { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list > div { background: var(--surface); padding: 10px 12px; font-size: 14px; }
.list .sub { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 4px; }
.badge.bad { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--manual-soft); color: var(--manual); }
.user-row { display: flex; align-items: center; gap: 8px; }
.user-row .grow { flex: 1; min-width: 0; }
.user-row .btn { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.temp-pw { font: 600 18px/1.4 ui-monospace, Consolas, monospace; background: var(--warn-soft); color: var(--text); padding: 10px 12px; border-radius: 10px; margin: 8px 0; user-select: all; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.check input { width: auto; margin: 0; }
.qa-q { font-weight: 600; }
.qa-a { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 50;
  background: #1d2725; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
}

@media (min-width: 760px) {
  .cards { grid-template-columns: repeat(4, 1fr); }
  .sheet.small-sheet { inset: 10% auto auto 50%; transform: translateX(-50%); width: 420px; border-radius: 18px; }
}
.viewer-quote.open { -webkit-line-clamp: unset; display: block; }
