:root {
  --warning: #855b13;
  --warning-soft: #fff3d6;
  --danger-soft: #f9e6e3;
}

.portal-header__inner,
.portal-main,
.portal-footer {
  width: min(100% - 2rem, 78rem);
}

.portal-main {
  min-width: 0;
}

.portal-nav {
  flex-wrap: wrap;
}

.workspace-heading {
  max-width: 52rem;
  margin-bottom: 2rem;
}

.workspace-heading--split {
  max-width: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}

.workspace-heading--split > div {
  min-width: 0;
}

.workspace-heading--split .button {
  flex: 0 0 auto;
}

.scope-switch {
  width: fit-content;
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
}

.scope-switch a {
  min-height: 2.65rem;
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 0.9rem;
  border-radius: 0.35rem;
  font-weight: 750;
  text-decoration: none;
}

.scope-switch a[aria-current="page"] {
  color: #fff;
  background: var(--green);
}

.operating-note,
.section-intro,
.result-count {
  color: var(--muted);
  line-height: 1.6;
}

.operating-note {
  max-width: 58rem;
  margin: 1rem 0 2rem;
}

.queue-sections {
  display: grid;
  gap: 2.5rem;
}

.queue-section,
.detail-section {
  min-width: 0;
  padding-top: 1.15rem;
  border-top: 2px solid var(--ink);
}

.section-heading {
  margin-bottom: 1rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.count-label {
  min-width: 2rem;
  min-height: 2rem;
  display: inline-grid;
  place-items: center;
  color: var(--green-dark);
  background: var(--green-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.empty-state {
  margin: 0;
  padding: 1.1rem 0;
  color: var(--muted);
}

.empty-state--large {
  max-width: 42rem;
  padding: 2rem 0;
  border-top: 2px solid var(--ink);
}

.empty-state--large h2 {
  margin-bottom: 0.5rem;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 58rem;
  border-collapse: collapse;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 0.9rem 0.75rem;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.data-table th {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: rgb(220 235 227 / 28%);
}

.table-detail,
.row-reason,
.mode-label,
.exception-label,
.detail-subvalue {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.row-reason {
  max-width: 30rem;
  color: var(--green-dark);
}

.mode-label {
  width: fit-content;
  padding: 0.15rem 0.42rem;
  color: var(--green-dark);
  background: var(--green-soft);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
}

.exception-label {
  color: var(--danger);
  font-weight: 750;
}

.table-action {
  text-align: right;
  white-space: nowrap;
}

.table-action a {
  font-weight: 750;
}

.terminal-row {
  background: var(--surface-alt);
  box-shadow: inset 4px 0 0 var(--muted);
}

.filter-form,
.record-form {
  margin-bottom: 2rem;
  padding: clamp(1.15rem, 3vw, 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}

.record-form--narrow {
  max-width: 52rem;
}

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

.filter-grid {
  grid-template-columns: repeat(5, minmax(9rem, 1fr));
}

.form-field--wide {
  grid-column: 1 / -1;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.8rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #8f968f;
  border-radius: 0.4rem;
}

.form-field textarea {
  min-height: 6rem;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 1px var(--focus);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset + fieldset {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

legend {
  margin-bottom: 0.4rem;
  padding: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.check-field {
  width: fit-content;
  min-height: 2.75rem;
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  cursor: pointer;
}

.check-field input {
  width: 1.2rem;
  height: 1.2rem;
}

.compliance-warning,
.exception-notice,
.confirmation {
  padding: 1rem 1.1rem;
  line-height: 1.55;
  border-left: 4px solid;
}

.compliance-warning {
  color: #62440e;
  background: var(--warning-soft);
  border-left-color: var(--warning);
}

.exception-notice {
  color: #701e19;
  background: var(--danger-soft);
  border-left-color: var(--danger);
}

.exception-notice h2 {
  margin-bottom: 0.45rem;
}

.exception-notice p,
.confirmation {
  margin: 0;
}

.confirmation {
  margin-bottom: 1.5rem;
  color: var(--green-dark);
  background: var(--green-soft);
  border-left-color: var(--green);
  font-weight: 700;
}

.pagination {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
}

.pagination a {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  font-weight: 750;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(18rem, 0.9fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: start;
}

.detail-primary {
  min-width: 0;
  display: grid;
  gap: 2.5rem;
}

.detail-secondary {
  min-width: 0;
}

.detail-list,
.stacked-detail-list {
  margin: 0;
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.detail-list > div {
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
}

.detail-list dt,
.stacked-detail-list dt {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.detail-list dd,
.stacked-detail-list dd {
  margin: 0;
}

.stacked-detail-list > div {
  padding-block: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.stacked-detail-list > div:last-child {
  border-bottom: 0;
}

.stacked-detail-list dd > span {
  display: block;
}

.contact-list,
.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.contact-list li {
  min-width: 0;
  padding: 1rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.contact-list li > div {
  min-width: 0;
}

.archived-contacts {
  margin-top: 1rem;
  color: var(--muted);
}

.archived-contacts summary {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  font-weight: 700;
  cursor: pointer;
}

.history-list li {
  position: relative;
  display: grid;
  grid-template-columns: 0.85rem minmax(0, 1fr);
  gap: 0.9rem;
  padding-bottom: 1.5rem;
}

.history-list li::before {
  content: "";
  position: absolute;
  top: 0.85rem;
  bottom: 0;
  left: 0.35rem;
  width: 1px;
  background: var(--line);
}

.history-list li:last-child::before {
  display: none;
}

.history-marker {
  position: relative;
  z-index: 1;
  width: 0.75rem;
  height: 0.75rem;
  margin-top: 0.3rem;
  background: var(--green);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--green);
}

.history-list h3 {
  margin: 0;
  font-size: 1rem;
}

.history-list p {
  margin: 0.35rem 0 0;
  line-height: 1.55;
}

.history-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.archive-action {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.archive-action h2 {
  margin-bottom: 0.4rem;
}

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

.button--danger:hover {
  color: #fff;
  background: #701e19;
}

.wrap-anywhere {
  overflow-wrap: anywhere;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 64rem) {
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .detail-secondary {
    order: -1;
  }
}

@media (max-width: 46rem) {
  .workspace-heading--split {
    align-items: flex-start;
    flex-direction: column;
  }

  .scope-switch {
    width: 100%;
  }

  .scope-switch a {
    flex: 1;
    justify-content: center;
  }

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

  .portal-nav {
    justify-content: flex-start;
  }

  .portal-nav a,
  .link-button {
    min-height: 2.5rem;
    font-size: 0.9rem;
  }

  .table-scroll {
    overflow: visible;
  }

  .data-table {
    min-width: 0;
  }

  .data-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
  }

  .data-table tr {
    padding: 0.75rem 0;
    border-top: 1px solid var(--line);
  }

  .data-table td {
    min-width: 0;
    padding: 0.55rem 0;
    display: grid;
    grid-template-columns: minmax(6rem, 0.38fr) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
    border: 0;
    text-align: left;
  }

  .data-table td::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .data-table td > * {
    min-width: 0;
    grid-column: 2;
  }

  .data-table td .mode-label {
    align-self: start;
    justify-self: start;
  }

  .data-table .table-action {
    display: block;
    padding-top: 0.75rem;
  }

  .data-table .table-action::before {
    display: none;
  }

  .data-table .table-action a {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
  }

  .terminal-row {
    padding-left: 0.75rem !important;
  }

  .contact-list li {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: no-preference) {
  select,
  textarea,
  .scope-switch a {
    transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
  }
}
