:root {
  --md-primary: #00639a;
  --md-on-primary: #ffffff;
  --md-primary-container: #cee5ff;
  --md-on-primary-container: #001d32;
  --md-secondary: #51606f;
  --md-secondary-container: #d5e4f6;
  --md-tertiary-container: #f2dcff;
  --md-surface: #f8f9ff;
  --md-surface-container-low: #f1f4f9;
  --md-surface-container: #e9edf3;
  --md-surface-container-high: #e3e8ee;
  --md-surface-bright: #f8f9ff;
  --md-on-surface: #191c20;
  --md-on-surface-variant: #42474e;
  --md-outline: #72777f;
  --md-outline-variant: #c2c7cf;
  --md-error: #ba1a1a;
  --md-error-container: #ffdad6;
  --md-warning-container: #ffdea5;
  --md-success: #146c43;
  --md-success-container: #b9f2cf;
  --md-shadow: 0 1px 2px rgb(25 28 32 / 10%), 0 2px 8px rgb(25 28 32 / 8%);
  --md-shadow-raised: 0 2px 6px rgb(25 28 32 / 12%), 0 8px 24px rgb(25 28 32 / 10%);
  --md-radius-sm: 8px;
  --md-radius-md: 12px;
  --md-radius-lg: 20px;
  --md-radius-xl: 28px;
  --app-bar-height: 72px;
  --drawer-width: 276px;
  --critical-font: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--md-surface);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--md-on-surface);
  background:
    radial-gradient(circle at 100% 0, rgb(206 229 255 / 48%), transparent 30rem),
    var(--md-surface);
  font-family: Roboto, "Segoe UI", Arial, sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--md-primary);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(0 99 154 / 28%);
  outline-offset: 2px;
}

/* On desktop the drawer is always visible, so there is no top bar. */
@media (min-width: 992px) {
  .app-bar {
    display: none;
  }
  :root {
    --app-bar-height: 0px;
  }
}

.app-bar {
  position: fixed;
  z-index: 1040;
  inset: 0 0 auto 0;
  height: var(--app-bar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  color: var(--md-on-surface);
  background: transparent;
  pointer-events: none;
}

/* Only the button itself is interactive; the empty bar must not block the page. */
.app-bar .icon-button {
  pointer-events: auto;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--md-on-primary);
  background: linear-gradient(145deg, #0078b9, var(--md-primary));
  box-shadow: var(--md-shadow);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.icon-button {
  width: 48px;
  height: 48px;
  display: none;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--md-on-surface-variant);
  background: transparent;
  font-size: 1.45rem;
  transition: background-color 150ms ease;
}

.icon-button:hover {
  background: var(--md-surface-container);
}

.status-chip,
.badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}

.status-chip-danger {
  color: #410002;
  background: var(--md-error-container);
}

/* Portal status trail on an order: a connected rail so the sequence and the
   silences between updates read at a glance. */
.timeline {
  margin: 0;
  padding-inline-start: 6px;
}

.timeline-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 0 12px 20px;
  border-inline-start: 2px solid var(--md-outline-variant);
}

.timeline-item:last-child {
  padding-bottom: 0;
  border-inline-start-color: transparent;
}

.timeline-item::before {
  content: "";
  position: absolute;
  inset-inline-start: -6px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--md-outline-variant);
}

