:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #1d2330;
  --muted: #5f6676;
  --line: #e3e1da;
  --accent: #ff9d00;
  --accent-ink: #1d2330;
  --hf: #ffd21e;
  --chat-bg: #b2c7da;
  --bubble: #ffffff;
  --bubble-me: #fee500;
  --bubble-ink: #111111;
  --chat-meta: #3b4a5a;
  --note-bg: #fff8d6;
  --note-ink: #4a3a00;
  --danger: #c92a2a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b; --surface: #1d2027; --ink: #e8eaf0; --muted: #a1a8b8; --line: #2e323c;
    --chat-bg: #3a4a5c; --chat-meta: #c4d0dc; --note-bg: #3a3214; --note-ink: #f5e6a8; --danger: #ff8787;
  }
}
:root[data-theme="dark"] {
  --bg: #14161b; --surface: #1d2027; --ink: #e8eaf0; --muted: #a1a8b8; --line: #2e323c;
  --chat-bg: #3a4a5c; --chat-meta: #c4d0dc; --note-bg: #3a3214; --note-ink: #f5e6a8; --danger: #ff8787;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.token-box input.need { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 30%, transparent); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.token-state { font-size: 13px; white-space: nowrap; }
.token-state.ok { color: #2b8a3e; }
.token-state.missing { color: var(--danger); font-weight: 700; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  word-break: keep-all; line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { padding: 20px 24px 8px; max-width: 1280px; margin: 0 auto; }
.top h1 { margin: 0 0 12px; font-size: 26px; }
.top h1 small { font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.token-box { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.token-box input[type="password"] { flex: 1 1 220px; min-width: 0; }
.token-help { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.inline { display: inline-flex; gap: 4px; align-items: center; font-size: 14px; white-space: nowrap; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; }
button, .file-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px;
  cursor: pointer; white-space: nowrap;
}
button:hover, .file-btn:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: progress; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; font-size: 17px; padding: 12px; width: 100%; }

.tabs { display: flex; gap: 4px; max-width: 1280px; margin: 8px auto 0; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; }
.tab.active { border-bottom-color: var(--accent); font-weight: 700; }

main { max-width: 1280px; margin: 0 auto; padding: 16px 24px 40px; }
.panel { display: none; }
.panel.active { display: block; }
.cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); gap: 20px; }
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.card.narrow { max-width: 760px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar select { flex: 1 1 200px; min-width: 0; }
.note { font-size: 13px; color: var(--muted); margin: 0; }

/* 카톡풍 채팅 */
.kchat {
  background: var(--chat-bg); border-radius: 16px; padding: 16px 14px; height: 560px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.kchat .row { display: flex; flex-direction: column; align-items: flex-start; }
.kchat .row.me { align-items: flex-end; }
.kchat .row.dim { opacity: .45; }
.kchat .name { font-size: 12px; color: var(--chat-meta); margin: 0 4px 3px; }
.kchat .line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.kchat .row.me .line { flex-direction: row-reverse; }
.kchat .bubble {
  background: var(--bubble); color: var(--bubble-ink); padding: 8px 12px; border-radius: 4px 14px 14px 14px;
  max-width: min(340px, 75vw); white-space: pre-wrap; word-break: break-word; font-size: 14px;
}
.kchat .row.me .bubble { background: var(--bubble-me); border-radius: 14px 4px 14px 14px; }
.kchat .bubble img { max-width: 220px; width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.kchat .meta { font-size: 11px; color: var(--chat-meta); white-space: nowrap; }
.kchat .start-marker { align-self: center; background: rgba(0,0,0,.25); color: #fff; font-size: 12px; padding: 3px 12px; border-radius: 999px; }
.kchat .empty { margin: auto; color: var(--chat-meta); }
.send { display: flex; gap: 8px; }
.send input { flex: 1; min-width: 0; }

.status { font-size: 14px; color: var(--muted); }
.status.error { color: var(--danger); }
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.pii { background: var(--note-bg); color: var(--note-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.context { font-size: 14px; gap: 4px; }
.context b { font-size: 15px; }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.rec { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; }
.rec .img-wrap { position: relative; background: #000; }
.rec img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.rec .badge { align-self: flex-start; background: var(--bg); color: var(--muted); border: 1px solid var(--line); font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.rec .note { font-size: 12px; color: var(--muted); }
.token-box + .token-box { margin-top: 8px; }
.token-box label small { color: var(--muted); font-weight: 400; }
.rec .body { padding: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; flex: 1; }
.rec h3 { margin: 0; font-size: 17px; }
.rec .caption { background: var(--note-bg); color: var(--note-ink); border-radius: 8px; padding: 6px 8px; }
.rec .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.rec .actions > * { font-size: 13px; padding: 6px 10px; text-decoration: none; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); }

fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; }
legend { padding: 0 6px; font-size: 14px; color: var(--muted); }
.choices { display: grid; gap: 8px; }
.choice { display: flex !important; flex-direction: row !important; gap: 10px !important; align-items: flex-start; padding: 8px; border-radius: 10px; cursor: pointer; }
.choice:hover { background: var(--bg); }
.choice small { display: block; color: var(--muted); }

.prose h2 { margin: 0; }
.prose h3 { margin: 12px 0 0; }
.prose p, .prose ul { margin: 0; }
.prose pre { background: var(--bg); padding: 10px; border-radius: 10px; white-space: pre-wrap; font-size: 13px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }

@media (max-width: 860px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .tabs { padding: 0 16px; }
  .cols { grid-template-columns: 1fr; }
  .kchat { height: 440px; }
}
