:root {
  color: #0e1627;
  background: #f7efee;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --navy: #0e1627;
  --mauve: #bd8e89;
  --prune: #7f6269;
  --pink: #e5c5c1;
  --blush: #f4e1e0;
  --paper: #fffdfb;
  --line: rgb(14 22 39 / 13%);
  --muted: #5b5f69;
  --success: #26724b;
  --warning: #8a5515;
  --danger: #a52f39;
  --shadow: 0 1.5rem 5rem rgb(84 53 58 / 12%);
}

* { box-sizing: border-box; }

html { min-width: 20rem; scroll-behavior: smooth; }

body {
  min-width: 20rem;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 12%, rgb(229 197 193 / 72%), transparent 28rem),
    radial-gradient(circle at 92% 6%, rgb(197 211 220 / 56%), transparent 31rem),
    linear-gradient(145deg, #fffaf8 0%, var(--blush) 58%, #efe4e4 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.58; }

:focus-visible { outline: 3px solid var(--prune); outline-offset: 3px; }

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  color: white;
  background: var(--navy);
  border-radius: 0.5rem;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  position: relative;
  z-index: 10;
  display: flex;
  min-height: 5rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgb(14 22 39 / 8%);
  background: rgb(255 253 251 / 72%);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 0.8rem; color: inherit; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: ui-serif, Georgia, serif; font-size: 1.1rem; font-weight: 600; }
.brand small { margin-top: 0.1rem; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }

.brand-mark {
  display: block;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.72rem;
  box-shadow: 0 0.35rem 0.9rem rgb(14 22 39 / 14%);
}

.session-actions { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: 0.88rem; }

.login-layout {
  display: grid;
  min-height: calc(100vh - 5rem);
  grid-template-columns: minmax(0, 1.2fr) minmax(20rem, 31rem);
  gap: clamp(2rem, 8vw, 8rem);
  align-items: center;
  width: min(100% - 2rem, 76rem);
  margin-inline: auto;
  padding: clamp(2rem, 7vw, 7rem) 0;
}

.login-intro { max-width: 45rem; }
.login-intro h1, .workspace-header h1 {
  max-width: 13ch;
  margin: 0;
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(2.75rem, 7vw, 6.6rem);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.94;
}
.login-intro > p:not(.eyebrow) { max-width: 57ch; margin: 1.7rem 0 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.7; }

.eyebrow, .step-label { margin: 0 0 0.75rem; color: var(--prune); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.13em; text-transform: uppercase; }
.step-label { margin-bottom: 0.45rem; }

.privacy-note {
  display: flex;
  max-width: 36rem;
  gap: 0.9rem;
  align-items: flex-start;
  margin-top: 2.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.privacy-note span { display: grid; flex: 0 0 2rem; height: 2rem; place-items: center; border: 1px solid var(--prune); border-radius: 50%; color: var(--prune); }
.privacy-note p { margin: 0; font-size: 0.88rem; line-height: 1.5; }
.privacy-note strong { display: block; margin-bottom: 0.2rem; }

.login-card {
  padding: clamp(1.5rem, 5vw, 3rem);
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 1.75rem 1.75rem 1.75rem 0.45rem;
  background: rgb(255 253 251 / 91%);
  box-shadow: var(--shadow);
}
.login-card h2, dialog h2, .section-heading h2, .side-navigation h2 { margin: 0; font-family: ui-serif, Georgia, serif; font-size: clamp(1.8rem, 4vw, 2.5rem); font-weight: 550; letter-spacing: -0.025em; }
.muted { color: var(--muted); line-height: 1.55; }

form label { display: block; margin: 1rem 0 0.4rem; font-size: 0.84rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid rgb(14 22 39 / 22%);
  border-radius: 0.7rem;
  color: var(--navy);
  background: white;
}
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--prune); }
input[type="file"] { padding: 0.45rem; background: rgb(255 255 255 / 72%); }
input[type="file"]::file-selector-button { min-height: 2.1rem; margin-right: 0.7rem; padding: 0.35rem 0.75rem; border: 0; border-radius: 999px; color: white; background: var(--navy); font-weight: 700; }

