/* Global styles for AlphaCore Web Application */
:root {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Roboto",
    "Oxygen",
    "Ubuntu",
    "Cantarell",
    "Fira Sans",
    "Droid Sans",
    "Helvetica Neue",
    sans-serif;
  line-height: 1.5;
  font-weight: 400;

  color-scheme: light;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--ink-1);
  /* Improved text rendering on mobile */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent horizontal scrolling on mobile */
  overflow-x: hidden;
}

#root {
  min-height: 100vh;
  width: 100%;
  /* Ensure proper stacking context */
  position: relative;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles for accessibility */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Responsive utilities */
.container-mobile {
  padding: 0 16px;
}

.container-tablet {
  padding: 0 24px;
}

.container-desktop {
  padding: 0 32px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Touch-friendly interactive elements */
@media (max-width: 899px) {
  .touch-target,
  button:not(.btn):not(.iconbtn),
  a,
  .MuiIconButton-root,
  .MuiButton-root,
  [role="button"]:not(.btn):not(.iconbtn) {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Exception for inline text links */
  a:not([role="button"]):not(.MuiButton-root) {
    min-height: unset !important;
    min-width: unset !important;
  }
}

/* Improved responsive grid */
.responsive-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .responsive-grid {
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

@media (min-width: 900px) {
  .responsive-grid {
    gap: 24px;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
}

/* Better mobile scrolling */
.mobile-scroll {
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Responsive text truncation */
.text-truncate-mobile {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 600px) {
  .text-truncate-mobile {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --line: #000000;
    --line-strong: #000000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }

  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-sunken);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-4);
}

/* ============================================================
   Design System Utilities — ported from handoff tokens.css
   ============================================================ */

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.card.flat {
  box-shadow: none;
}
.card.elev {
  box-shadow: var(--sh-1);
}
.card.pop {
  box-shadow: var(--sh-pop);
}

.card-action {
  cursor: pointer;
  transition:
    transform 120ms,
    box-shadow 120ms;
}
.card-action:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
}

/* ── Button ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink-1);
  font-weight: 500;
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition:
    background 120ms,
    border-color 120ms;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-sunken);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--ink-1);
  color: var(--bg);
  border-color: var(--ink-1);
}
.btn.primary:hover {
  opacity: 0.88;
}
.btn.accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.accent:hover {
  opacity: 0.88;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: var(--bg-sunken);
}
.btn.sm {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
}
.btn.lg {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}
.btn.icon {
  padding: 0;
  width: 32px;
}
.btn.sm.icon {
  width: 26px;
}

/* ── Pill ─────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--bg-sunken);
  color: var(--ink-2);
}
.pill.ok {
  background: var(--ok-soft);
  color: var(--ok-soft-ink);
}
.pill.warn {
  background: var(--warn-soft);
  color: var(--warn-soft-ink);
}
.pill.risk {
  background: var(--risk-soft);
  color: var(--risk-soft-ink);
}
.pill.info {
  background: var(--info-soft);
  color: var(--info-soft-ink);
}
.pill.accent {
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
}
.pill.dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ── Typography helpers ───────────────────────────────────── */
.h-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink-1);
}
.mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  letter-spacing: -0.01em;
}
.tnum {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}

/* ── Icon button ──────────────────────────────────────────── */
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  background: transparent;
  border: none;
  transition:
    background 120ms,
    color 120ms;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.iconbtn:hover {
  background: var(--bg-sunken);
  color: var(--ink-1);
}

/* ── Table ────────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 10px var(--pad-x);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--line);
}
.tbl td {
  padding: var(--pad-y) var(--pad-x);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}
.tbl tbody tr:hover td {
  background: var(--bg-sunken);
}
.tbl tbody tr:last-child td {
  border-bottom: none;
}

/* ── Form elements ────────────────────────────────────────── */
.input {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink-1);
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  outline: none;
  transition: border-color 120ms;
  width: 100%;
}
.input:focus {
  border-color: var(--accent);
}
.input::placeholder {
  color: var(--ink-4);
}
.input.sm {
  height: 26px;
  font-size: 12px;
}
/* Hide the native calendar-picker indicator for date inputs that use the DS
   DateInput component (appearance:none + custom SVG icon overlay). Without
   this the native icon bleeds through alongside the custom SVG on Chrome. */
