:root {
  color: #1f2723;
  background: #f4f3ee;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 243, 238, 0.96)),
    #f4f3ee;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1440px, calc(100vw - 24px));
  height: calc(100vh - 24px);
  margin: 0 auto;
  padding: 12px 0;
}

.topbar {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #d2d6d0;
  padding-bottom: 10px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow,
.section-kicker,
.dataset-menu-item span,
.dataset-menu-item small,
.query-card span,
.method-card small,
.evidence-box span,
.message-label,
.mini-stat small,
.file-name {
  color: #65726b;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd8d2;
  border-radius: 6px;
  background: #ffffff;
  color: #0f4b44;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.top-link:hover {
  border-color: #167064;
  background: #eef8f5;
  color: #0f3f39;
}

.page-view {
  min-width: 0;
  min-height: 0;
  padding-top: 12px;
}

.chat-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.chat-sidebar,
.chat-main {
  min-width: 0;
  min-height: 0;
  border: 1px solid #d4d8d2;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 16px 34px rgba(28, 38, 32, 0.06);
}

.chat-sidebar {
  display: grid;
  grid-template-rows: minmax(310px, 0.95fr) minmax(0, 1.05fr);
  overflow: hidden;
}

.sidebar-section {
  min-width: 0;
  min-height: 0;
  padding: 12px;
}

.dataset-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid #e3e5e1;
}

.eda-section {
  overflow: auto;
}

.section-title,
.eda-title,
.method-head,
.score-meter,
.file-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title h2,
.eda-title h2,
.section-title h3,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.section-title h2,
.eda-title h2 {
  font-size: 16px;
  line-height: 1.2;
}

.section-title h3 {
  font-size: 14px;
}

.dataset-menu {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.dataset-menu-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "kind extension"
    "title title";
  width: 100%;
  min-height: 76px;
  align-content: start;
  gap: 7px 10px;
  border: 1px solid #d9ddd7;
  border-radius: 8px;
  background: #fbfcfb;
  color: #1f2723;
  padding: 10px 11px;
  text-align: left;
}

.dataset-menu-item:hover,
.dataset-menu-item.is-active,
.query-card:hover,
.query-card.is-active {
  border-color: #167064;
  background: #eef8f5;
}

.dataset-menu-item strong {
  grid-area: title;
  font-size: 14px;
  line-height: 1.28;
  white-space: normal;
  overflow-wrap: anywhere;
}

.dataset-menu-item span {
  grid-area: kind;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dataset-menu-item small {
  grid-area: extension;
  justify-self: end;
  border: 1px solid #d2d9d4;
  border-radius: 999px;
  background: #ffffff;
  color: #173f38;
  padding: 2px 7px;
  line-height: 1.1;
}

.format-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid #ccd6d0;
  border-radius: 999px;
  background: #f6f8f6;
  color: #173f38;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.eda-empty,
.eda-card {
  display: grid;
  gap: 12px;
}

.eda-empty {
  min-height: 100%;
  align-content: center;
  color: #5a665f;
}

.eda-empty h2 {
  margin: 0;
  color: #1f2723;
  font-size: 22px;
  line-height: 1.1;
}

.eda-empty p,
.eda-card p {
  margin: 0;
  color: #536158;
  font-size: 13px;
  line-height: 1.45;
}

.sidebar-stats,
.welcome-stats,
.context-strip,
.token-ledger {
  display: grid;
  gap: 8px;
}

.sidebar-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.welcome-stats,
.context-strip {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.token-ledger {
  grid-template-columns: repeat(5, minmax(110px, 1fr));
}

.mini-stat {
  display: grid;
  min-height: 58px;
  align-content: center;
  gap: 3px;
  border: 1px solid #e0e4df;
  border-radius: 8px;
  background: #f8faf8;
  padding: 8px;
}

.mini-stat strong {
  color: #1f2723;
  font-size: 19px;
  line-height: 1;
}

.eda-block {
  display: grid;
  gap: 8px;
  border-top: 1px solid #edf0ed;
  padding-top: 11px;
}

.fit-list,
.term-list,
.sidebar-samples {
  display: grid;
  gap: 7px;
}

.fit-list span {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid #e1e6e1;
  border-radius: 8px;
  background: #f8faf8;
  color: #1f2723;
  padding: 7px;
  font-size: 13px;
  font-weight: 800;
}

.fit-list b {
  display: inline-grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: #167064;
  color: #ffffff;
  font-size: 11px;
}

.term-row {
  display: grid;
  grid-template-columns: minmax(64px, 92px) 1fr 28px;
  align-items: center;
  gap: 7px;
}

.term-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
}

.term-row i {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ecefeb;
}

.term-row b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #8b6f35;
}

