:root {
  --bg-rose: #f8dbc8;
  --bg-peach: #f4bc9f;
  --bg-mist: #c7e4de;
  --ink: #2f3742;
  --ink-soft: #5d6670;
  --ink-faint: #7c8591;
  --panel: rgba(255, 250, 246, 0.62);
  --panel-strong: rgba(255, 248, 242, 0.88);
  --line: rgba(96, 104, 114, 0.2);
  --accent: #d1736f;
  --accent-2: #5f8995;
  --ok: #3e8a6f;
  --warn: #aa6242;
  --shadow: 0 10px 30px rgba(87, 54, 51, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(199, 228, 222, 0.9) 0%, rgba(248, 219, 200, 0.92) 32%, rgba(244, 188, 159, 0.9) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  backdrop-filter: blur(2px);
}

.sidebar {
  background: rgba(246, 236, 227, 0.65);
  border-right: 1px solid var(--line);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: "Cormorant Garamond", serif;
  font-size: 21px;
  font-weight: 700;
  background: linear-gradient(145deg, #ec8f86, #f8e9d8);
  color: #5d4140;
}

.brand h1 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 30px;
  line-height: 1;
}

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

.sidebar-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.sidebar-actions .icon-btn {
  width: 100%;
  height: 46px;
  border-radius: 16px;
}

.action-btn,
.mode-btn,
.recent-chat-item,
.icon-btn,
.send-btn,
.topk-select,
.tiny-btn {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.action-btn {
  padding: 12px;
  font-weight: 600;
}

.recent-chats {
  display: grid;
  gap: 10px;
}

.recent-chats h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.recent-chats-list {
  display: grid;
  gap: 8px;
}

.recent-chat-item {
  text-align: left;
  padding: 10px;
  border-radius: 12px;
}

.recent-chat-empty {
  font-size: 12px;
  color: var(--ink-soft);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #3ea27d;
}

.content {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr auto;
  min-height: 100vh;
  background:
    radial-gradient(110% 80% at 12% 8%, rgba(199, 228, 222, 0.34), transparent 56%),
    radial-gradient(90% 72% at 88% 14%, rgba(244, 188, 159, 0.34), transparent 54%),
    linear-gradient(120deg, rgba(255, 247, 239, 0.78), rgba(255, 236, 220, 0.66) 44%, rgba(242, 196, 171, 0.72) 100%);
  border-left: 1px solid rgba(96, 104, 114, 0.14);
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
}

.topbar h2 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 34px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
}

.mobile-only {
  display: none;
}

.hero {
  text-align: center;
  margin: 8px auto 12px;
  max-width: 780px;
  padding: 0 22px;
}

.hero h3 {
  margin: 0;
  font-size: clamp(26px, 3.8vw, 46px);
  font-family: "Cormorant Garamond", serif;
  line-height: 1.05;
}

.hero p {
  margin: 10px 0 0;
  color: var(--ink-soft);
}

.insight-strip {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 250, 246, 0.6);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.insight-left {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.scope-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.4);
}

.scope-btn {
  border-radius: 999px;
  padding: 5px 10px;
}

.scope-btn.active {
  background: rgba(95, 137, 149, 0.18);
  border-color: rgba(95, 137, 149, 0.4);
}

.mode-pill {
  border-radius: 999px;
  border: 1px solid rgba(95, 137, 149, 0.35);
  background: rgba(95, 137, 149, 0.12);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.evidence-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}

.evidence-pill.high {
  background: rgba(62, 138, 111, 0.16);
  border-color: rgba(62, 138, 111, 0.4);
  color: #285f4b;
}

.evidence-pill.medium {
  background: rgba(209, 160, 74, 0.18);
  border-color: rgba(209, 160, 74, 0.36);
  color: #7f6428;
}

.evidence-pill.low,
.evidence-pill.unknown {
  background: rgba(170, 98, 66, 0.15);
  border-color: rgba(170, 98, 66, 0.34);
  color: #7c4a33;
}

.topk-label {
  font-size: 12px;
  color: var(--ink-soft);
}

.topk-select {
  border-radius: 10px;
  padding: 6px 8px;
  min-width: 62px;
}

