:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --paper: #f8f2ea;
  --paper-deep: #efe5d9;
  --surface: #fffdf9;
  --surface-muted: #f6f1e9;
  --text: #292b27;
  --text-secondary: #676960;
  --text-muted: #676960;
  --border: #ded7cd;
  --border-strong: #c8bfb3;
  --green: #2f7046;
  --green-hover: #245a37;
  --green-soft: #e3f0e7;
  --orange: #91431d;
  --orange-soft: #fff0df;
  --red: #9a3428;
  --red-soft: #fbe8e4;
  --blue: #285f91;
  --blue-soft: #e8f0f8;
  --focus: #1b64a5;
  --shadow: 0 12px 34px rgb(67 56 43 / 8%);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.55;
}

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

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgb(27 100 165 / 34%);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: white;
  background: var(--text);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-shell {
  width: min(100%, 920px);
  display: grid;
  grid-template-columns: minmax(260px, 0.82fr) minmax(340px, 1fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-context {
  min-height: 480px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px;
  border-right: 1px solid var(--border);
  background: var(--green-soft);
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(52 122 76 / 32%);
  border-radius: 9px;
  color: var(--green);
  background: rgb(255 255 255 / 62%);
  font-weight: 760;
  font-size: 17px;
}

.brand-name {
  margin: 0;
  font-size: 17px;
  font-weight: 720;
}

.brand-subtitle,
.eyebrow,
.helper,
.muted {
  color: var(--text-secondary);
}

.brand-subtitle {
  margin: 1px 0 0;
  font-size: 12px;
}

.login-context h1 {
  max-width: 9em;
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 39px);
  line-height: 1.18;
  letter-spacing: -0.025em;
}

.login-context > div > p:last-child {
  max-width: 28em;
  margin: 0;
  color: var(--text-secondary);
}

.login-form-wrap {
  display: flex;
  align-items: center;
  padding: 48px clamp(28px, 5vw, 64px);
}

.login-form,
.stack {
  width: 100%;
  display: grid;
  gap: 20px;
}

.login-form h2,
.page-title,
.section-title {
  margin: 0;
  line-height: 1.25;
}

.login-form h2 {
  font-size: 24px;
}

.login-form > p {
  margin: -12px 0 4px;
  color: var(--text-secondary);
}

.field {
  display: grid;
  gap: 7px;
}

.field > label,
.field-label {
  color: var(--text);
  font-weight: 650;
}

.field-help,
.field-error {
  margin: 0;
  font-size: 12px;
}

.field-help {
  color: var(--text-secondary);
}

.field-error {
  color: var(--red);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  background: white;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #9f978c;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  outline: 3px solid rgb(27 100 165 / 14%);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  cursor: pointer;
  font-weight: 680;
  overflow-wrap: anywhere;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button-primary {
  color: white;
  background: var(--green);
}

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

.button-secondary {
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
}

.button-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
}

.button-tertiary {
  min-height: 44px;
  padding: 8px 9px;
  color: var(--green);
  background: transparent;
}

.button-danger {
  border: 1px solid rgb(179 69 52 / 45%);
  color: var(--red);
  background: white;
}

.button-inline-loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 2px solid rgb(255 255 255 / 38%);
  border-top-color: currentcolor;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.75s linear infinite;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px 18px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-nav {
  display: grid;
  gap: 4px;
}

.nav-link {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 620;
}

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

.nav-link[aria-current="page"] {
  color: var(--green);
  background: var(--green-soft);
}

.nav-glyph {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: currentcolor;
  font-size: 15px;
}

.sidebar-account {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-account strong,
.sidebar-account span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-account span {
  color: var(--text-secondary);
  font-size: 12px;
}

.sidebar-account button {
  width: 100%;
  margin-top: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px clamp(20px, 3vw, 48px) 56px;
}

.workspace-inner {
  width: min(100%, 1360px);
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.page-title {
  font-size: clamp(25px, 3vw, 32px);
  letter-spacing: -0.02em;
}

.page-description {
  max-width: 64ch;
  margin: 7px 0 0;
  color: var(--text-secondary);
}

.page-actions,
.button-row,
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.table-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: max-content;
}

.table-actions button {
  padding-inline: 9px;
}

.toolbar {
  justify-content: space-between;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--border);
}

.section {
  padding: 24px 0;
  border-top: 1px solid var(--border);
}

.section:first-child {
  padding-top: 0;
  border-top: 0;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--text-secondary);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.7fr);
  gap: 24px;
  align-items: start;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2,
