:root {
  --admin-surface: rgba(255,255,255,.84);
  --admin-solid: #fff;
  --admin-subtle: #f4f6f3;
  --admin-code: #eef2ed;
  --admin-success: #2f7652;
  --admin-warning: #9b671f;
  --admin-danger: #a14d56;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ecf2ee;
  --muted: #aab8b0;
  --paper: #111714;
  --cream: #1b241f;
  --sage: #8eaa99;
  --sage-dark: #759784;
  --sage-soft: #22332a;
  --rose: #e08a93;
  --line: rgba(224,236,228,.14);
  --shadow: 0 24px 70px rgba(0,0,0,.28);
  --admin-surface: rgba(24,33,28,.9);
  --admin-solid: #18211c;
  --admin-subtle: #1d2822;
  --admin-code: #111915;
  --admin-success: #7bc49d;
  --admin-warning: #e0b064;
  --admin-danger: #ee969e;
}

html[data-theme="dark"] body {
  background: radial-gradient(circle at 8% 4%, rgba(79,111,91,.35), transparent 32rem),
              radial-gradient(circle at 92% 88%, rgba(100,72,66,.28), transparent 30rem), var(--paper);
}

.admin-shell { width: min(1320px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 72px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.head-actions { display: flex; gap: 9px; align-items: center; }
.link-button { display: inline-block; width: auto; margin: 0; text-decoration: none; text-align: center; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.stat { padding: 18px 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--admin-surface); box-shadow: var(--shadow); }
.stat strong { display: block; margin-top: 5px; font-size: 30px; }
.stat span { color: var(--muted); font-size: 13px; }
.admin-panel { margin-top: 18px; padding: 24px; border: 1px solid var(--line); border-radius: 22px; background: var(--admin-surface); box-shadow: var(--shadow); }
.admin-panel h2 { margin-bottom: 12px; font-size: 25px; }
.admin-panel h3 { margin: 0 0 12px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.wrap-title { align-items: flex-end; flex-wrap: wrap; }
.admin-list { display: grid; gap: 9px; }
.admin-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--admin-solid); }
.admin-row strong { display: block; margin-bottom: 4px; }
.admin-row span, .admin-note { color: var(--muted); font-size: 13px; line-height: 1.65; }
.admin-row button, .table-action { padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; color: var(--sage-dark); background: var(--sage-soft); white-space: nowrap; }
.admin-create-form { display: grid; grid-template-columns: repeat(3,1fr) auto; gap: 12px; align-items: end; }
.admin-create-form .field { margin: 0; }
.admin-create-form .primary { width: auto; min-width: 120px; margin: 0; }
.status-open { color: var(--rose) !important; font-weight: 700; }
.annotated-report { border-color: color-mix(in srgb, var(--admin-warning) 55%, var(--line)); box-shadow: inset 4px 0 0 var(--admin-warning); }
.annotation-badge { display: inline-flex !important; width: fit-content; margin-top: 7px; padding: 4px 8px; border-radius: 999px; color: var(--admin-warning) !important; background: color-mix(in srgb, var(--admin-warning) 12%, transparent); font-weight: 800; }
.report-dialog { width: min(820px, calc(100vw - 30px)); max-height: 88vh; overflow-y: auto; }
.report-dialog-meta { margin: 14px 0 18px; padding: 10px 12px; border-radius: 10px; color: var(--muted); background: var(--admin-subtle); font-size: 13px; }
.report-dialog-messages { display: grid; gap: 13px; margin-bottom: 18px; }
.report-message { width: min(88%, 650px); padding: 13px 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--admin-solid); }
.report-message-user { justify-self: end; border-top-right-radius: 4px; }
.report-message-assistant { justify-self: start; border-top-left-radius: 4px; background: var(--sage-soft); }
.report-message-label { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.report-message-content { margin: 0; line-height: 1.65; white-space: pre-wrap; }
.report-annotation { margin: 12px -3px -2px; padding: 11px 12px; border-left: 4px solid var(--admin-warning); border-radius: 9px; color: var(--ink); background: color-mix(in srgb, var(--admin-warning) 11%, var(--admin-solid)); }
.report-annotation strong, .report-annotation small { display: block; }
.report-annotation p { margin: 6px 0; line-height: 1.55; white-space: pre-wrap; }
.report-annotation small { color: var(--muted); }

.admin-tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--admin-solid) 90%, transparent); box-shadow: 0 10px 35px rgba(40,50,47,.08); backdrop-filter: blur(18px); }
.admin-tab { flex: 0 1 220px; padding: 12px 16px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-weight: 700; }
.admin-tab.active { color: white; background: var(--sage-dark); }
.tab-panel { padding-top: 1px; }

