:root {
  --bg: #f6f3ee;
  --bg-strong: #f0ebe2;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --surface-soft: rgba(255, 255, 255, 0.64);
  --ink: #181717;
  --muted: #63605b;
  --muted-strong: #4a4742;
  --line: rgba(24, 23, 23, 0.08);
  --line-strong: rgba(24, 23, 23, 0.14);
  --accent: #8a5d25;
  --accent-strong: #5f3c12;
  --accent-soft: rgba(138, 93, 37, 0.12);
  --assistant: rgba(255, 255, 255, 0.92);
  --user: linear-gradient(135deg, #23252a 0%, #33363c 100%);
  --success: #2a6a46;
  --danger: #b1462c;
  --shadow-lg: 0 30px 60px rgba(39, 32, 21, 0.12);
  --shadow-md: 0 16px 34px rgba(39, 32, 21, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --font-sans: "SUIT Variable", "Pretendard Variable", "Noto Sans KR", system-ui, sans-serif;
  --font-serif: "MaruBuri", "Noto Serif KR", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(138, 93, 37, 0.14), transparent 28%),
    radial-gradient(circle at bottom right, rgba(48, 76, 117, 0.1), transparent 32%),
    linear-gradient(160deg, #faf7f2 0%, #f2ede4 100%);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
  position: relative;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 16px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgba(244, 239, 231, 0.9);
  backdrop-filter: blur(24px);
  position: relative;
  z-index: 20;
}

.sidebar-head,
.section-label-row,
.topbar,
.topbar-left,
.topbar-actions,
.inspector-head,
.utility-actions {
  display: flex;
  align-items: center;
}

.sidebar-head,
.section-label-row,
.inspector-head,
.topbar {
  justify-content: space-between;
}

.sidebar-primary,
.send-button,
button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

.sidebar-primary,
.send-button {
  color: #fff8f1;
  background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 100%);
  box-shadow: 0 16px 28px rgba(95, 60, 18, 0.2);
}

.sidebar-primary {
  width: 100%;
  padding: 14px 18px;
  font-weight: 700;
  text-align: left;
}

.brand-panel,
.sidebar-section,
.chat-stage,
.inspector {
  border: 1px solid rgba(255, 255, 255, 0.56);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(26px);
}

.brand-panel,
.sidebar-section,
.inspector,
.chat-stage {
  border-radius: var(--radius-xl);
}

.brand-panel,
.sidebar-section {
  padding: 18px;
}

.brand-panel h1,
.topbar-copy h2,
.empty-state h3 {
  margin: 0;
  font-family: var(--font-serif);
  letter-spacing: -0.03em;
}

.brand-panel h1 {
  font-size: 1.95rem;
  line-height: 1;
  margin-bottom: 10px;
}

.eyebrow,
.section-label,
.panel-section h4 {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.section-meta,
.muted,
.brand-panel p,
.sidebar-section p,
.sidebar-section li,
.composer-hint,
.turn-subline,
.reference-item p,
.citation-card-meta,
.source-meta,
.source-excerpt {
  color: var(--muted);
  line-height: 1.55;
}

.conversation-list,
.source-list {
  display: grid;
  gap: 10px;
}

.conversation-item {
  width: 100%;
  padding: 14px 14px 12px;
  border-radius: 18px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.68);
  text-align: left;
  display: grid;
  gap: 6px;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.conversation-item:hover,
.conversation-item:focus-visible {
  border-color: rgba(138, 93, 37, 0.26);
  background: rgba(255, 255, 255, 0.92);
}

.conversation-item.is-active {
  border-color: rgba(138, 93, 37, 0.3);
  background: rgba(138, 93, 37, 0.1);
}

.conversation-item-title {
  font-weight: 700;
  color: var(--ink);
}

.conversation-item-meta {
  font-size: 0.84rem;
}

.conversation-item-preview {
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.main-shell {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 18px 20px 20px;
  gap: 16px;
}

.topbar {
  gap: 18px;
  padding: 4px 6px;
}

.topbar-left,
.topbar-actions,
.composer-toolbar,
.composer-controls,
.turn-actions,
.turn-header {
  gap: 10px;
}

.topbar-copy h2 {
  font-size: 1.28rem;
}

.topbar-copy .eyebrow {
  margin-bottom: 4px;
}

.icon-button,
.ghost-button {
  padding: 10px 14px;
  border: 1px solid rgba(138, 93, 37, 0.16);
  background: rgba(255, 255, 255, 0.76);
  color: var(--accent-strong);
  box-shadow: none;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.ghost-button:hover,
.icon-button:hover,
.sidebar-primary:hover,
.send-button:hover {
  transform: translateY(-1px);
}

.status-pill {
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 700;
}

.chat-shell {
  min-width: 0;
  display: grid;
  justify-items: center;
}

.chat-column {
  width: min(980px, 100%);
  min-width: 0;
}

.chat-stage {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.empty-state {
  margin: 0 auto;
  max-width: 720px;
  text-align: center;
  padding: 54px 24px 28px;
}

.empty-state h3 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  margin-top: 6px;
}

.empty-prompts {
  margin-top: 26px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.prompt-chip {
  padding: 11px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted-strong);
  box-shadow: none;
}

.prompt-chip:hover {
  border-color: rgba(138, 93, 37, 0.24);
  background: rgba(255, 255, 255, 0.92);
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 0 16px;
  scroll-padding-bottom: 32px;
}

.turn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 0 clamp(18px, 3vw, 26px);
}

.turn.user {
  align-items: flex-end;
}

.turn.assistant {
  align-items: stretch;
}

.turn-headline {
  max-width: 760px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.turn-headline .eyebrow {
  margin-bottom: 0;
}

.turn-actions {
  display: flex;
  align-items: center;
}

.turn-body {
  max-width: 760px;
  width: 100%;
  align-self: flex-start;
}

.turn.user .turn-body {
  align-self: flex-end;
  width: auto;
  max-width: min(760px, 84%);
}

.bubble {
  display: inline-block;
  width: auto;
  max-width: min(760px, 100%);
  padding: 16px 18px;
  border-radius: 24px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  background: var(--assistant);
  box-shadow: var(--shadow-md);
  animation: bubble-in 240ms ease forwards;
  overflow-wrap: anywhere;
}

.turn.user .bubble {
  background: var(--user);
  color: #f9f5ee;
}

.turn.user .bubble p {
  color: inherit;
}

.turn.assistant .bubble {
  width: 100%;
}

.turn-copy > *:first-child {
  margin-top: 0;
}

.turn-copy > *:last-child {
  margin-bottom: 0;
}

.turn-copy p,
.turn-copy ul {
  margin: 0 0 12px;
  line-height: 1.72;
  white-space: pre-wrap;
}

.turn-copy ul {
  padding-left: 20px;
}

.turn-copy h3 {
  margin: 18px 0 8px;
  font-size: 1rem;
  line-height: 1.4;
}

.turn-copy strong {
  color: var(--muted-strong);
}

.assistant-placeholder {
  display: grid;
  gap: 12px;
  padding: 2px 0;
}

.assistant-placeholder-line {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(138, 93, 37, 0.08) 0%, rgba(138, 93, 37, 0.18) 50%, rgba(138, 93, 37, 0.08) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.assistant-placeholder-line:nth-child(1) {
  width: 44%;
}

.assistant-placeholder-line:nth-child(2) {
  width: 92%;
}

.assistant-placeholder-line:nth-child(3) {
  width: 80%;
}

.assistant-status {
  font-size: 0.9rem;
  color: var(--muted);
}

.turn-subline {
  font-size: 0.86rem;
}

.citation-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 26px;
  margin: 0 3px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid rgba(138, 93, 37, 0.18);
  background: rgba(138, 93, 37, 0.08);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: none;
  vertical-align: baseline;
}

.citation-chip:hover,
.citation-chip:focus-visible,
.analysis-button:hover,
.analysis-button:focus-visible {
  background: rgba(138, 93, 37, 0.16);
  border-color: rgba(138, 93, 37, 0.28);
  transform: none;
}

.analysis-button {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(138, 93, 37, 0.16);
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent-strong);
  font-size: 0.84rem;
  box-shadow: none;
}

.turn-legend {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 8px;
}

.turn-legend-title {
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.reference-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.reference-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 28px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--accent-strong);
  background: rgba(138, 93, 37, 0.1);
}

.reference-item strong {
  display: block;
  margin-bottom: 3px;
}

.composer-shell {
  padding: 16px 22px 22px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(246, 243, 238, 0.4) 0%, rgba(246, 243, 238, 0.92) 36%, rgba(246, 243, 238, 1) 100%);
}

.composer-surface {
  border-radius: 28px;
  border: 1px solid rgba(24, 23, 23, 0.08);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 34px rgba(39, 32, 21, 0.08);
  padding: 16px;
}

textarea {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.62;
  padding: 0;
}

.composer-toolbar {
  margin-top: 12px;
  justify-content: space-between;
  align-items: flex-end;
}

.composer-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-field,
.compact-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(246, 243, 238, 0.96);
  border: 1px solid var(--line);
  color: var(--muted-strong);
}

