/* ============================================================================
   Nidan HMIS Bridge — design system
   Single source of truth for all UI styling.
   No frameworks, no CDN, no build step.
   ============================================================================ */


/* ─── 1. Font faces ───────────────────────────────────────────────────────── */

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/IBMPlexSans-Light.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/IBMPlexSans-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/IBMPlexSans-Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/IBMPlexSans-SemiBold.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/IBMPlexMono-Regular.woff2') format('woff2');
}


/* ─── 2. CSS custom properties (design tokens) ─────────────────────────── */

:root {
  color-scheme: light dark;

  /* Type families */
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Neutrals */
  --bg-canvas:      #F5F4F1;
  --bg-surface:     #FFFFFF;
  --bg-subtle:      #F0EEE9;
  --bg-overlay:     #E8E6E1;
  --border:         #E0DDD7;
  --border-strong:  #C8C5BF;

  /* Text */
  --text-primary:   #141311;
  --text-muted:     #6B6862;
  --text-faint:     #9E9B96;

  /* Sidebar — light appearance (tracks color-scheme like main content) */
  --sidebar-bg:       #FFFFFF;
  --sidebar-text:     #141311;
  --sidebar-muted:    #6B6862;
  --sidebar-faint:    #9E9B96;
  --sidebar-hover:    rgba(20, 19, 17, 0.05);
  --sidebar-active:   rgba(28, 95, 160, 0.10);
  --sidebar-divider:  #E0DDD7;
  --sidebar-accent:   #1C5FA0;
  --sidebar-logo-mark-bg: rgba(20, 19, 17, 0.04);
  --sidebar-control-bg: #F0EEE9;
  --sidebar-control-bg-hover: #E8E6E1;
  --sidebar-select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%236B6862'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");

  /* Semantic — light */
  --success-bg:     #EBF5EC;
  --success-text:   #1E6B2E;
  --success-border: #A8D5AD;
  --warning-bg:     #FDF4E3;
  --warning-text:   #7A4F00;
  --warning-border: #F0C96B;
  --danger-bg:      #FCEAEA;
  --danger-text:    #A82525;
  --danger-border:  #F0A8A8;
  --info-bg:        #EAF1FA;
  --info-text:      #1A4E8C;
  --info-border:    #A3C4EC;

  /* Accent (primary submission actions) */
  --accent:         #1C5FA0;
  --accent-hover:   #174D85;
  --accent-active:  #133F6E;
  --accent-text:    #FFFFFF;

  /* Status dot colors (paired with text/icons; never color-only) */
  --dot-success: #2A9D45;
  --dot-warning: #D69620;
  --dot-danger:  #C53030;
  --dot-muted:   #9E9B96;

  /* Spacing (8pt base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 48px;
  --sp-10: 64px;
  --sp-11: 80px;
  --sp-12: 96px;

  /* Radii */
  --r-sm: 3px;
  --r-md: 4px;
  --r-lg: 6px;
  --r-xl: 8px;

  /* Layout */
  --sidebar-w-expanded: 220px;
  --sidebar-w-collapsed: 52px;
  --topbar-h: 52px;
  --site-footer-h: 52px;
  --content-max: 1200px;
  --form-max: 720px;
  --settings-max: 480px;

  /* Motion */
  --motion-fast: 120ms;
  --motion-base: 180ms;
  --motion-slow: 250ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Appearance: defaults follow OS unless html[data-color-scheme] overrides ───── */

html[data-color-scheme="dark"] {
  --bg-canvas:     #111210;
  --bg-surface:    #1A1917;
  --bg-subtle:     #222120;
  --bg-overlay:    #2C2B29;
  --border:        #2E2D2B;
  --border-strong: #3D3C39;

  --text-primary:  #EDEAE5;
  --text-muted:    #8A8784;
  --text-faint:    #5C5B58;

  --sidebar-bg:              #161D2C;
  --sidebar-text:            rgba(255, 255, 255, 0.85);
  --sidebar-muted:           rgba(255, 255, 255, 0.35);
  --sidebar-faint:           rgba(255, 255, 255, 0.18);
  --sidebar-hover:           rgba(255, 255, 255, 0.06);
  --sidebar-active:          rgba(255, 255, 255, 0.10);
  --sidebar-divider:         rgba(255, 255, 255, 0.08);
  --sidebar-accent:          #5B9FD4;
  --sidebar-logo-mark-bg:    rgba(255, 255, 255, 0.06);
  --sidebar-control-bg:      rgba(255, 255, 255, 0.04);
  --sidebar-control-bg-hover: rgba(255, 255, 255, 0.07);
  --sidebar-select-chevron:  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='rgba(255,255,255,0.45)'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");

  --success-bg:     #1A3320;
  --success-text:   #9CD8A4;
  --success-border: #2C5C35;
  --warning-bg:     #3A2D11;
  --warning-text:   #F0C96B;
  --warning-border: #5C4319;
  --danger-bg:      #3A1A1A;
  --danger-text:    #F0A8A8;
  --danger-border:  #5C2525;
  --info-bg:        #1A2A40;
  --info-text:      #A3C4EC;
  --info-border:    #2C4569;

  --dot-success: #4DBD68;
  --dot-warning: #E5B454;
  --dot-danger:  #E26A6A;
  --dot-muted:   #6F6D6A;

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-color-scheme]),
  html[data-color-scheme="system"] {
    --bg-canvas:     #111210;
    --bg-surface:    #1A1917;
    --bg-subtle:     #222120;
    --bg-overlay:    #2C2B29;
    --border:        #2E2D2B;
    --border-strong: #3D3C39;

    --text-primary:  #EDEAE5;
    --text-muted:    #8A8784;
    --text-faint:    #5C5B58;

    --sidebar-bg:              #161D2C;
    --sidebar-text:            rgba(255, 255, 255, 0.85);
    --sidebar-muted:           rgba(255, 255, 255, 0.35);
    --sidebar-faint:           rgba(255, 255, 255, 0.18);
    --sidebar-hover:           rgba(255, 255, 255, 0.06);
    --sidebar-active:          rgba(255, 255, 255, 0.10);
    --sidebar-divider:         rgba(255, 255, 255, 0.08);
    --sidebar-accent:          #5B9FD4;
    --sidebar-logo-mark-bg:    rgba(255, 255, 255, 0.06);
    --sidebar-control-bg:      rgba(255, 255, 255, 0.04);
    --sidebar-control-bg-hover: rgba(255, 255, 255, 0.07);
    --sidebar-select-chevron:  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='rgba(255,255,255,0.45)'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");

    --success-bg:     #1A3320;
    --success-text:   #9CD8A4;
    --success-border: #2C5C35;
    --warning-bg:     #3A2D11;
    --warning-text:   #F0C96B;
    --warning-border: #5C4319;
    --danger-bg:      #3A1A1A;
    --danger-text:    #F0A8A8;
    --danger-border:  #5C2525;
    --info-bg:        #1A2A40;
    --info-text:      #A3C4EC;
    --info-border:    #2C4569;

    --dot-success: #4DBD68;
    --dot-warning: #E5B454;
    --dot-danger:  #E26A6A;
    --dot-muted:   #6F6D6A;

    color-scheme: dark;
  }
}

