/* KBB Portal UI foundation 2.0
 * Shared, low-specificity presentation primitives for all authenticated views.
 * Component names follow established web UI patterns: page header, callout,
 * disclosure, badge, data table, form field, empty state and focus ring.
 */
:root {
  --kbb-ui-control: 42px;
  --kbb-ui-transition: 150ms ease;
}

.main > :where(.page-intro, .process-hero, .record-hero, .dashboard-hero, .portal-context) {
  border-radius: var(--radius-lg);
}

.main > :where(.page-intro, .process-hero, .record-hero) {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--kbb-primary);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}

.main :where(.panel, .card, .metric-card, .task-card) {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.main :where(.panel, .card) > :where(h2, h3):first-child {
  color: var(--text-primary);
  letter-spacing: -0.015em;
}

.main :where(p, .muted, small) {
  max-width: 78ch;
}

.main :where(button, .btn, input, select, textarea, a) {
  transition:
    color var(--kbb-ui-transition),
    background-color var(--kbb-ui-transition),
    border-color var(--kbb-ui-transition),
    box-shadow var(--kbb-ui-transition);
}

.main :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
  border-color: var(--border-strong, var(--border));
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}

.main :where(input:not([type="checkbox"]):not([type="radio"]), select) {
  min-height: var(--kbb-ui-control);
}

.main :where(label):not(.check):not(.choice-card):not(.weekly-day-toggle) {
  color: var(--text-secondary);
  font-weight: 700;
}

.main :where(.form-grid, .filter-grid, .toolbar) {
  gap: 0.8rem;
}

.main :where(.btn, button):not(.link-button) {
  min-height: 38px;
  border-radius: var(--radius-md);
  font-weight: 700;
}

.main :where(.btn.danger, button.danger) {
  border-color: color-mix(in srgb, var(--kbb-danger) 38%, var(--border));
}

.main :where(.status, .status-pill, .status-chip, .traffic-status, .ue-badge) {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  width: fit-content;
  min-height: 26px;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
}

.main :where(.status-chip.success) {
  color: var(--kbb-success);
  background: color-mix(in srgb, var(--kbb-success) 18%, white);
}

.main :where(.status-chip.danger) {
  color: var(--kbb-danger);
  background: color-mix(in srgb, var(--kbb-danger) 14%, white);
}

.main :where(details) > summary {
  border-radius: var(--radius-md);
}

.main :where(details) > summary:hover {
  background: color-mix(in srgb, var(--kbb-primary) 6%, transparent);
}

.main :where(.flash, [role="alert"], [role="status"]) {
  scroll-margin-top: 5rem;
}

.main .ui-state {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  margin: 0.65rem;
  padding: 1rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: var(--surface-soft);
}

.main .ui-state[hidden] { display: none; }

.main .ui-state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--kbb-primary) 14%, var(--surface));
  font-weight: 800;
}

.main .ui-state strong { display: block; color: var(--text-primary); }
.main .ui-state p { margin: 0.2rem 0 0.7rem; }

.main :where(table) {
  border-collapse: separate;
  border-spacing: 0;
}

.main :where(th) {
  color: var(--text-secondary);
  font-size: 0.78rem;
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.main :where(th, td) {
  border-bottom-color: var(--border);
  vertical-align: top;
}

.main :where(tbody tr):hover {
  background: color-mix(in srgb, var(--kbb-primary) 5%, transparent);
}

.main :where(.table-wrap) {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}

.main :where(.inline-actions, .panel-actions, .card-actions) {
  align-items: center;
  gap: 0.5rem;
}

.main :where(.eyebrow) {
  color: var(--kbb-primary-light, var(--kbb-primary));
  letter-spacing: 0.075em;
}

/* Foundation components: shared contracts for incremental view migration. */
.main .kbb-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: clamp(1rem, 2vw, 1.35rem);
  border: 1px solid var(--border);
  border-left: 4px solid var(--kbb-primary);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}

.main .kbb-page-header-copy {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.main .kbb-page-header-copy :where(.eyebrow, h1, p) { margin: 0; }
.main .kbb-page-header-copy h1 { font-size: clamp(1.35rem, 2.3vw, 1.8rem); }

.main .kbb-page-header-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.main .kbb-section-nav {
  position: sticky;
  top: 4.8rem;
  z-index: 11;
  display: flex;
  max-width: 100%;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0.45rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-strong) 97%, transparent);
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}

.main .kbb-section-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 38px;
  padding: 0.4rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 700;
  white-space: nowrap;
}

.main .kbb-section-nav a:hover,
.main .kbb-section-nav a[aria-current] {
  border-color: color-mix(in srgb, var(--kbb-primary) 35%, var(--border));
  color: var(--text-primary);
  background: color-mix(in srgb, var(--kbb-primary) 9%, var(--surface));
  text-decoration: none;
}

.main .kbb-section-nav small {
  min-width: 1.4rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface-soft);
  text-align: center;
}

.main .kbb-list-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}

.main .kbb-list-toolbar-form {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
}

.main .kbb-list-toolbar-form label {
  display: grid;
  flex: 0 1 220px;
  gap: 0.25rem;
  min-width: 160px;
  font-size: var(--font-xs);
}

.main .kbb-list-toolbar-form .kbb-list-search { flex: 1 1 280px; }

.main .kbb-list-toolbar-meta {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.65rem;
}

.main .kbb-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  min-height: 26px;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  background: var(--surface-soft);
  font-size: var(--font-xs);
  font-weight: 800;
  line-height: 1.2;
}

.main .kbb-status-badge-dot {
  width: 0.5rem;
  height: 0.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.main .kbb-status-badge small {
  padding-left: 0.35rem;
  border-left: 1px solid currentColor;
  color: inherit;
  opacity: 0.78;
}

.main .kbb-status-badge--success { color: var(--kbb-success); background: color-mix(in srgb, var(--kbb-success) 10%, var(--surface)); }
.main .kbb-status-badge--warning { color: var(--kbb-warning); background: color-mix(in srgb, var(--kbb-warning) 10%, var(--surface)); }
.main .kbb-status-badge--danger { color: var(--kbb-danger); background: color-mix(in srgb, var(--kbb-danger) 10%, var(--surface)); }
.main .kbb-status-badge--info { color: var(--kbb-info); background: color-mix(in srgb, var(--kbb-info) 10%, var(--surface)); }

.main .kbb-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin: 1rem 0;
}

.main .kbb-pagination :where(a, .current, .disabled) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 38px;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: var(--surface-strong);
  font-weight: 700;
}

.main .kbb-pagination a:hover,
.main .kbb-pagination .current {
  border-color: var(--kbb-primary);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--kbb-primary) 10%, var(--surface));
  text-decoration: none;
}

.main .kbb-pagination .disabled { opacity: 0.55; }
.main .kbb-pagination .ellipsis { padding-inline: 0.2rem; color: var(--text-muted); }

.main .ui-state {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.main .ui-state-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: var(--kbb-primary);
  background: color-mix(in srgb, var(--kbb-primary) 12%, var(--surface));
  font-weight: 800;
}

