:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6b7890;
  --line: #dfe5ef;
  --accent: #1f6feb;
  --accent-soft: #e8f0ff;
  --good: #137a4b;
  --good-soft: #e3f6ec;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #b42318;
  --bad-soft: #ffe9e7;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafd;
}

.main-nav .nav-link {
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.main-nav .nav-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.main-nav .nav-link.active {
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(23, 32, 51, 0.1);
  color: var(--accent);
}

.main-nav .nav-docs {
  border-left: 1px solid var(--line);
  border-radius: 0 7px 7px 0;
  margin-left: 4px;
  padding-left: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1f6feb, #2fb8a6);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand h1 span {
  color: var(--muted);
  font-weight: 600;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  color: var(--good);
  background: var(--good-soft);
  border-color: transparent;
}

.badge.degraded {
  color: var(--warn);
  background: var(--warn-soft);
  border-color: transparent;
}

.badge.down {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: transparent;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-badge {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ auth */

.auth-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(31, 111, 235, 0.12), transparent 35%),
    radial-gradient(circle at 85% 85%, rgba(47, 184, 166, 0.12), transparent 35%),
    var(--bg);
}

.auth-shell {
  width: 100%;
  max-width: 470px;
  padding: 24px;
}

.auth-card {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.12);
}

.auth-brand {
  margin-bottom: 18px;
}

.auth-nav {
  justify-content: center;
  margin-bottom: 24px;
  padding: 4px;
  background: #f8fafd;
}

.auth-nav .nav-link {
  flex: 1;
  text-align: center;
}