.timeline-item-current::before {
  background: var(--md-primary, #2a6a4a);
}

.timeline-time {
  min-width: 46px;
  color: var(--md-on-surface-variant);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.navigation-drawer {
  position: fixed;
  z-index: 1030;
  inset: var(--app-bar-height) auto 0 0;
  width: var(--drawer-width);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 16px;
  background: var(--md-surface-container-low);
  border-inline-end: 1px solid var(--md-outline-variant);
}

/* The logo heads the drawer on its own row, lined up with the menu icons
   (drawer padding 12px + link padding 16px) and set off by a divider. */
.drawer-brand {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  height: 88px;
  margin: -14px 0 6px;
  padding: 0 14px;
  border-bottom: 1px solid var(--md-outline-variant);
}

.drawer-brand img {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.drawer-brand:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: -2px;
  border-radius: 12px;
}

.drawer-nav {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-section-label {
  margin: 18px 16px 7px;
  color: var(--md-on-surface-variant);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.nav-section-label:first-child {
  margin-top: 4px;
}

.drawer-link {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 2px 0;
  padding: 9px 16px;
  border-radius: 24px;
  color: var(--md-on-surface-variant);
  font-weight: 600;
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease;
}

.drawer-link:hover {
  color: var(--md-on-surface);
  background: var(--md-surface-container-high);
}

.drawer-link.active {
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
}

.nav-icon {
  width: 22px;
  flex: 0 0 22px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 500;
}

.drawer-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 14px 10px 0;
  border-top: 1px solid var(--md-outline-variant);
}

.account-copy {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.account-copy strong {
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy span {
  color: var(--md-on-surface-variant);
  font-size: 0.7rem;
  text-transform: capitalize;
}

.navigation-scrim {
  display: none;
}

.app-content {
  width: calc(100% - var(--drawer-width));
  min-height: 100vh;
  margin-inline-start: var(--drawer-width);
  padding: calc(var(--app-bar-height) + 32px) clamp(20px, 3vw, 48px) 48px;
}

.app-content > * {
  max-width: 1500px;
  margin-inline: auto;
}

.anonymous-content {
  min-height: 100vh;
}

h1,
.h1 {
  margin: 0 0 24px;
  color: var(--md-on-surface);
  font-size: clamp(1.75rem, 2vw, 2.25rem);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h2,
.h2 {
  margin: 32px 0 16px;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.text-muted,
small {
  color: var(--md-on-surface-variant) !important;
}

.card {
  color: var(--md-on-surface);
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  box-shadow: none;
  overflow: hidden;
}

.card.shadow-sm {
  box-shadow: var(--md-shadow) !important;
}

.card-body {
  padding: 22px;
}

.card-header {
  padding: 16px 22px;
  color: var(--md-on-surface);
  background: var(--md-surface-container-low);
  border-bottom: 1px solid var(--md-outline-variant);
  font-weight: 650;
}

.row > [class*="col-"] > .card.card-body > strong {
  color: var(--md-on-surface-variant);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.025em;
}

.row > [class*="col-"] > .card.card-body > span {
  margin-top: 10px;
  color: var(--md-on-surface);
  font-size: 1.25rem;
  font-weight: 650;
}

.btn {
  min-height: 42px;
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: none !important;
}

.btn-sm {
  min-height: 34px;
  padding: 5px 14px;
  font-size: 0.78rem;
}

.btn-primary,
.btn-success {
  color: var(--md-on-primary);
  background: var(--md-primary);
  border-color: var(--md-primary);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-success:hover,
.btn-success:focus {
  color: var(--md-on-primary);
  background: #004c77;
  border-color: #004c77;
}

.btn-outline-primary,
.btn-outline-success {
  color: var(--md-primary);
  background: transparent;
  border-color: var(--md-outline);
}

.btn-outline-primary:hover,
.btn-outline-success:hover {
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
  border-color: var(--md-primary-container);
}

.btn-outline-secondary,
.btn-tonal {
  color: #0d1d2a;
  background: var(--md-secondary-container);
  border-color: transparent;
}

.btn-outline-secondary:hover,
.btn-tonal:hover {
  color: #0d1d2a;
  background: #c7d7e9;
  border-color: transparent;
}

.btn-danger,
.btn-outline-danger {
  color: var(--md-error);
  background: transparent;
  border-color: var(--md-outline);
}

.btn-danger:hover,
.btn-outline-danger:hover {
  color: #410002;
  background: var(--md-error-container);
  border-color: var(--md-error-container);
}

.form-label {
  margin-bottom: 7px;
  color: var(--md-on-surface-variant);
  font-size: 0.82rem;
  font-weight: 650;
}

.form-control,
.form-select {
  min-height: 50px;
  padding: 11px 14px;
  color: var(--md-on-surface);
  background-color: var(--md-surface-bright);
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
}

textarea.form-control {
  min-height: 112px;
}

.form-control:hover,
.form-select:hover {
  border-color: var(--md-on-surface);
}

.form-control:focus,
.form-select:focus {
  border-width: 2px;
  border-color: var(--md-primary);
  box-shadow: none;
}

.form-check-input:checked {
  background-color: var(--md-primary);
  border-color: var(--md-primary);
}

.table-responsive {
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  overflow: auto;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: var(--md-surface-container-low);
  margin-bottom: 0;
  color: var(--md-on-surface);
}

.table > :not(caption) > * > * {
  padding: 14px 16px;
  border-bottom-color: var(--md-outline-variant);
  vertical-align: middle;
}

.table thead th {
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-low);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.table tbody tr {
  transition: background-color 120ms ease;
}

.table tbody tr:hover {
  background: rgb(206 229 255 / 34%);
}

.alert {
  padding: 14px 18px;
  border: 0;
  border-radius: var(--md-radius-md);
}

.alert-danger {
  color: #410002;
  background: var(--md-error-container);
}

.alert-warning {
  color: #261900;
  background: var(--md-warning-container);
}

.alert-info {
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
}

.text-bg-success {
  color: #07391f !important;
  background: var(--md-success-container) !important;
}

.text-bg-warning {
  color: #261900 !important;
  background: var(--md-warning-container) !important;
}

.text-bg-danger {
  color: #410002 !important;
  background: var(--md-error-container) !important;
}

.critical-value {
  font-family: var(--critical-font);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-all;
}

.reference-value {
  font-size: 1.15rem;
}

.evidence-crop {
  max-width: 100%;
  max-height: 90px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-sm);
}

.payload-preview,
pre {
  max-height: 360px;
  overflow: auto;
  padding: 16px;
  color: #e9edf3;
  background: #20262e;
  border-radius: var(--md-radius-md);
}

.audit-data {
  max-width: 380px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.htmx-request .progress-bar {
  opacity: 0.6;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
  background: var(--md-surface);
}

.login-brand-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(36px, 6vw, 88px);
  color: white;
  background:
    radial-gradient(circle at 85% 15%, rgb(255 255 255 / 20%), transparent 24rem),
    linear-gradient(145deg, #004c77 0%, #00639a 48%, #147dad 100%);
  overflow: hidden;
}

.login-brand-panel::after {
  position: absolute;
  right: -120px;
  bottom: -140px;
  width: 420px;
  height: 420px;
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 50%;
  box-shadow: 0 0 0 60px rgb(255 255 255 / 5%), 0 0 0 120px rgb(255 255 255 / 4%);
  content: "";
}

.login-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 16px;
}

.login-brand .brand-mark {
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
}

.login-brand h1 {
  margin: 0;
  color: white;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}

.login-message {
  position: relative;
  z-index: 1;
  max-width: 560px;
}

.login-message h2 {
  margin: 0 0 18px;
  font-size: clamp(2.25rem, 4vw, 4.5rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.login-message p {
  max-width: 480px;
  margin: 0;
  color: rgb(255 255 255 / 82%);
  font-size: 1.05rem;
}

.login-form-panel {
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-card {
  width: min(100%, 440px);
  background: transparent;
  border: 0;
  box-shadow: none !important;
}

.login-card .card-body {
  padding: 0;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.login-subtitle {
  margin-bottom: 30px;
  color: var(--md-on-surface-variant);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--md-primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.onboarding-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(560px, 1.28fr);
}

.onboarding-intro {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: clamp(36px, 6vw, 84px);
  color: white;
  background: linear-gradient(145deg, #003451, #00639a);
}

.onboarding-intro .eyebrow {
  margin-top: 72px;
  color: var(--md-primary-container);
}

.onboarding-intro h1 {
  max-width: 600px;
  color: white;
  font-size: clamp(2.5rem, 5vw, 4.75rem);
  letter-spacing: -0.055em;
}

.onboarding-intro > p:not(.eyebrow) {
  max-width: 520px;
  color: rgb(255 255 255 / 82%);
  font-size: 1.05rem;
}

.security-note {
  position: absolute;
  right: clamp(36px, 6vw, 84px);
  bottom: 64px;
  left: clamp(36px, 6vw, 84px);
  padding: 16px 18px;
  color: rgb(255 255 255 / 88%);
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: var(--md-radius-md);
}

.onboarding-form-panel {
  padding: clamp(32px, 5vw, 72px);
}

.onboarding-form {
  max-width: 840px;
  margin: 0 auto;
}

.form-heading h2 {
  margin: 0 0 6px;
  font-size: 2rem;
}

.onboarding-form fieldset {
  margin: 34px 0;
  padding: 24px;
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
}

.onboarding-form legend {
  float: none;
  width: auto;
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 700;
}

.field-hint {
  margin: 0 0 18px;
  color: var(--md-on-surface-variant);
  font-size: 0.84rem;
}

.onboarding-status {
  width: min(100% - 32px, 680px);
  margin: 0 auto;
  padding: 72px 0;
  text-align: center;
}

.progress-steps {
  margin-top: 36px;
  text-align: left;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--md-outline-variant);
}

.progress-step > span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--md-surface-container);
}

.progress-step.complete > span {
  color: #07391f;
  background: var(--md-success-container);
}

.progress-step.pending strong {
  color: var(--md-on-surface-variant);
  font-weight: 500;
}

@media (max-width: 991.98px) {
  .icon-button {
    display: grid;
  }

  .navigation-drawer {
    z-index: 1060;
    inset-block-start: 0;
    height: 100vh;
    padding-top: 20px;
    border-radius: 0 var(--md-radius-xl) var(--md-radius-xl) 0;
    box-shadow: var(--md-shadow-raised);
    transform: translateX(-105%);
    transition: transform 220ms cubic-bezier(0.2, 0, 0, 1);
  }

  body.navigation-open {
    overflow: hidden;
  }

  body.navigation-open .navigation-drawer {
    transform: translateX(0);
  }

  .navigation-scrim {
    position: fixed;
    z-index: 1050;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgb(25 28 32 / 45%);
  }

  body.navigation-open .navigation-scrim {
    display: block;
  }

  .app-content {
    width: 100%;
    margin-inline-start: 0;
  }
}

@media (max-width: 767.98px) {
  :root {
    --app-bar-height: 64px;
  }

  .app-bar {
    padding: 0 12px;
  }

  .app-content {
    padding: calc(var(--app-bar-height) + 22px) 14px 32px;
  }

  .login-page {
    display: block;
  }

  .login-brand-panel {
    min-height: 250px;
    padding: 28px 24px 36px;
  }

  .login-message h2 {
    margin-top: 52px;
    font-size: 2.25rem;
  }

  .login-message p {
    font-size: 0.92rem;
  }

  .login-form-panel {
    padding: 38px 24px 48px;
  }

  .onboarding-page {
    display: block;
  }

  .onboarding-intro {
    position: relative;
    height: auto;
    padding: 32px 24px;
  }

  .onboarding-intro .eyebrow {
    margin-top: 48px;
  }

  .onboarding-intro h1 {
    font-size: 2.4rem;
  }

  .security-note {
    position: static;
    margin-top: 28px;
  }

  .onboarding-form-panel {
    padding: 40px 20px;
  }

  .onboarding-form fieldset {
    padding: 20px 16px;
  }

  .d-flex.justify-content-between {
    gap: 14px;
    flex-wrap: wrap;
  }
}

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

/* --- Page headers, filter bars and data tables -------------------------- */
/* Material 3 surfaces and shape, built from the tokens already defined at the
   top of this file so these components match the rest of the application. */

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

.page-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--md-on-surface);
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--md-on-surface-variant);
  font-size: 0.9rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
}

/* The search box takes the room the selects do not need. */
.filter-field-grow {
  flex: 1 1 260px;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--md-on-surface-variant);
}

.filter-actions {
  display: flex;
  gap: 8px;
  margin-inline-start: auto;
}

.data-card {
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow);
  overflow: hidden;
}

.data-table {
  margin: 0;
}

.data-table thead th {
  background: var(--md-surface-container);
  color: var(--md-on-surface-variant);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--md-outline-variant);
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--md-outline-variant);
}

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

.data-table tbody tr:hover {
  background: var(--md-surface-container-low);
}

.data-table td {
  vertical-align: middle;
}

/* Two lines per cell: the value, then the context under it, so a row stays
   readable without a second column for every detail.

   The lines are stacked by making the spans block-level, NOT by putting flex on
   the cell: display:flex removes the implicit display:table-cell and the row
   collapses into one block per cell, stacked down the page. */
.cell-stack > * {
  display: block;
}

.cell-stack > * + * {
  margin-top: 2px;
}

.cell-strong {
  font-weight: 600;
  color: var(--md-on-surface);
}

.cell-muted {
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
  overflow-wrap: anywhere;
}

.empty-cell {
  padding: 32px 16px;
  text-align: center;
  color: var(--md-on-surface-variant);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container-low);
}

.pagination-status {
  font-size: 0.85rem;
  color: var(--md-on-surface-variant);
}

.status-chip-success {
  color: #04301b;
  background: var(--md-success-container);
}

.status-chip-warning {
  color: #3d2c00;
  background: var(--md-warning-container);
}

.status-chip-info,
.status-chip-live {
  color: var(--md-on-primary-container);
  background: var(--md-primary-container);
}

.status-chip-muted {
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container-high);
}