.main .ui-state-copy { display: grid; gap: 0.18rem; min-width: 0; }
.main .ui-state-copy > span { color: var(--text-secondary); }
.main .ui-state--success { border-color: color-mix(in srgb, var(--kbb-success) 42%, var(--border)); }
.main .ui-state--success .ui-state-mark { color: var(--kbb-success); background: color-mix(in srgb, var(--kbb-success) 12%, var(--surface)); }
.main .ui-state--error { border-color: color-mix(in srgb, var(--kbb-danger) 42%, var(--border)); }
.main .ui-state--error .ui-state-mark { color: var(--kbb-danger); background: color-mix(in srgb, var(--kbb-danger) 12%, var(--surface)); }
.main .ui-state--info .ui-state-mark { color: var(--kbb-info); background: color-mix(in srgb, var(--kbb-info) 12%, var(--surface)); }

.kbb-dialog {
  width: min(520px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border-strong, var(--border));
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  background: var(--surface-strong);
  box-shadow: var(--shadow-md);
}

.kbb-dialog::backdrop { background: rgba(10, 16, 20, 0.68); }
.kbb-dialog-body { padding: 1rem; }
.kbb-dialog-body h2 { margin: 0 0 0.5rem; }
.kbb-dialog-body p { margin: 0; color: var(--text-secondary); }

.kbb-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
}

.kbb-dialog-actions form { margin: 0; }
.kbb-dialog--danger { border-color: color-mix(in srgb, var(--kbb-danger) 45%, var(--border)); }

@media (max-width: 980px) {
  .main > :where(.page-intro, .process-hero, .record-hero) {
    align-items: stretch;
  }

  .main :where(.form-grid, .filter-grid) {
    grid-template-columns: 1fr;
  }

  /* Prevent a former two-column span from creating an implicit overflow
     column after the grid collapses to one mobile column. */
  .main :where(.form-grid, .filter-grid) > .span-2 {
    grid-column: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .main :where(.table-wrap) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .main :where(.table-wrap table) {
    min-width: 680px;
  }
}

@media (max-width: 700px) {
  .main {
    padding-inline: 0.75rem;
  }

  .main > :where(.page-intro, .process-hero, .record-hero, .dashboard-hero) {
    padding: 1rem;
  }

  .main :where(.inline-actions, .panel-actions, .card-actions) {
    flex-wrap: wrap;
  }

  .main :where(.inline-actions > .btn, .panel-actions > .btn) {
    justify-content: center;
  }

  .main .kbb-page-header,
  .main .kbb-list-toolbar,
  .main .kbb-page-header-actions,
  .main .kbb-list-toolbar-meta {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .main .kbb-page-header-actions > .btn,
  .main .kbb-list-toolbar-meta > .btn { width: 100%; }
  .main .kbb-list-toolbar-form { display: grid; grid-template-columns: 1fr; width: 100%; }
  .main .kbb-list-toolbar-form label { min-width: 0; }
  .main .ui-state { grid-template-columns: auto minmax(0, 1fr); }
  .main .ui-state-action { grid-column: 1 / -1; justify-self: stretch; }
  .kbb-dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .kbb-dialog-actions form,
  .kbb-dialog-actions button { width: 100%; }
}

@media (forced-colors: active) {
  .main :where(.panel, .card, .table-wrap, .page-intro, .process-hero, .record-hero) {
    border: 1px solid CanvasText;
  }
}

/* Staff qualification and competency matrices */
.matrix-purpose-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.matrix-purpose-card {
  display: grid;
  align-content: start;
  gap: 0.55rem;
  padding: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}

.matrix-purpose-card.active {
  border-color: color-mix(in srgb, var(--kbb-primary) 55%, var(--border));
  background: color-mix(in srgb, var(--kbb-primary) 7%, var(--surface-strong));
}

.matrix-purpose-card h2,
.matrix-purpose-card p { margin: 0; }
.matrix-purpose-card .btn { justify-self: start; margin-top: 0.35rem; }
.matrix-purpose-kicker { color: var(--kbb-primary); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.matrix-summary-grid { margin-bottom: 1rem; }
.matrix-workspace { min-width: 0; }
.matrix-toolbar-head { align-items: flex-start; }

.matrix-filter-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 0.7fr) minmax(220px, 1.2fr) auto auto;
  align-items: end;
  gap: 0.7rem;
  margin: 1rem 0;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.matrix-filter-bar label { display: grid; gap: 0.3rem; font-weight: 700; }
.matrix-filter-bar [role="status"] { align-self: center; white-space: nowrap; }
.matrix-legend { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.85rem; }
.level-chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.28rem 0.55rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); }

/* Feedback workspace: task navigation with visible state and touch-safe targets. */
.feedback-subnav {
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.feedback-subnav a {
  min-height: 44px;
  justify-content: center;
  background: var(--surface);
}
.feedback-subnav-more { position: relative; }
.feedback-subnav-more > summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.feedback-subnav-more > summary::-webkit-details-marker { display: none; }
.feedback-subnav-more > summary::after { content: "⌄"; margin-left: 0.45rem; }
.feedback-subnav-more > summary:hover,
.feedback-subnav-more > summary.active { color: var(--text-primary); border-color: color-mix(in srgb, var(--kbb-primary) 45%, var(--border)); background: color-mix(in srgb, var(--kbb-primary) 12%, var(--surface)); }
.feedback-subnav-more > div {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  display: grid;
  width: max-content;
  min-width: 220px;
  gap: 0.3rem;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  box-shadow: var(--shadow-md);
}
.feedback-subnav-more > div a { justify-content: flex-start; }

@media (max-width: 700px) {
  .feedback-subnav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .feedback-subnav-more > summary { width: 100%; justify-content: center; }
  .feedback-subnav-more > div { position: static; width: 100%; margin-top: 0.35rem; box-shadow: none; }
}

@media (max-width: 420px) {
  .feedback-subnav { grid-template-columns: 1fr; }
}

.matrix-table-wrap { max-height: min(68vh, 760px); border: 1px solid var(--border); }
.staff-matrix-table { border-collapse: separate; border-spacing: 0; min-width: max-content; }
.staff-matrix-table th,
.staff-matrix-table td { min-width: 138px; max-width: 180px; padding: 0.5rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); vertical-align: middle; }
.staff-matrix-table thead th { position: sticky; z-index: 3; top: 0; background: var(--surface-strong); box-shadow: 0 1px 0 var(--border); }
.staff-matrix-table .matrix-person-column { position: sticky; left: 0; z-index: 2; min-width: 220px; max-width: 260px; background: var(--surface-strong); text-align: left; }
.staff-matrix-table thead .matrix-person-column { z-index: 4; }
.staff-matrix-table .matrix-person-column small { display: block; margin-top: 0.2rem; color: var(--text-secondary); font-weight: 500; }
.staff-matrix-table thead th > span { display: inline; }

.matrix-info-button {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  min-width: 1.35rem;
  height: 1.35rem;
  margin-left: 0.2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 0.72rem;
}

.matrix-cell-button {
  display: grid;
  justify-items: start;
  gap: 0.1rem;
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  background: var(--surface-soft);
  text-align: left;
}

