/* ==========================================================================
   AI Scientist — Literature Review Demo
   "Polished scientific" theme: emerald + gold on warm paper.

   1. Design tokens          6. Auth gate
   2. Base + typography      7. New Review page
   3. App shell              8. Review Library page
   4. Nav rail               9. Diagnostics drawer
   5. Shared primitives     10. Keyframes / responsive / reduced motion
   ========================================================================== */

/* 1. Design tokens
   ========================================================================== */

:root {
  color-scheme: light;

  /* Paper + warm green-grey neutrals */
  --paper: #f7f6f1;
  --surface: #ffffff;
  --surface-soft: #faf9f4;
  --surface-strong: #eef0e7;
  --ink: #16211c;
  --ink-2: #3f4d46;
  --muted: #67746c;
  --faint: #97a29a;
  --line: #e2e4da;
  --line-strong: #ccd1c4;

  /* Emerald ramp */
  --accent: #0f6b55;
  --accent-strong: #0b523f;
  --accent-deep: #083b2e;
  --accent-tint: #ddeee6;
  --accent-wash: #f0f6f2;
  --accent-line: #b9d6c9;

  /* Gold — used sparingly: eyebrows, active-nav bar, keylines */
  --gold: #96660a;
  --gold-bright: #c9990f;
  --gold-tint: #f7efdb;
  --gold-line: #e8d6a6;

  /* Danger */
  --danger: #a93832;
  --danger-strong: #8f2d28;
  --danger-tint: #fbeeec;
  --danger-line: #ecc8c3;

  /* Dark rail + code scale */
  --rail-bg: #0e1f19;
  --rail-bg-2: #16342a;
  --rail-line: rgba(235, 246, 240, 0.12);
  --rail-text: #eef5f0;
  --rail-text-dim: #a8bdb2;
  --rail-eyebrow: #8fae9f;
  --code-bg: #0d1b16;
  --code-text: #cfe9dd;
  --code-line: #1e332a;

  /* Status ramps */
  --status-ok-text: #0c5a41;
  --status-ok-bg: #ddf0e6;
  --status-ok-line: #b9e0cd;
  --status-warm-text: #7a5a08;
  --status-warm-bg: #f8eecd;
  --status-warm-line: #ead9a2;
  --status-bad-text: #93312b;
  --status-bad-bg: #f7e2de;
  --status-bad-line: #ecc8c3;
  --status-neutral-text: #46554d;
  --status-neutral-bg: #edefe6;
  --status-neutral-line: #dde0d3;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Layered, green-tinted shadows */
  --shadow-sm: 0 1px 2px rgba(22, 33, 28, 0.05), 0 1px 3px rgba(22, 33, 28, 0.05);
  --shadow-md: 0 2px 4px rgba(22, 33, 28, 0.04), 0 8px 20px rgba(22, 33, 28, 0.07);
  --shadow-lg: 0 4px 10px rgba(22, 33, 28, 0.05), 0 22px 48px rgba(22, 33, 28, 0.1);
  --shadow-drawer: -2px 0 8px rgba(13, 27, 22, 0.08), -20px 0 44px rgba(13, 27, 22, 0.18);

  /* Focus + motion */
  --focus-ring: 0 0 0 3px rgba(15, 107, 85, 0.2);
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --t-fast: 120ms;
  --t-med: 180ms;
  --t-slow: 260ms;

  /* Type */
  --font-sans:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --font-mono:
    ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* 2. Base + typography
   ========================================================================== */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
}

h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

::selection {
  background: rgba(15, 107, 85, 0.18);
}