/* Force light while OS prefers dark */
html[data-color-scheme="light"] {
  --bg-canvas:      #F5F4F1;
  --bg-surface:     #FFFFFF;
  --bg-subtle:      #F0EEE9;
  --bg-overlay:     #E8E6E1;
  --border:         #E0DDD7;
  --border-strong:  #C8C5BF;

  --text-primary:   #141311;
  --text-muted:     #6B6862;
  --text-faint:     #9E9B96;

  --sidebar-bg:       #FFFFFF;
  --sidebar-text:     #141311;
  --sidebar-muted:    #6B6862;
  --sidebar-faint:    #9E9B96;
  --sidebar-hover:    rgba(20, 19, 17, 0.05);
  --sidebar-active:   rgba(28, 95, 160, 0.10);
  --sidebar-divider:  #E0DDD7;
  --sidebar-accent:   #1C5FA0;
  --sidebar-logo-mark-bg: rgba(20, 19, 17, 0.04);
  --sidebar-control-bg: #F0EEE9;
  --sidebar-control-bg-hover: #E8E6E1;
  --sidebar-select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%236B6862'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");

  --success-bg:     #EBF5EC;
  --success-text:   #1E6B2E;
  --success-border: #A8D5AD;
  --warning-bg:     #FDF4E3;
  --warning-text:   #7A4F00;
  --warning-border: #F0C96B;
  --danger-bg:      #FCEAEA;
  --danger-text:    #A82525;
  --danger-border:  #F0A8A8;
  --info-bg:        #EAF1FA;
  --info-text:      #1A4E8C;
  --info-border:    #A3C4EC;

  --dot-success: #2A9D45;
  --dot-warning: #D69620;
  --dot-danger:  #C53030;
  --dot-muted:   #9E9B96;

  color-scheme: light;
}

/* ─── 3. CSS reset / base ─────────────────────────────────────────────── */

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

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 500;
  color: var(--text-primary);
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

img, svg {
  display: block;
  max-width: 100%;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--r-md);
  font-weight: 500;
  z-index: 1000;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: var(--sp-3);
  text-decoration: none;
}

.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
  fill: currentColor;
}

.mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0;
}


/* ─── 4. App shell (sidebar + main wrapper layout) ─────────────────── */

.app-shell {
  display: block;
  min-height: 100vh;
}

.main-wrapper {
  margin-left: var(--sidebar-w-expanded);
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--motion-base) var(--ease-out);
  padding-bottom: var(--site-footer-h);
  overflow-x: hidden;
}

/* Login and other anonymous pages: sidebar is omitted; main area uses full width. */
.app-shell:not(.app-shell--authed) .main-wrapper {
  margin-left: 0;
}

.app-shell.sidebar-collapsed .main-wrapper {
  margin-left: var(--sidebar-w-collapsed);
}

/* ─── Fixed site footer (Trigonal attribution) ──────────────────────── */

.site-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: var(--sidebar-w-expanded);
  z-index: 45;
  min-height: var(--site-footer-h);
  padding: 0 clamp(var(--sp-4), 3vw, var(--sp-8));
  padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--sidebar-divider);
  color: var(--sidebar-muted);
  font-size: 12px;
  line-height: 1.35;
  transition: left var(--motion-base) var(--ease-out);
}

.app-shell:not(.app-shell--authed) .site-footer {
  left: 0;
}

.app-shell.sidebar-collapsed.app-shell--authed .site-footer {
  left: var(--sidebar-w-collapsed);
}

@media (max-width: 767px) {
  .site-footer {
    left: 0;
  }
}