.auth-card h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.auth-lead {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.auth-form label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.auth-form input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-submit {
  margin-top: 14px;
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #1f6feb, #2b8fe0);
  color: #fff;
  font-weight: 800;
}

.auth-submit:disabled {
  cursor: progress;
  opacity: 0.65;
}

.auth-error {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bad-soft);
  color: var(--bad);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.auth-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.auth-foot {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.auth-link {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.auth-link:hover {
  text-decoration: underline;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 73px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
}

.sidebar,
.trace {
  padding: 16px;
  overflow: auto;
}

.sidebar-section + .settings-details {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfe;
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.icon-btn:hover,
button.secondary:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.settings-details {
  border: 0;
}

.settings-details + .settings-details {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.settings-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  list-style: none;
  text-transform: uppercase;
}

.settings-details summary::-webkit-details-marker {
  display: none;
}

.settings-details summary::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: var(--muted);
  transition: transform 120ms ease;
}

.settings-details[open] summary::before {
  transform: rotate(90deg);
}

.details-body {
  padding-top: 12px;
}

.small {
  font-size: 11px;
}

.session-list {
  display: grid;
  gap: 6px;
  max-height: 248px;
  overflow: auto;
  padding-right: 2px;
}

.session-item {
  display: flex;
  gap: 4px;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fbfcfe;
}

.session-item:hover {
  border-color: var(--line);
}

.session-item.active {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: var(--accent-soft);
}

.session-main {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 8px 9px;
  text-align: left;
}

.session-title {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  color: var(--muted);
  font-size: 10px;
}

.session-delete {
  width: 26px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 10px 10px 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.session-delete:hover {
  background: var(--bad-soft);
  color: var(--bad);
}

#exportBtn {
  margin-top: 8px;
}

h2 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: #fbfcfe;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button.primary,
.composer button {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

button.secondary {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fbfcfe;
  font-weight: 700;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.muted {
  color: var(--muted);
}

.samples {
  display: grid;
  gap: 8px;
}

.samples button {
  text-align: left;
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.samples button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.image-result {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
}

.image-result img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-bottom: 8px;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
}

.chat-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-title h2 {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.chat-title .muted {
  font-size: 11px;
}

button.secondary.compact {
  width: auto;
  margin-top: 0;
  padding: 6px 11px;
  font-size: 11px;
}

.messages {
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.empty strong {
  color: var(--ink);
  font-size: 15px;
}

.bubble {
  max-width: 88%;
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.bubble.active-turn {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 2px;
}

.bubble .answer {
  white-space: pre-wrap;
}

.bubble.error {
  align-self: flex-start;
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid transparent;
}

.bubble .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.chip.good {
  background: var(--good-soft);
  color: var(--good);
}

.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.cite {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.cite:hover {
  text-decoration: underline;
}

.cite.missing {
  color: var(--bad);
  text-decoration: line-through;
}

.context {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.context-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  font-size: 12px;
  line-height: 1.5;
}

.context-card:target,
.context-card.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.context-card.highlight {
  animation: context-flash 1.8s ease-out;
}

@keyframes context-flash {
  0% {
    background: var(--accent-soft);
  }
  100% {
    background: #fff;
  }
}

.context-card.selected {
  border-color: var(--accent);
}

.context-card .card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  margin-bottom: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.context-card .card-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.context-card .ranks {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-card .card-text {
  color: var(--ink);
  font-family: inherit;
}

.mini {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  color: var(--muted);
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
}

.mini:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
}

.composer textarea {
  resize: none;
  min-height: 46px;
  max-height: 180px;
  line-height: 1.5;
}

.trace-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.trace-head h2 {
  margin-bottom: 8px;
}

.trace-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfe;
}

.tab {
  flex: 1;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
}

.tab.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(23, 32, 51, 0.1);
}

.hidden {
  display: none !important;
}

.tree-head {
  display: grid;
  gap: 2px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  margin-bottom: 10px;
}

.tree-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree {
  position: relative;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 0 14px;
  list-style: none;
}

.tree::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: var(--line);
  content: "";
}

.tree-turn {
  position: relative;
}

.tree-turn::before {
  position: absolute;
  top: 15px;
  left: -10px;
  width: 7px;
  height: 1px;
  background: var(--line);
  content: "";
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  padding: 7px 8px;
  text-align: left;
}

.tree-node:hover,
.tree-turn.active .tree-node {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tree-index {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

.tree-label {
  flex: 1;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-details {
  margin: 4px 0 0 8px;
  color: var(--muted);
  font-size: 11px;
}

.tree-details summary {
  cursor: pointer;
  padding: 2px 0;
}

.tree-children {
  display: grid;
  gap: 3px;
  margin: 4px 0 6px;
  padding-left: 16px;
}

.tree-leaf {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: 11px;
  text-align: left;
}

.tree-link:hover {
  text-decoration: underline;
}

.chip.action {
  border: 0;
  cursor: pointer;
  font-family: inherit;
}

.chip.action:hover {
  filter: brightness(0.96);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}

#requestId {
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trace-body {
  font-size: 12px;
  line-height: 1.55;
}

.trace-block {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.trace-block:first-child {
  border-top: 0;
  padding-top: 0;
}

.trace-block h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 4px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  word-break: break-word;
}

.subqueries {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.gate {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.gate th,
.gate td {
  text-align: left;
  padding: 4px 4px;
  border-bottom: 1px solid var(--line);
}

.gate th {
  color: var(--muted);
  font-weight: 600;
}

.gate td.num {
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.ok-text {
  color: var(--good);
  font-weight: 700;
}

.bad-text {
  color: var(--bad);
  font-weight: 700;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 230px minmax(0, 1fr);
    height: auto;
  }

  .trace {
    grid-column: 1 / -1;
    max-height: 420px;
  }

  .chat {
    min-height: 60vh;
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    padding: 12px;
  }

  .main-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .top-actions {
    order: 2;
    margin-left: auto;
  }

  .auth-shell {
    padding: 14px;
  }

  .auth-card {
    padding: 22px;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .user-badge {
    max-width: 180px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .sidebar {
    order: 2;
  }

  .chat {
    order: 1;
    min-height: 65vh;
  }

  .trace {
    order: 3;
  }

  .bubble {
    max-width: 100%;
  }

  .session-list {
    max-height: 160px;
  }
}