:root {
  --bg: #f7f7f2;
  --surface: #ffffff;
  --surface-muted: #f0f4f1;
  --border: #d9ded7;
  --text: #20251f;
  --muted: #667063;
  --primary: #116a5c;
  --primary-dark: #0a4a40;
  --secondary: #3a5f7d;
  --danger: #a3382b;
  --warning: #8a6819;
  --success: #26734d;
  --focus: #d08b39;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  margin-left: 0.75rem;
  padding: 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.nav,
.action-row,
.panel-header,
.segmented {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-header h2 {
  margin-bottom: 0;
}

.nav-link {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.nav-link.active,
.nav-link:hover {
  background: var(--surface-muted);
  color: var(--text);
  text-decoration: none;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  list-style: none;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-trigger {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  cursor: pointer;
}

.avatar {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 900;
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 0.65rem);
  right: 0;
  z-index: 10;
  width: min(20rem, calc(100vw - 2rem));
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(32, 37, 31, 0.14);
}

.account-identity {
  display: grid;
  gap: 0.25rem;
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}

.account-identity span {
  color: var(--muted);
  font-size: 0.86rem;
}

.account-identity .role-pill {
  width: fit-content;
  margin-left: 0;
}

.dropdown-action {
  display: flex;
  width: 100%;
  min-height: 2.35rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  text-align: left;
  text-decoration: none;
}

.dropdown-action:hover {
  background: var(--surface-muted);
  text-decoration: none;
}

.dropdown-action.danger {
  color: var(--danger);
}

.dropdown-form {
  display: block;
  margin: 0;
}

.main-content {
  width: min(1220px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.auth-page {
  background: #eef2ed;
}

.auth-page .main-content {
  width: 100%;
  min-height: 100vh;
  padding: 0;
}

.auth-panel,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(32, 37, 31, 0.04);
}

.auth-surface {
  width: min(980px, calc(100vw - 2rem));
  min-height: 580px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid #ccd6cf;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(32, 37, 31, 0.12);
}

.auth-brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(2rem, 5vw, 3.5rem);
  background: #153b34;
  color: #ffffff;
}

.auth-logo-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.auth-mark {
  width: 3.75rem;
  height: 3.75rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: #f7f7f2;
  color: #153b34;
  font-size: 2rem;
  font-weight: 900;
}

.auth-kicker {
  margin-bottom: 0.2rem;
  color: #ffffff;
  font-size: 1.35rem;
  font-weight: 900;
}

.auth-product,
.auth-brand-copy p {
  color: rgba(255, 255, 255, 0.78);
}

.auth-product {
  margin-bottom: 0;
  font-weight: 700;
}

.auth-brand-copy {
  max-width: 28rem;
}

.auth-brand-copy h1 {
  margin-bottom: 1rem;
  color: #ffffff;
  font-size: clamp(2.2rem, 5vw, 4.2rem);
}

.auth-brand-copy p {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.55;
}

.auth-panel {
  width: min(420px, 100%);
  padding: clamp(2rem, 5vw, 3.5rem);
}

.auth-surface .auth-panel {
  width: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.auth-heading {
  margin-bottom: 1.5rem;
}

.auth-heading h2 {
  margin-bottom: 0;
  font-size: 2rem;
}

.panel {
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.panel.narrow {
  max-width: 680px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.45rem;
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 1rem;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.eyebrow {
  margin-bottom: 0.4rem;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.muted,
.hint,
.empty-state {
  color: var(--muted);
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
}

.empty-state {
  margin: 0;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 1rem;
  align-items: start;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metric-grid.compact-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.side-stack {
  display: grid;
  gap: 1rem;
}

.metric {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.metric span {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.metric strong {
  font-size: 1.45rem;
  line-height: 1;
}

.form-stack {
  display: grid;
  gap: 1rem;
}

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

.field-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.source-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.source-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 0.65rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.source-option:has(input:checked) {
  border-color: #9bc7aa;
  background: #f2faf4;
}

.source-option input {
  width: auto;
  margin-top: 0.15rem;
}

.source-option span {
  display: grid;
  gap: 0.2rem;
}

.source-option small {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.candidate-source-fields {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.candidate-source-panel:has(input[value="csv"]:checked) .csv-source-fields,
.candidate-source-panel:has(input[value="pubmed_search"]:checked) .pubmed-source-fields {
  display: block;
}

.field label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
  font-weight: 800;
}

.field-marker {
  display: inline-flex;
  align-items: center;
  min-height: 1.35rem;
  padding: 0 0.45rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.field-marker.required {
  background: #e8f2f9;
  color: var(--secondary);
}

.field-marker.optional {
  background: var(--surface-muted);
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #bfc9bd;
  border-radius: 8px;
  padding: 0.72rem 0.8rem;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent);
  border-color: var(--focus);
}

.button,
input[type="submit"],
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.35rem;
  padding: 0.58rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  line-height: 1.1;
  cursor: pointer;
  text-decoration: none;
  white-space: normal;
}

.button:hover {
  text-decoration: none;
}

.button.primary {
  background: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary,
.button.subtle {
  background: var(--surface-muted);
  color: var(--text);
  border-color: var(--border);
}

.button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.button.danger {
  background: var(--danger);
  color: #ffffff;
}

.button.full-width {
  width: 100%;
}

.dropdown-form .dropdown-action {
  justify-content: flex-start;
  padding: 0.55rem 0.65rem;
  border: 0;
  background: transparent;
  color: var(--danger);
  text-align: left;
}

.dropdown-form .dropdown-action:hover {
  background: var(--surface-muted);
}

.inline-form,
.inline-form div {
  display: inline;
}

.flash,
.error-panel,
.report-block {
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.flash.notice {
  border-color: #9bc7aa;
  background: #edf8f0;
}

.flash.alert,
.error-panel,
.report-block.danger {
  border-color: #dfb0aa;
  background: #fff1ef;
}

.report-block.warning {
  border-color: #e1ca83;
  background: #fff8df;
}

.error-panel ul,
.report-block ul {
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: 0 0.55rem;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-draft,
.status-withdrawn {
  background: #eef0ef;
  color: #4e5750;
}

.status-pending-approval,
.status-queued,
.status-running {
  background: #e8f2f9;
  color: var(--secondary);
}

.status-rejected,
.status-failed,
.status-canceled {
  background: #fff1ef;
  color: var(--danger);
}

.status-completed {
  background: #edf8f0;
  color: var(--success);
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(125px, 0.22fr) minmax(0, 0.78fr);
  gap: 0.75rem 1rem;
  margin: 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
  min-width: 0;
}

.compact-list {
  grid-template-columns: minmax(115px, 0.42fr) minmax(0, 0.58fr);
}

.notification-list {
  display: grid;
  gap: 0.75rem;
}

.notification {
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.notification.unread {
  border-color: #9bc7aa;
  background: #f2faf4;
}

.notification p {
  margin: 0.25rem 0;
}

.notification small {
  color: var(--muted);
}

.tool-list,
.audit-list,
.query-list {
  display: grid;
  gap: 0.75rem;
}

.tool-link,
.audit-item,
.query-item {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.tool-link {
  color: var(--text);
}

.tool-link:hover {
  border-color: #9bc7aa;
  text-decoration: none;
}

.tool-link span,
.audit-item span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.query-item code {
  display: block;
  padding: 0.65rem;
  border-radius: 8px;
  background: var(--surface-muted);
  white-space: pre-wrap;
}

.segmented {
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.segmented a {
  padding: 0.42rem 0.7rem;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.segmented a.active {
  background: var(--primary);
  color: #ffffff;
}

.approval-actions,
.danger-zone {
  margin-top: 1rem;
}

.reject-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

code {
  word-break: break-word;
}

@media (max-width: 840px) {
  .topbar,
  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    gap: 0.35rem;
  }

  .account-menu {
    align-self: flex-start;
  }

  .main-content {
    width: min(100vw - 1rem, 1220px);
    padding-top: 1rem;
  }

  .two-column,
  .field-grid,
  .source-options {
    grid-template-columns: 1fr;
  }

  .auth-surface {
    width: min(100vw - 1rem, 540px);
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .auth-brand-panel {
    min-height: 300px;
    gap: 2rem;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }
}