.site-footer__inner {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.site-footer__copyright {
  margin: 0;
  color: var(--sidebar-muted);
}

.site-footer__credit {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: 0.01em;
  max-width: 100%;
}

.site-footer__credit:hover {
  color: var(--sidebar-accent);
  text-decoration: none;
}

.site-footer__credit:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.site-footer__logo {
  width: auto;
  height: 40px;
  max-height: calc(var(--site-footer-h) - 12px);
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.site-footer__credit-text {
  text-align: right;
}

@media (max-width: 520px) {
  .site-footer__inner {
    flex-direction: column;
    align-items: flex-start;
    padding-block: var(--sp-2);
  }
  .site-footer__credit-text {
    text-align: left;
  }
}

/* ─── 5. Sidebar — expanded state ─────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w-expanded);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-divider);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--motion-base) var(--ease-out);
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-4) var(--sp-6);
  flex-shrink: 0;
}
.sidebar-logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--sidebar-logo-mark-bg);
}

.sidebar-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
  overflow: hidden;
}
.sidebar-brand {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--sidebar-text);
}
.sidebar-subbrand {
  font-size: 11px;
  font-weight: 400;
  color: var(--sidebar-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-faint);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-3);
  font-size: 13px;
  font-weight: 400;
  color: var(--sidebar-text);
  border-radius: var(--r-md);
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
  position: relative;
  min-height: 36px;
}
.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
  text-decoration: none;
}
.sidebar-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-accent);
  font-weight: 500;
}
.sidebar-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--sidebar-accent);
  border-radius: 1px;
}
.sidebar-item:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: -2px;
}

.sidebar-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--sidebar-muted);
}
.sidebar-item:hover .sidebar-icon,
.sidebar-item.active .sidebar-icon {
  color: var(--sidebar-accent);
}
.sidebar-icon .icon {
  width: 18px;
  height: 18px;
}

.sidebar-label {
  flex: 1;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
}

.sidebar-footer {
  padding: var(--sp-3);
  border-top: 1px solid var(--sidebar-divider);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 32px;
  border-radius: var(--r-md);
  color: var(--sidebar-muted);
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
}
.sidebar-collapse-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}
.sidebar-collapse-btn:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: -2px;
}
.sidebar-collapse-btn .icon {
  width: 16px;
  height: 16px;
  transition: transform var(--motion-base) var(--ease-out);
}
.app-shell.sidebar-collapsed .sidebar-collapse-btn .icon {
  transform: rotate(180deg);
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-1) var(--sp-3);
  font-size: 11px;
  color: var(--sidebar-muted);
  line-height: 1.3;
  min-width: 0;
}
.sidebar-user-role {
  color: var(--sidebar-text);
  font-weight: 500;
  text-transform: capitalize;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-bs-year {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--sidebar-faint);
  letter-spacing: 0.02em;
}

.color-scheme-toggle {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: var(--sp-3);
  min-height: 32px;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-md);
  border: none;
  background: transparent;
  color: var(--sidebar-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.color-scheme-toggle:hover {
  background: var(--sidebar-hover);
  color: rgba(255, 255, 255, 0.94);
}

.color-scheme-toggle:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: -2px;
}

.color-scheme-toggle__icons {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.color-scheme-toggle__icons .icon {
  width: 16px;
  height: 16px;
}

.color-scheme-toggle__icons .scheme-icon {
  opacity: 0.28;
}

.color-scheme-toggle__icons .scheme-icon.is-active {
  opacity: 1;
  color: var(--sidebar-accent);
}

.color-scheme-toggle__label {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell.sidebar-collapsed .color-scheme-toggle__label {
  display: none;
}

.app-shell.sidebar-collapsed .color-scheme-toggle {
  justify-content: center;
}

.locale-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-muted);
}

.sidebar-footer .locale-switcher {
  padding: 0 var(--sp-1);
}

.locale-switcher__link {
  color: inherit;
  text-decoration: none;
  opacity: 0.55;
  border-radius: var(--r-sm);
  padding: 2px 4px;
}

.locale-switcher__link:hover {
  opacity: 1;
  color: rgba(255, 255, 255, 0.92);
}

.locale-switcher__link.is-active {
  opacity: 1;
  color: var(--sidebar-accent);
  font-weight: 600;
}

.locale-switcher__sep {
  opacity: 0.35;
  user-select: none;
}

.app-shell.sidebar-collapsed .locale-switcher {
  flex-direction: column;
  gap: 2px;
  font-size: 9px;
  line-height: 1.2;
}

.app-shell.sidebar-collapsed .locale-switcher__sep {
  display: none;
}

.login-controls-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

.login-controls-bar .locale-switcher {
  color: var(--text-muted);
}

.login-controls-bar .locale-switcher__link:hover {
  color: var(--text-primary);
}

.login-controls-bar .locale-switcher__link.is-active {
  color: var(--accent);
}

/* Dropdown mode (many locales): reuse .select chevron/focus from forms */
.locale-switcher--dropdown {
  width: 100%;
  justify-content: stretch;
  flex-wrap: nowrap;
}

.sidebar-footer .locale-switcher__select.select {
  width: 100%;
  max-width: none;
  margin: 0;
  flex: 1 1 auto;
  min-height: 32px;
  padding-top: var(--sp-2);
  padding-bottom: var(--sp-2);
  padding-left: var(--sp-3);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--sidebar-muted);
  background-color: var(--sidebar-control-bg);
  border-color: var(--sidebar-divider);
  background-image: var(--sidebar-select-chevron);
}

.sidebar-footer .locale-switcher__select.select:hover {
  background-color: var(--sidebar-control-bg-hover);
}

.sidebar-footer .locale-switcher__select.select:focus,
.sidebar-footer .locale-switcher__select.select:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: 0;
  border-color: var(--sidebar-accent);
}

.app-shell.sidebar-collapsed .locale-switcher__select.select {
  min-height: 28px;
  padding-left: var(--sp-2);
  font-size: 9px;
}

.login-controls-bar .locale-switcher__select.select {
  max-width: none;
  width: 100%;
  margin: 0;
  font-size: 11px;
  font-weight: 500;
}

.login-theme-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  padding: 0;
  margin: 0;
}

.login-theme-toggle {
  gap: var(--sp-2);
  min-height: 36px;
  padding: var(--sp-2) var(--sp-4);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-subtle);
}

.login-theme-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-overlay);
  border-color: var(--border-strong);
}

.login-theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.login-theme-toggle.color-scheme-toggle {
  width: auto;
  max-width: 100%;
}

.login-theme-toggle .scheme-icon.is-active {
  color: var(--accent);
}

.login-theme-toggle .color-scheme-toggle__icons .scheme-icon {
  opacity: 0.38;
}

.login-theme-toggle .color-scheme-toggle__icons .scheme-icon.is-active {
  opacity: 1;
}


/* ─── 6. Sidebar — collapsed state ────────────────────────────────── */

.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
}

.app-shell.sidebar-collapsed .sidebar-logo {
  padding: var(--sp-5) var(--sp-2) var(--sp-6);
  justify-content: center;
}
.app-shell.sidebar-collapsed .sidebar-logo-text,
.app-shell.sidebar-collapsed .sidebar-label,
.app-shell.sidebar-collapsed .sidebar-section-label,
.app-shell.sidebar-collapsed .sidebar-user {
  display: none;
}
.app-shell.sidebar-collapsed .sidebar-item {
  justify-content: center;
  padding: 9px 0;
  gap: 0;
}
.app-shell.sidebar-collapsed .sidebar-item.active::before {
  left: 0;
}
.app-shell.sidebar-collapsed .sidebar-nav {
  padding: var(--sp-2);
}


/* ─── 7. Sidebar — mobile drawer ─────────────────────────────────── */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 150;
  opacity: 0;
  transition: opacity var(--motion-base) var(--ease-out);
}
.app-shell.drawer-open .sidebar-backdrop {
  display: block;
  opacity: 1;
}

@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 200;
    transition: transform var(--motion-base) var(--ease-out);
  }
  .app-shell.drawer-open .sidebar {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .app-shell.sidebar-collapsed .main-wrapper {
    margin-left: 0;
  }
  .app-shell.sidebar-collapsed .sidebar {
    width: 260px;
  }
  .app-shell.sidebar-collapsed .sidebar-logo-text,
  .app-shell.sidebar-collapsed .sidebar-label,
  .app-shell.sidebar-collapsed .sidebar-section-label,
  .app-shell.sidebar-collapsed .sidebar-user {
    display: revert;
  }
  .app-shell.sidebar-collapsed .sidebar-logo {
    padding: var(--sp-5) var(--sp-4) var(--sp-6);
    justify-content: flex-start;
  }
  .app-shell.sidebar-collapsed .sidebar-item {
    justify-content: flex-start;
    padding: 9px var(--sp-3);
    gap: var(--sp-3);
  }
  .app-shell.sidebar-collapsed .sidebar-nav {
    padding: 0 var(--sp-2);
  }
  .sidebar-collapse-btn {
    display: none;
  }
}


/* ─── 8. Mobile topbar ───────────────────────────────────────────── */

.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 80;
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: var(--sp-3);
}

.hamburger {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-primary);
  transition: background var(--motion-fast) var(--ease-out);
}
.hamburger:hover {
  background: var(--bg-subtle);
}
.hamburger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.mobile-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

@media (max-width: 767px) {
  .mobile-topbar {
    display: flex;
  }
}