.primary-button, .secondary-button, .text-button, .icon-button, .tab-button {
  min-height: 2.75rem;
  border: 0;
  border-radius: 999px;
  font-weight: 720;
}
.primary-button { width: 100%; margin-top: 1.3rem; padding: 0.75rem 1.15rem; color: white; background: var(--navy); box-shadow: 0 0.5rem 1.4rem rgb(14 22 39 / 15%); }
.primary-button:hover { background: #25314a; transform: translateY(-1px); }
.secondary-button { width: 100%; padding: 0.7rem 1.1rem; border: 1px solid var(--navy); color: var(--navy); background: transparent; }
.secondary-button:hover { background: rgb(244 225 224 / 68%); }
.compact { width: auto; min-height: 2.75rem; margin: 0; padding: 0.55rem 1rem; }
.text-button { min-height: 2.75rem; padding: 0.45rem 0.75rem; color: var(--navy); background: transparent; text-decoration: underline; text-underline-offset: 0.2em; }
.icon-button { width: 2.7rem; padding: 0; color: var(--navy); background: var(--blush); font-size: 1.5rem; }

.divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.25rem 0; color: var(--muted); font-size: 0.74rem; text-transform: uppercase; }
.divider::before, .divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.form-status { min-height: 1.4rem; margin: 1rem 0 0; color: var(--danger); font-size: 0.85rem; line-height: 1.45; }

.admin-shell { display: grid; min-height: calc(100vh - 5rem); grid-template-columns: 17rem minmax(0, 1fr); }
.side-navigation { display: flex; min-width: 0; flex-direction: column; padding: 2.5rem 1.5rem; border-right: 1px solid var(--line); background: rgb(255 253 251 / 58%); }
.side-navigation h2 { font-size: 2rem; }
.tab-list { display: grid; gap: 0.35rem; margin-top: 2.25rem; }
.tab-button { width: 100%; padding: 0.7rem 0.85rem; border-radius: 0.7rem; color: var(--muted); background: transparent; text-align: left; }
.tab-button:hover { color: var(--navy); background: rgb(255 255 255 / 68%); }
.tab-button.is-active { color: white; background: var(--navy); }
.side-note { display: flex; gap: 0.65rem; align-items: flex-start; margin-top: auto; padding: 1rem; border: 1px solid var(--line); border-radius: 1rem; background: rgb(244 225 224 / 65%); }
.side-note span { color: var(--success); font-size: 0.65rem; }
.side-note p { margin: 0; font-size: 0.78rem; line-height: 1.45; }