.foundation-hero { display: flex; justify-content: space-between; align-items: center; gap: 28px; border-left: 5px solid var(--sage); }
.foundation-hero > div { max-width: 820px; }
.foundation-hero .admin-note { margin-bottom: 0; font-size: 14px; }
.primary.compact { width: auto; min-width: 220px; margin: 0; }
.foundation-flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 18px 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--admin-surface); box-shadow: var(--shadow); }
.foundation-flow li { position: relative; min-height: 92px; padding: 17px 18px 16px 56px; border-right: 1px solid var(--line); }
.foundation-flow li:last-child { border-right: 0; }
.foundation-flow span { position: absolute; left: 18px; top: 17px; display: grid; width: 27px; height: 27px; place-items: center; border-radius: 50%; color: white; background: var(--sage-dark); font-size: 13px; font-weight: 800; }
.foundation-flow strong, .foundation-flow small { display: block; }
.foundation-flow small { margin-top: 5px; color: var(--muted); line-height: 1.4; }
.foundation-message { min-height: 24px; margin: 8px 2px 0; color: var(--sage-dark); font-size: 14px; font-weight: 700; }

.table-filters { display: flex; flex-wrap: wrap; gap: 9px; align-items: end; }
.table-filters label { color: var(--muted); font-size: 12px; font-weight: 700; }
.table-filters label span { display: block; margin-bottom: 5px; }
.table-filters select, .table-filters input { width: auto; min-width: 150px; margin: 0; padding: 9px 11px; border-radius: 10px; }
.table-filters .search-field input { min-width: 210px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--admin-solid); }
.admin-table { width: 100%; min-width: 880px; border-collapse: collapse; }
.admin-table th { padding: 12px 14px; color: var(--muted); background: var(--admin-subtle); text-align: left; font-size: 12px; letter-spacing: .04em; white-space: nowrap; }
.admin-table td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: top; font-size: 14px; line-height: 1.55; }
.admin-table tbody tr:hover { background: color-mix(in srgb, var(--sage-soft) 36%, transparent); }
.admin-table strong, .admin-table small { display: block; }
.admin-table small { margin-top: 4px; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px !important; }
.empty-cell { padding: 28px !important; color: var(--muted); text-align: center; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager .outline { padding: 8px 12px; }

.status-pill { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; color: var(--muted); background: var(--admin-subtle); font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-approved, .status-completed, .status-evidence_verified, .status-published, .status-ready { color: var(--admin-success); background: color-mix(in srgb, var(--admin-success) 13%, transparent); }
.status-changes_requested, .status-in_review, .status-teacher_approved, .status-indexed { color: var(--admin-warning); background: color-mix(in srgb, var(--admin-warning) 13%, transparent); }
.status-rejected { color: var(--admin-danger); background: color-mix(in srgb, var(--admin-danger) 13%, transparent); }

.review-detail { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); scroll-margin-top: 86px; }
.review-heading { display: flex; align-items: center; gap: 10px; }
.review-heading h3 { margin: 0; }
.review-table { min-width: 1120px; }
.review-table th:nth-child(1) { width: 20%; }
.review-table th:nth-child(2) { width: 34%; }
.review-table th:nth-child(3) { width: 11%; }
.review-table th:nth-child(4) { width: 35%; }
.review-question { margin: 0; line-height: 1.65; }
.mini-details { margin-top: 8px; color: var(--muted); font-size: 12px; }
.mini-details p { margin: 7px 0 0; }
.review-controls-cell { min-width: 320px; }
.review-notes { width: 100%; min-height: 68px; padding: 9px 11px; resize: vertical; border-radius: 10px; line-height: 1.45; }
.review-actions { display: flex; gap: 6px; margin-top: 7px; }
.review-actions button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--admin-subtle); }
.review-approve { color: var(--admin-success); }
.review-change { color: var(--admin-warning); }
.review-reject { color: var(--admin-danger); }

