:root {
  /* Professional “shining” theme */
  --bg0: #f6f7fb;
  --bg1: #eef2ff;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --border: rgba(17, 24, 39, 0.1);
  --border-strong: rgba(17, 24, 39, 0.14);

  --text: #0f172a;
  --muted: rgba(15, 23, 42, 0.62);

  --accent: #6366f1; /* indigo */
  --accent-2: #22c55e; /* green (subtle secondary) */
  --accent-ink: #ffffff;

  --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.06);
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.1);
  --shadow-glow: 0 0 0 4px rgba(99, 102, 241, 0.18);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background: radial-gradient(1200px 800px at 15% 10%, rgba(99, 102, 241, 0.18), transparent 55%),
    radial-gradient(900px 700px at 85% 0%, rgba(34, 197, 94, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
}

::selection {
  background: rgba(99, 102, 241, 0.22);
}
.wrap {
  max-width: none;
  margin: 0 auto;
  padding: 18px;
  min-height: 100vh;
  height: 100vh;
  display: flex;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.72));
  position: relative;
}

header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.55), rgba(34, 197, 94, 0.25), transparent);
  pointer-events: none;
}

header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0.2px;
}
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}
.meta {
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  flex-basis: 100%;
}
#messages {
  padding: 14px 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: radial-gradient(900px 600px at 20% 0%, rgba(99, 102, 241, 0.07), transparent 55%),
    radial-gradient(800px 600px at 90% 40%, rgba(34, 197, 94, 0.05), transparent 55%);
}

#messages::-webkit-scrollbar {
  width: 10px;
}
#messages::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.14);
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.65);
}
#messages::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.2);
}
.msg {
  margin: 10px 0;
  display: flex;
}
.bubble {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  max-width: 88%;
  border: 1px solid rgba(17, 24, 39, 0.08);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.user {
  justify-content: flex-end;
}
.user .bubble {
  color: var(--accent-ink);
  border-color: rgba(99, 102, 241, 0.22);
  background: linear-gradient(135deg, rgba(99, 102, 241, 1), rgba(79, 70, 229, 1));
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.assistant {
  justify-content: flex-start;
}
.assistant .bubble {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  border-color: rgba(17, 24, 39, 0.1);
}
.assistant .bubble.wide {
  max-width: 100%;
  width: 100%;
}

/* Side-by-side A/B assistant answers */
.msg.ab {
  gap: 10px;
  width: 100%;
  align-items: stretch;
}
.msg.ab .bubble {
  max-width: 100%;
  flex: 1 1 0;
  min-width: 0;
}
.ab-title {
  color: #6b7280;
  font-size: 12px;
  margin: 0 0 6px;
}
@media (max-width: 720px) {
  .msg.ab .ab-body {
    min-width: 0;
    overflow-x: auto;
  }
  .msg.ab {
    flex-direction: column;
  }
}

.bubble pre {
  overflow-x: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
}

.bubble blockquote {
  margin: 0.6em 0;
  padding: 0.6em 0.8em;
  border-left: 4px solid rgba(15, 23, 42, 0.16);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 10px;
}

.bubble blockquote.citation {
  border-left-color: rgba(99, 102, 241, 0.95);
}
.bubble blockquote p {
  margin: 0.25em 0;
}
footer {
  padding: 12px 16px;
  overflow-wrap: anywhere;
  word-break: break-word;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

textarea {
  flex: 1;
  resize: none;
  height: 48px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

textarea::placeholder {
  color: rgba(15, 23, 42, 0.42);
}

textarea:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.55);
  box-shadow: var(--shadow-glow);
  background: rgba(255, 255, 255, 0.95);
}

button {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 120ms ease, box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.1);
}

button:active {
  transform: translateY(0px);
  box-shadow: var(--shadow-sm);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
}

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

/* Primary/secondary actions */
#send {
  color: var(--accent-ink);
  border-color: rgba(99, 102, 241, 0.35);
  background: linear-gradient(135deg, rgba(99, 102, 241, 1), rgba(79, 70, 229, 1));
  box-shadow: 0 14px 26px rgba(79, 70, 229, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

#send:hover {
  box-shadow: 0 18px 34px rgba(79, 70, 229, 0.26), 0 0 0 5px rgba(99, 102, 241, 0.12);
}

#clear,
#follow {
  background: rgba(255, 255, 255, 0.92);
}
.meta {
  padding: 0 16px 12px;
  color: var(--muted);
  font-size: 12px;
}

a {
  color: inherit;
}

/* Modal (chunks viewer) */
.hidden {
  display: none !important;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal {
  width: min(980px, 100%);
  max-height: min(80vh, 900px);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 22px 70px rgba(2, 6, 23, 0.35);
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.84));
}

.modal-title {
  font-weight: 650;
}

.modal-close {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

.modal-meta {
  padding: 10px 16px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 12px 16px;
  overflow: auto;
}
.settings-textarea {
  width: 100%;
  height: 40vh;
  min-height: 260px;
  resize: vertical;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}
.chunk {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 10px 0;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-sm);
}
.chunk-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.chunk-file {
  font-weight: 600;
}
.chunk-score {
  color: #6b7280;
  font-size: 12px;
}
.chunk-text {
  white-space: pre-wrap;
  margin: 0;
}

/* Sub-questions block (chunks viewer) */
.subq {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 10px 0;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-sm);
}

.subq-title {
  font-weight: 650;
  margin-bottom: 8px;
}
.subq-list {
  margin: 0;
  padding-left: 18px;
}
.subq-item {
  margin: 4px 0;
}

/* Button for chunk viewer in A/B column header */
.ab-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ab-action-btn {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: transform 120ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.ab-action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 10px 18px rgba(2, 6, 23, 0.1);
}

/* Markdown tables (assessment) */
.bubble table {
  width: 100%;
  border-collapse: collapse;
}
.bubble th,
.bubble td {
  padding: 6px 10px;
  vertical-align: top;
}
.bubble th:last-child,
.bubble td:last-child {
  padding-right: 16px;
}