.matrix-cell-button:hover:not(:disabled) { border-color: var(--kbb-primary); transform: translateY(-1px); }
.matrix-cell-button.success { border-color: color-mix(in srgb, var(--kbb-success) 45%, var(--border)); background: color-mix(in srgb, var(--kbb-success) 10%, var(--surface-strong)); }
.matrix-cell-button.warning { border-color: color-mix(in srgb, var(--kbb-warning) 55%, var(--border)); background: color-mix(in srgb, var(--kbb-warning) 12%, var(--surface-strong)); }
.matrix-cell-button.danger { color: var(--text-primary); border-color: color-mix(in srgb, var(--kbb-danger) 50%, var(--border)); background: color-mix(in srgb, var(--kbb-danger) 9%, var(--surface-strong)); }
.matrix-cell-button.info { border-color: color-mix(in srgb, var(--kbb-info, var(--kbb-primary)) 45%, var(--border)); background: color-mix(in srgb, var(--kbb-info, var(--kbb-primary)) 9%, var(--surface-strong)); }
.matrix-cell-button small { color: var(--text-secondary); }
.matrix-cell-button.competency { grid-template-columns: auto 1fr; align-items: baseline; }
.matrix-cell-button.competency strong { font-size: 1.35rem; }
.matrix-dialog { width: min(720px, calc(100vw - 2rem)); }
.matrix-info-dialog { width: min(520px, calc(100vw - 2rem)); }
.matrix-mode-options { display: grid; gap: 0.45rem; margin: 1rem 0; padding: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-md); }
.matrix-mode-options label { display: flex; align-items: flex-start; gap: 0.5rem; }
.matrix-dialog .notice { margin-block: 0.8rem; }
.matrix-catalog-form { margin-top: 0.8rem; }
.competency-scale-help { margin-top: 0.8rem; }
.competency-scale-help li + li { margin-top: 0.45rem; }
.matrix-process-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 1rem 0;
  padding: 0;
  list-style: none;
}
.matrix-process-steps li { position: relative; display: grid; justify-items: center; gap: 0.3rem; color: var(--text-secondary); font-size: 0.76rem; text-align: center; }
.matrix-process-steps li::before { position: absolute; z-index: 0; top: 15px; left: 0; width: 100%; height: 2px; content: ""; background: var(--border); }
.matrix-process-steps li:first-child::before { left: 50%; width: 50%; }
.matrix-process-steps li:last-child::before { width: 50%; }
.matrix-process-steps span { position: relative; z-index: 1; display: grid; width: 30px; height: 30px; place-items: center; border: 2px solid var(--border); border-radius: 50%; background: var(--surface-strong); }
.matrix-process-steps li.active span { border-color: var(--kbb-primary); color: white; background: var(--kbb-primary); }
.matrix-evidence-source { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; margin: 0; padding: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-md); }
.matrix-evidence-source label { display: flex; gap: 0.55rem; min-height: 72px; padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-soft); cursor: pointer; }
.matrix-evidence-source label:has(input:checked) { border-color: var(--kbb-primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--kbb-primary) 16%, transparent); background: color-mix(in srgb, var(--kbb-primary) 7%, var(--surface-strong)); }
.matrix-evidence-source label > span { display: grid; align-content: start; gap: 0.2rem; }
.matrix-evidence-source small { color: var(--text-secondary); font-weight: 500; }
.matrix-upload-zone,
.matrix-internal-form { display: grid; gap: 0.65rem; padding: 0.85rem; border: 2px dashed color-mix(in srgb, var(--kbb-primary) 45%, var(--border)); border-radius: var(--radius-md); background: color-mix(in srgb, var(--kbb-primary) 4%, var(--surface-strong)); }
.matrix-dialog [hidden],
.matrix-upload-zone[hidden],
.matrix-internal-form[hidden],
[data-evidence-source-panel][hidden] { display: none !important; }
.matrix-current-document { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; padding: 0.65rem 0.75rem; border-left: 4px solid var(--kbb-success); background: color-mix(in srgb, var(--kbb-success) 8%, var(--surface-strong)); }
.staff-matrix-entry-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.staff-profile-export-card { border-top-color: var(--kbb-accent, var(--kbb-primary)); }

