/* ICA-MIS shared styles. Values come from tokens.css. Sections:
   base · utilities · grids · brand · auth layout · app shell · sidebar · topbar · page header ·
   cards · KPI · charts · badges · buttons · forms · alerts & states · tables · pagination ·
   filter bar · dialog · component reference · responsive */

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-page);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
}

h1,
h2,
h3,
p {
  margin: 0;
}
img,
svg {
  display: block;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
a {
  color: var(--color-primary);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Utilities ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.muted {
  color: var(--color-text-muted);
}
.stack {
  display: grid;
  gap: var(--space-6);
}
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

.link {
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-decoration: none;
}
.link:hover {
  text-decoration: underline;
}

/* ---------- Grids ---------- */
.grid {
  display: grid;
  gap: var(--space-4);
}
.grid-kpi {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ---------- Brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: var(--weight-bold);
  font-size: 16px;
}
.brand-text {
  display: grid;
  min-width: 0;
}
.brand-name {
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  white-space: nowrap;
}
.brand-subtitle {
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: 10px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.brand--compact .brand-mark {
  width: 34px;
  height: 34px;
  font-size: 13px;
  background: var(--color-sidebar);
}
.brand--compact .brand-name {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
}

/* ---------- Auth layout (wireframe 8.1) ---------- */
.auth {
  display: grid;
  grid-template-columns: minmax(320px, 5fr) 7fr;
  min-height: 100vh;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-10);
  background: var(--color-sidebar);
  color: #fff;
}
.auth-headline {
  max-width: 14em;
  font-size: clamp(24px, 2.6vw, 34px);
  font-weight: var(--weight-bold);
  line-height: 1.25;
}
.auth-institution {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-sidebar-muted);
  font-size: var(--text-xs);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
}
.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  min-width: 0;
  padding: var(--space-10) var(--space-4);
}
.auth-mobile-brand {
  display: none;
  width: 100%;
  max-width: 400px;
}
.auth-mobile-brand .brand-subtitle {
  white-space: normal;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-8) 28px;
}
.auth-card .card-title {
  font-size: var(--text-xl);
}
.auth-card .card-subtitle {
  margin: var(--space-1) 0 var(--space-6);
}
.auth-card .field {
  margin-bottom: 18px;
}
.auth-card .check {
  margin-bottom: 22px;
}

/* ---------- App shell (wireframes 8.2-8.6) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  /* Paint the sidebar column full height even when the page is taller than the sticky sidebar. */
  background: linear-gradient(
    to right,
    var(--color-sidebar) var(--sidebar-w),
    transparent 0
  );
}
.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.app-content {
  width: 100%;
  max-width: var(--content-max);
  padding: var(--space-6);
  display: grid;
  gap: var(--space-5);
  align-content: start;
}
.app-content:focus {
  box-shadow: none;
}
.app-backdrop {
  display: none;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--space-5) var(--space-3);
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-2);
}
.sidebar-label {
  color: var(--color-sidebar-muted);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sidebar-close {
  color: var(--color-sidebar-text);
}
.nav-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nav-list--footer {
  margin-top: auto;
  padding: var(--space-2);
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: var(--radius);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--color-sidebar-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.nav-link:hover {
  background: var(--color-sidebar-hover);
  color: #fff;
}
.nav-link.is-active {
  background: var(--color-primary);
  color: #fff;
  font-weight: var(--weight-semibold);
}
.nav-list--footer .nav-link {
  min-height: 34px;
  color: var(--color-sidebar-muted);
  font-size: var(--text-xs);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding: var(--space-2) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.topbar-end {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--color-surface-muted);
  color: var(--color-text);
}
.sidebar .icon-btn:hover {
  background: var(--color-sidebar-hover);
  color: #fff;
}
/* Drawer controls exist only below 1024px (see Responsive). */
.icon-btn.menu-btn,
.icon-btn.sidebar-close {
  display: none;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
}
.avatar .icon {
  width: 32px;
  height: 32px;
}
.avatar--sm {
  width: 32px;
  height: 32px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--text-xs);
}

/* Disclosure menu (native <details>) */
.menu {
  position: relative;
}
.menu > summary {
  list-style: none;
  cursor: pointer;
}
.menu > summary::-webkit-details-marker {
  display: none;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  font-weight: var(--weight-semibold);
}
.user-chip:hover {
  background: var(--color-surface-muted);
}
.menu[open] .user-chip .icon {
  transform: rotate(180deg);
}
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-1));
  z-index: 30;
  min-width: 200px;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-pop);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
}
.menu-item:hover {
  background: var(--color-surface-muted);
}
/* Sign-out is a POST form; make its button look like the links around it. */
button.nav-link,
button.menu-item {
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-panel form,
.nav-list form {
  margin: 0;
}

/* Definition list for account and record details */
.details {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: var(--space-3) var(--space-4);
  margin: 0;
}
.details dt {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.capability-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}
.capability-list li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}
.capability-list .icon {
  margin-top: 2px;
  color: var(--color-success);
}
.auth-error {
  margin-bottom: var(--space-5);
}

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
}
.page-header-text {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.page-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: 1.3;
}
.page-title--caps {
  text-transform: uppercase;
}
.page-description {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.eyebrow {
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- Cards ---------- */
.card {
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}
.card-header + .card-body {
  padding-top: 0;
}
.card-header--divided {
  border-bottom: 1px solid var(--color-border);
}
.card-header--divided + .card-body {
  padding-top: var(--space-5);
}
.card-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}
.card-subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.card-body {
  padding: var(--space-5);
}
.card-body--flush,
.card-header + .card-body--flush {
  padding: 0;
}
.card-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: 56px var(--space-6);
  text-align: center;
}
.empty-state .btn {
  margin-top: var(--space-2);
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-2);
  border-radius: 50%;
  background: var(--color-surface-muted);
  color: var(--color-text-subtle);
}
.empty-icon .icon {
  width: 28px;
  height: 28px;
}