.tiny-btn {
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1;
}

.insight-right {
  font-size: 13px;
  color: var(--ink-soft);
}

.insight-right[data-tone="warn"] {
  color: var(--warn);
}

.score-explainer {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.48);
}

.score-explainer p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.pinned-sources,
.debug-panel {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
  padding: 10px 12px;
}

.upload-library {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
  padding: 10px 12px;
}

.upload-library-list {
  display: grid;
  gap: 6px;
}

.upload-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-main {
  display: grid;
  gap: 2px;
}

.upload-name {
  font-size: 13px;
  font-weight: 600;
}

.upload-meta {
  font-size: 12px;
  color: var(--ink-soft);
}

.upload-actions {
  display: inline-flex;
  gap: 6px;
}

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

.pinned-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pinned-item {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
  padding: 6px 10px;
  font-size: 12px;
}

.pinned-item a {
  color: inherit;
  text-decoration: none;
}

.pinned-item a:hover {
  text-decoration: underline;
}

.debug-panel pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.icon-btn.active {
  border-color: rgba(95, 137, 149, 0.48);
  background: rgba(95, 137, 149, 0.14);
}

.chat-thread {
  width: min(960px, 100% - 32px);
  margin: 0 auto;
  padding: 10px 0 120px;
  display: grid;
  gap: 14px;
}

.message {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  animation: rise 160ms ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, #6f9ead, #f0a2a0);
  box-shadow: var(--shadow);
}