/* --- Metric tiles, section titles and code cells ------------------------ */

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--md-on-surface);
  overflow-wrap: anywhere;
}

.section-title {
  margin: 28px 0 12px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--md-on-surface);
}

/* --------------------------------------------------------------------------
   Dashboard analytics. Charts are drawn from the same tokens as every other
   surface, so they read as part of the panel rather than a bolted-on widget,
   and need no charting library.
   -------------------------------------------------------------------------- */
.metric-tile-primary {
  background: linear-gradient(160deg, var(--md-primary-container), var(--md-surface-bright));
  border-color: var(--md-primary-container);
}

.metric-value-lg {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.metric-hint {
  font-size: 0.78rem;
  color: var(--md-on-surface-variant);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

/* Vertical columns: a day-by-day or hour-by-hour rhythm. */
.chart-columns {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 168px;
  padding-top: 8px;
}

.chart-column {
  position: relative;
  flex: 1 1 0;
  min-width: 4px;
  display: flex;
  align-items: flex-end;
  height: 100%;
}

.chart-column-fill {
  width: 100%;
  min-height: 2px;
  border-radius: var(--md-radius-sm) var(--md-radius-sm) 2px 2px;
  background: var(--md-primary);
  opacity: 0.85;
  transition: opacity 120ms ease;
}

.chart-column:hover .chart-column-fill {
  opacity: 1;
}

.chart-column-empty .chart-column-fill {
  background: var(--md-outline-variant);
  opacity: 0.55;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--md-on-surface-variant);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

/* Horizontal bars: ranked categories such as districts or statuses. */
.chart-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}

.chart-row {
  display: grid;
  grid-template-columns: 86px 1fr auto;
  align-items: center;
  gap: 12px;
}

.chart-row-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--md-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-track {
  height: 22px;
  border-radius: 999px;
  background: var(--md-surface-container);
  overflow: hidden;
}

.chart-track-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 999px;
  background: var(--md-primary);
}

