:root {
  color-scheme: light;
  --ink: #17233b;
  --muted: #667085;
  --quiet: #8994a8;
  --line: #dce4f2;
  --surface: #ffffff;
  --surface-soft: #f5f8ff;
  --sidebar: #0b2558;
  --sidebar-soft: #153b7b;
  --accent: #256ef4;
  --accent-dark: #1758d4;
  --accent-soft: #e8f0ff;
  --warning: #f6c945;
  --danger: #b94040;
  --shadow: 0 22px 70px rgba(37, 110, 244, 0.13);
  --radius-lg: 24px;
  --radius-md: 16px;
  --sidebar-width: 284px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #eef3ff;
  font-family: "Noto Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: white;
  background: var(--accent-dark);
  border-radius: 8px;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  color: #f1f6ff;
  background:
    radial-gradient(circle at 20% 0%, rgba(74, 137, 255, 0.36), transparent 38%),
    var(--sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header {
  padding: 28px 20px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 24px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-logo {
  width: min(100px, 35%);
  height: auto;
  object-fit: contain;
}

.new-chat-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  color: #f7faff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  transition: background 160ms ease, border-color 160ms ease;
}

.new-chat-button:hover,
.new-chat-button:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

.history-heading {
  margin: 6px 20px 10px;
  color: rgba(238, 244, 255, 0.58);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.history-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.history-empty,
.sidebar-note {
  color: rgba(238, 244, 255, 0.5);
  font-size: 12px;
  line-height: 1.6;
}

.history-empty {
  padding: 10px;
}

.sidebar-note {
  margin: 0;
  padding: 16px 20px 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.history-item {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  border-radius: 11px;
}

.history-item:hover,
.history-item.is-active {
  background: rgba(255, 255, 255, 0.1);
}

.history-select {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 6px 10px 11px;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
}

.history-title {
  width: 100%;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  color: rgba(238, 244, 255, 0.46);
  font-size: 10px;
}

.history-delete {
  width: 30px;
  height: 30px;
  padding: 0;
  color: rgba(255, 255, 255, 0.52);
  background: transparent;
  border: 0;
  border-radius: 8px;
  opacity: 0;
}

.history-item:hover .history-delete,
.history-delete:focus-visible {
  opacity: 1;
}

.history-delete:hover {
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.main {
  position: relative;
  height: 100%;
  margin-left: var(--sidebar-width);
  background:
    linear-gradient(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.92)),
    radial-gradient(circle at 75% 12%, #dce8ff, transparent 40%);
}

.landing {
  display: grid;
  height: 100%;
  place-items: center;
  padding: 48px 24px;
}

.landing-content {
  width: min(720px, 100%);
  text-align: center;
}

.landing h1 {
  margin: 0;
  color: var(--accent);
  font-size: clamp(56px, 10vw, 96px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.055em;
  text-shadow: 0 16px 44px rgba(37, 110, 244, 0.2);
}

.landing-copy {
  margin: 20px auto 34px;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 17px);
  line-height: 1.8;
}

.landing-scan {
  position: relative;
  display: inline-block;
  color: var(--muted);
}

.landing-scan-glow {
  display: block;
  white-space: nowrap;
  filter: blur(1.5px);
  opacity: 0.5;
}

.landing-scan-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 25%;
  height: 100%;
  overflow: hidden;
  color: var(--accent);
  background-image:
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(to right, var(--accent), var(--accent)),
    linear-gradient(to right, var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(to right, var(--accent), var(--accent)),
    linear-gradient(to right, var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: top left, top left, bottom left, bottom left, bottom right, bottom right, top right, top right;
  background-size: 5px 1px, 1px 5px, 1px 5px, 5px 1px, 1px 5px, 5px 1px, 5px 1px, 1px 5px;
  animation: landing-scan-move 2.6s ease-in-out infinite alternate;
}

.landing-scan-text {
  display: block;
  width: 400%;
  white-space: nowrap;
  animation: landing-scan-text-move 2.6s ease-in-out infinite alternate;
}

@keyframes landing-scan-move {
  to { transform: translateX(300%); }
}

@keyframes landing-scan-text-move {
  to { transform: translateX(-75%); }
}

.landing-form,
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.landing-form {
  border-radius: 22px;
}

.landing-form:focus-within,
.composer:focus-within {
  border-color: rgba(37, 110, 244, 0.56);
  box-shadow: 0 0 0 4px rgba(37, 110, 244, 0.1), var(--shadow);
}

textarea {
  min-width: 0;
  flex: 1;
  max-height: 144px;
  padding: 9px 0;
  resize: none;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.6;
}

textarea::placeholder {
  color: var(--quiet);
}

.primary-send,
.send-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: white;
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  transition: transform 140ms ease, background 140ms ease;
}

.primary-send {
  width: 48px;
  height: 48px;
  font-size: 23px;
}

.primary-send:hover,
.send-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.landing-hint {
  margin-top: 16px;
  color: var(--quiet);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.chat {
  display: grid;
  height: 100%;
  grid-template-rows: auto 1fr auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 28px;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.chat-header > div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.chat-header > span {
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #27aa75;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(39, 170, 117, 0.12);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 38px max(28px, calc((100% - 920px) / 2)) 44px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  width: 100%;
  margin-bottom: 28px;
}

.message--user {
  flex-direction: column;
  align-items: flex-end;
}

.message--assistant {
  align-items: flex-start;
  gap: 12px;
}

.kaia-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  color: white;
  background: var(--accent-dark);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.assistant-body {
  min-width: 0;
  width: min(780px, calc(100% - 44px));
}

.message-bubble {
  font-size: 14px;
  line-height: 1.78;
}

.message-bubble--user {
  max-width: min(680px, 86%);
  padding: 12px 16px;
  color: white;
  background: var(--accent-dark);
  border-radius: 18px 18px 5px 18px;
  white-space: pre-wrap;
}

.message-bubble--assistant {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px 18px 18px 18px;
  box-shadow: 0 10px 32px rgba(37, 71, 132, 0.08);
}

.message-bubble--error {
  color: #7e2929;
  background: #fff7f7;
  border-color: #f0caca;
}

.message-time {
  display: block;
  margin-top: 7px;
  color: var(--quiet);
  font-size: 10px;
}

.message--user .message-time {
  text-align: right;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 1.1em 0 0.45em;
  line-height: 1.4;
}

.markdown-body h1 { font-size: 1.35em; }
.markdown-body h2 {
  color: var(--accent-dark);
  font-size: 1.2em;
}
.markdown-body h3 { font-size: 1.08em; }

.markdown-body .answer-category {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.62em;
  font-weight: 600;
  vertical-align: 0.18em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body table,
.markdown-body blockquote {
  margin: 0.7em 0;
}

.markdown-body pre,
.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.markdown-body code {
  padding: 0.12em 0.35em;
  background: var(--surface-soft);
  border-radius: 5px;
}

.markdown-body pre {
  overflow: auto;
  padding: 14px;
  background: #f2f6fd;
  border-radius: 10px;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--line);
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 14px;
  color: var(--muted);
  border-left: 3px solid var(--accent);
}

.citation-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.citation-card {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-align: left;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.citation-card:hover,
.citation-card:focus-visible {
  background: var(--accent-soft);
  border-color: rgba(37, 110, 244, 0.34);
}

.citation-card-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.citation-card-copy strong {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-card-copy small {
  color: var(--muted);
  font-size: 9px;
}

.thinking-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  padding: 14px 17px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px 16px 16px 16px;
  box-shadow: 0 10px 32px rgba(37, 71, 132, 0.08);
  font-size: 13px;
}

.thinking-spinner {
  width: 17px;
  height: 17px;
  border: 2px solid #d8e3f6;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.composer-shell {
  padding: 18px max(28px, calc((100% - 920px) / 2)) 20px;
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.96) 25%);
}

.composer {
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(37, 71, 132, 0.11);
}

.send-button {
  width: 42px;
  height: 42px;
  font-size: 20px;
}

.send-button:disabled {
  cursor: not-allowed;
  background: #aab8d1;
  transform: none;
}

.composer-shell > p {
  margin: 8px 0 0;
  color: var(--quiet);
  text-align: center;
  font-size: 10px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 10px;
  /* The grid centres the line box, not the glyph inside it, so an inherited
     body line-height left the ☰ and × sitting low in the button. Setting it
     here fixes every glyph button at once, and because line-height inherits it
     also covers a text node an in-app browser translator has wrapped in its own
     element. */
  line-height: 1;
  font-size: 21px;
}

.mobile-menu img {
  width: 16px;
  height: 20px;
  object-fit: contain;
}

.mobile-menu,
.sidebar-close {
  display: none;
}

.evidence-viewer {
  width: min(1180px, calc(100vw - 32px));
  height: min(900px, calc(100vh - 32px));
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: 0 34px 110px rgba(8, 31, 74, 0.34);
}

.evidence-viewer::backdrop {
  background: rgba(8, 27, 63, 0.68);
  backdrop-filter: blur(5px);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.viewer-header p {
  margin: 0 0 3px;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.viewer-header h2 {
  max-width: min(800px, 70vw);
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-body {
  height: calc(100% - 76px);
  overflow: auto;
  background: #eef3fb;
}

.pdf-panel {
  min-height: 100%;
  padding: 58px 16px 30px;
}

.pdf-toolbar {
  position: absolute;
  z-index: 2;
  top: 82px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 9px;
  background: rgba(18, 52, 112, 0.94);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(8, 31, 74, 0.22);
  transform: translateX(-50%);
}

.pdf-toolbar button {
  width: 30px;
  height: 30px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  border: 0;
  border-radius: 8px;
}

.pdf-toolbar button:disabled {
  cursor: default;
  opacity: 0.35;
}

.pdf-toolbar span {
  min-width: 72px;
  color: white;
  text-align: center;
  font-size: 11px;
}

.pdf-stage {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  background: white;
  box-shadow: 0 12px 45px rgba(23, 48, 40, 0.18);
}

.pdf-stage canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.text-evidence {
  width: min(760px, calc(100% - 40px));
  margin: 60px auto;
  padding: 30px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.text-evidence h3 {
  margin: 14px 0 16px;
  font-size: 20px;
}

.text-evidence p {
  margin: 0;
  color: #384540;
  line-height: 1.9;
  white-space: pre-wrap;
}

.evidence-kind {
  display: inline-flex;
  padding: 4px 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
}

.viewer-error {
  color: var(--danger) !important;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  .sidebar {
    width: min(86vw, 310px);
    visibility: hidden;
    transform: translateX(-102%);
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }

  .sidebar.is-open {
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: block;
    visibility: hidden;
    background: rgba(7, 26, 19, 0.52);
    opacity: 0;
    transition: opacity 180ms ease, visibility 180ms ease;
  }

  .sidebar-backdrop.is-open {
    visibility: visible;
    opacity: 1;
  }

  .main {
    margin-left: 0;
  }

  .mobile-menu,
  .sidebar-close {
    display: grid;
  }

  .mobile-menu {
    position: fixed;
    z-index: 10;
    top: 12px;
    left: 12px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--line);
  }

  .sidebar-close {
    position: absolute;
    top: 18px;
    right: 14px;
  }

  .chat-header {
    padding-left: 62px;
  }

  .messages,
  .composer-shell {
    padding-right: 18px;
    padding-left: 18px;
  }
}

@media (max-width: 560px) {
  .landing {
    padding: 70px 16px 30px;
  }

  .landing-copy {
    max-width: 320px;
    margin-bottom: 26px;
  }

  .landing-form {
    padding-left: 14px;
    border-radius: 18px;
  }

  .messages {
    padding-top: 26px;
  }

  .message--assistant {
    gap: 8px;
  }

  .kaia-avatar {
    width: 28px;
    height: 28px;
  }

  .assistant-body {
    width: calc(100% - 36px);
  }

  .message-bubble--assistant {
    padding: 15px;
  }

  .message-bubble--user {
    max-width: 92%;
  }

  .citation-list {
    grid-template-columns: 1fr;
  }

  .chat-header > span {
    display: none;
  }

  .evidence-viewer {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .viewer-header h2 {
    max-width: 72vw;
  }

  .text-evidence {
    padding: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 카카오톡 인앱 브라우저에서 오른쪽이 잘리던 폭 보정. 진단용 빨간 테두리는 제거함. */
.chat,
.composer-shell,
.composer {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.landing,
.landing-content,
.landing-form {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.landing-scan {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
