/* 토큰: 글자 13/14/16/20/24, 간격 4/8/12/16/24/32, 반경 6/10 */
:root {
  --bg: #f6f7f9;
  --surface: #fcfcfd;
  --ink: #15181d;
  --slate: #545c69;
  --faint: #646c78;
  --line: #d9dde3;
  --soft: #eef0f3;
  --accent: #2357e8;
  --accent-ink: #f7f9ff;
  --accent-soft: #e6ecfd;
  --pass: #157046;
  --pass-soft: #e2f2e9;
  --fail: #b8322a;
  --fail-soft: #fbe8e6;
  --wait: #8f5a0b;
  --wait-soft: #fbf0dc;
  --up: #b8322a;
  --down: #2357e8;
  --fs-xs: 13px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 24px;
  --r-sm: 6px;
  --r-md: 10px;
  --tap: 44px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --sans: "Pretendard", "Pretendard Variable", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #181c21;
    --ink: #e8ebef;
    --slate: #aab2bd;
    --faint: #8b939e;
    --line: #2e343c;
    --soft: #21262d;
    --accent: #7395f6;
    --accent-ink: #0c1222;
    --accent-soft: #1e2942;
    --pass: #55c891;
    --pass-soft: #142a1f;
    --fail: #f2837a;
    --fail-soft: #351a1a;
    --wait: #e4b457;
    --wait-soft: #2f2615;
    --up: #f2837a;
    --down: #8aa7f8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: clip; }
body { margin: 0; word-break: keep-all; overflow-wrap: break-word; font: var(--fs-md)/1.55 var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
h1, h2 { text-wrap: balance; }
p { text-wrap: pretty; }
.value { font-family: var(--mono); font-size: var(--fs-sm); }
.muted { color: var(--faint); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; top: -100px; left: 16px; z-index: 10; padding: 8px 16px; border-radius: var(--r-sm); background: var(--accent); color: var(--accent-ink); }
.skip:focus { top: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 레이아웃 ---------- */
.layout { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: 100dvh; }
.panel { display: flex; flex-direction: column; gap: 24px; padding: 24px; overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); }
.brand h1 { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin-top: 4px; color: var(--slate); font-size: var(--fs-sm); }
.section-title { margin-bottom: 12px; font-size: var(--fs-sm); font-weight: 700; color: var(--slate); }

/* ---------- 입력 ---------- */
.connect { display: flex; flex-direction: column; gap: 16px; }
.field label { display: block; margin-bottom: 4px; font-size: var(--fs-sm); font-weight: 600; }
.hint { margin-top: 4px; color: var(--faint); font-size: var(--fs-xs); }
.error { margin-top: 4px; color: var(--fail); font-size: var(--fs-xs); font-weight: 600; }
input, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: inherit;
}
input.value, textarea.value { font-family: var(--mono); font-size: var(--fs-sm); }
input:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--fail); }
.with-action { display: flex; gap: 8px; }
.with-action input { flex: 1; min-width: 0; }
.extra summary { display: flex; align-items: center; min-height: var(--tap); color: var(--slate); font-size: var(--fs-sm); cursor: pointer; }

button {
  min-height: var(--tap); padding: 8px 16px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: 600 var(--fs-sm)/1.4 var(--sans); cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--soft); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.danger { border-color: var(--fail); color: var(--fail); }
#connect-btn { font-size: var(--fs-md); }