.nav-rail ::selection,
.json-block ::selection,
.debug-body pre ::selection {
  background: rgba(201, 153, 15, 0.35);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-rail :focus-visible {
  outline-color: #9fd4c0;
}

/* 3. App shell
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-width, 248px) 6px minmax(0, 1fr);
  min-height: 100vh;
}

.workspace {
  min-width: 0;
  padding: 32px;
}

.workspace-content {
  display: grid;
  gap: 20px;
}

body:not(.is-authenticated) .workspace-content {
  display: none;
}

body.is-authenticated .auth-gate {
  display: none;
}

body:not(.is-authenticated) .signed-in-link,
body.is-authenticated .signed-out-link {
  display: none;
}

.page-view {
  display: none;
}

.page-view.is-active {
  display: grid;
  gap: 20px;
  animation: fade-up var(--t-med) var(--ease-out);
}

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

.nav-resizer {
  position: sticky;
  top: 0;
  height: 100vh;
  background: transparent;
  cursor: col-resize;
}

.nav-resizer::before {
  display: block;
  width: 1px;
  height: 100%;
  margin: 0 auto;
  background: rgba(14, 31, 25, 0.14);
  content: "";
  transition:
    width var(--t-fast) ease,
    background var(--t-fast) ease;
}

.nav-resizer:hover::before,
body.is-resizing-nav .nav-resizer::before {
  width: 3px;
  background: var(--accent);
}

body.is-resizing-nav {
  cursor: col-resize;
  user-select: none;
}

/* 4. Nav rail
   ========================================================================== */

.nav-rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 28px 22px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--rail-text);
  background:
    radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(180deg, var(--rail-bg-2), var(--rail-bg) 46%);
}

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

.brand-mark {
  flex: none;
  margin-top: 3px;
  border-radius: 9px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.brand-text {
  min-width: 0;
}

.nav-rail .eyebrow {
  margin-bottom: 4px;
  color: var(--rail-eyebrow);
}

.nav-rail h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.rail-subtitle {
  margin: 3px 0 0;
  color: var(--rail-text-dim);
  font-size: 0.8125rem;
}

.status-stack {
  display: grid;
  gap: 10px;
  padding: 16px 0;
  border-top: 1px solid var(--rail-line);
  border-bottom: 1px solid var(--rail-line);
}

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

.status-label {
  flex: none;
  color: var(--rail-text-dim);
  font-size: 0.8125rem;
}

.status-pill {
  display: inline-block;
  max-width: 136px;
  overflow: hidden;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  color: #07281f;
  background: #bde5d4;
  font-size: 0.72rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.65;
  vertical-align: 1px;
  content: "";
}

.identity-status .status-pill {
  min-width: 0;
}

.status-pill.muted {
  color: #c9d8d0;
  background: rgba(255, 255, 255, 0.1);
}

.status-pill.muted::before {
  opacity: 0.4;
}

.rail-actions {
  display: grid;
  gap: 6px;
}

.rail-actions a,
.rail-link {
  position: relative;
  display: block;
  width: 100%;
  padding: 9px 12px 9px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  color: #cfe0d7;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  transition:
    color var(--t-fast) ease,
    background var(--t-fast) ease;
}

.rail-actions a::before,
.rail-link::before {
  position: absolute;
  top: 50%;
  left: 4px;
  width: 3px;
  height: 16px;
  margin-top: -8px;
  border-radius: var(--radius-pill);
  background: var(--gold-bright);
  opacity: 0;
  transform: scaleY(0.4);
  transition:
    opacity var(--t-fast) ease,
    transform var(--t-fast) var(--ease-out);
  content: "";
}

.rail-actions a:hover,
.rail-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.rail-link.is-active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.09);
}

.rail-link.is-active::before {
  opacity: 1;
  transform: scaleY(1);
}

.rail-logout {
  margin-top: 6px;
  border-top: 1px solid var(--rail-line);
}

.rail-utility-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

body:not(.developer-mode) .developer-only {
  display: none;
}

.rail-utility-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  margin-top: auto;
  padding: 0 12px;
  border: 1px solid var(--rail-line);
  border-radius: var(--radius-md);
  color: var(--rail-text);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--t-fast) ease;
}

.rail-utility-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.language-control {
  display: grid;
  gap: 7px;
  padding: 10px 12px 12px;
  border: 1px solid var(--rail-line);
  border-radius: var(--radius-md);
  color: var(--rail-text-dim);
  background: rgba(255, 255, 255, 0.04);
}

.language-control span {
  font-size: 0.75rem;
  font-weight: 600;
}