/* ---------- KPI card ---------- */
.kpi {
  position: relative;
  display: grid;
  gap: var(--space-2);
  align-content: start;
  padding: var(--space-4) var(--space-5);
}
.kpi-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
/* "MOUs", not "MOUS": keep the plural s lower-case inside upper-cased labels */
.kpi-label .keep-case {
  text-transform: none;
}

.kpi-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1.15;
}
.kpi-value--empty {
  color: var(--color-text-subtle);
}
.kpi-hint {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.kpi-alert {
  flex: none;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  background: var(--color-danger-soft);
}
.kpi-anchor {
  color: inherit;
  text-decoration: none;
}
.kpi-anchor::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
}
.kpi--link:hover {
  border-color: var(--color-primary);
}
.kpi--link:focus-within {
  box-shadow: var(--focus-ring);
}
.kpi-anchor:focus-visible {
  box-shadow: none;
}

/* ---------- Charts ---------- */
.chart-body {
  display: grid;
  gap: var(--space-5);
}
.chart-body--legend {
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  align-items: center;
}
.chart-canvas {
  position: relative;
  height: 220px;
  min-width: 0;
}
.chart-legend {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}
.chart-legend li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
}
.chart-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.chart-key li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.swatch--primary {
  background: var(--color-primary);
}
.swatch--accent {
  background: var(--color-accent);
}
.swatch--danger {
  background: var(--color-danger);
}
.swatch--success {
  background: var(--color-success);
}
.swatch--neutral {
  background: var(--color-text-subtle);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  line-height: 1.6;
  white-space: nowrap;
}
.badge--primary,
.badge--info {
  background: var(--color-info-soft);
  color: var(--color-info);
}
.badge--success {
  background: var(--color-success-soft);
  color: var(--color-success);
}
.badge--warning {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}
.badge--danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.badge--neutral {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn .icon {
  width: 16px;
  height: 16px;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.btn--primary:hover {
  background: var(--color-primary-hover);
}
.btn--outline {
  border-color: var(--color-primary);
  background: var(--color-surface);
  color: var(--color-primary);
}
.btn--outline:hover {
  background: var(--color-primary-soft);
}
.btn--neutral {
  border-color: var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
}
.btn--neutral:hover {
  background: var(--color-surface-muted);
}
.btn--danger {
  background: var(--color-danger);
  color: #fff;
}
.btn--danger:hover {
  background: #991b1b;
}
.btn--sm {
  min-height: var(--control-h-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn--block {
  width: 100%;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}
.form-actions .btn,
.dialog-actions .btn {
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5) var(--space-6);
}
.field {
  display: grid;
  gap: 6px;
  align-content: start;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.field--wide {
  grid-column: 1 / -1;
}
.fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 6px;
}
.label {
  display: block;
  padding: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.req {
  color: var(--color-danger);
}
.help {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.input,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field select,
.field textarea,
.filter-pill select {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.field textarea {
  min-height: 96px;
  padding: 10px var(--space-3);
  resize: vertical;
}
.field select[multiple] {
  min-height: 112px;
  padding: var(--space-2);
}
.input::placeholder,
.field input::placeholder,
.field textarea::placeholder {
  color: var(--color-text-subtle);
}
.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.filter-pill select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}
.has-error input,
.has-error select,
.has-error textarea,
.has-error .dropzone {
  border-color: var(--color-danger);
}
.field-errors .errorlist,
.alert .errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-danger);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* Radios and checkbox groups render inline (wireframe 8.5) */
.field--radioselect .fieldset > div,
.field--checkboxselectmultiple .fieldset > div {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
}
.field--radioselect label,
.field--checkboxselectmultiple label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  cursor: pointer;
}
.field input[type="radio"],
.field input[type="checkbox"],
.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-primary);
}
.check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  cursor: pointer;
}
.field .check {
  color: var(--color-text);
}