/* ─── 9. Page header ─────────────────────────────────────────────── */

.page-header {
  padding: var(--sp-7) var(--sp-7) var(--sp-5);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-canvas);
}

.page-header-content {
  min-width: 0;
}

.page-title {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-primary);
  margin: 0;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: var(--sp-1) 0 0;
  max-width: 65ch;
}

.page-header-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-shrink: 0;
}

@media (max-width: 767px) {
  .page-header {
    padding: var(--sp-5) var(--sp-4) var(--sp-4);
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }
  .page-header-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}


/* ─── 10. Flash alerts ───────────────────────────────────────────── */

.flash-container {
  padding: var(--sp-3) var(--sp-7) 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  font-size: 13px;
  line-height: 1.45;
  transition: opacity var(--motion-base) var(--ease-out);
}
.alert.is-dismissing {
  opacity: 0;
}

.alert-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}
.alert-icon .icon {
  width: 16px;
  height: 16px;
}

.alert-message {
  flex: 1;
  min-width: 0;
}

.alert-dismiss {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  opacity: 0.55;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  transition: opacity var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}
.alert-dismiss:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}
.alert-dismiss:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.alert-info,
.alert-message-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-text); }

@media (max-width: 767px) {
  .flash-container { padding: var(--sp-3) var(--sp-4) 0; }
}


/* ─── 11. Cards ──────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.card + .card { margin-top: var(--sp-4); }

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 var(--sp-3);
}

.card-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  font-size: 12px;
  color: var(--text-muted);
}
.card-meta dt {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 2px;
}
.card-meta dd {
  margin: 0;
  font-size: 13px;
  color: var(--text-primary);
}

.section-heading {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 var(--sp-3);
}


/* ─── 12. Badges / pills / chips ─────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--bg-subtle);
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
}
.badge .icon {
  width: 11px;
  height: 11px;
}

.badge-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }
.badge-info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border); }
.badge-neutral { background: var(--bg-subtle);  color: var(--text-muted);   border-color: var(--border); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-muted);
  flex-shrink: 0;
}
.status-dot--success { background: var(--dot-success); }
.status-dot--warning { background: var(--dot-warning); }
.status-dot--danger  { background: var(--dot-danger); }
.status-dot--muted   { background: var(--dot-muted); }


/* ─── 13. Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease-out),
              border-color var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
  min-height: 32px;
}
.btn .icon { width: 14px; height: 14px; }

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-primary:active:not(:disabled):not([aria-disabled="true"]) {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--bg-surface);
  border-color: var(--danger-border);
  color: var(--danger-text);
}
.btn-danger:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--danger-bg);
}

.btn-success {
  background: var(--bg-surface);
  border-color: var(--success-border);
  color: var(--success-text);
}
.btn-success:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--success-bg);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 14px;
  min-height: 40px;
}
.btn-lg .icon { width: 16px; height: 16px; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  min-height: 26px;
}
.btn-sm .icon { width: 12px; height: 12px; }

/* Loading state for buttons mid-submit */
.btn.is-loading {
  cursor: progress;
  pointer-events: none;
}
.btn.is-loading .btn-text { opacity: 0.7; }
.btn.is-loading .spinner {
  display: inline-flex;
}

.spinner {
  display: none;
  width: 14px;
  height: 14px;
  animation: spin 720ms linear infinite;
  flex-shrink: 0;
}
.spinner svg { width: 100%; height: 100%; }
@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ─── 14. Form elements ──────────────────────────────────────────── */

.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}
.form-row:last-child { margin-bottom: 0; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.form-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.form-error {
  font-size: 12px;
  color: var(--danger-text);
  margin-top: 2px;
}

.input,
.select,
.textarea {
  width: 100%;
  max-width: 400px;
  padding: 7px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  line-height: 1.4;
  min-height: 32px;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--text-muted);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}
.input-readonly {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%236B6862'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  padding-right: 30px;
}

/* Native dropdown popup colors: explicit so the OS-default rendering
   doesn't paint light-on-light (or dark-on-dark) inside the dropdown. */
.select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}
.select option:disabled {
  color: var(--text-faint);
}

.select-sm {
  font-size: 12px;
  padding: 5px 26px 5px 8px;
  min-height: 28px;
  background-size: 10px 10px;
  background-position: right 8px center;
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.input-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.input-group-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  margin-right: var(--sp-1);
}

.form-card {
  max-width: var(--settings-max);
}


/* ─── 15. Tables ─────────────────────────────────────────────────── */

.data-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.data-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 12px var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.data-table tbody tr.is-expandable {
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out);
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr.is-expandable:hover {
  background: var(--bg-subtle);
}
.data-table tbody tr.is-expanded {
  background: var(--bg-subtle);
}
.data-table tbody tr.is-expanded + tr.log-row {
  display: table-row;
}

.cell-mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.cell-mono-primary {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
}

.cell-program strong {
  display: block;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.3;
}

.cell-program small {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.cell-numeric {
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-toggle {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
}
.row-toggle:hover {
  background: var(--bg-overlay);
  color: var(--text-primary);
}
.row-toggle .icon {
  transition: transform var(--motion-base) var(--ease-out);
}
tr.is-expanded .row-toggle .icon {
  transform: rotate(180deg);
}


/* ─── 16. Execution log ──────────────────────────────────────────── */

.log-row {
  display: none;
}

.log-row td {
  padding: 0 !important;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border);
}

.log-panel {
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
  background: var(--bg-canvas);
}

.log-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--sp-3);
  padding: 0 var(--sp-2);
}

.log-panel-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}

.log-entry {
  display: grid;
  grid-template-columns: minmax(140px, 0.25fr) minmax(60px, 0.1fr) 1fr;
  gap: var(--sp-3);
  padding: 6px var(--sp-3) 6px var(--sp-4);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-surface);
  border-left: 3px solid var(--border);
}

.log-entry--error    { border-left-color: var(--danger-border);  color: var(--danger-text); }
.log-entry--warning  { border-left-color: var(--warning-border); color: var(--warning-text); }
.log-entry--info     { border-left-color: var(--border); }