.chart-track-fill-warning { background: var(--md-warning-container); }
.chart-track-fill-danger { background: var(--md-error); }
.chart-track-fill-success { background: var(--md-success); }

.chart-row-value {
  min-width: 96px;
  text-align: end;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--md-on-surface-variant);
}

.chart-empty {
  padding: 28px 8px;
  text-align: center;
  color: var(--md-on-surface-variant);
  font-size: 0.85rem;
}

/* Long JSON must not push a table sideways forever. */
.code-cell {
  max-height: 120px;
  max-width: 420px;
  overflow: auto;
  padding: 8px;
  font-size: 0.75rem;
  background: var(--md-surface-container-low);
  border-radius: var(--md-radius-sm);
}

.form-card {
  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow);
}

.form-card .card-body {
  padding: 20px;
}

/* --- Filter bar and table refinements ----------------------------------- */
/* The first pass let the search field and the selects stack full width, which
   turned a one-line control strip into four stacked rows. */

.filter-bar {
  align-items: end;
}

.filter-bar .form-control,
.filter-bar .form-select {
  min-height: 44px;
}

.filter-field {
  flex: 0 1 220px;
}

.filter-field-grow {
  flex: 2 1 320px;
}

@media (max-width: 640px) {
  .filter-field,
  .filter-field-grow {
    flex: 1 1 100%;
  }
  .filter-actions {
    margin-inline-start: 0;
    width: 100%;
  }
}