input[type="date"].input::-webkit-calendar-picker-indicator {
  display: none;
}
/* Textarea variant — override the fixed height so rows attribute controls size */
textarea.input {
  height: auto;
  padding-top: 8px;
  padding-bottom: 8px;
  line-height: 1.5;
  resize: vertical;
}
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  min-width: 18px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  font: 500 10px/1 var(--font-mono);
  color: var(--ink-3);
  background: var(--bg-elev);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}
.helptext {
  font-size: 11px;
  color: var(--ink-3);
}

/* ── Dividers ─────────────────────────────────────────────── */
.hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0;
}
.vr {
  border: none;
  border-left: 1px solid var(--line);
  margin: 0;
}

/* ── Scroll ───────────────────────────────────────────────── */
.scroll {
  overflow-y: auto;
}

/* ── DS Batch A additions (ALH-546) ─────────────────────────────────── */

/* Pills — solid (AA-verified ink pairs) */
.pill.solid-ok {
  background: var(--ok);
  color: var(--ok-ink);
}
.pill.solid-risk {
  background: var(--risk);
  color: var(--risk-ink);
}

/* IconButton active modifier */
.iconbtn.active {
  background: var(--bg-sunken);
  color: var(--ink-1);
}

/* Field required / optional markers + error helper text */
.label .req {
  color: var(--risk);
  margin-left: 2px;
}
.label .opt {
  color: var(--ink-3);
  font-weight: 400;
}
.helptext.error {
  color: var(--risk);
}

/* EmptyState placeholder */
.stripe-ph {
  width: 56px;
  height: 70px;
  background: repeating-linear-gradient(
    135deg,
    var(--bg-sunken) 0 6px,
    var(--bg-elev) 6px 12px
  );
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  opacity: 0.6;
}

/* ── KPI card hover reveal ────────────────────────────────── */
.kpi-view-link {
  opacity: 0.6;
  transition: opacity 120ms;
}
.kpi-card:hover .kpi-view-link {
  opacity: 1;
}

/* ── Loading progress animation ──────────────────────────── */
@keyframes progress-slide {
  0% {
    transform: translateX(-100%);
    width: 40%;
  }
  50% {
    width: 70%;
  }
  100% {
    transform: translateX(300%);
    width: 40%;
  }
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Brief highlight when a checklist item is navigated to via a cross-ref chip,
   so the user can spot exactly which element they landed on. */
@keyframes checklistItemFlash {
  0% {
    background: color-mix(in oklab, var(--accent) 22%, transparent);
  }
  100% {
    background: transparent;
  }
}

/* === Batch C: composite primitives ====================================== */

/* -- Tabs (underline pattern; complements segmented DashboardTabBar) ----- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  /* On narrow screens the row scrolls horizontally instead of the tab labels
     wrapping onto multiple lines. Scrollbar hidden for a clean look. */
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tabs .tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 120ms;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tabs .tab:hover {
  color: var(--ink-2);
}
.tabs .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-sm);
}
.tabs .tab.active,
.tabs .tab[aria-selected="true"] {
  color: var(--ink-1);
  border-bottom-color: var(--accent);
}

/* -- Pipeline strip ------------------------------------------------------ */
.pipeline-strip {
  padding: 16px;
}
.pipeline-strip .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.pipeline-strip .head .summary {
  font-weight: 500;
  font-size: 11px;
  line-height: 1;
  font-family: var(--font-mono);
  color: var(--ink-3);
}
.pipeline-strip .grid {
  display: grid;
  gap: 8px;
}
.pipeline-cell {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
}
.pipeline-cell.tone-info {
  background: var(--info-soft);
}
.pipeline-cell.tone-warn {
  background: var(--warn-soft);
}
.pipeline-cell.tone-ok {
  background: var(--ok-soft);
}
.pipeline-cell.tone-risk {
  background: var(--risk-soft);
}
.pipeline-cell.tone-ghost {
  background: var(--bg-elev);
}
.pipeline-cell .bar {
  height: 3px;
  margin-top: 8px;
  background: var(--bg-sunken);
  border-radius: var(--r-xs, 4px);
  overflow: hidden;
}
.pipeline-cell .bar > span {
  display: block;
  height: 100%;
  background: var(--ink-3);
}
.pipeline-cell.tone-info .bar > span {
  background: var(--info);
}
.pipeline-cell.tone-warn .bar > span {
  background: var(--warn);
}
.pipeline-cell.tone-ok .bar > span {
  background: var(--ok);
}
.pipeline-cell.tone-risk .bar > span {
  background: var(--risk);
}
.pipeline-cell.tone-ghost .bar > span {
  background: var(--ink-3);
}