.log-step {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-level {
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 10px;
}
.log-entry--info .log-level { color: var(--info-text); }
.log-entry--error .log-level { color: var(--danger-text); }
.log-entry--warning .log-level { color: var(--warning-text); }

.log-message {
  min-width: 0;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 11px;
}

.log-empty,
.log-loading {
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}


/* ─── 17. Step indicator (reporter wizard) ───────────────────────── */

.wizard {
  max-width: var(--form-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.step {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  position: relative;
  transition: opacity var(--motion-base) var(--ease-out);
}
.step.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.step-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.step-number {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.step.is-active .step-number {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.step.is-complete .step-number {
  background: var(--success-text);
  color: #FFFFFF;
  border-color: var(--success-text);
}
.step.is-complete .step-number-num { display: none; }
.step.is-complete .step-number-check { display: inline-flex; }
.step-number-check { display: none; }

.step-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}

.step-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.3;
}


/* ─── 18. Program cards (reporter grid) ─────────────────────────── */

.program-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
}
@media (min-width: 640px) {
  .program-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.program-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
  position: relative;
}
.program-card:hover {
  border-color: var(--border-strong);
}
.program-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.program-card.is-selected {
  border: 2px solid var(--accent);
  background: var(--info-bg);
  padding: calc(var(--sp-4) - 1px);
}
.program-card.is-selected:hover {
  border-color: var(--accent-hover);
}
.program-card--stale {
  border-color: var(--warning-border);
}
.program-card--stale.is-selected {
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

.program-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-2);
}

.program-card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
  margin: 0;
}

.program-card-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 11px;
  color: var(--text-muted);
}
.program-card-meta .mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.program-card-targets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.program-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.program-card.is-selected .program-card-footer {
  border-top-color: rgba(28, 95, 160, 0.18);
}


/* Period selection row */
.period-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
}

/* Mapping generator — step 1 fields (hint spans full width below controls) */
.mg-step1-toolbar {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(16rem, 1.5fr) auto;
  gap: var(--sp-3) var(--sp-4);
  align-items: end;
}

.mg-step1-field {
  margin: 0;
  min-width: 0;
}

.mg-step1-refresh {
  align-self: end;
  white-space: nowrap;
}

.mg-step1-hint {
  grid-column: 1 / -1;
  margin: 0;
}

@media (max-width: 720px) {
  .mg-step1-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .mg-step1-refresh {
    justify-self: start;
  }
}

.period-arrow {
  color: var(--text-faint);
}

.period-range {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  padding: 5px 10px;
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

/* Review card targets list */
.review-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.review-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  gap: var(--sp-3);
}
.review-list li:last-child { border-bottom: none; }
.review-list li > span:first-child {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.review-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-3) 0 var(--sp-4);
  font-size: 13px;
}
.review-summary dt {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
}
.review-summary dd {
  margin: 0;
  color: var(--text-primary);
}

/* Result card (post-submit) */
.result-card {
  margin-top: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  overflow: hidden;
}
.result-card--success { border-color: var(--success-border); }
.result-card--danger  { border-color: var(--danger-border); }

.result-card-header {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 500;
  font-size: 13px;
}
.result-card--success .result-card-header { background: var(--success-bg); color: var(--success-text); border-bottom-color: var(--success-border); }
.result-card--danger .result-card-header  { background: var(--danger-bg);  color: var(--danger-text); border-bottom-color: var(--danger-border); }

.result-card-body {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.result-target {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  font-size: 13px;
}
.result-target .icon { width: 14px; height: 14px; }
.result-target-name {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.result-target-name strong {
  font-weight: 500;
  color: var(--text-primary);
}
.result-target-stats {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.result-target--success { background: var(--success-bg); color: var(--success-text); }
.result-target--success strong { color: var(--success-text); }
.result-target--danger  { background: var(--danger-bg); color: var(--danger-text); }
.result-target--danger strong  { color: var(--danger-text); }

.result-card-footer {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

/* Stale notice bar for program-config cards */
.stale-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--warning-bg);
  border-top: 1px solid var(--warning-border);
  color: var(--warning-text);
  font-size: 12px;
}
.stale-bar > span { flex: 1; }
.stale-bar .btn { margin-left: auto; }


/* ─── 19. Loading states ────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 0%,
    var(--bg-overlay) 50%,
    var(--bg-subtle) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.skeleton-line {
  height: 12px;
  width: 100%;
  margin-bottom: 6px;
}
.skeleton-line:last-child { margin-bottom: 0; width: 70%; }

.loading-row {
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-5);
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
}
.empty-state-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto var(--sp-3);
  color: var(--text-faint);
}
.empty-state-icon .icon { width: 100%; height: 100%; }
.empty-state-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--sp-1);
}
.empty-state p {
  font-size: 13px;
  max-width: 40ch;
  margin: 0 auto;
}


/* ─── 20. Utility classes (sparingly used) ─────────────────────── */

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

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-mono  { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-4) 0;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}
.cluster-tight { gap: var(--sp-1); }

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.spread {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
}


/* Page body shared container */
.page-body {
  padding: var(--sp-5) var(--sp-7) var(--sp-9);
  flex: 1;
  max-width: var(--content-max);
  width: 100%;
  min-width: 0;
}
@media (max-width: 767px) {
  .page-body { padding: var(--sp-4) var(--sp-4) var(--sp-8); }
}

/* Wide variant — for data tables and dashboard-style pages where the
   1200px content cap leaves too much empty space on wider monitors.
   The breakpoint chain widens it progressively so it never feels
   stretched on a 14-inch laptop but uses the full width on a 4K. */
.page-body--wide {
  max-width: 1400px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
@media (min-width: 1600px) {
  .page-body--wide { max-width: 1700px; }
}
@media (min-width: 2000px) {
  .page-body--wide { max-width: 2000px; }
}

/* Admin programs toolbar — stay compact in one row on laptop (1080 + sidebar) */
.toolbar--programs-admin {
  flex-wrap: wrap;
  align-items: center;
}

.toolbar--programs-admin .search-input {
  min-width: min(100%, 220px);
  flex: 1 1 220px;
  max-width: 360px;
}

.toolbar--programs-admin .toolbar-section--status {
  flex: 1 1 auto;
  min-width: 0;
}

.toolbar--programs-admin .toolbar-section--count {
  margin-left: auto;
}

/* Filter row */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.filter-row .select { width: auto; min-width: 140px; max-width: 200px; }
.filter-row .select-sm { min-width: 120px; }

/* Toolbar — search + pills + year picker above the program table */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.toolbar-section {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }
.toolbar-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Search input with leading icon */
.search-input {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 240px;
}
.search-input .icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 14px;
  height: 14px;
}
.search-input input {
  width: 100%;
  max-width: none;
  padding-left: 30px;
}
.search-input .clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  background: transparent;
}
.search-input.has-value .clear-btn { display: inline-flex; }
.search-input .clear-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }

/* Pill filter group — single-select, behaves like radio buttons visually */
.pill-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out),
              border-color var(--motion-fast) var(--ease-out);
  min-height: 28px;
}
.pill:hover { color: var(--text-primary); border-color: var(--border-strong); }
.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill.is-active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.pill-count {
  font-size: 11px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: inherit;
  font-weight: 500;
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}
.pill.is-active .pill-count { background: rgba(255, 255, 255, 0.18); }

