:root {
  --bg: #f4f8fb;
  --card: #ffffff;
  --ink: #102a43;
  --muted: #627d98;
  --line: #d9e2ec;
  --brand: #0b7285;
  --brand-2: #0d5f70;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1000px 500px at 10% -10%, #d8f0ff 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #d7f5f3 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
}

.app-layout {
  max-width: 1400px;
  margin: 24px auto;
  padding: 0 16px 26px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
}

.sidebar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 10px 24px rgba(16, 42, 67, 0.07);
  margin-top: 92px;   /* drop the sidebar below the top tab row on the right */
  max-height: calc(100vh - 148px);
  overflow: auto;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.sidebar-top h2 {
  margin: 0;
  font-size: 1rem;
}

#new-conv-btn,
.conv-new {
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
}

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

.conv-item {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
}

.conv-item.active {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.conv-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #0b3d4f;
}

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

.conv-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.conv-export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 18px;
  border-radius: 6px;
  color: #1f6f8b;
  font-size: 11px;
  line-height: 1;
  user-select: none;
  border: 1px solid #d4e7ef;
  background: #f4fbff;
  padding: 0 6px;
}

.conv-export:hover {
  color: #0b7285;
  border-color: #9fd3e6;
  background: #e9f7ff;
}

.conv-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  color: #8a9fb3;
  font-size: 14px;
  line-height: 1;
  user-select: none;
}

.conv-delete:hover {
  color: #b42318;
  background: #fff1f2;
}

.conv-time {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-image {
  cursor: zoom-in;
}

body.lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 18, 32, 0.82);
  padding: 22px;
}

.image-lightbox.active {
  display: flex;
}

.image-lightbox-inner {
  position: relative;
  width: min(96vw, 1600px);
  max-height: 94vh;
  display: grid;
  grid-template-rows: auto auto;
  justify-items: center;
}

.image-lightbox-img {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
  background: #fff;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
}

.image-lightbox-close {
  position: absolute;
  top: -14px;
  right: -8px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
  color: #0b1f34;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.image-lightbox-caption {
  margin-top: 10px;
  color: #e5edf5;
  font-size: 0.9rem;
  text-align: center;
}

.conv-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.main {
  min-width: 0;
}

.search-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 24px rgba(16, 42, 67, 0.07);
}

.panel-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
}

.help-wrap {
  position: relative;
}

.help-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  font-weight: 700;
}

.help-tip {
  position: absolute;
  top: 30px;
  right: 0;
  width: 290px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 10px 20px rgba(16, 42, 67, 0.15);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: 0.15s;
  font-size: 0.88rem;
}

.help-wrap:hover .help-tip {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.help-tip p {
  margin: 6px 0;
}

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
}

.search-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input {
  border: 1px solid var(--line);
  border-radius: 10px;
  height: 42px;
  padding: 0 12px;
  font-size: 0.95rem;
}

button[type="submit"] {
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0 16px;
  cursor: pointer;
}

button[type="submit"]:hover {
  background: var(--brand-2);
}

.advanced {
  margin-top: 10px;
}

.chat-hint {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.advanced summary {
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
}

.advanced-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.checkbox-line input {
  width: auto;
  height: auto;
}

.selection-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fbff;
}

.selection-panel.hidden {
  display: none;
}

.selection-help {
  color: var(--ink);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.selection-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.selection-row button[type="button"] {
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0 14px;
  height: 42px;
  cursor: pointer;
}

.chat-panel {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(16, 42, 67, 0.07);
  min-height: 520px;
}

.chat-panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.viz-panel {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 10px 24px rgba(16, 42, 67, 0.07);
}

.viz-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.viz-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.viz-image {
  display: block;
  width: 100%;
  max-height: 620px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef5fb;
}

.chat-history {
  display: grid;
  gap: 8px;
  max-height: 640px;
  overflow: auto;
}

.chat-msg {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.chat-msg.user {
  background: #f3fbff;
}

.chat-msg.assistant {
  background: #f7fff7;
}

.chat-role {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.chat-image-wrap {
  margin: 8px 0 2px;
}

.chat-image {
  display: block;
  width: 100%;
  max-height: 620px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef5fb;
}

.chat-image-colorbar {
  width: min(200px, 45%);
  max-height: none;
}

.results-banner {
  display: none;
}

.selection-row .ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.selection-error {
  min-height: 18px;
  color: #b42318;
  font-size: 0.82rem;
  margin-top: 6px;
}

.status {
  margin: 12px 2px 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.results-banner {
  margin: 12px 0 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.results-banner h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.raw-panel {
  margin: 6px 0 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.raw-panel summary {
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
}

.dataset-selection-panel {
  margin: 6px 0 12px;
  background: #fff;
  border: 1px solid #9fd3e6;
  border-radius: 12px;
  padding: 10px 12px 12px;
  box-shadow: 0 8px 20px rgba(11, 114, 133, 0.08);
}

.dataset-selection-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--brand);
  font-weight: 700;
  cursor: pointer;
}

.dataset-selection-countdown {
  min-width: 58px;
  border-radius: 999px;
  background: #e9f7fb;
  color: #075666;
  padding: 3px 9px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.dataset-selection-countdown.expired {
  background: #fff1f2;
  color: #b42318;
}

.dataset-selection-intro,
.dataset-selection-reason {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.dataset-selection-reason:empty {
  display: none;
}

.dataset-selection-candidates {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.dataset-candidate {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
}

.dataset-candidate:hover,
.dataset-candidate.selected {
  border-color: var(--brand);
  background: #f1fbfd;
}

.dataset-candidate input {
  margin-top: 4px;
  accent-color: var(--brand);
}

.dataset-candidate-title {
  color: #0b3d4f;
  font-size: 0.92rem;
  font-weight: 650;
}

.dataset-candidate-meta,
.dataset-candidate-snippet {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.dataset-recommended-badge {
  display: inline-block;
  margin-left: 7px;
  border-radius: 999px;
  background: #dff6e8;
  color: #176b3a;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.dataset-selection-pagination,
.dataset-selection-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.dataset-selection-pagination button,
.dataset-selection-actions button {
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 7px 12px;
  font-weight: 600;
  cursor: pointer;
}

.dataset-selection-pagination button {
  background: #fff;
  color: var(--brand);
}

.dataset-selection-actions .secondary-action {
  background: #fff;
  color: var(--brand);
}

.dataset-selection-pagination button:disabled,
.dataset-selection-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.raw-output {
  margin: 8px 0 0;
  max-height: 280px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.final-answer {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  font-size: 0.86rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.results-col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 220px;
}

.results-col > summary {
  color: var(--brand);
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 10px;
}

h2 {
  margin: 2px 0 10px;
  font-size: 1rem;
}

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

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #0b3d4f;
}

.meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.snippet {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.35;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .results-grid {
    grid-template-columns: 1fr;
  }
  .advanced-grid {
    grid-template-columns: 1fr;
  }
}

.panel-hidden {
  display: none !important;
}