/* -- Form section (label / body two-column form layout) ------------------ */
.form-section {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 32px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}
.form-section.first {
  border-top: 0;
  padding-top: 8px;
}
.form-section > :first-child > h2,
.form-section > :first-child > h3,
.form-section > :first-child > h4,
.form-section > :first-child > h5 {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  color: var(--ink-1);
}
.form-section > :first-child > p {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}
.form-section > .body {
  display: grid;
  gap: 16px;
}
@media (max-width: 900px) {
  .form-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* -- DataTable empty-state row & clickable rows -------------------------- */
.tbl tbody tr.empty td {
  padding: 32px;
  text-align: center;
  color: var(--ink-3);
}
.tbl tbody tr[role="button"] {
  cursor: pointer;
}
.tbl tbody tr[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* === Batch D: ported from prototype (forms, layout, focus) ============== */

/* -- Field row grids ----------------------------------------------------- */
.field-row {
  display: grid;
  gap: 14px;
}
.field-row.cols-2 {
  grid-template-columns: 1fr 1fr;
}
.field-row.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}
@media (max-width: 720px) {
  .field-row.cols-2,
  .field-row.cols-3 {
    grid-template-columns: 1fr;
  }
}

/* -- Helptext OK variant ------------------------------------------------- */
.helptext.ok {
  color: var(--ok);
}

/* -- Operator-specific input focus -------------------------------------- */
[data-theme="operator"] .input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent);
}

/* -- Checkbox + Radio (custom) ------------------------------------------ */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-1);
  line-height: 1.4;
  user-select: none;
}
.check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.check .box {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1.5px solid var(--line-strong);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  transition: all 120ms;
}
.check .box.radio {
  border-radius: 50%;
}
.check input:checked + .box {
  background: var(--accent);
  border-color: var(--accent);
}
.check input:checked + .box svg {
  opacity: 1;
  transform: scale(1);
  color: var(--accent-ink);
}
.check .box svg {
  opacity: 0;
  transform: scale(0.6);
  transition: all 120ms;
}
.check input:checked + .box.radio::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-ink);
}
.check.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.check .sub {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 1px;
}

/* -- Toggle switch ------------------------------------------------------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-1);
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch .track {
  width: 30px;
  height: 18px;
  border-radius: 9px;
  background: var(--line-strong);
  position: relative;
  transition: background 120ms;
  flex-shrink: 0;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  transition: transform 120ms;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.switch input:checked + .track {
  background: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(12px);
}

/* -- Segmented chip-row (radio styled as buttons) ----------------------- */
.chip-row {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-elev);
}
.chip-row label {
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  border-right: 1px solid var(--line);
  transition:
    background 100ms,
    color 100ms;
}
.chip-row label:last-child {
  border-right: 0;
}
.chip-row input {
  display: none;
}
.chip-row input:checked + label {
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
  font-weight: 600;
}

/* ── Responsive design tokens ─────────────────────────────────────────── */
/* Mobile (≤767px): compact density — affects every token-aware component  */
@media (max-width: 767px) {
  :root {
    --gap: 12px;
    --pad-x: 16px;
    --pad-y: 8px;
    --row-h: 36px;
    --topbar-h: 52px;
  }
}