.term-row em {
  color: #27372f;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  text-align: right;
}

.sample-card {
  display: grid;
  align-content: start;
  gap: 5px;
  border: 1px solid #e0e4df;
  border-radius: 8px;
  background: #fbfcfb;
  padding: 9px;
}

.sample-card span {
  color: #65726b;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.sample-card strong {
  color: #1f2723;
  font-size: 13px;
  line-height: 1.25;
}

.sample-card p {
  margin: 0;
  color: #536158;
  font-size: 12px;
  line-height: 1.4;
}

.eda-actions {
  display: grid;
}

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

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: 8px 8px 16px;
}

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 100%;
}

.user-message {
  justify-content: flex-end;
}

.avatar {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: #167064;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.message-bubble {
  display: grid;
  max-width: min(920px, 100%);
  gap: 10px;
  border: 1px solid #e0e4df;
  border-radius: 10px;
  background: #ffffff;
  padding: 13px;
}

.user-message .message-bubble {
  max-width: min(740px, 92%);
  border-color: #c5d8d2;
  background: #eaf6f3;
}

.message-bubble h3,
.message-bubble p {
  margin: 0;
}

.message-bubble h3 {
  font-size: 18px;
  line-height: 1.2;
}

.message-bubble p {
  color: #46544c;
  line-height: 1.5;
}

.processing-bubble {
  border-color: #c5d8d2;
  background: #f3faf8;
}

.processing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #173f38;
}

.processing-row strong {
  font-size: 14px;
}

.processing-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #167064;
  animation: processingPulse 900ms ease-in-out infinite;
}

.processing-dot:nth-child(2) {
  animation-delay: 120ms;
}

.processing-dot:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes processingPulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.query-option-panel {
  display: grid;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0;
}

.query-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 280px;
  overflow: auto;
}

.query-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(78px, 104px) minmax(0, 1fr) 26px;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 1px solid #d8ddd7;
  border-radius: 8px;
  background: #ffffff;
  color: #1f2723;
  padding: 7px 9px 7px 11px;
  text-align: left;
}

.query-card::after {
  position: static;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid #cbd8d2;
  border-radius: 999px;
  color: #167064;
  content: "\2192";
  font-size: 15px;
  font-weight: 900;
  opacity: 1;
  transform: none;
  transition:
    background 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.query-card:hover::after,
.query-card.is-active::after {
  background: #167064;
  color: #ffffff;
  transform: translateX(2px);
}

.query-card strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.chat-empty-space {
  flex: 1 1 auto;
  min-height: clamp(320px, 48vh, 620px);
}

.result-bubble {
  width: min(100%, 1060px);
}

.answer-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid #c5d8d2;
  border-radius: 8px;
  background: #eaf6f3;
  padding: 12px;
}

.answer-summary h3 {
  margin-top: 3px;
}

.answer-summary p {
  max-width: 620px;
}