/* ---------- 단계 레일: 이 화면에서 가장 눈에 띄어야 하는 부분 ---------- */
.steps { margin: 0; padding: 0; list-style: none; }
.step { position: relative; display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding-bottom: 16px; }
.step:last-child { padding-bottom: 0; }
.step::before { content: ""; position: absolute; top: 32px; bottom: 0; left: 15px; width: 2px; background: var(--line); }
.step:last-child::before { display: none; }
.step[data-state="pass"]::before { background: var(--pass); }
.dot { position: relative; display: grid; place-items: center; width: 32px; height: 32px; border: 2px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--faint); font-weight: 700; font-size: var(--fs-sm); transition: background-color .2s var(--ease), border-color .2s var(--ease); }
.dot::after { position: absolute; font-size: var(--fs-md); }
.step strong { display: block; padding-top: 4px; font-size: var(--fs-md); }
.step .detail { margin-top: 2px; color: var(--slate); font-size: var(--fs-sm); word-break: break-word; }
.step[data-state="run"] .dot { border-color: var(--accent); border-top-color: transparent; color: var(--accent); animation: spin .9s linear infinite; }
.step[data-state="run"] .num { animation: spin .9s linear infinite reverse; }
.step[data-state="pass"] .dot { border-color: var(--pass); background: var(--pass); color: var(--surface); }
.step[data-state="fail"] .dot { border-color: var(--fail); background: var(--fail); color: var(--surface); }
.step[data-state="warn"] .dot { border-color: var(--wait); background: var(--wait); color: var(--surface); }
.step[data-state="pass"] .num, .step[data-state="fail"] .num, .step[data-state="warn"] .num { visibility: hidden; }
.step[data-state="pass"] .dot::after { content: "✓"; }
.step[data-state="fail"] .dot::after, .step[data-state="warn"] .dot::after { content: "!"; }
.step[data-state="skip"] { opacity: .55; }
.step[data-state="fail"] .detail { color: var(--fail); }
.step[data-state="warn"] .detail { color: var(--wait); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .step[data-state="run"] .dot, .step[data-state="run"] .num { animation: none; }
  .dot { transition: none; }
}

/* ---------- Agent Card ---------- */
.card-info { padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); font-size: var(--fs-sm); }
.card-info .name { font-weight: 700; font-size: var(--fs-md); }
.card-info .desc { margin-top: 2px; color: var(--slate); }
.card-info .skills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.card-info .skills span { padding: 2px 8px; border-radius: var(--r-sm); background: var(--soft); color: var(--slate); font-size: var(--fs-xs); }