.workspace { width: min(100%, 88rem); min-width: 0; padding: clamp(1.5rem, 5vw, 4rem); }
.workspace-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; padding-bottom: 2rem; }
.workspace-header h1 { max-width: none; font-size: clamp(2.4rem, 5vw, 4.5rem); }
.notice { margin-bottom: 1.5rem; padding: 0.9rem 1rem; border-left: 3px solid var(--prune); border-radius: 0 0.7rem 0.7rem 0; background: var(--paper); font-size: 0.9rem; }
.notice.is-error { border-color: var(--danger); color: var(--danger); }
.notice.is-success { border-color: var(--success); color: var(--success); }
.loading-state { display: flex; min-height: 16rem; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.spinner { width: 2rem; height: 2rem; border: 2px solid var(--pink); border-top-color: var(--navy); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.section-heading h2 { font-size: clamp(1.9rem, 4vw, 2.8rem); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; }
.stat-card { min-height: 9rem; padding: 1.25rem; border: 1px solid rgb(255 255 255 / 72%); border-radius: 1.1rem; background: rgb(255 253 251 / 78%); box-shadow: 0 0.8rem 2.4rem rgb(84 53 58 / 6%); }
.stat-card strong { display: block; font-family: ui-serif, Georgia, serif; font-size: 3rem; font-weight: 500; }
.stat-card span { color: var(--muted); font-size: 0.82rem; }
.editorial-grid { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 1rem; margin-top: 1rem; }
.feature-card { min-height: 15rem; padding: clamp(1.25rem, 4vw, 2.2rem); border-radius: 1.2rem 1.2rem 1.2rem 0.3rem; color: white; background: var(--navy); }
.feature-card.soft { color: var(--navy); background: rgb(229 197 193 / 76%); }
.feature-card h3 { max-width: 18ch; margin: 0; font-family: ui-serif, Georgia, serif; font-size: 1.8rem; font-weight: 500; }
.feature-card p:last-child { max-width: 44ch; line-height: 1.6; }
.journey-list { display: grid; gap: 0.7rem; margin: 1.5rem 0 0; padding: 0; list-style: none; }
.journey-list li { display: flex; align-items: center; gap: 0.7rem; }
.journey-list span { display: grid; width: 1.8rem; height: 1.8rem; place-items: center; border: 1px solid rgb(255 255 255 / 35%); border-radius: 50%; font-size: 0.75rem; }

.resource-list { display: grid; gap: 0.65rem; }
.resource-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: 1rem 1.15rem; border: 1px solid rgb(255 255 255 / 72%); border-radius: 0.95rem; background: rgb(255 253 251 / 83%); }
.resource-card h3 { margin: 0; font-size: 1rem; }
.resource-card p { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.4; }
.resource-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.resource-actions button { min-height: 2.75rem; margin: 0; padding: 0.55rem 0.9rem; font-size: 0.85rem; }
.status-badge { display: inline-flex; align-items: center; gap: 0.35rem; margin-left: 0.45rem; padding: 0.2rem 0.5rem; border-radius: 999px; color: var(--success); background: rgb(38 114 75 / 9%); font-size: 0.7rem; font-weight: 750; vertical-align: middle; }
.status-badge::before { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; content: ""; }
.status-badge.disabled { color: var(--warning); background: rgb(138 85 21 / 9%); }
.status-badge.archived { color: var(--muted); background: rgb(91 95 105 / 9%); }
.empty-state { padding: 3rem 1.5rem; border: 1px dashed rgb(14 22 39 / 24%); border-radius: 1rem; color: var(--muted); background: rgb(255 253 251 / 44%); text-align: center; }
.empty-state strong { display: block; margin-bottom: 0.4rem; color: var(--navy); font-family: ui-serif, Georgia, serif; font-size: 1.35rem; font-weight: 550; }
.audit-list .resource-card { grid-template-columns: minmax(0, 1fr) auto; }
.audit-list time { color: var(--muted); font-size: 0.76rem; }

.section-intro { max-width: 55ch; margin: 0.7rem 0 0; color: var(--muted); line-height: 1.55; }
.source-workspace { display: grid; grid-template-columns: minmax(20rem, 0.8fr) minmax(24rem, 1.2fr); gap: 1.25rem; align-items: start; }
.source-upload-card, .source-preview { padding: clamp(1.25rem, 3vw, 2rem); border: 1px solid rgb(255 255 255 / 72%); border-radius: 1.25rem 1.25rem 1.25rem 0.35rem; background: rgb(255 253 251 / 86%); box-shadow: 0 0.8rem 2.4rem rgb(84 53 58 / 6%); }
.source-upload-card h3, .source-list-heading h3, .source-preview h3 { margin: 0; font-family: ui-serif, Georgia, serif; font-size: 1.65rem; font-weight: 550; letter-spacing: -0.02em; }
.source-upload-card .primary-button { margin-bottom: 0; }
.source-library-column { min-width: 0; }
.source-list-heading { display: flex; min-height: 4.5rem; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.corpus-pill { flex: 0 0 auto; padding: 0.35rem 0.65rem; border: 1px solid var(--prune); border-radius: 999px; color: var(--prune); background: rgb(244 225 224 / 72%); font-size: 0.72rem; font-weight: 750; }
.optional { color: var(--muted); font-size: 0.72rem; font-weight: 500; }
.compact-note { margin-top: 1.3rem; padding-top: 1rem; }
.compact-note p { color: var(--muted); }
.source-preview { margin-top: 1rem; }
.source-preview-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.source-preview-copy { margin: 0.65rem 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.55; }
.source-progress { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 1.25rem 0; padding: 0; list-style: none; }
.source-progress li { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.55rem; border-radius: 999px; color: var(--muted); background: rgb(14 22 39 / 5%); font-size: 0.7rem; font-weight: 700; }
.source-progress li::before { content: "✓"; color: var(--success); }
.segment-preview-list { display: grid; gap: 0.65rem; margin-top: 1rem; }
.segment-preview { padding: 0.9rem 1rem; border-left: 3px solid var(--pink); border-radius: 0 0.75rem 0.75rem 0; background: rgb(244 225 224 / 42%); }
.segment-preview p { margin: 0.35rem 0 0; color: var(--navy); font-size: 0.84rem; line-height: 1.55; }
.segment-locator { color: var(--prune); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.02em; }
.source-preview-limit { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.75rem; }
.source-preview-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; margin-top: 1rem; color: var(--muted); font-size: 0.78rem; }
.source-preview-pagination span { margin-right: auto; }
.source-review-checklist { display: grid; gap: 0.75rem; margin: 1.25rem 0 0; padding: 1rem; border: 1px solid rgb(127 98 105 / 24%); border-radius: 0.9rem; background: rgb(255 253 251 / 92%); }
.source-review-checklist legend { padding: 0 0.35rem; font-weight: 750; color: var(--navy); }
.source-review-checklist label { display: flex; align-items: flex-start; gap: 0.65rem; color: var(--navy); font-size: 0.84rem; line-height: 1.45; text-align: left; }
.source-review-checklist input[type="checkbox"] {
  flex: 0 0 auto;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.2rem 0 0;
  accent-color: var(--navy);
}
.source-review-actions { margin-top: 0.35rem; justify-content: flex-end; }
.source-review-actions .primary-button,
.source-review-actions .secondary-button { width: auto; margin-top: 0; }
.source-next-step { margin: 0.35rem 0 0; color: var(--prune); font-size: 0.78rem; font-weight: 650; line-height: 1.4; }
.status-badge.uploaded, .status-badge.validated, .status-badge.text-extracted, .status-badge.segmented, .status-badge.indexed, .status-badge.unpublished { color: var(--warning); background: rgb(138 85 21 / 9%); }
.status-badge.ready-for-review { color: var(--prune); background: rgb(127 98 105 / 10%); }
.status-badge.published { color: var(--success); background: rgb(38 114 75 / 9%); }
.status-badge.rejected, .status-badge.ingestion-failed { color: var(--danger); background: rgb(165 47 57 / 9%); }
.source-action-note { margin: 0.75rem 0 0; padding: 0.7rem 0.8rem; border-radius: 0.65rem; color: var(--muted); background: rgb(14 22 39 / 5%); font-size: 0.78rem; line-height: 1.5; }

dialog { width: min(calc(100% - 2rem), 38rem); max-height: calc(100vh - 2rem); padding: 0; border: 1px solid rgb(255 255 255 / 72%); border-radius: 1.4rem; color: var(--navy); background: var(--paper); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(14 22 39 / 48%); backdrop-filter: blur(4px); }
dialog form { padding: clamp(1.25rem, 5vw, 2rem); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.7rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.field-hint { margin: 1rem 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.5; }

@media (max-width: 64rem) {
  .login-layout { grid-template-columns: 1fr; gap: 2.5rem; }
  .login-intro h1 { max-width: 15ch; font-size: clamp(3rem, 10vw, 5rem); }
  .login-card { width: min(100%, 36rem); }
  .admin-shell { grid-template-columns: 1fr; }
  .side-navigation { position: sticky; z-index: 5; top: 0; padding: 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-navigation > div:first-child, .side-note { display: none; }
  .tab-list { display: flex; gap: 0.3rem; overflow-x: auto; margin: 0; padding-bottom: 0.2rem; }
  .tab-button { width: auto; flex: 0 0 auto; padding-inline: 0.85rem; }
  .source-workspace { grid-template-columns: 1fr; }
}

@media (max-width: 48rem) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .editorial-grid { grid-template-columns: 1fr; }
  .resource-card { grid-template-columns: 1fr; }
  .resource-actions { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 34rem) {
  .site-header { align-items: flex-start; }
  .session-actions { align-items: flex-end; flex-direction: column; gap: 0.25rem; }
  .session-actions span { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .login-layout { width: min(100% - 1.25rem, 76rem); padding: 1.5rem 0; }
  .login-intro h1 { font-size: clamp(2.6rem, 15vw, 4rem); }
  .workspace { padding: 1.25rem 0.8rem 2rem; }
  .tab-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  .tab-button { width: 100%; padding: 0.55rem 0.35rem; font-size: 0.76rem; text-align: center; }
  .workspace-header, .section-heading { align-items: flex-start; flex-direction: column; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 7rem; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .spinner { animation: none; }
}