.panel-header h3,
.panel-header p {
  margin: 0;
}

.panel-header p {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 12px;
}

.panel-body {
  padding: 18px;
}

.entity-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.entity-list > li + li {
  border-top: 1px solid var(--border);
}

.entity-button {
  width: 100%;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-radius: 0;
  padding: 13px 16px;
  text-align: left;
  color: var(--text);
  background: transparent;
}

.entity-button:hover,
.entity-button[aria-pressed="true"] {
  background: var(--surface-muted);
}

.entity-button[aria-pressed="true"] {
  box-shadow: inset 3px 0 var(--green);
}

.entity-title,
.entity-meta {
  display: block;
}

.entity-title {
  font-weight: 680;
  overflow-wrap: anywhere;
}

.entity-meta {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--text-secondary);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 680;
  white-space: nowrap;
}

.status[data-tone="positive"] {
  color: var(--green);
  background: var(--green-soft);
}

.status[data-tone="warning"] {
  color: var(--orange);
  background: var(--orange-soft);
}

.status[data-tone="danger"] {
  color: var(--red);
  background: var(--red-soft);
}

.status[data-tone="info"] {
  color: var(--blue);
  background: var(--blue-soft);
}

.revision-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.revision-line::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table th {
  color: var(--text-secondary);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 680;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  white-space: nowrap;
}

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

.data-table tbody tr:hover {
  background: #fcf9f4;
}

.data-table tbody .selected-row {
  background: var(--green-soft);
}

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

.definition-grid > div {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.definition-grid dt {
  color: var(--text-secondary);
  font-size: 12px;
}

.definition-grid dd {
  margin: 3px 0 0;
  font-weight: 620;
  overflow-wrap: anywhere;
}

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

.form-grid .span-full {
  grid-column: 1 / -1;
}

.checkbox-field {
  min-height: 44px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 0;
}

.checkbox-field input {
  width: 20px;
  min-height: 20px;
  margin-top: 2px;
}

.checkbox-field input:disabled + span {
  color: var(--text-secondary);
}

.empty-state,
.error-state,
.loading-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
}

.state-copy {
  max-width: 44ch;
}

.state-copy h2,
.state-copy h3,
.state-copy p {
  margin: 0;
}

.state-copy p {
  margin-top: 7px;
  color: var(--text-secondary);
}

.state-copy .button-row {
  justify-content: center;
  margin-top: 18px;
}

.loading-line {
  height: 13px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--paper-deep);
}

.loading-line::after {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 75%), transparent);
  animation: loading 1.2s ease-in-out infinite;
}

.notice {
  padding: 12px 14px;
  border-left: 3px solid var(--blue);
  color: var(--text);
  background: var(--blue-soft);
}

.notice[data-tone="error"] {
  border-left-color: var(--red);
  background: var(--red-soft);
}

.notice[data-tone="success"] {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.notice p {
  margin: 0;
  overflow-wrap: anywhere;
}

.readonly-value {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-secondary);
  background: var(--surface-muted);
  overflow-wrap: anywhere;
}

.validation-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.validation-summary > div {
  padding: 15px 16px;
}

.validation-summary > div + div {
  border-left: 1px solid var(--border);
}

.validation-summary strong,
.validation-summary span {
  display: block;
}

.validation-summary strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.validation-summary span {
  color: var(--text-secondary);
  font-size: 12px;
}

.issue-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.issue-list li {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.issue-list li:last-child {
  border-bottom: 0;
}

.issue-path {
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.pagination-actions {
  display: flex;
  justify-content: center;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border);
}

.pagination-stack {
  display: grid;
  gap: 12px;
}

.pagination-stack .notice {
  width: 100%;
  text-align: left;
}

.pagination-stack button {
  justify-self: center;
}

.custom-library-layout {
  grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.7fr);
}

.custom-library-queue-item {
  min-height: 76px;
}

.custom-library-detail-header,
.delivery-result {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.custom-library-detail-header h2,
.custom-library-detail-header p,
.delivery-result h2,
.delivery-result p {
  margin: 0;
}

.custom-library-detail-header p,
.delivery-result p {
  margin-top: 4px;
  color: var(--text-secondary);
}

.delivery-result {
  margin-bottom: 24px;
}

.active-deliveries {
  margin-bottom: 24px;
}

.active-delivery-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
}