/* Program table — in-table inline controls + Submit/Resubmit row affordances */
.program-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.program-table col.col-program { width: 28%; }
.program-table col.col-targets { width: 10%; }
.program-table col.col-month { width: 11%; }
.program-table col.col-dates { width: 15%; }
.program-table col.col-last-sub { width: 20%; }
.program-table col.col-actions { width: 16%; }

.program-table thead th {
  white-space: normal;
  word-wrap: break-word;
}

/* Clip controls only — never text columns (program / last submission). */
.program-table td.cell-targets,
.program-table td.cell-month,
.program-table td.cell-dates {
  overflow: hidden;
}

.table-cell-fit {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.program-table .select {
  max-width: 100%;
  box-sizing: border-box;
}

.program-table thead th.action-cell {
  white-space: nowrap;
}

.program-table tbody tr[data-program-row] > td {
  vertical-align: top;
}

/* One bottom edge per program block (main / feedback / expand), not per cell */
.program-table tbody tr[data-program-row] > td,
.program-table tbody tr.row-feedback > td,
.program-table tbody tr.row-expand > td {
  border-bottom: none;
}

.program-table tbody tr[data-program-row]:has(+ tr.row-feedback:not([hidden])) > td,
.program-table tbody tr[data-program-row]:has(+ tr.row-expand.is-open) > td {
  border-bottom: none;
}

.program-table tbody tr.row-feedback:not([hidden]) > td {
  border-bottom: 1px solid var(--border);
}

.program-table tbody tr.row-feedback:not([hidden]):has(+ tr.row-expand.is-open) > td {
  border-bottom: none;
}

.program-table tbody tr.row-expand.is-open > td {
  border-bottom: 1px solid var(--border);
}

.program-table .cell-program-name {
  display: block;
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
}
.program-table .cell-program-name a {
  font-weight: 500;
  color: var(--text-primary);
  display: inline;
}
.program-table .cell-program-name a:hover { text-decoration: underline; }
.program-table .cell-program-name .mono {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-faint);
}

.program-table .cell-targets .badge {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
}

.program-table .row-month .select-sm {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 11px;
  padding: 4px 22px 4px 6px;
}

/* Editable AD date-range cell — two compact date inputs with an arrow
   separator. Same height as the row-month select so the row reads as
   one continuous control band. */
.date-range-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 100%;
}
.program-table .date-input {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 4px 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 28px;
  box-sizing: border-box;
}

.date-input {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 4px 6px;
  width: 132px;
  max-width: 100%;
  min-width: 7.5rem;
  min-height: 28px;
  line-height: 1.2;
  transition: border-color var(--motion-fast) var(--ease-out);
}
.date-input::-webkit-calendar-picker-indicator {
  filter: invert(0.5);
  cursor: pointer;
  padding: 0;
}
.date-input:hover { border-color: var(--text-muted); }
.date-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
.date-input:disabled,
.date-input:read-only {
  background: var(--bg-subtle);
  color: var(--text-muted);
}
.date-input.is-overridden { border-color: var(--warning-border); }
.date-range-sep {
  color: var(--text-faint);
  font-size: 11px;
  user-select: none;
}
.date-range-cell-note {
  display: block;
  font-size: 10px;
  color: var(--warning-text);
  margin-top: 2px;
  font-family: var(--font-mono);
  line-height: 1.2;
}

.program-table .cell-last-sub {
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: normal;
}
.program-table .cell-last-sub > span:first-child {
  display: block;
  white-space: normal;
}
.program-table .cell-last-sub small {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  white-space: normal;
}
.program-table .cell-last-sub--empty {
  font-style: italic;
  color: var(--text-faint);
  font-size: 12px;
}

body.modal-open {
  overflow: hidden;
}

.program-table .action-cell {
  text-align: right;
  white-space: normal;
  overflow: visible;
}

.program-table .program-table__actions {
  overflow: visible;
}

.program-table__actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  margin-left: auto;
}

.program-table__actions .btn {
  width: 100%;
  justify-content: center;
  padding-left: 8px;
  padding-right: 8px;
  font-size: 11px;
}

/* [hidden] loses to .btn { display: inline-flex } without !important */
.program-table__actions .row-cf-open[hidden],
.program-table__actions .row-submit[hidden] {
  display: none !important;
}

.program-table .row-download {
  position: relative;
}

.program-table .row-download__summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  user-select: none;
}

.program-table .row-download__summary::-webkit-details-marker {
  display: none;
}

.program-table .row-download__menu {
  position: fixed;
  left: auto;
  min-width: 11rem;
  z-index: 2500;
  margin: 0;
  padding: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.1),
    0 12px 32px rgba(0, 0, 0, 0.14);
}

.program-table .row-download__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
}

.program-table .row-download__item:hover {
  background: var(--bg-subtle);
}

.program-table tr.is-stale td.cell-program-name strong { color: var(--warning-text); }
.program-table tr.row-loading { opacity: 0.55; pointer-events: none; }