.compact-field span,
.compact-check span {
  font-size: 0.88rem;
  font-weight: 700;
}

.compact-field select {
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
}

.compact-check input {
  margin: 0;
}

.send-button {
  min-width: 92px;
  padding: 12px 18px;
  font-weight: 700;
}

.composer-hint {
  margin: 10px 8px 0;
  font-size: 0.88rem;
}

.inspector {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(380px, calc(100vw - 36px));
  display: grid;
  grid-template-rows: auto 1fr;
  z-index: 30;
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms ease, opacity 220ms ease;
}

.app-shell.inspector-open .inspector {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.app-shell.inspector-open .chat-column {
  width: min(860px, 100%);
}

.inspector-head {
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.inspector-head h3 {
  margin: 0;
  font-family: var(--font-serif);
}

.inspector-scroll {
  overflow-y: auto;
  padding: 18px 20px 22px;
  display: grid;
  gap: 18px;
}

.panel-section h4 {
  margin-bottom: 8px;
}

.source-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(24, 23, 23, 0.06);
}

.source-card strong {
  display: block;
  margin: 6px 0 4px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(138, 93, 37, 0.12);
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
}

.citation-popover {
  position: fixed;
  z-index: 60;
  width: min(300px, calc(100vw - 24px));
  padding: 14px 15px;
  border-radius: 18px;
  background: rgba(23, 23, 23, 0.94);
  color: #f7f3ec;
  box-shadow: 0 24px 44px rgba(10, 10, 10, 0.3);
  pointer-events: none;
}

.citation-popover strong {
  display: block;
  margin: 6px 0 4px;
  color: #fffdf8;
}

.citation-card-meta {
  color: rgba(247, 243, 236, 0.78);
  font-size: 0.86rem;
}

.citation-card-snippet {
  margin-top: 8px;
  font-size: 0.92rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mobile-scrim {
  position: fixed;
  inset: 0;
  border: 0;
  background: rgba(18, 17, 16, 0.36);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 15;
}

.app-shell.sidebar-open .mobile-scrim,
.app-shell.inspector-open .mobile-scrim {
  opacity: 1;
  pointer-events: auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mobile-only {
  display: none;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(520px, 100%);
  padding: 32px;
  border-radius: 30px;
  background: var(--surface-strong);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.login-card h1 {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  letter-spacing: -0.03em;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.login-form label {
  font-size: 0.92rem;
  color: var(--accent-strong);
  font-weight: 700;
}

.login-form input {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  padding: 16px 18px;
  font: inherit;
  outline: none;
}

.login-form input:focus,
textarea:focus {
  box-shadow: 0 0 0 4px rgba(138, 93, 37, 0.08);
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

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

  .sidebar {
    position: fixed;
    top: 18px;
    left: 18px;
    bottom: 18px;
    width: min(320px, calc(100vw - 36px));
    transform: translateX(calc(-100% - 24px));
    transition: transform 220ms ease;
    z-index: 25;
  }

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

  .mobile-only {
    display: inline-grid;
  }

  .main-shell {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 820px) {
  .main-shell {
    padding: 14px;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .turn,
  .composer-shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .turn.user .turn-body {
    max-width: 100%;
  }

  .composer-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-controls {
    width: 100%;
  }

  .compact-field,
  .compact-check {
    flex: 1 1 auto;
  }

  .send-button {
    width: 100%;
  }

  .inspector {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: min(72vh, 720px);
    transform: translateY(calc(100% + 20px));
  }

  .app-shell.inspector-open .inspector {
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .empty-state {
    padding-top: 36px;
  }

  .empty-state h3 {
    font-size: 1.8rem;
  }

  .status-pill {
    order: -1;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .citation-popover {
    width: min(280px, calc(100vw - 20px));
  }
}