.live-dot {
  width: 8px;
  height: 8px;
  margin-inline-end: 6px;
  border-radius: 50%;
  background: var(--md-success);
  box-shadow: 0 0 0 3px rgb(20 108 67 / 18%);
}

/* Rows carry two lines of text, so they need more room than Bootstrap's
   default and a clear separation between the value and its context. */
.data-table td,
.data-table thead th {
  padding: 14px 16px;
}

.data-table tbody tr {
  transition: background 120ms ease;
}

.data-table .cell-strong {
  font-size: 0.95rem;
}

/* Keep the address from stretching a row across the whole screen. */
.data-table .cell-muted {
  max-width: 42ch;
}

.data-table .btn-sm {
  border-radius: 999px;
  padding-inline: 16px;
}

.page-header {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--md-outline-variant);
}

/* ---------------------------------------------------------------------------
   Dashboard: trend chart, split bar and comparison table.

   Everything is drawn with the design-system tokens and plain SVG/CSS -- no
   charting library -- so the page keeps the same palette as the rest of the
   portal and stays readable when a value is zero.
   --------------------------------------------------------------------------- */

/* Five tiles across need more room than the default 180px track. */
.metric-row-wide {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.metric-unit {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-left: 2px;
}

/* A trend arrow against the previous window. Green means the direction the
   operator wants, which is not always "up" -- spend rising is not good news. */
.metric-delta {
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 8px;
  vertical-align: middle;
  white-space: nowrap;
}

.metric-delta-up { color: var(--md-success); }
.metric-delta-down { color: var(--md-error); }

/* How each dispatched order got through, as one bar: untouched, repaired by
   the bridge, needed a person. */
.metric-split {
  display: flex;
  height: 6px;
  margin-top: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--md-surface-container);
}