/* File drop zone (wireframes 8.3, 8.4, 8.6) */
.dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  padding: var(--space-6) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-page);
  text-align: center;
}
.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}
.dropzone:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}
.dropzone-icon {
  color: var(--color-primary);
}
.dropzone-icon .icon {
  width: 24px;
  height: 24px;
}
.dropzone-text {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}
.dropzone-name {
  color: var(--color-primary);
  font-weight: var(--weight-medium);
}
.dropzone-hint {
  color: var(--color-text-muted);
  font-size: 11px;
}
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* Password field with reveal button */
.input-wrap {
  position: relative;
}
.input-wrap .input {
  padding-right: 44px;
}
.reveal {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 44px;
  height: var(--control-h);
  border: 0;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}
.reveal .icon-show,
.reveal[aria-pressed="true"] .icon-hide {
  display: none;
}
.reveal[aria-pressed="true"] .icon-show {
  display: block;
}

/* Generate, show and copy buttons under a new-password field */
.password-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------- Alerts and states ---------- */
.messages {
  display: grid;
  gap: var(--space-3);
}
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid;
  border-radius: var(--radius);
  font-size: var(--text-sm);
}
.alert .icon {
  margin-top: 2px;
}
.alert-title {
  font-weight: var(--weight-semibold);
}
.alert--success {
  border-color: #86efac;
  background: var(--color-success-soft);
  color: #14532d;
}
.alert--success .icon {
  color: var(--color-success);
}
.alert--info {
  border-color: #bfdbfe;
  background: var(--color-info-soft);
  color: #1e3a8a;
}
.alert--warning {
  border-color: #fcd34d;
  background: var(--color-warning-soft);
  color: var(--color-warning);
}
.alert--danger {
  border-color: #fca5a5;
  background: var(--color-danger-soft);
  color: #7f1d1d;
}

.state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}
.state .icon {
  width: 24px;
  height: 24px;
}
.state--error {
  color: var(--color-danger);
}
.spinner .icon {
  animation: spin 0.9s linear infinite;
  color: var(--color-primary);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--color-surface-muted) 25%,
    var(--color-border) 50%,
    var(--color-surface-muted) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton--value {
  width: 60%;
  height: 32px;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- Tables ---------- */
/* position: relative keeps absolutely positioned children (e.g. .visually-hidden labels) inside the
   scroll box; without it they escape and widen the whole page on phones. */
.table-wrap {
  position: relative;
  overflow-x: auto;
}
.table-wrap:focus-visible {
  box-shadow: inset var(--focus-ring);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-page);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-align: left;
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover {
  background: var(--color-page);
}
.table-empty {
  color: var(--color-text-muted);
  text-align: center;
}
.table .col-action {
  width: 1%;
  text-align: right;
}
.table-link {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--color-primary);
}
.table-link:hover {
  background: var(--color-primary-soft);
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
}
.pagination-info {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.pagination-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}
.page-link {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
}
.page-link:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.page-link .icon {
  width: 16px;
  height: 16px;
}
.page-link.is-current {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  font-weight: var(--weight-semibold);
}
.page-link.is-disabled {
  color: var(--color-text-subtle);
  pointer-events: none;
}
.page-gap {
  display: grid;
  place-items: center;
  width: 24px;
  color: var(--color-text-muted);
}