@media (max-width: 980px) {
  .matrix-purpose-grid { grid-template-columns: 1fr; }
  .staff-matrix-entry-grid { grid-template-columns: 1fr; }
  .matrix-filter-bar { grid-template-columns: 1fr 1fr; }
  .matrix-filter-bar [role="status"] { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .matrix-filter-bar { grid-template-columns: 1fr; }
  .matrix-filter-bar button { width: 100%; }
  .staff-matrix-table .matrix-person-column { min-width: 175px; max-width: 190px; }
  .staff-matrix-table th,
  .staff-matrix-table td { min-width: 125px; }
  .matrix-purpose-card .btn { justify-self: stretch; }
  .matrix-evidence-source { grid-template-columns: 1fr; }
  .matrix-process-steps strong { font-size: 0.68rem; }
}

/* Room-plan inspector: NameThatUI segmented control + inspector patterns */
.room-view-switch.segmented {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  width: fit-content;
  margin-block: 0.8rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
}
.room-view-switch.segmented .muted { margin-inline: 0.65rem 0.35rem; }
.room-plan-canvas {
  border-color: color-mix(in srgb, var(--kbb-primary) 22%, var(--border));
  background: radial-gradient(circle at 52% 15%, rgba(255,255,255,.95), rgba(238,244,243,.92) 70%, rgba(225,236,234,.95));
}
.room-plan-canvas-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.room-plan-canvas-head > div { display: grid; gap: 0.15rem; }
.room-plan-svg { color: var(--kbb-primary); }
.room-plan-svg .plan-board { fill: #edf4f2; stroke: color-mix(in srgb, var(--kbb-primary) 24%, white); stroke-width: 2; }
.room-plan-svg .plan-grid { fill: url(#plan-grid); }
.room-plan-svg .floor-shell { fill: #fff; stroke: #415653; stroke-width: 6; }
.room-plan-svg .floor-wall { fill: none; stroke: #415653; stroke-width: 6; }
.room-plan-svg .corridor-zone { fill: #f0f5f4; stroke: none; }
.room-plan-svg .context-label { fill: #50615f; font: 650 13px system-ui, sans-serif; }
.room-plan-svg .corridor-label { fill: #748481; font: 700 10px system-ui, sans-serif; letter-spacing: .16em; }
.room-plan-svg .window { fill: none; stroke: #29a99d; stroke-width: 9; stroke-linecap: round; }
.room-plan-svg .door { fill: none; stroke: #71807e; stroke-width: 3; }
.room-plan-svg .north-marker circle { fill: #fff; stroke: #72817e; stroke-width: 2; }
.room-plan-svg .north-marker path { fill: var(--kbb-primary); }
.room-plan-svg .north-marker text { fill: #334542; font: 800 9px system-ui, sans-serif; }
.room-shape rect { rx: 9px; stroke-width: 3; filter: url(#room-lift); }
.room-shape .room-status-dot { fill: currentColor; stroke: #fff; stroke-width: 3; }
.room-shape .room-capacity { fill: #50615f; font-size: 10px; font-weight: 650; }
.room-shape.status-free { color: #167846; }
.room-shape.status-soon { color: #a66500; }
.room-shape.status-occupied { color: #a32632; }
.room-shape.status-conflict { color: #7a1b92; }
.room-shape.status-blocked,
.room-shape.status-no-data,
.room-shape.status-error { color: #5f6a69; }
.room-shape:hover rect { filter: url(#room-lift) brightness(.97); }
.room-shape:focus-visible rect,
.room-shape[aria-pressed="true"] rect {
  filter: url(#room-lift) brightness(.98);
  stroke-width: 7;
}
.room-detail { position: sticky; top: 1rem; align-self: start; }

@media (max-width: 700px) {
  .room-view-switch.segmented { display: grid; grid-template-columns: 1fr 1fr; width: 100%; border-radius: var(--radius-md); }
  .room-view-switch.segmented .muted { grid-column: 1 / -1; margin: 0.25rem; }
  .room-plan-canvas-head { align-items: stretch; flex-direction: column; }
}

/* Feedback workspace: process, editor, questionnaire and dashboard task */
.feedback-process,
.feedback-analysis-explainer,
.feedback-editor-hero,
.feedback-section-card,
.survey-shell,
.feedback-dashboard-notice {
  border: 1px solid color-mix(in srgb, var(--kbb-primary) 22%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}
.feedback-process { display: grid; grid-template-columns: minmax(220px, .75fr) minmax(0, 2fr); gap: 1.4rem; margin-bottom: 1rem; padding: 1.2rem; }
.feedback-process-head { display: grid; align-content: start; gap: .35rem; }
.feedback-process-head h2,
.feedback-analysis-explainer h2 { margin: 0; }
.feedback-process-head p { margin: 0; color: var(--text-secondary); }
.feedback-process-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem; margin: 0; padding: 0; list-style: none; }
.feedback-process-steps li { display: grid; grid-template-columns: 32px 1fr; align-content: start; gap: .55rem; min-height: 128px; padding: .8rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-soft); }
.feedback-process-steps li > span { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; color: #fff; background: var(--kbb-primary); font-weight: 800; }
.feedback-process-steps li div { display: grid; align-content: start; gap: .3rem; }
.feedback-process-steps small { color: var(--text-secondary); line-height: 1.35; }

.feedback-analysis-explainer { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(0, 2fr); gap: 1.2rem; margin-bottom: 1rem; padding: 1.1rem; }
.feedback-analysis-explainer ol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin: 0; padding: 0; list-style: none; }
.feedback-analysis-explainer li { display: grid; gap: .2rem; padding: .75rem; border-left: 3px solid var(--kbb-primary); background: var(--surface-soft); }
.feedback-analysis-explainer li span { color: var(--text-secondary); }

.feedback-editor-hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding: 1rem 1.15rem; border-left: 5px solid var(--kbb-primary); }
.feedback-editor-hero.is-published { border-left-color: var(--kbb-success); }
.feedback-editor-hero h2,
.feedback-editor-hero p { margin: .1rem 0 0; }
.feedback-editor-actions { display: flex; align-items: end; gap: .65rem; }
.feedback-editor-actions label { min-width: 190px; }
.feedback-editor-settings > summary,
.feedback-template-create > summary,
.feedback-inline-editor > summary,
.feedback-add-question > summary,
.feedback-add-section > summary { min-height: 44px; cursor: pointer; }
.feedback-editor-settings > summary > span { display: grid; gap: .15rem; }
.feedback-template-create > summary > span { display: grid; gap: .15rem; }
.feedback-editor-settings > summary small { color: var(--text-secondary); font-weight: 500; }
.feedback-template-create > summary small { color: var(--text-secondary); font-weight: 500; }
.feedback-editor-settings[open] > summary { margin-bottom: 1rem; }
.feedback-template-create[open] > summary { margin-bottom: 1rem; }
.feedback-template-list { display: grid; gap: .55rem; }
.feedback-template-list > a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: .8rem; min-height: 68px; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-primary); background: var(--surface-soft); text-decoration: none; }
.feedback-template-list > a:hover { border-color: var(--kbb-primary); background: var(--surface-strong); transform: translateY(-1px); }
.feedback-template-list > a > span:nth-child(2) { display: grid; gap: .15rem; }
.feedback-template-list small { color: var(--text-secondary); }
.feedback-template-list em { color: var(--kbb-primary); font-style: normal; font-weight: 800; }
.feedback-template-code { padding: .35rem .5rem; border-radius: var(--radius-sm); color: var(--kbb-primary); background: color-mix(in srgb, var(--kbb-primary) 9%, white); font-size: .78rem; font-weight: 800; }
.feedback-editor-canvas { display: grid; gap: 1rem; }
.feedback-section-card { overflow: hidden; }
.feedback-section-card > header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--kbb-primary) 5%, var(--surface-strong)); }
.feedback-section-card > header h2,
.feedback-section-card > header p { margin: .15rem 0 0; }
.feedback-inline-editor,
.feedback-add-question { margin: .75rem 1rem; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-soft); }
.feedback-inline-editor[open] > summary,
.feedback-add-question[open] > summary { margin-bottom: .75rem; }
.feedback-question-list { display: grid; }
.feedback-question-editor { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: .8rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.feedback-question-editor:last-child { border-bottom: 0; }
.feedback-question-number { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid color-mix(in srgb, var(--kbb-primary) 38%, var(--border)); border-radius: 50%; color: var(--kbb-primary); background: color-mix(in srgb, var(--kbb-primary) 7%, white); font-weight: 800; }
.feedback-question-content,
.feedback-question-heading > div { display: grid; gap: .2rem; }
.feedback-question-heading { display: flex; align-items: start; justify-content: space-between; gap: .75rem; }
.feedback-question-heading small { color: var(--text-secondary); }
.feedback-question-tools { display: flex; gap: .3rem; }
.feedback-question-tools form { margin: 0; }
.feedback-editor-footer { display: flex; align-items: start; justify-content: space-between; gap: 1rem; margin-top: 1rem; padding: 1rem; border-top: 3px solid var(--kbb-primary); background: var(--surface-strong); }
.feedback-editor-footer > form { display: grid; justify-items: end; gap: .3rem; }
.feedback-editor-footer small { color: var(--text-secondary); }
.feedback-add-section { flex: 1; }

.survey-shell { width: min(920px, 100%); margin-inline: auto; overflow: hidden; }
.survey-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: clamp(1rem, 3vw, 2rem); background: linear-gradient(135deg, color-mix(in srgb, var(--kbb-primary) 12%, white), var(--surface-strong)); }
.survey-header h1 { margin: .2rem 0; font-size: clamp(1.65rem, 4vw, 2.4rem); }
.survey-header p { max-width: 65ch; margin: 0; color: var(--text-secondary); }
.survey-overview { display: grid; grid-template-columns: repeat(3, 1fr); border-block: 1px solid var(--border); background: var(--surface-soft); }
.survey-overview span { display: grid; justify-items: center; gap: .1rem; padding: .75rem; text-align: center; }
.survey-overview span + span { border-left: 1px solid var(--border); }
.survey-privacy { margin: 1rem; }
.survey-form { display: grid; gap: 1rem; }
.survey-section { display: grid; gap: .75rem; padding: 0 clamp(1rem, 3vw, 2rem); }
.survey-section > header { padding-top: .5rem; }
.survey-section > header h2,
.survey-section > header p { margin: .15rem 0 0; }
.survey-question-card { display: grid; gap: .7rem; margin: 0; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-strong); }
.survey-question-card:focus-within { border-color: var(--kbb-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--kbb-primary) 12%, transparent); }
.survey-question-card.has-error { border-color: var(--kbb-danger); }
.survey-question-card legend { display: flex; align-items: center; gap: .55rem; width: auto; max-width: 100%; padding: 0 .25rem; }
.survey-question-card legend > span { display: grid; min-width: 30px; height: 30px; place-items: center; border-radius: 50%; color: var(--kbb-primary); background: color-mix(in srgb, var(--kbb-primary) 10%, white); font-weight: 800; }
.survey-question-card legend em { padding: .15rem .35rem; border-radius: 999px; color: var(--kbb-danger); background: color-mix(in srgb, var(--kbb-danger) 8%, white); font-size: .72rem; font-style: normal; }
.survey-help { margin: 0; color: var(--text-secondary); }
.survey-rating { display: grid; grid-template-columns: minmax(90px, 1fr) auto minmax(90px, 1fr); align-items: center; gap: .65rem; color: var(--text-secondary); font-size: .82rem; }
.survey-rating > span:last-child { text-align: right; }
.survey-rating [role="radiogroup"] { display: flex; gap: .35rem; }
.survey-rating label input { position: absolute; opacity: 0; }
.survey-rating label span { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--border); border-radius: 50%; color: var(--text-primary); background: var(--surface-soft); cursor: pointer; font-weight: 800; }
.survey-rating label input:checked + span { border-color: var(--kbb-primary); color: #fff; background: var(--kbb-primary); }
.survey-rating label input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--kbb-primary) 28%, transparent); outline-offset: 2px; }
.survey-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.survey-choices label,
.survey-na { display: flex; align-items: center; gap: .55rem; min-height: 48px; padding: .65rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-soft); cursor: pointer; }
.survey-choices label:has(input:checked),
.survey-na:has(input:checked) { border-color: var(--kbb-primary); background: color-mix(in srgb, var(--kbb-primary) 8%, white); }
.survey-na { width: fit-content; }
.survey-action-bar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem clamp(1rem, 3vw, 2rem); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface-strong) 94%, transparent); box-shadow: 0 -10px 22px rgba(25,48,45,.08); backdrop-filter: blur(8px); }
.survey-action-bar > div:first-child { display: grid; gap: .1rem; }
.survey-action-bar small { color: var(--text-secondary); }

.feedback-dashboard-notice { display: grid; grid-template-columns: minmax(220px, .65fr) minmax(0, 1.6fr); gap: 1rem; margin: 1rem 0; padding: 1rem; border-left: 5px solid var(--kbb-accent, var(--kbb-primary)); background: linear-gradient(120deg, color-mix(in srgb, var(--kbb-accent, var(--kbb-primary)) 8%, white), var(--surface-strong)); }
.feedback-dashboard-notice h2,
.feedback-dashboard-notice p { margin: .15rem 0 0; }
.feedback-dashboard-items { display: grid; gap: .45rem; }
.feedback-dashboard-items a { display: flex; align-items: center; justify-content: space-between; gap: .8rem; min-height: 56px; padding: .65rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); background: var(--surface-strong); text-decoration: none; }
.feedback-dashboard-items a:hover { border-color: var(--kbb-primary); transform: translateY(-1px); }
.feedback-dashboard-items a > span { display: grid; gap: .15rem; }
.feedback-dashboard-items small { color: var(--text-secondary); }
.feedback-dashboard-items em { color: var(--kbb-primary); font-style: normal; font-weight: 800; white-space: nowrap; }

@media (max-width: 980px) {
  .feedback-process,
  .feedback-analysis-explainer,
  .feedback-dashboard-notice { grid-template-columns: 1fr; }
  .feedback-process-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .feedback-process-steps,
  .feedback-analysis-explainer ol,
  .survey-choices { grid-template-columns: 1fr; }
  .feedback-editor-hero,
  .feedback-editor-footer,
  .survey-header,
  .survey-action-bar { align-items: stretch; flex-direction: column; }
  .feedback-editor-actions { align-items: stretch; flex-direction: column; }
  .feedback-question-editor { grid-template-columns: 32px minmax(0, 1fr); padding-inline: .75rem; }
  .survey-overview { grid-template-columns: 1fr; }
  .survey-overview span + span { border-top: 1px solid var(--border); border-left: 0; }
  .survey-rating { grid-template-columns: 1fr; }
  .survey-rating > span:last-child { text-align: left; }
  .survey-rating [role="radiogroup"] { justify-content: space-between; }
  .survey-rating label span { width: 42px; height: 42px; }
  .survey-action-bar .button-row { display: grid; grid-template-columns: 1fr; }
  .survey-action-bar button { width: 100%; }
  .feedback-dashboard-items a { align-items: flex-start; flex-direction: column; }
  .feedback-template-list > a { grid-template-columns: 1fr auto; }
  .feedback-template-code { width: fit-content; }
  .feedback-template-list > a > span:nth-child(2),
  .feedback-template-list > a > em { grid-column: 1 / -1; }
}
.learning-workflow-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .65rem;
  margin: 0 0 1rem;
}

.learning-workflow-nav a {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .05rem .6rem;
  align-items: center;
  min-height: 64px;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--text-primary);
  text-decoration: none;
}

.learning-workflow-nav a > span { grid-row: 1 / 3; display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: color-mix(in srgb, var(--kbb-primary) 12%, white); color: var(--kbb-primary); font-weight: 800; }
.learning-workflow-nav small { color: var(--text-secondary); }
.learning-workflow-nav a.active { border-color: var(--kbb-primary); background: color-mix(in srgb, var(--kbb-primary) 6%, var(--surface-strong)); }
.material-generator form { margin-top: 1rem; }

@media (max-width: 760px) {
  .learning-workflow-nav { grid-template-columns: 1fr; }
}

/* KBB Portal visual system 3.0
 * One shared treatment for shell, controls, forms, cards and data views.
 * Translucency is limited to navigation/control layers; work surfaces stay
 * nearly opaque for contrast and long-form readability.
 */
.portal-shell-page .sidebar,
.portal-shell-page .topbar,
.main .kbb-section-nav,
.main :where(.toolbar, .filter-bar, .filters, .workspace-switcher) {
  background: color-mix(in srgb, var(--surface-strong) 88%, transparent);
  border-color: color-mix(in srgb, var(--kbb-primary) 14%, var(--border));
  backdrop-filter: blur(16px) saturate(125%);
  -webkit-backdrop-filter: blur(16px) saturate(125%);
}

.portal-shell-page .sidebar {
  box-shadow: 12px 0 34px rgba(10, 47, 43, 0.08);
}

.portal-shell-page .topbar {
  box-shadow: 0 7px 24px rgba(10, 47, 43, 0.07);
}

/* The shared button contract must not turn the mobile navigation trigger into
   a desktop control. Its visibility remains owned by the shell breakpoint. */
.main button.nav-toggle { display: none; }

.main :where(.panel, .card, .metric-card, .task-card, .kbb-page-header, .process-hero, .record-hero, .page-intro) {
  border: 1px solid color-mix(in srgb, var(--kbb-primary) 12%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow-sm);
}

.main :where(.panel, .card, .metric-card, .task-card) {
  overflow: clip;
}

.main :where(.panel, .card, .metric-card, .task-card, .kbb-page-header) {
  transition: border-color var(--kbb-ui-transition), box-shadow var(--kbb-ui-transition), transform var(--kbb-ui-transition);
}

.main :where(.panel.interactive, .card.interactive, a.task-card):hover {
  border-color: color-mix(in srgb, var(--kbb-primary) 42%, var(--border));
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.main :where(button, .btn):not(.link-button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 42px;
  padding: 0.58rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--kbb-primary-dark) 68%, var(--border));
  border-radius: var(--radius-md);
  color: #fff;
  background: linear-gradient(180deg, color-mix(in srgb, var(--kbb-primary-light) 72%, var(--kbb-primary)), var(--kbb-primary-dark));
  box-shadow: 0 5px 14px color-mix(in srgb, var(--kbb-primary) 20%, transparent);
  font-weight: 750;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
}

.main :where(button, .btn):not(.link-button):hover {
  color: #fff;
  background: linear-gradient(180deg, var(--kbb-primary-light), var(--kbb-primary));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--kbb-primary) 25%, transparent);
  text-decoration: none;
  transform: translateY(-1px);
}

.main :where(button.ghost, .btn.ghost):not(.link-button) {
  border-color: color-mix(in srgb, var(--kbb-primary) 27%, var(--border));
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-strong) 91%, transparent);
  box-shadow: none;
}