.score-note {
  display: flex;
  gap: 8px;
  border: 1px solid #e0e4df;
  border-radius: 8px;
  background: #f9f7ee;
  color: #4d4534;
  padding: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.comparison-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(215px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.method-card {
  display: grid;
  min-width: 215px;
  align-content: start;
  gap: 10px;
  border: 1px solid #e0e4df;
  border-radius: 8px;
  background: #ffffff;
  padding: 11px;
}

.rank-badge {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 999px;
  background: #eef2ef;
  color: #173f38;
  font-size: 12px;
  font-weight: 900;
}

.method-card strong {
  display: block;
  color: #1f2723;
  line-height: 1.2;
}

.score-meter strong {
  color: #1f2723;
  font-size: 28px;
  line-height: 1;
}

.score-meter span {
  display: block;
  width: 100%;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0ee;
}

.score-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #167064;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.metric-grid span {
  display: grid;
  gap: 2px;
  border: 1px solid #edf0ee;
  border-radius: 7px;
  background: #fbfcfb;
  padding: 7px;
}

.metric-grid b {
  color: #1f2723;
  font-size: 14px;
}

.metric-grid small {
  color: #65726b;
  font-size: 11px;
  text-transform: uppercase;
}

.evidence-box {
  display: grid;
  gap: 5px;
  border-top: 1px solid #edf0ee;
  padding-top: 8px;
}

.evidence-box p {
  margin: 0;
  color: #536158;
  font-size: 12px;
  line-height: 1.4;
}

.chat-input-stack {
  display: grid;
  gap: 9px;
  border-top: 1px solid #e3e5e1;
  background: #fbfcfb;
  padding: 8px;
}

.input-toolbar {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.input-hint {
  color: #69766f;
  font-size: 12px;
  font-weight: 700;
}

.toolbar-button {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #cbd8d2;
  border-radius: 999px;
  background: #ffffff;
  color: #173f38;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.toolbar-button:hover {
  border-color: #167064;
  background: #eef8f5;
}

.toolbar-button span {
  color: #167064;
  font-size: 14px;
  line-height: 1;
}

.prompt-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  background: transparent;
  padding: 0;
}

.prompt-composer textarea {
  width: 100%;
  min-height: 70px;
  max-height: 140px;
  resize: vertical;
  border: 1px solid #d6ddd7;
  border-radius: 10px;
  background: #ffffff;
  color: #1f2723;
  padding: 16px 14px;
  line-height: 1.4;
}

.composer-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.download-button,
.primary-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.download-button {
  border: 1px solid #cbd4ce;
  background: #ffffff;
  color: #173f38;
}

.primary-button {
  border: 1px solid #167064;
  background: #167064;
  color: #ffffff;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  border: 1px solid #d4d8d2;
  border-radius: 10px;
  background: #ffffff;
  color: #5e6e67;
}

.empty-state h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.file-name {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
}

.file-preview {
  max-height: 460px;
  margin: 0;
  overflow: auto;
  border: 1px solid #d9e0dc;
  border-radius: 8px;
  background: #101815;
  color: #e9f0ed;
  padding: 14px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

@media (max-width: 1100px) {
  .chat-workspace {
    grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  }

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

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 16px, 1440px);
    height: auto;
    min-height: 100vh;
    padding-top: 8px;
  }

  .topbar,
  .answer-summary,
  .prompt-composer,
  .score-note {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-sidebar {
    grid-template-rows: auto auto;
    overflow: visible;
  }

  .dataset-menu {
    max-height: 360px;
  }

  .chat-main {
    min-height: 680px;
  }

  .prompt-composer {
    grid-template-columns: 1fr;
  }

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

  .toolbar-button {
    width: 100%;
  }

  .composer-actions {
    justify-content: stretch;
  }

  .composer-actions button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 12px;
  }

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

  .top-link {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  .sidebar-stats,
  .welcome-stats,
  .context-strip,
  .token-ledger,
  .query-grid {
    grid-template-columns: 1fr;
  }

  .chat-thread {
    padding: 12px;
  }

  .query-card {
    grid-template-columns: minmax(0, 1fr) 26px;
    align-items: start;
  }

  .query-card span {
    grid-column: 1 / -1;
  }

  .message-bubble,
  .user-message .message-bubble {
    max-width: 100%;
  }

  .term-row {
    grid-template-columns: minmax(68px, 86px) 1fr 28px;
  }
}