.language-control select {
  min-height: 34px;
  margin-top: 0;
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--rail-text);
  background-color: rgba(255, 255, 255, 0.08);
}

.debug-badge {
  min-width: 24px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  color: #5a4106;
  background: var(--gold-tint);
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.debug-badge.is-empty {
  color: var(--rail-text-dim);
  background: rgba(255, 255, 255, 0.12);
}

/* 5. Shared primitives
   ========================================================================== */

.message-bar {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 50;
  display: block;
  visibility: hidden;
  width: min(460px, calc(100vw - 40px));
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition:
    opacity var(--t-med) ease,
    transform var(--t-med) var(--ease-out),
    visibility var(--t-med) ease;
}

.message-bar.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  animation: message-in 200ms var(--ease-out);
}

.message-bar.error {
  border-color: var(--danger-line);
  border-left-color: var(--danger);
  color: var(--danger-strong);
  background: var(--danger-tint);
}

.message-bar.success {
  border-color: var(--accent-line);
  border-left-color: var(--accent);
  color: var(--accent-deep);
  background: #eff8f3;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition:
    background var(--t-fast) ease,
    border-color var(--t-fast) ease,
    color var(--t-fast) ease,
    box-shadow var(--t-fast) ease,
    transform var(--t-fast) ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

.button.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

.button.primary {
  border-color: var(--accent-strong);
  color: #ffffff;
  background: linear-gradient(180deg, #13735c, var(--accent));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    var(--shadow-sm);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface);
}

.button.secondary:hover:not(:disabled) {
  border-color: var(--accent-line);
  color: var(--accent-strong);
  background: var(--accent-wash);
}

.button.danger {
  border-color: var(--danger-line);
  color: var(--danger);
  background: var(--danger-tint);
}

.button.danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: #f6e0dc;
}

.tab-list {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  margin-top: 20px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}

.tab {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: calc(var(--radius-md) - 3px);
  color: var(--muted);
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 600;
  transition:
    color var(--t-fast) ease,
    background var(--t-fast) ease;
}

.tab:hover {
  color: var(--ink-2);
}

.tab.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

label,
fieldset {
  min-width: 0;
}

label,
legend {
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 500;
}

legend {
  padding: 0 6px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  margin-top: 7px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition:
    border-color var(--t-fast) ease,
    box-shadow var(--t-fast) ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) {
  border-color: #b3bcab;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  flex: none;
  accent-color: var(--accent);
}

select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2367746c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

textarea {
  min-height: 120px;
  line-height: 1.6;
  resize: vertical;
}

fieldset {
  margin: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: transparent;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.split-actions,
.detail-actions,
.debug-actions,
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.section-heading,
.debug-header,
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading .eyebrow,
.debug-header .eyebrow,
.settings-header .eyebrow {
  margin-bottom: 6px;
}

/* Disclosure chrome (settings + payload details) */

.demo-settings summary::-webkit-details-marker,
.review-settings summary::-webkit-details-marker,
.payload-details summary::-webkit-details-marker {
  display: none;
}

.demo-settings summary,
.review-settings summary,
.payload-details summary {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
  list-style: none;
  transition: color var(--t-fast) ease;
}

.demo-settings summary:hover,
.review-settings summary:hover,
.payload-details summary:hover {
  color: var(--accent-strong);
}

.demo-settings summary::before,
.review-settings summary::before,
.payload-details summary::before {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: -3px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform var(--t-fast) ease;
  content: "";
}

.demo-settings[open] > summary::before,
.review-settings[open] > summary::before,
.payload-details[open] > summary::before {
  margin-top: -5px;
  transform: rotate(45deg);
}

.demo-settings,
.review-settings {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.demo-settings[open] > summary,
.review-settings[open] > summary {
  margin-bottom: 14px;
}

.demo-settings .button {
  margin-top: 14px;
}

/* Meta chips + status coding */

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 2px 9px;
  border: 1px solid var(--status-neutral-line);
  border-radius: var(--radius-pill);
  color: var(--status-neutral-text);
  background: var(--status-neutral-bg);
  font-size: 0.6875rem;
  font-weight: 600;
}

.meta-chip[class*="status-"]::before {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.75;
  content: "";
}

.meta-chip.status-succeeded {
  border-color: var(--status-ok-line);
  color: var(--status-ok-text);
  background: var(--status-ok-bg);
}

.meta-chip.status-running,
.meta-chip.status-pending,
.meta-chip.status-cancel_requested {
  border-color: var(--status-warm-line);
  color: var(--status-warm-text);
  background: var(--status-warm-bg);
}

.meta-chip.status-failed,
.meta-chip.status-canceled {
  border-color: var(--status-bad-line);
  color: var(--status-bad-text);
  background: var(--status-bad-bg);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 32px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.875rem;
  text-align: center;
}

/* Card bases */

.welcome-panel,
.auth-card,
.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.surface {
  padding: 24px;
  box-shadow: var(--shadow-md);
}

/* 6. Auth gate
   ========================================================================== */

.auth-gate {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.72fr);
  gap: 24px;
  align-items: stretch;
  min-height: calc(100vh - 64px);
}

.welcome-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 560px;
  padding: clamp(32px, 5vw, 56px);
  background:
    radial-gradient(rgba(15, 107, 85, 0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    radial-gradient(120% 90% at 0% 0%, rgba(15, 107, 85, 0.1), transparent 55%),
    radial-gradient(100% 80% at 100% 100%, rgba(201, 153, 15, 0.08), transparent 50%),
    var(--surface);
  box-shadow: var(--shadow-lg);
}

.welcome-panel h2 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(1.75rem, 1.1rem + 2.4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.12;
}

.welcome-copy {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
}

.proof-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 40px;
}

.proof-grid div {
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.75);
}