/* Laptop / small desktop (e.g. 1080×720 with sidebar ≈860px content) */
@media (max-width: 1280px) {
  .page-body--wide {
    max-width: none;
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }

  .page-header {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }

  /* Reporter submit table: stack toolbar; admin programs keeps compact row */
  .toolbar:not(.toolbar--programs-admin) {
    flex-direction: column;
    align-items: stretch;
    max-width: 100%;
    gap: var(--sp-3);
  }

  .toolbar--programs-admin {
    flex-direction: row;
    align-items: center;
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
  }

  .toolbar--programs-admin .toolbar-section {
    width: auto;
  }

  .toolbar--programs-admin .toolbar-spacer {
    display: block;
    flex: 1 1 var(--sp-2);
    min-width: var(--sp-2);
  }

  .toolbar--programs-admin .search-input {
    min-width: 0;
    flex: 1 1 180px;
    max-width: none;
  }

  .toolbar--programs-admin .pill-group {
    flex-wrap: wrap;
  }

  .toolbar:not(.toolbar--programs-admin) .toolbar-section {
    width: 100%;
    min-width: 0;
  }

  .toolbar:not(.toolbar--programs-admin) .toolbar-spacer {
    display: none;
  }

  .toolbar:not(.toolbar--programs-admin) .search-input {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .toolbar:not(.toolbar--programs-admin) .pill-group {
    max-width: 100%;
  }

  .pill {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .program-table-wrap .data-table-scroll,
  .admin-programs-table-wrap .data-table-scroll {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  .program-table {
    min-width: 52rem;
  }

  /* Admin programs: fit ~860px content; hide Source on laptop */
  .admin-programs-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }

  .admin-programs-table col.col-program { width: 30%; }
  .admin-programs-table col.col-status { width: 10%; }
  .admin-programs-table col.col-version { width: 7%; }
  .admin-programs-table col.col-targets { width: 28%; }
  .admin-programs-table col.col-period { width: 14%; }
  .admin-programs-table col.col-last-period { width: 10%; }
  .admin-programs-table col.col-actions { width: 5%; }

  .admin-programs-table .admin-col--hide-lg {
    display: none;
  }

  .admin-programs-table .col-period-cell {
    font-size: 11px;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
  }

  .admin-programs-table .admin-program-detail-row td {
    min-width: 0;
  }

  .admin-programs-table thead th,
  .admin-programs-table tbody tr[data-admin-program-row] > td {
    padding-left: 8px;
    padding-right: 8px;
  }

  .program-table thead th,
  .program-table tbody tr[data-program-row] > td {
    padding-left: 8px;
    padding-right: 8px;
  }

  .program-table col.col-program { width: 26%; }
  .program-table col.col-targets { width: 9%; }
  .program-table col.col-month { width: 10%; }
  .program-table col.col-dates { width: 14%; }
  .program-table col.col-last-sub { width: 22%; }
  .program-table col.col-actions { width: 19%; }

  .program-table .cell-targets .badge {
    font-size: 9px;
    padding: 2px 5px;
    letter-spacing: 0.02em;
    text-transform: none;
    line-height: 1.25;
  }

  .program-table .date-range-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .program-table .date-range-sep {
    display: none;
  }

  .program-table .date-input {
    font-size: 10px;
    padding: 3px 4px;
  }

  .program-table__actions .btn {
    font-size: 10px;
    padding-left: 6px;
    padding-right: 6px;
  }
}

/* Phone: allow horizontal scroll inside the card only */
@media (max-width: 640px) {
  .program-table-wrap .data-table-scroll,
  .admin-programs-table-wrap .data-table-scroll {
    overflow-x: auto;
  }

  .program-table {
    min-width: 34rem;
    table-layout: auto;
  }

  .admin-programs-table {
    min-width: 38rem;
    table-layout: auto;
  }

  .admin-programs-table .admin-col--hide-lg,
  .admin-programs-table .admin-col--hide-sm {
    display: none;
  }
}

@media (max-width: 900px) {
  .toolbar--programs-admin {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar--programs-admin .toolbar-section,
  .toolbar--programs-admin .search-input {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
  }

  .toolbar--programs-admin .toolbar-spacer {
    display: none;
  }

  .toolbar--programs-admin .toolbar-section--count {
    margin-left: 0;
  }
}

.pd-carry-forward-callout {
  align-items: flex-start;
  margin-bottom: var(--sp-3);
}
.pd-carry-forward-callout__body {
  flex: 1;
  min-width: 0;
}

.carry-forward-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: var(--sp-3);
}
.carry-forward-field .form-label {
  margin-bottom: 4px;
  font-size: 11px;
}
.carry-forward-field .input {
  width: 100%;
}

.modal-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: -8px -6px -8px 0;
  padding: 0;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.carry-forward-modal {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  align-items: end;
  justify-items: stretch;
  padding: 0;
}

.carry-forward-modal[hidden] {
  display: none !important;
}

@media (min-width: 640px) {
  .carry-forward-modal {
    align-items: center;
    justify-items: center;
    padding: var(--sp-4);
    background: transparent;
  }
}

.carry-forward-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 16, 24, 0.55);
  backdrop-filter: blur(2px);
}

.carry-forward-modal__dialog {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 100%;
  max-width: 560px;
  max-height: min(92vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border: 1px solid var(--border-strong);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.12),
    0 12px 48px rgba(0, 0, 0, 0.16);
  outline: none;
}

@media (min-width: 640px) {
  .carry-forward-modal__dialog {
    border-radius: var(--r-lg);
    max-height: min(85vh, 680px);
  }
}

html[data-color-scheme="dark"] .carry-forward-modal__backdrop {
  background: oklch(0.18 0.02 250 / 0.72);
}

@media (prefers-color-scheme: dark) {
  html:not([data-color-scheme]) .carry-forward-modal__backdrop,
  html[data-color-scheme="system"] .carry-forward-modal__backdrop {
    background: oklch(0.18 0.02 250 / 0.72);
  }
}

.carry-forward-modal__header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.carry-forward-modal__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.carry-forward-modal__program {
  margin: var(--sp-2) 0 0;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.carry-forward-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}