.active-delivery-row strong,
.active-delivery-row p {
  margin: 0;
}

.active-delivery-row p {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 13px;
}

.active-delivery-row button {
  flex: 0 0 auto;
}

.active-delivery-pagination {
  border-top: 1px solid var(--border);
}

.delivery-result h2 {
  font-size: 16px;
}

.delivery-result button {
  flex: 0 0 auto;
}

.custom-library-detail-body {
  display: grid;
  gap: 0;
}

.detail-section {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.compact-heading {
  margin-bottom: 12px;
}

.long-copy {
  margin: 10px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.custom-library-files-table {
  min-width: 600px;
}

.custom-library-files-table td:first-child {
  max-width: 320px;
  white-space: normal;
}

.compact-empty {
  padding: 18px 0 2px;
  color: var(--text-secondary);
}

.compact-empty p {
  margin: 0;
}

.publication-subjects {
  gap: 14px;
}

.publication-subject {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px 12px;
}

.publication-subject legend {
  max-width: 100%;
  padding: 0 6px;
  font-weight: 680;
  overflow-wrap: anywhere;
}

.inline-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-left: 29px;
}

.file-drop {
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 156px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  background: var(--surface-muted);
}

.file-drop input {
  max-width: 360px;
  border: 0;
  padding: 7px;
  background: transparent;
}

.toast-region {
  position: fixed;
  z-index: 80;
  right: 20px;
  bottom: 20px;
  width: min(380px, calc(100vw - 40px));
  display: grid;
  gap: 8px;
}

.toast {
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toast[data-tone="error"] {
  border-color: rgb(179 69 52 / 45%);
}

dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(32 30 26 / 42%);
}

.dialog-header,
.dialog-body,
.dialog-actions {
  padding: 18px 22px;
}

.dialog-header {
  border-bottom: 1px solid var(--border);
}

.dialog-header h2,
.dialog-header p {
  margin: 0;
}

.dialog-header p {
  margin-top: 4px;
  color: var(--text-secondary);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes loading {
  from { transform: translateX(-120%); }
  to { transform: translateX(300%); }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 14px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    display: flex;
    justify-content: center;
  }

  .nav-link {
    min-height: 44px;
  }

  .sidebar-account {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .sidebar-account > div {
    display: none;
  }

  .sidebar-account button {
    width: auto;
    margin: 0;
  }

  .workspace {
    padding-top: 24px;
  }
}

@media (max-width: 760px) {
  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-context {
    min-height: auto;
    gap: 48px;
    padding: 28px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .login-context h1 {
    max-width: none;
    font-size: 28px;
  }

  .login-form-wrap {
    padding: 32px 28px;
  }

  .sidebar {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 16px;
  }

  .sidebar .brand-lockup {
    grid-column: 1;
  }

  .sidebar-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-link {
    white-space: nowrap;
  }

  .sidebar-account {
    grid-column: 2;
    grid-row: 1;
  }

  .workspace {
    padding: 22px 16px 48px;
  }

  .page-header,
  .section-heading,
  .custom-library-detail-header,
  .delivery-result {
    align-items: stretch;
    flex-direction: column;
  }

  .delivery-result button {
    width: 100%;
  }

  .active-delivery-row {
    align-items: stretch;
    flex-direction: column;
  }

  .active-delivery-row button {
    width: 100%;
  }

  .page-actions > button {
    flex: 1;
  }

  .split-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .custom-library-layout .entity-list {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .custom-library-layout .entity-list > li {
    flex: 0 0 min(78vw, 280px);
    scroll-snap-align: start;
  }

  .custom-library-layout .entity-list > li + li {
    border-top: 0;
    border-left: 1px solid var(--border);
  }

  .form-grid .span-full {
    grid-column: auto;
  }

  .definition-grid {
    grid-template-columns: 1fr 1fr;
  }

  .data-table {
    min-width: 680px;
  }

  .validation-summary {
    grid-template-columns: 1fr;
  }

  .validation-summary > div + div {
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions button {
    width: 100%;
  }
}

@media (max-width: 440px) {
  .nav-glyph {
    display: none;
  }

  .definition-grid {
    grid-template-columns: 1fr;
  }

  .data-table th,
  .data-table td {
    padding: 10px 11px;
  }

  .issue-list li {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

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