.message.user .avatar {
  background: linear-gradient(145deg, #e38079, #f5bfaa);
}

.bubble-wrap {
  display: grid;
  gap: 8px;
}

.message.user .bubble-wrap {
  margin-left: 14px;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  color: var(--ink-faint);
  font-size: 12px;
}

.result-type-head {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  border: 1px solid rgba(95, 137, 149, 0.35);
  background: rgba(95, 137, 149, 0.14);
  color: #365966;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.bubble {
  margin: 0;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  line-height: 1.5;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
}

.message.user .bubble {
  border-color: rgba(209, 115, 111, 0.4);
}

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

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

.hybrid-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.hybrid-panel h5 {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hybrid-panel-body {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(95, 137, 149, 0.18);
  border-radius: 8px;
  padding: 8px;
}

.hybrid-panel-empty {
  margin: 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.hybrid-evidence-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.followup-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.followup-label {
  font-size: 12px;
  color: var(--ink-soft);
}

.followup-chip {
  border: 1px solid rgba(95, 137, 149, 0.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.citation-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  padding: 8px 10px;
  display: grid;
  gap: 8px;
}

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

.citation-lead {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.citation-rank {
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  background: rgba(95, 137, 149, 0.15);
  border: 1px solid rgba(95, 137, 149, 0.35);
  padding: 2px 8px;
}

.citation-path {
  font-size: 12px;
  color: var(--ink-soft);
}

.citation-score {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(209, 115, 111, 0.12);
  border: 1px solid rgba(209, 115, 111, 0.3);
  padding: 2px 8px;
}

.source-badge {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
}

.source-badge.repo {
  border-color: rgba(95, 137, 149, 0.42);
  background: rgba(95, 137, 149, 0.15);
}

.source-badge.upload,
.source-badge.temp-upload {
  border-color: rgba(209, 115, 111, 0.38);
  background: rgba(209, 115, 111, 0.14);
}

.citation-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.score-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(95, 137, 149, 0.18);
  overflow: hidden;
}

.score-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5f8995, #d1736f);
}

.citation-snippet {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-x: auto;
}

.citation-chip {
  justify-self: start;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.64);
  padding: 6px 10px;
  font-size: 12px;
}

body.compact-mode .citation-card .score-track,
body.compact-mode .citation-card .citation-snippet,
body.compact-mode .citation-card .toggle-snippet-btn {
  display: none;
}

.chat-input-wrap {
  position: sticky;
  bottom: 0;
  padding: 16px;
  background: linear-gradient(180deg, rgba(243, 221, 209, 0), rgba(243, 221, 209, 0.9) 32%);
}

.mode-row {
  width: min(960px, 100% - 16px);
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-btn {
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  line-height: 1;
}

.mode-btn.active {
  border-color: rgba(95, 137, 149, 0.44);
  background: rgba(95, 137, 149, 0.14);
  font-weight: 600;
}

.audit-launch-btn {
  border-color: rgba(209, 115, 111, 0.45);
  background: rgba(209, 115, 111, 0.12);
  font-weight: 600;
}

.audit-launch-btn.active {
  border-color: rgba(209, 115, 111, 0.55);
  background: rgba(209, 115, 111, 0.2);
}

.attachment-list {
  width: min(960px, 100% - 16px);
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}

.attachment-remove {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.chat-input {
  width: min(960px, 100% - 16px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: end;
  gap: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 8px;
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--ink);
  min-height: 44px;
  max-height: 180px;
  padding: 12px 8px;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  border-color: transparent;
  background: linear-gradient(145deg, var(--accent), #da8f89);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 38;
  background: rgba(32, 36, 43, 0.4);
}

.prompt-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(254, 248, 244, 0.97);
  box-shadow: 0 24px 56px rgba(39, 35, 35, 0.26);
  padding: 14px;
  display: grid;
  gap: 12px;
  z-index: 39;
}

.prompt-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.prompt-modal-head h3 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 34px;
}

.prompt-modal-head p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.prompt-modal-body {
  display: grid;
  gap: 14px;
}

.prompt-category {
  border-top: 1px solid rgba(96, 104, 114, 0.18);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.prompt-category h4 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: #49525c;
}

.prompt-chip-list {
  display: grid;
  gap: 8px;
}

.prompt-chip {
  border: 1px solid rgba(95, 137, 149, 0.32);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  text-align: left;
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  cursor: pointer;
}

.prompt-modal-foot {
  border-top: 1px solid rgba(96, 104, 114, 0.18);
  padding-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.prompt-modal-foot a {
  color: #2f5f6a;
  text-decoration: none;
  font-weight: 600;
}

.prompt-modal-foot a:hover {
  text-decoration: underline;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 36, 43, 0.36);
  z-index: 29;
}

.settings-drawer {
  position: fixed;
  right: 12px;
  top: 12px;
  width: min(360px, calc(100vw - 24px));
  background: rgba(254, 248, 244, 0.96);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(39, 35, 35, 0.22);
  padding: 14px;
  display: grid;
  gap: 14px;
  z-index: 30;
}

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

.settings-head h3 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 28px;
}

.settings-row {
  display: grid;
  gap: 8px;
  font-size: 14px;
}

.settings-note {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.settings-row output {
  font-size: 13px;
  color: var(--ink-soft);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn:hover,
.mode-btn:hover,
.recent-chat-item:hover,
.action-btn:hover,
.send-btn:hover,
.topk-select:hover,
.tiny-btn:hover,
.citation-chip:hover,
.followup-chip:hover,
.prompt-chip:hover {
  filter: brightness(0.98);
}

.icon-btn:disabled,
.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 82%;
    max-width: 320px;
    transform: translateX(-102%);
    transition: transform 0.25s ease;
    z-index: 20;
  }

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

  .mobile-only {
    display: grid;
  }

  .topbar {
    display: flex;
    padding: 14px 16px;
    justify-content: flex-start;
  }

  .topbar h2 {
    font-size: 30px;
  }

  .hero {
    margin-top: 0;
  }

  .chat-thread {
    width: calc(100% - 20px);
  }

  .chat-input,
  .mode-row,
  .attachment-list,
  .insight-strip,
  .score-explainer,
  .upload-library,
  .pinned-sources,
  .debug-panel {
    width: calc(100% - 8px);
  }

  .hybrid-panels {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar h2 {
    font-size: 26px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .hero h3 {
    font-size: 34px;
  }

  .message {
    grid-template-columns: 30px 1fr;
    gap: 8px;
  }

  .avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
  }

  .chat-input {
    grid-template-columns: auto 1fr auto auto auto;
    border-radius: 20px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
  }

  .message-meta {
    flex-wrap: wrap;
  }

  .message.user .bubble-wrap {
    margin-left: 8px;
  }

  .prompt-modal-head h3 {
    font-size: 30px;
  }
}