/* ── Mobile page-content helpers ─────────────────────────────────────── */
/* Tables: always scroll horizontally rather than overflow the viewport */
@media (max-width: 767px) {
  /* Ensure MUI table container scrolls on narrow viewports */
  .MuiTableContainer-root {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Tighten table cell padding */
  .MuiTableCell-root {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }
  /* Pill/badge — slightly smaller on mobile */
  .pill {
    font-size: 10px;
    height: 18px;
    padding: 0 6px;
  }
}

/* Toolbar / page-header: stack actions on narrow viewports */
@media (max-width: 599px) {
  /* Page header: stack title row and actions vertically */
  .page-header-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  /* SearchToolbar filters and actions wrap + take full width */
  .search-toolbar-filters,
  .search-toolbar-actions {
    flex-wrap: wrap;
    width: 100%;
  }
  /* Input in SearchToolbar goes full width */
  .search-toolbar-input {
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }
}

/* ── Tablet (768-1023px): intermediate density ────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --pad-x: 14px;
    --gap: 10px;
  }
  /* Subnav overlay when open on tablet */
  .subnav-overlay-tablet {
    position: fixed;
    top: var(--topbar-h);
    left: var(--rail-w);
    bottom: 0;
    width: var(--subnav-w);
    background: var(--bg);
    border-right: 1px solid var(--line);
    z-index: 25;
    overflow-y: auto;
    box-shadow: var(--sh-2);
    transform: translateX(0);
    transition: transform 200ms ease;
  }
  .subnav-overlay-tablet.closed {
    transform: translateX(-100%);
    pointer-events: none;
  }
  /* Backdrop for subnav overlay */
  .subnav-overlay-tablet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 24;
    background: transparent;
  }
}

/* -- Sticky form footer / action bar ------------------------------------ */
.form-actionbar {
  position: sticky;
  bottom: 0;
  background: color-mix(in oklab, var(--bg) 96%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
}

/* -- Focus ring helper -------------------------------------------------- */
.focus-ring:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Hero strip (DashboardHeroStrip) ─────────────────────────────────────── */
/* Desktop/tablet: grid with column widths set via --hero-grid-cols CSS var. */
/* Mobile: horizontal scroll carousel so cards don't squish below ~200 px.  */
.hero-strip {
  display: grid;
  grid-template-columns: var(--hero-grid-cols, repeat(3, 1fr));
  gap: 12px;
  margin-bottom: var(--gap);
}

@media (max-width: 767px) {
  .hero-strip {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding-bottom: 4px;
    /* Negative side-margin so cards bleed to viewport edge while still showing
       the peek of the next card — classic mobile carousel affordance. */
    margin-left: calc(-1 * var(--gap));
    margin-right: calc(-1 * var(--gap));
    padding-left: var(--gap);
    padding-right: var(--gap);
  }
  .hero-strip > * {
    flex: 0 0 min(260px, 78vw);
    scroll-snap-align: start;
  }
}

/* ── Horizontal-scroll table wrapper ─────────────────────────────────────── */
/* Applied directly to the .card wrapping .tbl tables (via DataTable).       */
/* On mobile, tables scroll within their card rather than overflowing.       */
@media (max-width: 767px) {
  .tbl {
    min-width: 480px; /* tables always get at least this wide — enables scroll */
  }
  /* Allow long chapter / rule labels to wrap inside their cells instead of   */
  /* being clipped with an ellipsis. Combined with min-width above this gives */
  /* readable wrapping plus a horizontal scroll fallback for very wide rows. */
  .tbl td,
  .tbl th {
    white-space: normal;
    word-break: break-word;
  }
  /* Hide the redundant readiness mini-grid inside the hero "Compliance       */
  /* snapshot" tile on mobile — same data is already shown by the standalone */
  /* ReadinessByChapter card further down the dashboard.                     */
  .hero-readiness-bars {
    display: none;
  }
}

/* ── Page horizontal padding token ───────────────────────────────────────── */
/* Page components that use the 28px horizontal gutter should reference      */
/* var(--page-pad-x) instead of the hardcoded value. On mobile the token     */
/* resolves to var(--pad-x) (16px) so content doesn't get crushed against    */
/* the AppShell's own gap padding.                                            */
/*   desktop: 28px  |  mobile (≤767px): 16px                                 */
:root {
  --page-pad-x: 28px;
}
@media (max-width: 767px) {
  :root {
    --page-pad-x: var(--pad-x); /* 16px on mobile */
  }
}

/* ── Cards containing .tbl tables scroll horizontally on mobile ───────────── */
@media (max-width: 767px) {
  .card:has(> .tbl),
  .card:has(> div > .tbl),
  .card:has(> * > div > .tbl) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  /* Subtle right-edge fade as a scroll affordance — hints there's more       */
  /* content off-screen. Static (no animation) so prefers-reduced-motion is   */
  /* automatically respected.                                                 */
  .card:has(> .tbl)::after,
  .card:has(> div > .tbl)::after,
  .card:has(> * > div > .tbl)::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-elev));
    pointer-events: none;
  }
}