/* ---------- Filter bar (wireframe 8.2) ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.filter-icon {
  color: var(--color-text-muted);
}
.user-search {
  flex: 1 1 16rem;
  min-width: 0;
}
.form-card-narrow {
  max-width: 36rem;
}
.filter-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding-left: var(--space-3);
  font-size: var(--text-xs);
}
.filter-pill:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}
.filter-pill-label {
  color: var(--color-text-muted);
  white-space: nowrap;
}
.filter-pill select {
  width: auto;
  min-height: var(--control-h-sm);
  padding: 0 var(--space-2) 0 var(--space-1);
  border: 0;
  background: transparent;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.filter-pill select:focus {
  box-shadow: none;
}
.filter-clear {
  margin-left: auto;
}
.htmx-ready [data-hide-with-htmx] {
  display: none;
}

/* ---------- Dialog ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop {
  background: rgb(11 19 41 / 50%);
}
.dialog-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
.dialog-message {
  margin: var(--space-2) 0 var(--space-6);
  color: var(--color-text-muted);
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ---------- Component reference page ---------- */
.ref-section {
  display: grid;
  gap: var(--space-4);
  scroll-margin-top: calc(var(--topbar-h) + var(--space-4));
}
.ref-section > h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}
.ref-code {
  overflow-x: auto;
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-sidebar);
  color: #e2e8f0;
  font-size: var(--text-xs);
  line-height: 1.6;
}
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3);
}
.swatch-card {
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  font-size: var(--text-xs);
}
.swatch-card span {
  display: block;
  height: 48px;
}
.swatch-card p {
  padding: var(--space-2) var(--space-3);
}

/* ---------- Responsive ---------- */
@media (max-width: 1279px) {
  .grid-kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    background: none;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform 0.2s ease,
      visibility 0.2s;
  }
  .sidebar-open .sidebar {
    transform: none;
    visibility: visible;
  }
  .icon-btn.menu-btn,
  .icon-btn.sidebar-close {
    display: inline-grid;
  }
  .sidebar-open .app-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgb(11 19 41 / 50%);
  }
  .topbar {
    padding: var(--space-2) var(--space-4);
  }
  .app-content {
    padding: var(--space-5) var(--space-4);
  }
  .grid-2,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .chart-body--legend {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Tablet: narrower side panel */
@media (max-width: 1023px) {
  .auth {
    grid-template-columns: minmax(280px, 2fr) 3fr;
  }
  .auth-brand {
    padding: var(--space-8) var(--space-6);
  }
}

/* Phone: no side panel; brand sits above the form */
@media (max-width: 767px) {
  .auth {
    grid-template-columns: minmax(0, 1fr);
  }
  .auth-brand {
    display: none;
  }
  .auth-mobile-brand {
    display: block;
  }
  .auth-panel {
    justify-content: flex-start;
    padding: var(--space-8) var(--space-4);
  }
}

@media (max-width: 400px) {
  .auth-panel {
    padding: var(--space-6) var(--space-3);
  }
  .auth-card {
    padding: var(--space-6) var(--space-4);
  }
}

@media (max-width: 639px) {
  .grid-kpi {
    grid-template-columns: minmax(0, 1fr);
  }
  .brand--compact .brand-text,
  .user-name {
    display: none;
  }
  .page-header-actions,
  .page-header-actions .btn {
    width: 100%;
  }
  .form-actions .btn {
    flex: 1 1 100%;
  }
  .filter-clear {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
  .spinner .icon,
  .skeleton {
    animation: none;
  }
}

/* ---------- Breadcrumbs ---------- */
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.breadcrumbs li + li::before {
  content: "/";
  margin-right: var(--space-2);
  color: var(--color-border-strong);
}
.breadcrumbs a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.breadcrumbs a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}
.breadcrumbs [aria-current] {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  border-bottom: 1px solid var(--color-border);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  margin-bottom: -1px;
  padding: 0 var(--space-3);
  border-bottom: 2px solid transparent;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover {
  color: var(--color-text);
}
.tab.is-active {
  border-bottom-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: var(--weight-semibold);
}
.tab-count {
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  font-size: 11px;
}
.tab.is-active .tab-count {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

/* ---------- Search bar ---------- */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: 480px;
  padding: 0 4px 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.search-bar:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}
.search-icon {
  color: var(--color-text-muted);
}
.search-bar input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-h);
  border: 0;
  background: transparent;
}
.search-bar input:focus {
  outline: none;
  box-shadow: none;
}