.main :where(button.ghost, .btn.ghost):not(.link-button):hover {
  border-color: color-mix(in srgb, var(--kbb-primary) 48%, var(--border));
  color: var(--kbb-primary-light);
  background: color-mix(in srgb, var(--kbb-primary) 8%, var(--surface-strong));
}

.main :where(button.small, .btn.small) { min-height: 36px; padding: 0.4rem 0.68rem; }
.main :where(button, .btn)[disabled],
.main :where(button, .btn)[aria-disabled="true"] { cursor: not-allowed; box-shadow: none; opacity: 0.55; transform: none; }

.main :where(label) {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.25;
  text-align: left;
}

.main :where(label > small, .field-help) {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.4;
}

.main :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
  width: 100%;
  min-height: 44px;
  padding: 0.68rem 0.78rem;
  border: 1px solid var(--border-strong, var(--border));
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-strong) 96%, var(--background));
  box-shadow: inset 0 1px 2px rgba(17, 47, 43, 0.04);
  line-height: 1.35;
  text-align: left;
}

.main :where(textarea) { min-height: 106px; resize: vertical; }
.main :where(input, select, textarea)::placeholder { color: var(--text-muted); opacity: 0.78; }
.main :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea):hover { border-color: color-mix(in srgb, var(--kbb-primary) 32%, var(--border)); }
.main :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea):focus {
  border-color: var(--kbb-primary);
  outline: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kbb-primary) 17%, transparent), inset 0 1px 2px rgba(17, 47, 43, 0.04);
}
.main :where(input, select, textarea):user-invalid { border-color: var(--kbb-danger); }