/* ---------- 세션 ---------- */
.sessions { padding-top: 16px; border-top: 1px solid var(--line); }
.sessions-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sessions-head .section-title { margin: 0; }
.sessions-head span { color: var(--faint); font-weight: 500; }
.row { display: flex; gap: 8px; }
.session-list { margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); }
.session-list button { display: block; width: 100%; padding: 8px 12px; border-color: transparent; background: none; text-align: left; font-weight: 500; }
.session-list button[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.session-list .s-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-list .s-meta { display: block; color: var(--faint); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

/* ---------- 채팅 ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; height: 100dvh; outline: none; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--surface); }
.chat-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.chat-title h2 { overflow: hidden; font-size: var(--fs-md); text-overflow: ellipsis; white-space: nowrap; }
.modes { display: flex; gap: 4px; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); }
.modes label { display: flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 4px; color: var(--slate); font-size: var(--fs-sm); cursor: pointer; }
.modes input { position: absolute; width: 1px; min-height: 0; opacity: 0; }
.modes label:has(input:checked) { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.modes label:has(input:focus-visible) { outline: 2px solid var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 24px; }
.empty { max-width: 400px; margin: 12vh auto 0; color: var(--slate); text-align: center; }
.empty-title { margin-bottom: 4px; color: var(--ink); font-size: var(--fs-lg); font-weight: 700; }
.msg { display: flex; margin-bottom: 16px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(720px, 88%); padding: 12px 16px; border-radius: var(--r-md); }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; word-break: break-word; border-bottom-right-radius: 4px; }
.msg.agent .bubble { width: min(720px, 88%); border: 1px solid var(--line); background: var(--surface); border-bottom-left-radius: 4px; }

.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 24px 16px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { max-height: 180px; resize: vertical; }
.composer-actions { display: flex; justify-content: flex-end; gap: 8px; }
.composer-actions #sample { margin-right: auto; }
.notice { margin: 0 24px 12px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--wait-soft); color: var(--wait); font-size: var(--fs-sm); }

/* ---------- 에이전트 응답 ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.badge { padding: 0 8px; border-radius: var(--r-sm); background: var(--soft); color: var(--slate); font-size: var(--fs-xs); line-height: 1.7; font-variant-numeric: tabular-nums; }
.badge.ok { background: var(--pass-soft); color: var(--pass); }
.badge.err { background: var(--fail-soft); color: var(--fail); }
.badge.warn { background: var(--wait-soft); color: var(--wait); }
.progress { margin: 0 0 8px; padding: 0; list-style: none; color: var(--slate); font-size: var(--fs-sm); }
.progress li::before { content: "· "; }
.progress li.done::before { content: "✓ "; color: var(--pass); }
.preview { margin-bottom: 8px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--bg); color: var(--slate); white-space: pre-wrap; }
.c-h1 { margin: 2px 0 8px; font-size: var(--fs-lg); font-weight: 700; }
.c-h2 { margin: 12px 0 4px; font-size: var(--fs-md); font-weight: 700; }
.c-sub { margin-bottom: 8px; color: var(--slate); font-size: var(--fs-sm); }
.c-primary { margin: 4px 0 8px; font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.c-msg { margin: 2px 0; white-space: pre-wrap; word-break: break-word; }
.c-disc { margin: 12px 0 2px; color: var(--faint); font-size: var(--fs-xs); white-space: pre-wrap; }
.c-divider { margin: 12px 0; border: 0; border-top: 1px solid var(--line); }
.c-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.c-metrics div { padding: 8px 12px; border-left: 2px solid var(--line); }
.c-metrics span { display: block; color: var(--slate); font-size: var(--fs-xs); }
.c-metrics b { font-variant-numeric: tabular-nums; }
.c-table-wrap { overflow-x: auto; }
.c-table { width: 100%; margin: 8px 0; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.c-table th, .c-table td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.c-table th { color: var(--slate); font-weight: 600; text-align: center; }
.c-table td:first-child { text-align: left; }
.c-code { margin: 8px 0; padding: 12px; overflow-x: auto; border-radius: var(--r-sm); background: var(--bg); font: var(--fs-xs)/1.5 var(--mono); white-space: pre; }
.c-code-lang { color: var(--faint); font-size: var(--fs-xs); }
.c-link a, .sources a { color: var(--accent); }
.tone-up { color: var(--up); }
.tone-down { color: var(--down); }
.tone-flat { color: var(--slate); }
.chart { display: block; width: 100%; height: 220px; margin: 8px 0; }
.chart .grid { stroke: var(--soft); }
.chart .axis { fill: var(--slate); font-size: 10px; }
.chart .up { stroke: var(--up); fill: var(--up); }
.chart .down { stroke: var(--down); fill: var(--down); }
.sources { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: var(--fs-sm); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions button { font-weight: 500; }
.waiting { margin: 8px 0; padding: 12px; border-radius: var(--r-sm); background: var(--accent-soft); }
.waiting .prompt { margin-bottom: 8px; font-weight: 600; white-space: pre-wrap; }
.waiting .options { display: flex; flex-wrap: wrap; gap: 8px; }
.waiting .options.stack { flex-direction: column; align-items: flex-start; }
.raw { margin-top: 12px; padding-top: 4px; border-top: 1px dashed var(--line); font-size: var(--fs-xs); }
.raw summary { padding: 4px 0; color: var(--slate); cursor: pointer; }
.raw summary:hover { color: var(--accent); }
.raw pre { max-height: 320px; margin: 4px 0 8px; padding: 8px; overflow: auto; border-radius: var(--r-sm); background: var(--bg); font: var(--fs-xs)/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; }
.more { display: block; margin: 0 auto 16px; }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 340px minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .panel { padding: 24px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat { height: 90dvh; }
  .chat-head, .messages, .composer { padding-left: 16px; padding-right: 16px; }
  .chat-head { flex-wrap: wrap; }
  .notice { margin-left: 16px; margin-right: 16px; }
}

abbr { text-decoration: none; }