.carry-forward-modal__summary {
  margin: 0 0 var(--sp-4);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

.carry-forward-modal .carry-forward-field .form-label {
  color: var(--text-primary);
  font-weight: 500;
}

.carry-forward-modal .carry-forward-field .input {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.carry-forward-modal__status {
  margin: var(--sp-3) 0 0 !important;
  font-size: 12px;
}

.carry-forward-modal__footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  justify-content: stretch;
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

.carry-forward-modal__footer .btn {
  flex: 1 1 auto;
  min-height: 40px;
  justify-content: center;
}

.carry-forward-modal__footer .btn-ghost {
  flex: 1 1 100%;
}

@media (min-width: 480px) {
  .carry-forward-modal__footer {
    justify-content: flex-end;
    flex-wrap: nowrap;
  }
  .carry-forward-modal__footer .btn {
    flex: 0 0 auto;
    min-height: unset;
    min-width: 120px;
  }
  .carry-forward-modal__footer .btn-ghost {
    flex: 0 0 auto;
  }
}

.mapping-upgrade-diff__group {
  margin-top: var(--sp-3);
}

.mapping-upgrade-diff__heading {
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0 0 var(--sp-2);
}

.mapping-upgrade-diff__item {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: baseline;
  padding: var(--sp-1) 0;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
}

.mapping-upgrade-diff__status {
  text-transform: uppercase;
  font-size: var(--text-xs);
  font-weight: 600;
  min-width: 5rem;
}

.mapping-upgrade-diff__item--added .mapping-upgrade-diff__status {
  color: var(--success-text);
}

.mapping-upgrade-diff__item--removed .mapping-upgrade-diff__status {
  color: var(--danger-text);
}

.mapping-upgrade-diff__key {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.mg-upgrade-card {
  margin-bottom: var(--sp-6);
}

.badge-version {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.admin-programs-table tbody tr.is-archived > td {
  opacity: 0.85;
}

.admin-programs-table tbody tr.is-legacy > td {
  opacity: 1;
}

.admin-programs-table .col-version-cell {
  white-space: nowrap;
  text-align: center;
}

.badge--inline {
  display: inline-flex;
  margin-top: var(--sp-1);
  vertical-align: middle;
}

.status-dot--warning {
  background: var(--warning);
}

.admin-program-detail__archive-note {
  margin: 0 0 var(--sp-3);
  max-width: 52rem;
}

.row-expand {
  display: none;
}
.row-expand.is-open { display: table-row; }
.row-expand td {
  padding: 0 !important;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}
.row-expand-panel {
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: flex-end;
}
.row-expand-panel .form-row {
  flex: 1 1 320px;
  min-width: 0;
  margin: 0;
}
.row-expand-panel .row-expand-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.row-expand-message {
  flex: 1 1 100%;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}
.row-expand-message.is-error { color: var(--danger-text); }
.row-expand-message.is-success { color: var(--success-text); }

tr.row-feedback {
  display: none;
}
tr.row-feedback:not([hidden]) {
  display: table-row;
}

tr.row-feedback td {
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-subtle);
}
.row-feedback-message {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.45;
}
.row-feedback-message.is-error { color: var(--danger-text); }
.row-feedback-message.is-success { color: var(--success-text); }
.row-feedback-message strong { font-weight: 600; }
.row-feedback-reason {
  display: block;
  margin-top: var(--sp-1);
  color: var(--text-secondary);
}
.cell-last-sub-reason {
  display: block;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

/* Stale chip variant — visually distinct from regular warning so reporters
   immediately see a row they cannot submit. */
.stale-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

@media (max-width: 1024px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-section { width: 100%; }
  .search-input { min-width: 0; width: 100%; }
}

/* History — meta strip above table */
.history-meta {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* Mapping generator preview block */
.code-block {
  position: relative;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  max-height: 320px;
  overflow: auto;
  padding: var(--sp-3) var(--sp-4);
  white-space: pre;
  line-height: 1.6;
}
.code-block-wrap { position: relative; }
.code-block-copy {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
}

/* Login (kept minimal — reuse base.html's main-wrapper) */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: var(--bg-canvas);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: var(--sp-7);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
}
.login-brand-icon {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-brand-icon .icon { width: 24px; height: 24px; }
.login-title {
  font-size: 18px;
  font-weight: 500;
}
.login-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Connection / Program cards (admin pages) */
.config-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-4);
  overflow: hidden;
}
.config-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  flex-wrap: wrap;
}
.config-card-header h2 {
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 2px;
}
.config-card-header .mono {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.config-card-status {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.config-card-body {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3) var(--sp-5);
}
.config-card-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.config-card-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-left: auto;
}
.config-card-footer-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: var(--sp-2);
}
.config-field dt {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.config-field dd {
  margin: 0;
  font-size: 13px;
  color: var(--text-primary);
  word-break: break-word;
}
.config-field dd.mono,
.config-field dd code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
}
.config-card-files {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.config-card-files .file {
  display: inline-block;
  margin-right: var(--sp-3);
}

/* Admin programs table */
.admin-programs-table-wrap {
  margin-bottom: var(--sp-4);
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.admin-programs-table-wrap .data-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.admin-programs-table {
  width: 100%;
  min-width: 52rem;
  table-layout: fixed;
}

/* Default: large monitors */
@media (min-width: 1281px) {
  .admin-programs-table .admin-col--hide-lg,
  .admin-programs-table .admin-col--hide-sm {
    display: table-cell;
  }
}

.admin-programs-table col.col-program { width: 30%; }
.admin-programs-table col.col-status { width: 8%; }
.admin-programs-table col.col-meta { width: 9%; }
.admin-programs-table col.col-source { width: 7%; }
.admin-programs-table col.col-targets { width: 22%; }
.admin-programs-table col.col-period { width: 10%; }
.admin-programs-table col.col-last-period { width: 9%; }
.admin-programs-table col.col-actions { width: 5%; }

.admin-programs-table .cell-program strong {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.admin-programs-table .cell-program .cell-mono {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-programs-table .cell-targets__text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-muted);
}

.admin-programs-table tr.is-stale .cell-program strong {
  color: var(--warning-text);
}

.admin-programs-table .admin-program-detail-row td {
  min-width: 52rem;
}

.admin-program-detail__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-3) var(--sp-5);
  margin-bottom: var(--sp-4);
}

.admin-program-detail__files {
  margin-bottom: var(--sp-4);
}

.admin-program-detail__file-list {
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
}

.admin-program-detail__file-list .file {
  display: inline-block;
}

.admin-program-detail__stale {
  margin-bottom: var(--sp-4);
}

.admin-program-detail__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.admin-programs-empty {
  margin-top: var(--sp-5);
}


/* ─── 21. Dark mode overrides (component-level) ────────────────── */

html[data-color-scheme="dark"] .alert-dismiss:hover {
  background: rgba(255, 255, 255, 0.06);
}
html[data-color-scheme="dark"] .result-card--success .result-card-header,
html[data-color-scheme="dark"] .result-card--danger .result-card-header {
  border-bottom-color: var(--border);
}
html[data-color-scheme="dark"] .program-card.is-selected {
  background: rgba(91, 159, 212, 0.08);
}
html[data-color-scheme="dark"] .stale-bar {
  background: rgba(214, 150, 32, 0.1);
}

@media (prefers-color-scheme: dark) {
  html:not([data-color-scheme]) .alert-dismiss:hover,
  html[data-color-scheme="system"] .alert-dismiss:hover {
    background: rgba(255, 255, 255, 0.06);
  }
  html:not([data-color-scheme]) .result-card--success .result-card-header,
  html:not([data-color-scheme]) .result-card--danger .result-card-header,
  html[data-color-scheme="system"] .result-card--success .result-card-header,
  html[data-color-scheme="system"] .result-card--danger .result-card-header {
    border-bottom-color: var(--border);
  }
  html:not([data-color-scheme]) .program-card.is-selected,
  html[data-color-scheme="system"] .program-card.is-selected {
    background: rgba(91, 159, 212, 0.08);
  }
  html:not([data-color-scheme]) .stale-bar,
  html[data-color-scheme="system"] .stale-bar {
    background: rgba(214, 150, 32, 0.1);
  }
}


/* ─── 22. Print styles ─────────────────────────────────────────── */

@media print {
  .sidebar,
  .mobile-topbar,
  .page-header-actions,
  .sidebar-backdrop,
  .alert-dismiss,
  .filter-row,
  .row-toggle,
  .site-footer,
  .btn { display: none !important; }
  .main-wrapper { margin: 0 !important; }
  .page-body { padding: 0 !important; }
  .page-header { padding: 12pt 0 8pt !important; border-bottom: 1px solid #000 !important; }
  body {
    font-size: 11pt;
    color: #000;
    background: #fff;
  }
  .card,
  .config-card,
  .data-table-wrap { border-color: #999 !important; box-shadow: none !important; }
  a { color: #000; text-decoration: underline; }
  .log-row { display: table-row !important; }
}


/* ─── 23. Reduced motion ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
  .spinner { animation: none !important; }
  .skeleton { animation: none !important; background: var(--bg-subtle); }
}