.main :where(input[type="checkbox"], input[type="radio"]) {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--kbb-primary);
}

.main :where(table) { font-variant-numeric: tabular-nums; }
.main :where(th) { background: color-mix(in srgb, var(--kbb-primary) 5%, var(--surface-soft)); }
.main :where(th, td) { padding: 0.72rem 0.78rem; }
.main :where(td[data-type="number"], .numeric, .money) { text-align: right; font-variant-numeric: tabular-nums; }

.weekly-schedule {
  display: grid;
  grid-column: 1 / -1;
  gap: 0.85rem;
  margin: 0;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--kbb-primary) 28%, var(--border));
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--kbb-primary) 5%, var(--surface-strong));
}
.weekly-schedule[hidden] { display: none; }
.weekly-schedule legend { padding: 0 0.4rem; color: var(--text-primary); font-size: 1rem; font-weight: 800; }
.weekly-schedule-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.weekly-schedule-head p { margin: 0; color: var(--text-secondary); }
.weekly-schedule-head strong { white-space: nowrap; color: var(--kbb-primary-light); }
.weekly-schedule-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.55rem; }
.weekly-schedule-day { display: grid; align-content: start; gap: 0.55rem; padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-strong); }
.weekly-schedule-day:has(.weekly-day-toggle input:checked) { border-color: color-mix(in srgb, var(--kbb-primary) 45%, var(--border)); box-shadow: 0 5px 15px color-mix(in srgb, var(--kbb-primary) 8%, transparent); }
.weekly-day-toggle { display: flex !important; grid-template-columns: auto 1fr; align-items: center !important; gap: 0.5rem !important; min-height: 42px; padding-bottom: 0.45rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.weekly-day-toggle > span { display: grid; }
.weekly-day-toggle strong { color: var(--text-primary); font-size: 1rem; }
.weekly-day-toggle small { color: var(--text-muted); font-size: 0.68rem; }
.weekly-schedule-day > label:not(.weekly-day-toggle) { font-size: 0.7rem; }
.weekly-schedule-day input { min-width: 0; padding-inline: 0.45rem !important; }

@media (max-width: 1180px) { .weekly-schedule-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .weekly-schedule-head { align-items: flex-start; flex-direction: column; }
  .weekly-schedule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) { .weekly-schedule-grid { grid-template-columns: 1fr; } }

@media (max-width: 980px) {
  .main button.nav-toggle { display: inline-flex; }
}

/* Modern portal rhythm inspired by the public dirks-jaeger.systems design:
   strong typography, calm space and technical status surfaces. KBB colors,
   semantic controls and solid reading surfaces remain authoritative. */
.portal-shell-page .main :where(h1, h2, h3) {
  letter-spacing: -0.028em;
  text-wrap: balance;
}

.portal-shell-page .main :where(.panel, .card, .metric-card, .task-card) {
  box-shadow: 0 12px 32px rgba(10, 47, 43, 0.065), 0 1px 2px rgba(10, 47, 43, 0.06);
}

.measure-command-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: center;
  min-height: 390px;
  margin-bottom: 1.25rem;
  padding: clamp(1.5rem, 4vw, 3.5rem);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--kbb-primary-light) 28%, transparent);
  border-radius: var(--radius-lg);
  color: #f6fffd;
  background:
    radial-gradient(circle at 8% 20%, color-mix(in srgb, var(--kbb-primary-light) 30%, transparent), transparent 34rem),
    radial-gradient(circle at 92% 88%, color-mix(in srgb, var(--kbb-accent) 16%, transparent), transparent 27rem),
    linear-gradient(135deg, #0b2926 0%, #103d38 52%, #09221f 100%);
  box-shadow: 0 26px 70px rgba(7, 48, 43, 0.19);
}

.measure-command-hero::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(90deg, black, transparent 78%);
}