/* ---------- Workflow steps ---------- */
.steps {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
}
.step {
  position: relative;
  flex: 1;
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  min-width: 0;
  text-align: center;
}
.step:not(:first-child)::before {
  content: "";
  position: absolute;
  top: 15px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--color-border);
}
.step--complete:not(:first-child)::before,
.step--current::before,
.step--rejected::before,
.step--returned::before {
  background: var(--color-primary);
}
.step-marker {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--color-border-strong);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.step-marker .icon {
  width: 16px;
  height: 16px;
}
.step--complete .step-marker {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}
.step--current .step-marker {
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-soft);
}
.step--rejected .step-marker {
  border-color: var(--color-danger);
  background: var(--color-danger);
  color: #fff;
}
.step--returned .step-marker {
  border-color: var(--color-accent);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}
.step-label {
  display: grid;
  gap: 2px;
  padding: 0 var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.step-state {
  color: var(--color-text-muted);
  font-weight: var(--weight-regular);
}
.step--upcoming .step-label {
  color: var(--color-text-muted);
}

/* ---------- Summary, action and person cards ---------- */
.summary-heading {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.action-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  color: inherit;
  text-decoration: none;
}
.action-card:hover {
  border-color: var(--color-primary);
}
.action-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.action-text {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
}
.action-title {
  font-weight: var(--weight-semibold);
}
.action-arrow {
  color: var(--color-text-muted);
}

.person-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}
.person-text {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}
.person-name {
  font-weight: var(--weight-semibold);
}
.avatar--md {
  width: 40px;
  height: 40px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--text-sm);
}

/* ---------- Activity timeline ---------- */
.timeline {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.timeline-item:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 16px;
  bottom: calc(-1 * var(--space-4));
  left: 5px;
  width: 2px;
  background: var(--color-border);
}
.timeline-dot {
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--color-text-subtle);
}
.timeline-item--success .timeline-dot {
  background: var(--color-success);
}
.timeline-item--info .timeline-dot {
  background: var(--color-primary);
}
.timeline-item--warning .timeline-dot {
  background: var(--color-accent);
}
.timeline-item--danger .timeline-dot {
  background: var(--color-danger);
}
.timeline .muted {
  font-size: var(--text-xs);
}

/* ---------- Partner dashboard: proposals and KPI progress ---------- */
.proposal-list { display: grid; gap: var(--space-6); margin: 0; padding: 0; list-style: none; }
.proposal-item { display: grid; gap: var(--space-4); }
.proposal-item + .proposal-item { padding-top: var(--space-6); border-top: 1px solid var(--color-border); }
.proposal-list:has(.proposal-item--compact) { gap: var(--space-4); }
.proposal-item--compact + .proposal-item--compact, .proposal-item + .proposal-item--compact { padding-top: var(--space-4); }
.proposal-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.proposal-title { font-weight: var(--weight-semibold); }
.proposal-head .muted { font-size: var(--text-xs); }

.kpi-progress { display: grid; gap: var(--space-5); margin: 0; padding: 0; list-style: none; }
.kpi-progress li { display: grid; gap: var(--space-2); font-size: var(--text-sm); }
.kpi-progress-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2) var(--space-3); }
.kpi-progress-note { font-size: var(--text-xs); }
progress.meter {
  width: 100%; height: 8px; border: 0; border-radius: var(--radius-pill); overflow: hidden;
  background: var(--color-surface-muted); appearance: none;
}
progress.meter::-webkit-progress-bar { background: var(--color-surface-muted); border-radius: var(--radius-pill); }
progress.meter::-webkit-progress-value { background: var(--color-primary); border-radius: var(--radius-pill); }
progress.meter::-moz-progress-bar { background: var(--color-primary); border-radius: var(--radius-pill); }