.metric-split-seg { display: block; height: 100%; }
.metric-split-clean { background: var(--md-success); }
.metric-split-fixed { background: var(--md-primary); }
.metric-split-human { background: var(--md-warning-container); }

/* Orders per day, as a filled line. A picket fence of 30-90 bars reads as
   noise; the area shows the shape of the month at a glance. */
.trend-chart {
  display: block;
  width: 100%;
  height: 200px;
  overflow: visible;
}

.trend-grid {
  stroke: var(--md-outline-variant);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.trend-line {
  fill: none;
  stroke: var(--md-primary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.trend-area { stroke: none; }
.trend-fill-top { stop-color: var(--md-primary); stop-opacity: 0.28; }
.trend-fill-bottom { stop-color: var(--md-primary); stop-opacity: 0.02; }

/* Seven bars, not twenty-four: give them room to be read. */
.chart-columns-wide { gap: 8px; }
.chart-columns-wide .chart-column { border-radius: var(--md-radius-sm); }

.chart-axis-spread {
  display: flex;
  justify-content: space-between;
}

/* Long labels get their own line above the bar.

   A fixed 86px label column cannot hold "Ambiguous house number", and a grid
   track that size does not grow from the child's min-width -- the text simply
   overflowed and ran underneath the bar. Stacking gives both the full width of
   the card. */
.chart-rows-stacked { gap: 14px; }

.chart-row-stacked {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chart-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.chart-row-stacked .chart-row-label {
  white-space: normal;
  overflow: visible;
  text-transform: capitalize;
}

.chart-row-stacked .chart-track { height: 14px; }

/* A district row that leads into the orders list already filtered to it. */
.chart-row-link {
  color: inherit;
  text-decoration: none;
  border-radius: var(--md-radius-sm);
  transition: background 120ms ease;
}

.chart-row-link:hover {
  background: var(--md-surface-container-low);
  color: inherit;
}

.chart-row-link:hover .chart-track-fill {
  filter: brightness(1.08);
}

/* ---------------------------------------------------------------------------
   Trend chart axes and readout.

   The line alone showed a shape with no magnitude, and the browser's own
   title tooltip was slow to appear and easy to miss. Both axes now carry real
   values and each day has its own instant readout.
   --------------------------------------------------------------------------- */

.trend-wrap {
  display: flex;
  gap: 10px;
}

.trend-axis-y {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 200px;
  min-width: 26px;
  text-align: right;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--md-on-surface-variant);
}

.trend-plot {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.trend-axis-x {
  position: relative;
  height: 18px;
  margin-top: 6px;
  margin-left: 36px;
  font-size: 0.7rem;
  color: var(--md-on-surface-variant);
}

.trend-axis-x span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.trend-axis-x span:first-child { transform: none; }
.trend-axis-x span:last-child { transform: translateX(-100%); }

/* One cell per day, sitting over the chart. */
.trend-hover {
  position: absolute;
  inset: 0;
  display: flex;
}

.trend-hover-cell {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border-radius: var(--md-radius-sm);
  outline: none;
}

.trend-hover-cell:hover,
.trend-hover-cell:focus-visible {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}

/* A vertical guide, so the eye can find the exact day being read. */
.trend-hover-cell::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--md-primary);
  opacity: 0;
  transition: opacity 90ms ease;
}

.trend-hover-cell:hover::before,
.trend-hover-cell:focus-visible::before { opacity: 0.45; }

/* The point on the line for that day. */
.trend-dot {
  position: absolute;
  left: 50%;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--md-surface-bright);
  border: 2px solid var(--md-primary);
  opacity: 0;
  transition: opacity 90ms ease;
  pointer-events: none;
}

.trend-hover-cell:hover .trend-dot,
.trend-hover-cell:focus-visible .trend-dot { opacity: 1; }

.trend-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  border-radius: var(--md-radius-sm);
  background: var(--md-inverse-surface, #1f2430);
  color: var(--md-inverse-on-surface, #ffffff);
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: var(--md-shadow-lg, 0 6px 18px rgba(0, 0, 0, 0.22));
  z-index: 5;
  pointer-events: none;
}

.trend-hover-cell:hover .trend-tip,
.trend-hover-cell:focus-visible .trend-tip { display: flex; }

/* Keep the readout inside the card at both ends of the axis. */
.trend-hover-cell:first-child .trend-tip { left: 0; transform: none; }
.trend-hover-cell:last-child .trend-tip { left: auto; right: 0; transform: none; }

.trend-tip-date { opacity: 0.75; }

/* ---------------------------------------------------------------------------
   Vienna district map.

   Real boundaries from the city's open data, shaded by volume. One colour at
   varying strength reads as a scale; several colours would need a legend the
   operator has to decode.
   --------------------------------------------------------------------------- */

/* Direct child only. ".vienna-map svg" also matched the little key icon in
   the legend below the map, and it outranks a single class, so the icon was
   stretched to the full width of the card as a giant blue circle. */
.vienna-map > svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 460px;
}

.vienna-district { cursor: pointer; }

.vienna-shape {
  fill: var(--md-error);
  fill-opacity: 0.12;
  stroke: var(--md-surface-bright);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  transition: fill-opacity 120ms ease, stroke 120ms ease;
}

/* A district with no deliveries is part of the city, not part of the data. */
.vienna-shape-quiet {
  fill: var(--md-surface-container);
  fill-opacity: 1;
  stroke: var(--md-outline-variant);
}

.vienna-district:hover .vienna-shape {
  stroke: var(--md-primary);
  stroke-width: 2.5;
}

.vienna-label {
  fill: var(--md-on-surface-variant);
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Once a district is dark enough, dark text on it stops being readable. */
.vienna-label-on-dark { fill: #ffffff; }

.vienna-legend {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.vienna-legend-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 220px;
  max-width: 420px;
}

.vienna-legend-key {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vienna-legend .vienna-key-icon {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  overflow: visible;
}

/* Where each restaurant sends from. A pin has to survive being drawn on a dark
   district, so it carries its own light halo rather than relying on contrast
   with whatever is underneath. */
.vienna-pin { pointer-events: none; }

.vienna-pin-halo {
  fill: var(--md-surface-bright);
  fill-opacity: 0.65;
  stroke: none;
}

.vienna-pin-ring {
  fill: none;
  stroke: var(--md-surface-bright);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.vienna-pin-dot {
  fill: var(--md-primary);
  stroke: var(--md-surface-bright);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.vienna-pin-name {
  fill: var(--md-on-surface);
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--md-surface-bright);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.vienna-scale {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--md-error) 12%, transparent),
    var(--md-error)
  );
}

/* In the stacked head the value sits directly beside its label, so the 96px
   reservation that keeps the inline rows aligned would push it off on its own. */
.chart-row-head .chart-row-value {
  min-width: 0;
  font-weight: 700;
  color: var(--md-on-surface);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Action panels: say what already happened instead of offering a dead button.
   --------------------------------------------------------------------------- */

/* A completed or inapplicable action, stated as a fact. */
.action-done {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--md-radius-lg);
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  font-size: 0.85rem;
  color: var(--md-on-surface-variant);
}

.action-done strong { color: var(--md-on-surface); }

.status-chip-neutral {
  background: var(--md-surface-container);
  color: var(--md-on-surface-variant);
}

/* A disabled control must look unavailable, not merely faded. Bootstrap's own
   0.65 opacity leaves a filled danger button still reading as a call to
   action, which is how a dispatched order looked clickable. */
.btn:disabled,
.btn.disabled {
  background: var(--md-surface-container) !important;
  border-color: var(--md-outline-variant) !important;
  color: var(--md-on-surface-variant) !important;
  box-shadow: none !important;
  opacity: 1;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
   Column charts: a y axis and a readout per bar.

   Bars without an axis show a shape but no magnitude, so a quiet week and a
   busy one look identical. Values also had to be hunted for with the browser's
   own tooltip, which is slow and easy to miss.
   --------------------------------------------------------------------------- */

.column-wrap {
  display: flex;
  gap: 10px;
}

.column-axis-y {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 26px;
  text-align: right;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--md-on-surface-variant);
}

.column-plot {
  flex: 1 1 auto;
  min-width: 0;
}

/* The axis labels take a fixed gutter, so the tick row underneath has to start
   where the bars do rather than at the edge of the card. */
.chart-axis-inset { margin-left: 36px; }

.chart-column { position: relative; }

.column-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  border-radius: var(--md-radius-sm);
  background: var(--md-inverse-surface, #1f2430);
  color: var(--md-inverse-on-surface, #ffffff);
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: var(--md-shadow-lg, 0 6px 18px rgba(0, 0, 0, 0.22));
  z-index: 5;
  pointer-events: none;
}

.chart-column:hover .column-tip { display: flex; }

/* Keep the readout inside the card at both ends of the axis. */
.chart-column:first-child .column-tip { left: 0; transform: none; }
.chart-column:last-child .column-tip { left: auto; right: 0; transform: none; }

/* The date boxes should not stretch like the selects beside them. */
.filter-field input[type="date"] { min-width: 150px; }

/* ---- The menu folded into an icon rail (desktop) --------------------------- */
.drawer-head {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  margin: -14px 0 6px;
  border-bottom: 1px solid var(--md-outline-variant);
}

.drawer-head .drawer-brand {
  flex: 1;
  margin: 0;
  border-bottom: 0;
}

.drawer-collapse {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-inline-end: 4px;
  border: 0;
  border-radius: 50%;
  color: var(--md-on-surface-variant);
  background: transparent;
  transition: background-color 150ms, transform 220ms cubic-bezier(0.2, 0, 0, 1);
}

.drawer-collapse:hover { background: var(--md-surface-container-high); color: var(--md-on-surface); }
.drawer-collapse:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.drawer-collapse .m3-icon { width: 22px; height: 22px; }

.drawer-logout { display: inline-flex; align-items: center; gap: 6px; }
.drawer-logout .m3-icon { display: none; width: 18px; height: 18px; }

@media (min-width: 992px) {
  .navigation-drawer,
  .app-content {
    transition: width 220ms cubic-bezier(0.2, 0, 0, 1), margin 220ms cubic-bezier(0.2, 0, 0, 1);
  }

  body.nav-collapsed { --drawer-width: 80px; }

  body.nav-collapsed .navigation-drawer { padding-inline: 12px; }

  body.nav-collapsed .drawer-head {
    flex-direction: column;
    gap: 4px;
    margin-top: 0;
    padding-bottom: 8px;
  }

  body.nav-collapsed .drawer-head .drawer-brand {
    justify-content: center;
    height: 56px;
    padding: 0;
  }

  body.nav-collapsed .drawer-collapse { margin: 0; transform: rotate(180deg); }

  body.nav-collapsed .nav-label,
  body.nav-collapsed .account-copy {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* Section names become a thin rule between the groups. */
  body.nav-collapsed .nav-section-label {
    height: 1px;
    margin: 10px 8px;
    overflow: hidden;
    color: transparent;
    background: var(--md-outline-variant);
  }

  body.nav-collapsed .nav-section-label:first-child { margin-top: 2px; }

  body.nav-collapsed .drawer-link {
    position: relative;
    justify-content: center;
    padding: 9px 0;
  }

  body.nav-collapsed .drawer-account {
    justify-content: center;
    padding-inline: 0;
  }

  body.nav-collapsed .drawer-logout { padding: 0; width: 40px; height: 40px; justify-content: center; border-radius: 50%; }
  body.nav-collapsed .drawer-logout .m3-icon { display: block; }
}

@media (max-width: 991.98px) {
  .drawer-collapse { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .navigation-drawer, .app-content, .drawer-collapse { transition: none; }
}

/* The link's name beside the rail, on hover or keyboard focus. One floating
   element placed by app.js, so the rail can still scroll on short screens. */
.rail-tip {
  position: fixed;
  z-index: 1100;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--m3-inverse-on-surface, #f1f0f4);
  background: var(--m3-inverse-surface, #2e3135);
  box-shadow: var(--md-shadow-raised);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-4px, -50%);
  transition: opacity 120ms, transform 120ms;
}

.rail-tip.is-shown { opacity: 1; transform: translate(0, -50%); }

/* On a phone the menu button floats over the page: give it its own surface,
   so it no longer draws over the text scrolling under it. */
@media (max-width: 991.98px) {
  .app-bar .navigation-toggle {
    color: var(--md-on-surface);
    background: color-mix(in srgb, var(--md-surface-container-high) 92%, transparent);
    box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
    backdrop-filter: blur(8px);
  }
}