.measure-command-copy,
.measure-command-board { position: relative; z-index: 1; }
.measure-command-copy { display: grid; gap: 1rem; }
.measure-command-copy :where(h1, p) { margin: 0; }
.measure-command-copy h1 { max-width: 19ch; color: #fff; font-size: clamp(2rem, 4vw, 3.65rem); line-height: 1.02; }
.measure-command-copy p { max-width: 64ch; color: rgba(239, 251, 248, 0.78); font-size: clamp(1rem, 1.35vw, 1.15rem); line-height: 1.65; }
.measure-command-copy .eyebrow { color: #77d7cd; }
.measure-command-copy .btn { border-color: #4fc4b8; color: #062a26; background: linear-gradient(135deg, #72d8ce, #3fb7ac); }
.measure-command-copy .btn.ghost { border-color: rgba(255,255,255,.25); color: #fff; background: rgba(7, 32, 29, .38); }

.measure-command-board {
  display: grid;
  gap: 1.1rem;
  padding: clamp(1rem, 2.2vw, 1.5rem);
  border: 1px solid rgba(129, 222, 211, 0.22);
  border-radius: 12px;
  background: rgba(5, 24, 22, 0.68);
  box-shadow: inset 0 1px rgba(255,255,255,.05), 0 18px 46px rgba(0,0,0,.22);
  backdrop-filter: blur(18px) saturate(120%);
}
.measure-board-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: rgba(239,251,248,.72); }
.measure-phase-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .55rem; }
.measure-phase-strip > div { display: grid; gap: .3rem; min-height: 94px; padding: .8rem; border: 1px solid rgba(255,255,255,.1); background: rgba(255,255,255,.025); }
.measure-phase-strip > div.active { border-color: #52c7bc; background: rgba(68,184,173,.14); box-shadow: inset 0 -3px #52c7bc; }
.measure-phase-strip strong { color: #fff; font-size: .79rem; letter-spacing: .08em; }
.measure-phase-strip span { color: rgba(239,251,248,.62); font-size: .72rem; line-height: 1.4; }
.measure-board-facts { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .7rem; margin: 0; }
.measure-board-facts div { display: grid; gap: .2rem; padding-top: .75rem; border-top: 1px solid rgba(255,255,255,.11); }
.measure-board-facts dt { color: rgba(239,251,248,.6); font-size: .72rem; }
.measure-board-facts dd { margin: 0; color: #fff; font-size: 1.2rem; font-weight: 800; }

.measure-planning-shell { display: grid; grid-template-columns: minmax(250px, .28fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.measure-planning-rail {
  position: sticky;
  top: 5.75rem;
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--kbb-primary) 16%, var(--border));
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface-strong) 91%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px) saturate(120%);
}
.measure-rail-progress { display: grid; gap: .35rem; padding: .25rem .25rem .75rem; border-bottom: 1px solid var(--border); }
.measure-rail-progress .measure-progress { margin: .35rem 0 0; }
.measure-rail-steps { display: grid; gap: .25rem; }
.measure-rail-steps a { display: grid; grid-template-columns: 2.2rem minmax(0,1fr); gap: .65rem; align-items: center; min-height: 62px; padding: .55rem; border: 1px solid transparent; border-radius: 10px; color: var(--text-primary); text-decoration: none; }
.measure-rail-steps a:hover { border-color: var(--border); background: var(--surface-soft); }
.measure-rail-steps a.current { border-color: color-mix(in srgb, var(--kbb-primary) 42%, var(--border)); background: color-mix(in srgb, var(--kbb-primary) 8%, var(--surface)); box-shadow: inset 3px 0 var(--kbb-primary); }
.measure-rail-steps a > span:first-child { display: grid; width: 2rem; height: 2rem; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); background: var(--surface-strong); font-weight: 800; }
.measure-rail-steps a.current > span:first-child { border-color: var(--kbb-primary); color: #fff; background: var(--kbb-primary); }
.measure-rail-steps a > span:last-child { display: grid; gap: .12rem; min-width: 0; }
.measure-rail-steps small { color: var(--text-muted); font-size: .7rem; line-height: 1.3; }
.measure-rail-note { margin: 0; padding: .75rem; border-left: 3px solid var(--kbb-accent); color: var(--text-muted); background: color-mix(in srgb, var(--kbb-accent) 7%, transparent); font-size: .75rem; line-height: 1.45; }

.measure-workflow-stage { min-width: 0; }
.measure-stage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-strong); }
.measure-stage-head :where(h2,p) { margin: .12rem 0; }
.measure-workflow-stage > .workflow-section:not([open]) { display: none; }
.measure-workflow-stage > .workflow-section[open] { padding: clamp(1rem, 2vw, 1.4rem); }
.measure-workflow-stage > .workflow-section[open] > summary { display: none; }
.measure-workflow-stage > .workflow-section[open] > .list-head:first-of-type { margin-top: 0; }

.planning-form-block { min-width: 0; margin: 0; padding: clamp(1rem, 2.2vw, 1.35rem); border: 1px solid var(--border); border-radius: 12px; background: color-mix(in srgb, var(--surface-strong) 95%, var(--background)); }
.planning-form-block > legend { display: inline-flex; align-items: center; gap: .55rem; padding: 0 .5rem; color: var(--text-primary); font-size: 1rem; font-weight: 800; }
.planning-form-block > legend span { display: grid; width: 1.8rem; height: 1.8rem; place-items: center; border-radius: 7px; color: #fff; background: var(--kbb-primary); font-size: .8rem; }
.planning-form-block > p { margin: 0 0 1rem; color: var(--text-muted); }
.planning-form-block > .form-grid { margin: 0; }
.planning-save-bar { position: sticky; bottom: .75rem; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; border: 1px solid color-mix(in srgb, var(--kbb-primary) 30%, var(--border)); border-radius: 12px; background: color-mix(in srgb, var(--surface-strong) 92%, transparent); box-shadow: 0 16px 38px rgba(7,48,43,.14); backdrop-filter: blur(18px); }
.planning-save-bar > div { display: grid; gap: .15rem; }
.planning-save-bar small { color: var(--text-muted); }

@media (max-width: 1120px) {
  .measure-command-hero { grid-template-columns: 1fr; min-height: 0; }
  .measure-planning-shell { grid-template-columns: 1fr; }
  .measure-planning-rail { position: static; }
  .measure-rail-steps { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .measure-rail-steps a { grid-template-columns: auto minmax(0,1fr); }
  .measure-rail-note { display: none; }
}

@media (max-width: 760px) {
  .measure-command-hero { gap: .9rem; margin-inline: -.25rem; padding: 1.1rem; border-radius: 12px; }
  .measure-command-copy { gap: .7rem; }
  .measure-command-copy h1 { font-size: clamp(1.75rem, 8.5vw, 2.35rem); }
  .measure-command-copy p { font-size: .92rem; line-height: 1.5; }
  .measure-command-copy .actions { gap: .45rem; }
  .measure-command-copy .actions .btn { min-height: 42px; }
  .measure-command-board { gap: .7rem; padding: .8rem; }
  .measure-phase-strip, .measure-board-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .measure-phase-strip > div { min-height: 58px; padding: .55rem; }
  .measure-phase-strip span { display: none; }
  .measure-board-facts strong { font-size: 1rem; }
  .measure-board-facts span { font-size: .62rem; }
  .measure-rail-steps {
    display: grid;
    grid-auto-columns: minmax(142px, 58vw);
    grid-auto-flow: column;
    grid-template-columns: none;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding-bottom: .25rem;
    scroll-snap-type: inline proximity;
  }
  .measure-rail-steps a { min-height: 54px; scroll-snap-align: start; }
  .measure-rail-steps small { display: none; }
  .measure-stage-head, .planning-save-bar { align-items: stretch; flex-direction: column; }
  .planning-save-bar button { width: 100%; }
}

@media (max-width: 420px) {
  .measure-command-copy .actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .main :where(button, .btn, .panel, .card, .metric-card, .task-card) { transition: none; }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .portal-shell-page .sidebar,
  .portal-shell-page .topbar,
  .main .kbb-section-nav,
  .main :where(.toolbar, .filter-bar, .filters, .workspace-switcher) { background: var(--surface-strong); }
}
.cost-planner {
  margin-top: 1.25rem;
}

.cost-planner-basics,
.cost-result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.cost-planner-basics article,
.cost-result-grid article {
  min-width: 0;
  padding: 0.9rem;
  border: 1px solid var(--border, #d9e1e8);
  border-radius: 0.8rem;
  background: var(--surface-soft, #f5f8fa);
}

.cost-planner-basics span,
.cost-result-grid span,
.cost-card-total span {
  display: block;
  color: var(--text-muted, #586574);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.cost-planner-basics strong,
.cost-result-grid output {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.05rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.cost-result-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cost-result-grid article.primary {
  border-color: #1f6f8b;
  background: color-mix(in srgb, var(--surface, #fff) 90%, #ccebf3);
}

.cost-result-grid article.primary output {
  font-size: 1.35rem;
}

.cost-planner-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 1.25rem 0;
}

.cost-planner-nav a {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.6rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--border, #d9e1e8);
  border-radius: 0.7rem;
  color: inherit;
  background: var(--surface, #fff);
  text-decoration: none;
}

.cost-planner-nav a > span,
.cost-step-number {
  display: inline-grid;
  width: 1.8rem;
  height: 1.8rem;
  grid-row: span 2;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #1f6f8b;
  font-weight: 750;
}

.cost-planner-nav small {
  color: var(--text-muted, #586574);
}

.cost-group {
  margin-top: 1.25rem;
  scroll-margin-top: 1rem;
}

.cost-group-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding-bottom: 0.65rem;
  border-bottom: 2px solid var(--border, #d9e1e8);
}

.cost-group-heading > div {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.cost-group-heading h4,
.cost-group-heading p {
  margin: 0;
}

.cost-group-heading p {
  color: var(--text-muted, #586574);
  font-size: 0.88rem;
}

.cost-card-list {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.cost-entry-card {
  padding: 1rem;
  border: 1px solid var(--border, #d9e1e8);
  border-left: 0.35rem solid #b27b00;
  border-radius: 0.8rem;
  background: var(--surface, #fff);
  scroll-margin-top: 1rem;
}

.cost-entry-card.cost-state-incomplete {
  border-left-color: #b54708;
}

.cost-entry-card.cost-state-checked {
  border-left-color: #177245;
}

.cost-entry-card header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.cost-entry-card h5 {
  margin: 0.2rem 0 0;
  font-size: 1.05rem;
}

.cost-state-label {
  display: inline-block;
  color: #6f4b00;
  font-size: 0.76rem;
  font-weight: 750;
  text-transform: uppercase;
}

.cost-state-incomplete .cost-state-label { color: #9a3412; }
.cost-state-checked .cost-state-label { color: #177245; }

.cost-card-total {
  flex: 0 0 auto;
  text-align: right;
}

.cost-card-total output {
  display: block;
  margin-top: 0.15rem;
  font-size: 1.15rem;
  font-weight: 750;
}

.cost-entry-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

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

.structured-cost-card [hidden] {
  display: none !important;
}

.structured-cost-fields {
  align-items: start;
}

.structured-cost-card select,
.structured-cost-card input {
  width: 100%;
}

.structured-cost-card.cost-state-incomplete {
  border-color: #b45309;
}

@media (max-width: 760px) {
  .structured-cost-basics {
    grid-template-columns: 1fr;
  }
}

.cost-entry-fields label,
.cost-advanced label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 700;
}

.cost-entry-fields label.span-2 { grid-column: span 2; }

.cost-entry-fields small,
.cost-advanced small {
  color: var(--text-muted, #586574);
  font-weight: 400;
  line-height: 1.35;
}

.cost-suggestion,
.cost-calculation-explanation {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-top: 0.8rem;
  padding: 0.75rem;
  border-radius: 0.65rem;
  background: var(--surface-soft, #f5f8fa);
}

.cost-suggestion span,
.cost-calculation-explanation output {
  display: block;
  color: var(--text-muted, #586574);
  font-size: 0.88rem;
}

.cost-calculation-explanation output {
  color: inherit;
  font-weight: 700;
  text-align: right;
}

.cost-advanced {
  margin-top: 0.65rem;
}

.cost-advanced summary {
  cursor: pointer;
  font-weight: 700;
}

.cost-advanced label {
  margin-top: 0.65rem;
}

.cost-error-summary {
  margin: 1rem 0;
  padding: 1rem;
  border: 2px solid #b42318;
  border-radius: 0.8rem;
  background: color-mix(in srgb, var(--surface, #fff) 92%, #fee4e2);
}

.cost-error-summary:focus { outline: 3px solid color-mix(in srgb, #b42318 35%, transparent); }
.cost-error-summary ul { margin-bottom: 0; }

.cost-planner-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 0.8rem;
  background: var(--surface-soft, #f5f8fa);
}

.facility-cost-profile {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--success, #18864b) 35%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--success, #18864b) 7%, var(--surface));
}
.facility-cost-profile > div { display: grid; gap: .18rem; }
.facility-cost-profile > div > span { font-size: .72rem; font-weight: 800; letter-spacing: .08em; color: var(--success, #18864b); }
.facility-cost-profile dl { display: grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr)); gap: .65rem; margin: .9rem 0; }
.facility-cost-profile dl div { display: grid; gap: .15rem; padding: .65rem .75rem; border-radius: 10px; background: var(--surface); }
.facility-cost-profile dt { color: var(--muted); font-size: .78rem; }
.facility-cost-profile dd { margin: 0; font-weight: 750; }
.facility-cost-profile p { margin: 0; color: var(--muted); font-size: .84rem; }
.automatic-cost-source { display: grid; gap: .2rem; padding: .7rem .8rem; border-radius: 10px; background: color-mix(in srgb, var(--success, #18864b) 8%, var(--surface)); }
.automatic-cost-source span { color: var(--muted); font-size: .82rem; }

.cost-planner-actions output {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
}

.link-button {
  appearance: none;
  padding: 0;
  border: 0;
  color: var(--link, #165d8f);
  background: transparent;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

@media (max-width: 760px) {
  .cost-planner-basics,
  .cost-result-grid,
  .cost-planner-nav,
  .cost-entry-fields { grid-template-columns: 1fr; }
  .cost-entry-fields label.span-2 { grid-column: auto; }
  .cost-entry-card header,
  .cost-group-heading,
  .cost-suggestion,
  .cost-calculation-explanation { align-items: stretch; flex-direction: column; }
  .cost-card-total,
  .cost-calculation-explanation output { text-align: left; }
  .cost-planner-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

/* Preserve destructive-action semantics after the shared UI layer. */
.main :where(button.danger, .btn.danger):not(.link-button) {
  background: var(--kbb-danger);
  border-color: var(--kbb-danger);
  color: #fff;
}