/* ---------- Dashboard ---------- */
.section-title { font-size: var(--text-lg); font-weight: var(--weight-bold); }
.dashboard-panels { align-items: start; }
.plain-list { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.plain-list .badge { margin-left: var(--space-1); }
.plain-list .is-unread { padding-left: var(--space-3); border-left: 3px solid var(--color-primary); }
.table-note { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--color-border); font-size: var(--text-xs); }

/* ---------- Documents ---------- */
.file-link { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-semibold); text-decoration: none; overflow-wrap: anywhere; }
.file-link:hover span { text-decoration: underline; }
.file-checksum { display: block; margin-top: 2px; font-size: 11px; }
.table-actions { flex-wrap: nowrap; justify-content: flex-end; }

/* ---------- Document preview ---------- */
.preview-title { overflow-wrap: anywhere; }
.preview-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--space-5); align-items: start; }
.preview-card { overflow: hidden; }
.preview-note { padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--color-border); font-size: var(--text-xs); }
.preview-tabs { padding: 0 var(--space-4); }
.details--stacked { grid-template-columns: 1fr; gap: var(--space-1); }
.details--stacked dd { margin-bottom: var(--space-3); }
.checksum { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 11px; color: var(--color-text-muted); }

.image-preview { display: grid; justify-items: center; gap: var(--space-3); margin: 0; padding: var(--space-5); background: var(--color-surface-muted); }
.image-preview img { max-width: 100%; max-height: 75vh; height: auto; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); background: #fff; }

.pdf-viewer:focus-visible { box-shadow: inset var(--focus-ring); }
.pdf-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--color-border); }
.pdf-toolbar .icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.pdf-page, .pdf-zoom { font-size: var(--text-sm); color: var(--color-text-muted); white-space: nowrap; }
.pdf-zoom { min-width: 48px; text-align: center; }
.pdf-toolbar-gap { flex: 1; }
.pdf-stage { overflow: auto; max-height: 80vh; padding: var(--space-4); background: var(--color-surface-muted); text-align: center; }
.pdf-stage canvas { display: inline-block; background: #fff; box-shadow: var(--shadow-sm); }
.pdf-status { padding: var(--space-6); color: var(--color-text-muted); font-size: var(--text-sm); }
.pdf-viewer.is-error canvas { display: none; }

.doc-preview { max-width: 78ch; padding: var(--space-6); font-size: var(--text-md); line-height: 1.65; overflow-wrap: anywhere; }
.doc-preview > * + * { margin-top: var(--space-3); }
.doc-preview h1, .doc-preview h2, .doc-preview h3 { margin-top: var(--space-6); font-weight: var(--weight-bold); line-height: 1.3; }
.doc-preview h1 { font-size: var(--text-xl); }
.doc-preview h2 { font-size: var(--text-lg); }
.doc-preview ul, .doc-preview ol { padding-left: var(--space-6); }
.doc-preview table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.doc-preview td, .doc-preview th { padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border); vertical-align: top; }

.sheet-table td { white-space: nowrap; }
.sheet-row { width: 1%; color: var(--color-text-subtle); font-weight: var(--weight-regular); text-align: right; }

@media (max-width: 1023px) {
  .preview-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-preview { padding: var(--space-4); }
}

/* ---------- Dropdown (row actions) ---------- */
.dropdown {
  display: inline-block;
}
.dropdown .menu-panel {
  min-width: 180px;
}
.menu-item--danger {
  color: var(--color-danger);
}

@media (max-width: 767px) {
  .steps {
    flex-direction: column;
    gap: var(--space-4);
  }
  .step {
    grid-template-columns: 32px 1fr;
    justify-items: start;
    align-items: center;
    text-align: left;
  }
  .step:not(:first-child)::before {
    top: calc(-1 * var(--space-4));
    right: auto;
    left: 15px;
    width: 2px;
    height: var(--space-4);
  }
}