.release-grid { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(360px, 1.2fr); gap: 26px; }
.release-form { padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: var(--admin-subtle); }
.release-form .field { margin: 0 0 14px; }
.release-form .primary { margin: 2px 0 10px; }
.release-form small { color: var(--muted); line-height: 1.5; }
.compact-list .admin-row { padding: 11px 13px; }
.audit-details { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.audit-details summary { color: var(--sage-dark); cursor: pointer; font-weight: 700; }
.audit-list { display: grid; gap: 7px; margin-top: 12px; }
.audit-list .admin-row { padding: 10px 12px; }

.object-dialog { max-height: min(760px, 88vh); overflow-y: auto; }
.review-object-card { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--admin-subtle); }
.review-object-card.reviewed { border-color: var(--sage); }
.review-object-card h3 { margin: 0 0 4px; }
.review-view-fields { display: grid; gap: 9px; margin-top: 12px; }
.review-view-fields label, .review-object-note { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.review-view-fields textarea, .review-object-note input { width: 100%; padding: 9px 11px; border-radius: 10px; color: var(--ink); background: var(--admin-surface); }
.review-view-fields textarea { min-height: 66px; resize: vertical; }
.review-object-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.object-facts { display: grid; grid-template-columns: 140px 1fr; margin: 18px 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.object-facts dt, .object-facts dd { margin: 0; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.object-facts dt { color: var(--muted); background: var(--admin-subtle); font-size: 12px; font-weight: 700; }
.object-facts dd { overflow-wrap: anywhere; }
.object-facts dt:nth-last-of-type(1), .object-facts dd:last-child { border-bottom: 0; }
.payload-details summary { cursor: pointer; color: var(--sage-dark); font-weight: 700; }
.payload-details pre { max-height: 360px; overflow: auto; padding: 16px; border-radius: 12px; color: var(--ink); background: var(--admin-code); font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--sage) 65%, transparent); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .48; }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2,1fr); }
  .foundation-flow { grid-template-columns: repeat(2,1fr); }
  .foundation-flow li:nth-child(2) { border-right: 0; }
  .foundation-flow li:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .release-grid { grid-template-columns: 1fr; }
  .admin-create-form { grid-template-columns: repeat(2,1fr); }
  .admin-create-form .primary { width: 100%; }
}

@media (max-width: 650px) {
  .admin-shell { width: min(100% - 20px, 1320px); padding-top: 18px; }
  .admin-head { align-items: flex-start; }
  .head-actions { align-items: stretch; flex-direction: column; }
  .admin-tabs { top: 4px; }
  .admin-tab { flex: 1; padding: 11px 9px; font-size: 13px; }
  .admin-row { grid-template-columns: 1fr; }
  .admin-create-form { grid-template-columns: 1fr; }
  .admin-panel { padding: 18px; border-radius: 18px; }
  .foundation-hero { align-items: stretch; flex-direction: column; }
  .primary.compact { width: 100%; }
  .foundation-flow { grid-template-columns: 1fr; }
  .foundation-flow li, .foundation-flow li:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .foundation-flow li:last-child { border-bottom: 0; }
  .table-filters { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .table-filters label, .table-filters select, .table-filters input { width: 100%; min-width: 0 !important; }
  .table-filters .search-field { grid-column: 1 / -1; }
  .pager { justify-content: space-between; }
  .object-facts { grid-template-columns: 1fr; }
  .object-facts dt { border-bottom: 0; }
}