.proof-grid strong,
.proof-grid span {
  display: block;
}

.proof-grid strong {
  margin-bottom: 6px;
  color: var(--accent-deep);
  font-size: 0.9rem;
  font-weight: 600;
}

.proof-grid span {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.auth-card {
  align-self: center;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.auth-form,
.settings-grid {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

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

.settings-grid {
  margin-top: 0;
}

/* 7. New Review page + workspace hero
   ========================================================================== */

.workspace-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(120deg, var(--accent-wash), rgba(247, 239, 219, 0.5) 55%, rgba(255, 255, 255, 0)),
    var(--surface);
  box-shadow: var(--shadow-sm);
}

.workspace-hero h2 {
  margin: 0;
  font-size: clamp(1.35rem, 1.05rem + 1.2vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.workspace-hero p {
  max-width: 640px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.prompt-chip {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-pill);
  color: var(--accent-strong);
  background: var(--accent-wash);
  font-size: 0.8125rem;
  font-weight: 500;
  transition:
    border-color var(--t-fast) ease,
    background var(--t-fast) ease,
    transform var(--t-fast) ease;
}

.prompt-chip:hover {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.prompt-chip:active {
  transform: translateY(1px);
}

.review-form {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.wide-field {
  display: block;
}

.source-fieldset {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.source-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 180px);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.source-limit-input:disabled {
  border-color: var(--line);
  color: var(--faint);
  background: var(--surface-strong);
}

.standalone-check {
  align-self: end;
  min-height: 40px;
  padding: 0 0 10px;
}

.calculated-summary {
  display: grid;
  align-self: end;
  min-height: 62px;
  padding: 10px 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-md);
  background: var(--accent-wash);
}

.calculated-summary span {
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.calculated-summary strong {
  margin-top: 2px;
  color: var(--accent-deep);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 8. Review Library page
   ========================================================================== */

.detail-cell span,
.question-preview span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-grid {
  display: grid;
  gap: 20px;
}

.work-grid {
  grid-template-columns: minmax(310px, 0.86fr) minmax(0, 1.14fr);
  align-items: start;
}

.library-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.library-controls .compact-label input {
  width: 88px;
  margin-top: 6px;
}

.review-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.review-item {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: inherit;
  background: var(--surface);
  text-align: left;
  transition:
    border-color var(--t-fast) ease,
    background var(--t-fast) ease,
    box-shadow var(--t-fast) ease;
}

.review-item:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  box-shadow: var(--shadow-sm);
}

.review-item.is-selected {
  border-color: var(--accent);
  background: var(--accent-wash);
  box-shadow:
    inset 3px 0 0 var(--accent),
    var(--shadow-sm);
}

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

.review-id {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.review-question {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.review-detail {
  display: grid;
  gap: 14px;
  min-height: 260px;
  margin-top: 16px;
}

.progress-shell {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: #e8ebe1;
  box-shadow: inset 0 1px 2px rgba(22, 33, 28, 0.06);
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #239274);
  transition: width 300ms var(--ease-out);
}

/* Animated stripe while a review is in flight (decorative; skipped by
   engines without :has support). */
@supports selector(:has(*)) {
  .review-detail div:has(.meta-chip.status-running) .progress-bar,
  .review-detail div:has(.meta-chip.status-pending) .progress-bar {
    background:
      repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.22) 0 8px,
        transparent 8px 16px
      ),
      linear-gradient(90deg, var(--accent), #239274);
    animation: progress-stripe 900ms linear infinite;
  }
}

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

.detail-cell {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-cell strong {
  font-size: 0.875rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.question-preview {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold-bright);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.question-preview p {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.9rem;
  line-height: 1.6;
}

.result-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.result-card .eyebrow {
  margin-bottom: 6px;
}

.result-card h4 {
  margin: 0 0 8px;
}

.result-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.55;
}

.report-download {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
}

.download-expiry {
  color: var(--muted);
}

.download-expiry.is-expired {
  color: var(--danger);
}

.markdown-preview {
  max-height: 720px;
  overflow: auto;
  margin-top: 14px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: #fbfdfa;
}

.markdown-preview > *:first-child {
  margin-top: 0;
}

.markdown-preview > *:last-child {
  margin-bottom: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  margin: 1.35em 0 0.55em;
  color: var(--ink);
  line-height: 1.25;
}

.markdown-preview h1 {
  font-size: 1.45rem;
}

.markdown-preview h2 {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 1.25rem;
}

.markdown-preview h3 {
  font-size: 1.05rem;
}

.markdown-preview p,
.markdown-preview li,
.markdown-preview td,
.markdown-preview th,
.markdown-preview blockquote {
  color: var(--ink-2);
  font-size: 0.9rem;
  line-height: 1.65;
}

.markdown-preview p {
  margin: 0 0 0.85em;
}

.markdown-preview ul,
.markdown-preview ol {
  margin: 0 0 1em;
  padding-left: 1.35rem;
}

.markdown-preview li + li {
  margin-top: 0.25em;
}

.markdown-preview a {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-preview code {
  padding: 0.12em 0.32em;
  border-radius: 4px;
  color: #185743;
  background: #e8f3ed;
  font-family: var(--font-mono);
  font-size: 0.82em;
}

.markdown-preview pre {
  overflow: auto;
  margin: 0 0 1em;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f3f6f2;
}

.markdown-preview pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  font-size: 0.78rem;
}

.markdown-preview blockquote {
  margin: 0 0 1em;
  padding: 0 0 0 14px;
  border-left: 3px solid var(--accent-line);
}

.markdown-preview hr {
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: var(--line);
}

.markdown-table-wrap {
  overflow-x: auto;
  margin: 0 0 1em;
}

.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-preview th,
.markdown-preview td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-preview th {
  color: var(--ink);
  background: var(--surface-soft);
}

.result-card .markdown-preview-error {
  margin-top: 12px;
  color: var(--danger);
}

.muted-result {
  border-left-color: var(--line-strong);
  background: var(--surface-soft);
  box-shadow: none;
}

.payload-details {
  margin-top: 12px;
}

.payload-details[open] > summary {
  margin-bottom: 10px;
}

.result-summary {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  color: #1d4a3c;
  background: #eef6f1;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

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

.json-block {
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--code-line);
  border-radius: var(--radius-md);
  color: var(--code-text);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.detail-actions {
  margin-top: 16px;
}

/* 9. Diagnostics drawer
   ========================================================================== */

.debug-scrim,
.settings-scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 20, 16, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

body.debug-open .debug-scrim,
body.settings-open .settings-scrim {
  opacity: 1;
  pointer-events: auto;
}

.debug-panel,
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(520px, 100vw);
  height: 100vh;
  min-width: 0;
  padding: 24px;
  border-left: 1px solid var(--line);
  background: var(--paper);
  transform: translateX(100%);
  transition: transform var(--t-slow) var(--ease-out);
}

body.debug-open .debug-panel,
body.settings-open .settings-panel {
  box-shadow: var(--shadow-drawer);
  transform: translateX(0);
}

.settings-panel .settings-grid {
  grid-template-columns: 1fr;
  margin-top: 20px;
}

.settings-actions {
  margin-top: 18px;
}

.debug-log {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  margin-top: 16px;
  overflow: auto;
  padding-right: 4px;
}

.debug-entry {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color var(--t-fast) ease;
}

.debug-entry[open] {
  border-color: var(--accent-line);
}

.debug-entry summary {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: calc(var(--radius-md) - 1px);
  cursor: pointer;
  list-style: none;
  transition: background var(--t-fast) ease;
}

.debug-entry summary:hover {
  background: var(--surface-soft);
}

.debug-entry summary::-webkit-details-marker {
  display: none;
}

.debug-method {
  min-width: 52px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: #ffffff;
  background: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
}

.debug-method.error {
  background: var(--danger);
}

.debug-path {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-status {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.debug-body {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.debug-body h4 {
  margin: 8px 0 6px;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.debug-body pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--code-line);
  border-radius: var(--radius-sm);
  color: var(--code-text);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Scrollbars (scrolling blocks only) */

.json-block,
.result-summary,
.debug-log,
.debug-body pre {
  scrollbar-width: thin;
  scrollbar-color: rgba(22, 33, 28, 0.3) transparent;
}

.json-block,
.debug-body pre {
  scrollbar-color: rgba(207, 233, 221, 0.3) transparent;
}

.json-block::-webkit-scrollbar,
.result-summary::-webkit-scrollbar,
.debug-log::-webkit-scrollbar,
.debug-body pre::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.json-block::-webkit-scrollbar-thumb,
.result-summary::-webkit-scrollbar-thumb,
.debug-log::-webkit-scrollbar-thumb,
.debug-body pre::-webkit-scrollbar-thumb {
  border-radius: var(--radius-pill);
  background: rgba(22, 33, 28, 0.25);
}

.json-block::-webkit-scrollbar-thumb,
.debug-body pre::-webkit-scrollbar-thumb {
  background: rgba(207, 233, 221, 0.28);
}

/* 10. Keyframes, responsive, reduced motion
   ========================================================================== */

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes progress-stripe {
  to {
    background-position:
      22.63px 0,
      0 0;
  }
}

@media (max-width: 1120px) {
  .app-shell,
  .auth-gate,
  .work-grid {
    grid-template-columns: 1fr;
  }

  .nav-resizer {
    display: none;
  }

  .nav-rail {
    position: relative;
    gap: 20px;
    height: auto;
    padding: 20px 24px;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .rail-utility-actions {
    margin-top: 0;
  }

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

  .workspace {
    padding: 20px;
  }

  .auth-gate {
    min-height: auto;
  }

  .welcome-panel {
    min-height: auto;
  }
}

@media (max-width: 820px) {
  .workspace-hero,
  .section-heading,
  .debug-header,
  .settings-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .proof-grid,
  .settings-grid,
  .options-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .source-row {
    grid-template-columns: 1fr;
  }

  .library-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .welcome-panel h2 {
    font-size: 1.6rem;
  }

  .workspace-hero h2 {
    font-size: 1.3rem;
  }

  .workspace-hero {
    padding: 20px;
  }

  .welcome-panel {
    padding: 24px 20px;
  }

  .auth-card {
    padding: 20px;
  }

  .debug-panel,
  .settings-panel {
    padding: 16px;
  }

  .message-bar {
    top: 16px;
    right: 20px;
    left: 20px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
