:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8e0ea;
  --accent: #146ef5;
  --accent-ink: #ffffff;
  --danger: #c2410c;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background: var(--bg);
}

/* Sidebar: flush to the far left, full height. */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  min-height: 100vh;
}

.sidebar-brand h1 {
  font-size: 18px;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.session-list-header {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
}

/* Bottom-of-sidebar "reset all sessions for this user" — pinned below the list. */
.sidebar-reset {
  margin-top: auto;
  padding: 9px 10px;
  border: 1px solid var(--danger, #d9534f);
  border-radius: 8px;
  background: transparent;
  color: var(--danger, #d9534f);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.sidebar-reset:hover {
  background: var(--danger, #d9534f);
  color: #fff;
}

.session-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.session-item-open {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
}

.session-item-delete {
  flex: 0 0 auto;
  width: 28px;
  border: none;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 0 8px 8px 0;
}

.session-item-delete:hover {
  color: #fff;
  background: var(--danger, #d9534f);
}

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

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

.session-empty {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 16px;
  /* Center the chat column in the space to the right of the sidebar. */
  width: min(100%, 760px);
  margin: 0 auto;
}

/* Mobile top bar + sidebar toggle/close are desktop-hidden; shown only ≤760px. */
.mobile-topbar {
  display: none;
}

.sidebar-toggle {
  min-width: 40px;
  min-height: 40px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 20px;
  line-height: 1;
}

.sidebar-brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-close {
  display: none;
  min-width: 32px;
  min-height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* Show the mobile top bar with the hamburger toggle. */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 40;
  }

  .mobile-topbar-title {
    font-weight: 800;
    font-size: 15px;
  }

  /* Sidebar becomes an off-canvas drawer: hidden off the left edge by default,
     slid in when body carries .sidebar-open. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: min(82vw, 300px);
    height: 100vh;
    min-height: 100vh;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-block;
  }

  /* Dim backdrop behind the open drawer. */
  body.sidebar-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.4);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 2px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.icon-button,
.composer button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tab {
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 800;
}

.tab.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.segment {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.segment.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.segment.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.composer input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--ink);
}

.suggestion-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.suggestion-list button {
  flex: 0 0 auto;
  min-height: 38px;
  border-radius: 999px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
  white-space: nowrap;
}

.suggestion-list button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.suggestion-list button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}

.hitl-approval .hitl-preview {
  white-space: pre-line;
  margin: 0 0 6px;
  font-size: 13px;
}

.hitl-approval .hitl-question {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 13px;
}

/* An answered plan-confirmation stays in the feed as history, dimmed so it reads
   as a past turn rather than an open prompt awaiting a choice. */
.hitl-approval:not(.pending) {
  opacity: 0.7;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 160px;
}

.progress-bubble {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-text {
  transition: opacity 0.2s ease;
  animation: progress-fade-in 0.25s ease;
}

@keyframes progress-fade-in {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

.progress-dots {
  display: inline-flex;
  gap: 3px;
}

.progress-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: progress-blink 1s infinite ease-in-out;
}

.progress-dots i:nth-child(2) {
  animation-delay: 0.2s;
}

.progress-dots i:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes progress-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.bubble {
  max-width: 88%;
  border-radius: 14px;
  padding: 11px 12px;
  line-height: 1.45;
  font-size: 14px;
}

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

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

/* Markdown rendered inside assistant bubbles / section notes. Reset default
   block margins so the first/last element doesn't add stray padding, and give
   lists, code, and headings sane compact spacing inside the chat flow. */
.bubble.assistant > :first-child,
.card-section-text > :first-child {
  margin-top: 0;
}
.bubble.assistant > :last-child,
.card-section-text > :last-child {
  margin-bottom: 0;
}
.bubble.assistant p,
.card-section-text p {
  margin: 0 0 8px;
}
.bubble.assistant ul,
.bubble.assistant ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}
.bubble.assistant li {
  margin: 2px 0;
}
.bubble.assistant h1,
.bubble.assistant h2,
.bubble.assistant h3 {
  margin: 10px 0 6px;
  line-height: 1.3;
}
.bubble.assistant h1 {
  font-size: 17px;
}
.bubble.assistant h2 {
  font-size: 16px;
}
.bubble.assistant h3 {
  font-size: 15px;
}
.bubble.assistant code,
.card-section-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble.assistant pre {
  margin: 6px 0 8px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 8px;
  overflow-x: auto;
}
.bubble.assistant pre code {
  background: none;
  padding: 0;
}
.bubble.assistant a,
.card-section-text a {
  color: var(--accent);
  text-decoration: underline;
}

.suggestion-bubble {
  width: min(100%, 420px);
  max-width: 100%;
}

.suggestion-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

/* 후속질문: 감싼 박스 없이 칩만 노출. 폭 제한/배경 제거해 칩이 안 잘리게 한다. */
.followup-suggestions {
  width: 100%;
  max-width: 100%;
  background: transparent;
  border: none;
  padding: 0;
}

.followup-suggestions .suggestion-list {
  flex-wrap: wrap;
  overflow-x: visible;
  row-gap: 8px;
}

.cards {
  display: grid;
  gap: 10px;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.result-card button {
  width: 100%;
  min-height: 40px;
  margin-top: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 700;
}

.result-card.ondemand {
  text-align: center;
}

.result-card.ondemand .card-head {
  justify-content: center;
}

.card-cta-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.card-section-text {
  margin: 14px 0 2px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.card-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  background: #e7f0ff;
  color: #0f58ca;
  font-size: 11px;
  font-weight: 800;
}

.facts {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
}

.fact {
  display: grid;
  grid-template-columns: minmax(84px, 34%) 1fr;
  gap: 8px;
  font-size: 13px;
  line-height: 1.35;
}

.fact span:first-child {
  color: var(--muted);
}

.handoff {
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 14px;
  background: #fff7ed;
  color: #7c2d12;
}

.handoff h2 {
  margin: 0 0 6px;
  font-size: 17px;
}

.handoff p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.hidden {
  display: none;
}

/* 선택바: HITL·다지선다·명확화 질문의 선택지를 입력창 바로 위에 위→아래로 stack. */
.choice-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  bottom: 56px;
  padding: 8px 0 4px;
  background: var(--bg);
}

.choice-bar.hidden {
  display: none;
}

.choice-bar-title {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.choice-option {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

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

.choice-option.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.choice-option.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding: 8px 0 0;
  background: var(--bg);
}

.api-spec-panel,
.logs-panel {
  display: grid;
  gap: 10px;
}

.api-spec-panel.hidden,
.logs-panel.hidden {
  display: none;
}

.api-spec-panel h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.api-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.logs-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.flow-log-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.flow-log-card h2 {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: 0;
}

.flow-log-card p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.flow-log-card pre {
  margin: 8px 0 0;
  overflow-x: auto;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
}

/* Per-turn node flow: each node is a collapsible row, click to drill into its metadata. */
.flow-steps {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.flow-step-head {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: #f1f5f9;
  list-style-position: inside;
}

.flow-step[open] .flow-step-head {
  background: color-mix(in srgb, var(--accent) 12%, #f1f5f9);
}

.flow-step-error .flow-step-head {
  color: var(--danger, #d9534f);
  background: color-mix(in srgb, var(--danger, #d9534f) 12%, #f1f5f9);
}

.flow-step-body {
  margin: 2px 0 4px !important;
  font-size: 11px !important;
}

.api-contract-card,
.api-endpoint-card,
.api-auth-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.api-contract-card h3,
.api-endpoint-card h3,
.api-auth-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: 0;
}

.api-section-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.api-contract-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.api-endpoint-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.api-flow-grid,
.api-two-column,
.api-endpoint-list {
  display: grid;
  gap: 10px;
}

.api-flow-step,
.api-mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.api-flow-step span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 900;
}

.api-flow-step h4,
.api-mini-card h4 {
  margin: 8px 0 4px;
  font-size: 14px;
  line-height: 1.35;
}

.api-flow-step p,
.api-mini-card p,
.api-auth-card p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.api-callout {
  margin-top: 10px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
}

.api-table-wrap {
  margin-top: 10px;
  overflow-x: auto;
}

.api-schema-title {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.35;
}

.api-field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
}

.api-field-table th,
.api-field-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.api-field-table th {
  background: var(--surface-2);
  color: var(--ink);
}

.api-endpoint-meta {
  display: grid;
  grid-template-columns: minmax(72px, 24%) 1fr;
  gap: 6px 8px;
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.api-endpoint-meta dt {
  color: var(--muted);
  font-weight: 800;
}

.api-endpoint-meta dd {
  margin: 0;
  color: var(--ink);
}

@media (min-width: 760px) {
  /* .app-shell stays full width (sidebar + content grid); the content column
     centers its own chat area via margin auto. No 920px cap here anymore. */
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .api-flow-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .api-two-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