/* -- App grid layout (rail + subnav + topbar + main) -------------------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--subnav-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "rail topbar topbar"
    "rail subnav main";
  height: 100vh;
  width: 100%;
  background: var(--bg);
}
.app.no-subnav {
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-areas:
    "rail topbar"
    "rail main";
}
.app.no-rail {
  grid-template-columns: var(--subnav-w) 1fr;
  grid-template-areas:
    "subnav topbar"
    "subnav main";
}

/* ── Split-editor pane (NeedsAssessment, TemplateEdit) ─────────────────────── */
/* Desktop: side-by-side editor + preview, constrained to viewport.            */
/* Mobile:  stack vertically, each pane gets a comfortable min-height.         */
.split-editor-pane {
  display: flex;
  height: calc(100vh - 220px);
}
@media (max-width: 767px) {
  .split-editor-pane {
    flex-direction: column;
    height: auto;
  }
  .split-editor-pane > * {
    min-height: 280px;
    flex: none !important;
    width: 100% !important;
  }
}

/* ── Kanban board (CaseList) ────────────────────────────────────────────────── */
/* Desktop: 3-column grid with fixed viewport height.                          */
/* Mobile:  horizontal scroll, each column 80vw, full natural height.          */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  height: calc(100vh - 300px);
  --kanban-col-maxh: calc(100vh - 320px);
}
@media (max-width: 767px) {
  .kanban-board {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    height: auto;
    gap: 10px;
    padding-bottom: 8px;
    --kanban-col-maxh: 420px;
  }
  .kanban-board > * {
    flex: 0 0 min(300px, 80vw);
    scroll-snap-align: start;
    height: auto;
  }
}

/* ── Questionnaire two-column layout ───────────────────────────────────────── */
/* Desktop: sidebar + scrollable main content side by side.                    */
/* Mobile:  sidebar stacks above content, full-width, non-sticky.             */
.questionnaire-two-col {
  display: flex;
}
@media (max-width: 767px) {
  .questionnaire-two-col {
    flex-direction: column;
  }
  .questionnaire-sidebar {
    position: static !important; /* remove sticky so it scrolls with page */
    width: 100% !important;
    max-height: none !important;
  }
}

/* ── hide-mobile utility ───────────────────────────────────────────────────── */
/* Add class="hide-mobile" to table columns (th + td) or any element that     */
/* should be hidden on narrow viewports. Works for block, inline, table-cell. */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

/* ── hide-md utility ───────────────────────────────────────────────────────── */
/* Add class="hide-md" to hide elements on tablet and smaller (≤900px).       */
/* Use instead of hide-mobile when a column is too narrow even at 768-900px.  */
@media (max-width: 900px) {
  .hide-md {
    display: none !important;
  }
}

/* ── Dashboard main grid ───────────────────────────────────────────────────── */
/* Two-column layout: left (Readiness + Active cases) | right (Notifications   */
/* + Activity + Milestones). Stacks to single column on mobile.                */
.dash-main-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: var(--gap);
}
/* Prevent grid-column blowout: fr tracks respect min-width only when direct  */
/* children declare min-width:0 (grid default is min-width:auto).             */
.dash-main-grid > * {
  min-width: 0;
}
@media (max-width: 767px) {
  .dash-main-grid {
    grid-template-columns: 1fr;
  }
}
