/* Maua Mazuri FRP-AG-0982 & EWS-AGRA Command Center
 * Built with modern CSS: color-scheme light-dark(), @container responsive tables,
 * native dialog top-layer scroll containment, focusgroup tabs with scroll-driven edge fades,
 * and brand-consistent accent-color controls with progressive fallbacks.
 */

@property --fade-start {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

@property --fade-end {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

:root {
  /* MANDATORY (dark-mode-toggle): base declaration stays light dark; reflect <meta> override in CSS */
  color-scheme: light dark;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  /* Semantic tokens using light-dark() — zero JS dependency for colors */
  --bg-page: light-dark(#f5f7f4, #0d1410);
  --bg-surface: light-dark(#ffffff, #151f19);
  --bg-subtle: light-dark(#edf2ec, #1c2a22);
  --bg-elevated: light-dark(#f9fbf8, #1a261f);
  --bg-header: light-dark(#12472d, #0f291c);

  --ink-primary: light-dark(#132219, #edf5ef);
  --ink-secondary: light-dark(#44594d, #a5baad);
  --ink-muted: light-dark(#5d7165, #89a092);
  --ink-on-brand: #ffffff;

  --border-subtle: light-dark(#d8e2d9, #27392e);
  --border-strong: light-dark(#b7c7b9, #3b5244);

  /* Brand & semantic accents (>= 3:1 UI contrast, >= 4.5:1 text contrast) */
  --brand-accent: light-dark(#156d44, #34d399);
  --brand-accent-strong: light-dark(#0f5132, #10b981);
  --brand-soft: light-dark(#e3f4ea, #123325);
  --brand-ink: light-dark(#0f5132, #6ee7b7);

  --amber-accent: light-dark(#b45309, #fbbf24);
  --amber-soft: light-dark(#fef3c7, #352711);
  --amber-ink: light-dark(#92400e, #fcd34d);

  --danger-accent: light-dark(#b91c1c, #f87171);
  --danger-soft: light-dark(#fee2e2, #38181a);
  --danger-ink: light-dark(#991b1b, #fca5a5);

  --info-accent: light-dark(#1d4ed8, #60a5fa);
  --info-soft: light-dark(#dbeafe, #172844);
  --info-ink: light-dark(#1e40af, #93c5fd);

  --agra-accent: light-dark(#6d28d9, #a78bfa);
  --agra-soft: light-dark(#ede9fe, #271b47);
  --agra-ink: light-dark(#5b21b6, #c4b5fd);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: light-dark(0 1px 2px rgb(16 32 22 / 0.06), 0 1px 2px rgb(0 0 0 / 0.35));
  --shadow-md: light-dark(0 6px 20px rgb(16 32 22 / 0.1), 0 8px 24px rgb(0 0 0 / 0.5));

  --sidebar-width: 260px;
  --header-height: 60px;
  --bottom-nav-height: 68px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--ink-primary);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  /* Brand-consistent native form controls */
  accent-color: var(--brand-accent);
  min-height: 100dvh;
}

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

a {
  color: var(--brand-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--brand-accent);
}

.num,
.kpi-value,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link {
  position: absolute;
  inset-block-start: -100px;
  inset-inline-start: 16px;
  z-index: 999;
  padding: 12px 16px;
  background: var(--brand-accent-strong);
  color: var(--ink-on-brand);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.skip-link:focus {
  inset-block-start: 12px;
}

/* --- Color-scheme 2-state toggle label visibility (zero JS needed for initial state) --- */
.theme-toggle .theme-label-light {
  display: none;
}

.theme-toggle .theme-label-dark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-toggle .theme-label-dark {
    display: none;
  }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-toggle .theme-label-light {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-toggle .theme-label-dark {
  display: none;
}
:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-toggle .theme-label-light {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

:root:has(> head > meta[name="color-scheme"][content="light"]) .theme-toggle .theme-label-light {
  display: none;
}
:root:has(> head > meta[name="color-scheme"][content="light"]) .theme-toggle .theme-label-dark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* --- Login Page --- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 20px;
  background:
    radial-gradient(circle at top right, light-dark(rgb(21 109 68 / 0.14), rgb(52 211 153 / 0.12)), transparent 55%),
    var(--bg-page);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-block-end: 20px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--brand-accent-strong);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  flex: none;
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.login-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-secondary);
}

/* --- App Layout Shell --- */
.app-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 40;
  height: var(--header-height);
  background: var(--bg-header);
  color: var(--ink-on-brand);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-inline: 16px;
  border-block-end: 1px solid rgb(255 255 255 / 0.12);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-brand .brand-mark {
  width: 34px;
  height: 34px;
  font-size: 14px;
  background: rgb(255 255 255 / 0.16);
}

.header-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-subtitle {
  display: block;
  font-size: 11px;
  color: rgb(255 255 255 / 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.header-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.14);
  color: #ffffff;
  white-space: nowrap;
}

.header-btn {
  min-height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgb(255 255 255 / 0.24);
  background: rgb(255 255 255 / 0.1);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.header-btn:hover {
  background: rgb(255 255 255 / 0.2);
}

.app-layout {
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100dvh - var(--header-height));
}

.sidebar-nav {
  display: none;
}

.app-main {
  padding: 16px 16px calc(var(--bottom-nav-height) + 28px);
  max-width: 1360px;
  width: 100%;
  margin-inline: auto;
  min-width: 0;
}

/* Mobile bottom navigation bar */
.bottom-nav {
  position: fixed;
  inset-block-end: 0;
  inset-inline: 0;
  z-index: 40;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-block-start: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 4px 4px env(safe-area-inset-bottom, 4px);
  box-shadow: 0 -2px 10px rgb(0 0 0 / 0.06);
}

.bottom-nav-btn {
  border: 0;
  background: transparent;
  color: var(--ink-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  padding: 4px 2px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
}

.bottom-nav-btn svg {
  width: 20px;
  height: 20px;
}

.bottom-nav-btn[aria-current="page"] {
  color: var(--brand-ink);
  background: var(--brand-soft);
}

.bottom-nav-btn[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 22%;
  border-block-start: 3px solid var(--brand-accent);
  border-radius: 0 0 4px 4px;
}

@media (min-width: 960px) {
  .app-layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 12px;
    background: var(--bg-surface);
    border-inline-end: 1px solid var(--border-subtle);
    position: sticky;
    inset-block-start: var(--header-height);
    height: calc(100dvh - var(--header-height));
    overflow-y: auto;
  }

  .sidebar-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
    padding: 12px 12px 6px;
  }

  .sidebar-btn {
    border: 0;
    background: transparent;
    color: var(--ink-secondary);
    text-align: start;
    padding: 11px 12px;
    min-height: 44px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: relative;
  }

  .sidebar-btn:hover {
    background: var(--bg-subtle);
    color: var(--ink-primary);
  }

  .sidebar-btn[aria-current="page"] {
    background: var(--brand-soft);
    color: var(--brand-ink);
  }

  .sidebar-btn[aria-current="page"]::before {
    content: "";
    position: absolute;
    inset-block: 8px;
    inset-inline-start: 0;
    border-inline-start: 4px solid var(--brand-accent);
    border-radius: 0 4px 4px 0;
  }

  .sidebar-btn-left {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .sidebar-btn svg {
    width: 18px;
    height: 18px;
    flex: none;
  }

  .sidebar-count {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--bg-subtle);
    color: var(--ink-secondary);
    font-variant-numeric: tabular-nums;
  }

  .sidebar-footer {
    margin-block-start: auto;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
    font-size: 12px;
    color: var(--ink-secondary);
  }

  .bottom-nav {
    display: none;
  }

  .app-main {
    padding: 24px 28px 48px;
  }
}

/* --- Views & Headers --- */
.view-section[hidden] {
  display: none;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-block-end: 18px;
}

.page-head h1,
.page-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.page-lead {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--ink-secondary);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* --- Banners & Alerts --- */
.banner {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-block-end: 16px;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.banner-brand {
  background: var(--brand-soft);
  border-color: light-dark(#9fd6b7, #1f5c3f);
  color: var(--ink-primary);
}

.banner-amber {
  background: var(--amber-soft);
  border-color: light-dark(#f2c97d, #6b4b16);
  color: var(--ink-primary);
}

.banner-danger {
  background: var(--danger-soft);
  border-color: light-dark(#f4a8a8, #78272b);
  color: var(--ink-primary);
}

.banner-agra {
  background: var(--agra-soft);
  border-color: light-dark(#c4b5fd, #4c3399);
  color: var(--ink-primary);
}

.banner-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
}

.banner-text {
  margin: 0;
  font-size: 13px;
  color: var(--ink-secondary);
}

/* --- Cards & Grids --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
  margin-block-end: 18px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin: 0 0 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.stat-meta {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 6px 0 0;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-block-end: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 12px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.card-subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--ink-secondary);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 760px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --- Badges & Pills --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-brand {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.badge-amber {
  background: var(--amber-soft);
  color: var(--amber-ink);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-ink);
}

.badge-info {
  background: var(--info-soft);
  color: var(--info-ink);
}

.badge-agra {
  background: var(--agra-soft);
  color: var(--agra-ink);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--ink-secondary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-subtle);
}

.btn-primary {
  background: var(--brand-accent-strong);
  border-color: var(--brand-accent-strong);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--brand-accent);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger-accent);
  border-color: var(--danger-accent);
  color: #ffffff;
}

.btn-amber {
  background: var(--amber-soft);
  border-color: var(--amber-accent);
  color: var(--amber-ink);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

/* --- Form Controls --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-block-end: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
}

.field-hint {
  font-size: 12px;
  color: var(--ink-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font: inherit;
  font-size: 14px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.inline-input {
  min-height: 36px !important;
  padding: 5px 8px !important;
  width: 112px !important;
  font-variant-numeric: tabular-nums;
}

.inline-select {
  min-height: 36px !important;
  padding: 5px 8px !important;
  width: auto !important;
  min-width: 125px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 44px;
  font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: none;
  margin: 0;
  cursor: pointer;
}

progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
}

/* Progressive fallback when accent-color is unsupported (brand-consistent-forms) */
@supports not (accent-color: auto) {
  .checkbox-label input[type="checkbox"].branded-check {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .checkbox-label {
    position: relative;
    padding-inline-start: 2rem;
  }

  .checkbox-label input[type="checkbox"].branded-check + span::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-strong);
    background: var(--bg-surface);
    border-radius: 4px;
  }

  .checkbox-label input[type="checkbox"].branded-check:focus-visible + span::before {
    outline: 2px solid var(--brand-accent);
    outline-offset: 2px;
  }

  .checkbox-label input[type="checkbox"].branded-check:checked + span::before {
    background-color: var(--brand-accent);
    border-color: var(--brand-accent);
  }

  .checkbox-label input[type="checkbox"].branded-check:checked + span::after {
    content: "✓";
    position: absolute;
    inset-inline-start: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.9rem;
  }

  progress {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background: var(--bg-subtle);
  }
  progress::-webkit-progress-bar {
    background: var(--bg-subtle);
    border-radius: 999px;
  }
  progress::-webkit-progress-value {
    background: var(--brand-accent);
    border-radius: 999px;
  }
  progress::-moz-progress-bar {
    background: var(--brand-accent);
    border-radius: 999px;
  }
}

/* --- Filter Bar & Quick Chips --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-block-end: 14px;
}

.filter-bar select,
.filter-bar input[type="search"],
.filter-bar input[type="date"] {
  width: auto;
  min-width: 140px;
  flex: 1 1 150px;
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-block: 4px 8px;
  margin-block-end: 12px;
  scrollbar-width: thin;
}

.chip-btn {
  flex: none;
  min-height: 38px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn[aria-pressed="true"] {
  background: var(--brand-accent-strong);
  border-color: var(--brand-accent-strong);
  color: #ffffff;
}

/* --- Daily Task Cards --- */
.task-day-group {
  margin-block-end: 18px;
}

.task-day-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  padding-block-end: 6px;
  border-block-end: 1px solid var(--border-subtle);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.task-card.is-done {
  background: var(--bg-elevated);
  opacity: 0.8;
}

.task-card.is-done .task-title {
  text-decoration: line-through;
  color: var(--ink-muted);
}

.task-check-wrap {
  padding-block-start: 2px;
  flex: none;
}

.task-check-wrap input[type="checkbox"] {
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-block-end: 4px;
}

.task-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-primary);
}

.task-details {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-secondary);
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-block-start: 8px;
  font-size: 12px;
  color: var(--ink-muted);
}

.task-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: none;
}

/* --- In-Page Tabbed Interfaces (modern-web-guidance: tabs) --- */
.tabs {
  margin-block-end: 16px;
}

.tablist-scroller {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: inline proximity;
  scroll-padding-inline: 2.5rem;
  border-block-end: 1px solid var(--border-subtle);
  margin-block-end: 14px;
  scrollbar-width: none;

  /* Edge fade using scroll-driven animation on self inline scroll */
  --fade-size: 2.5rem;
  --fade-dir: right;
  --fade-start-pos: 0;
  --fade-end-pos: 100%;
  mask:
    linear-gradient(black, black) no-clip subtract,
    linear-gradient(to var(--fade-dir), black, transparent) var(--fade-start-pos) 0 / var(--fade-start) 100% no-repeat no-clip,
    linear-gradient(to var(--fade-dir), transparent, black) var(--fade-end-pos) 0 / var(--fade-end) 100% no-repeat no-clip;
  animation: reveal-fade-start linear both, hide-fade-end linear both;
  animation-timeline: scroll(self inline);
  animation-range: 0 var(--fade-size), calc(100% - var(--fade-size)) 100%;
}

.tablist-scroller::-webkit-scrollbar {
  display: none;
}

@keyframes reveal-fade-start {
  to {
    --fade-start: var(--fade-size);
  }
}

@keyframes hide-fade-end {
  from {
    --fade-end: var(--fade-size);
  }
}

.tablist-scroller > button {
  flex: none;
  scroll-snap-align: start;
  position: relative;
  border: 0;
  background: transparent;
  color: var(--ink-secondary);
  min-height: 44px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tablist-scroller > button:hover {
  color: var(--ink-primary);
}

/* MANDATORY (tabs): style from aria-selected, underline with ::after border (forced-colors safe) */
.tablist-scroller > button[aria-selected="true"] {
  color: var(--brand-ink);
}

.tablist-scroller > button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 3px solid var(--brand-accent);
}

/* MANDATORY (tabs): zero padding/border/margin on tabpanel element itself for hidden=until-found */
.tab-panel-stack {
  display: grid;
}

.tab-panel-stack > [role="tabpanel"] {
  grid-area: 1 / 1;
  min-width: 0;
}

.tab-panel-stack > [role="tabpanel"][hidden] {
  pointer-events: none;
  z-index: 0;
}

.tab-panel-stack > [role="tabpanel"]:not([hidden]) {
  position: relative;
  z-index: 1;
}

.tab-panel-inner {
  padding-block-start: 4px;
}

/* --- Responsive Data Tables (modern-web-guidance: responsive-table) --- */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 76vh);
  container-type: inline-size;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.table-wrapper table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.table-wrapper caption {
  text-align: start;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-primary);
  background: var(--bg-elevated);
  border-block-end: 1px solid var(--border-subtle);
}

.table-wrapper thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

.table-wrapper thead th {
  text-align: start;
  padding: 10px 12px;
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 700;
  border-block-end: 1px solid var(--border-strong);
  white-space: nowrap;
}

.table-wrapper tbody th,
.table-wrapper tbody td {
  padding: 10px 12px;
  border-block-end: 1px solid var(--border-subtle);
  vertical-align: top;
}

.table-wrapper tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--bg-surface);
  text-align: start;
  font-weight: 700;
  color: var(--ink-primary);
  min-width: 140px;
}

.table-wrapper tbody tr:last-child th,
.table-wrapper tbody tr:last-child td {
  border-block-end: 0;
}

.table-wrapper tfoot td,
.table-wrapper tfoot th {
  padding: 10px 12px;
  background: var(--bg-subtle);
  font-weight: 800;
  border-block-start: 2px solid var(--border-strong);
}

@media (max-width: 640px) {
  .table-wrapper {
    border: 0;
    background: transparent;
    max-block-size: none;
    overflow: visible;
  }
}

/* Stacked mobile card transformation via @container query */
@container (width < 600px) {
  .table-wrapper table,
  .table-wrapper caption,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper tfoot,
  .table-wrapper tr,
  .table-wrapper th,
  .table-wrapper td {
    display: block;
    width: 100%;
  }

  .table-wrapper caption {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-block-end: 10px;
  }

  /* MANDATORY: Hide column header from layout and screen readers */
  .table-wrapper thead {
    display: none;
  }

  .table-wrapper tbody tr,
  .table-wrapper tfoot tr {
    margin-block-end: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    overflow: hidden;
  }

  .table-wrapper tbody th {
    position: sticky;
    inset-block-start: 0;
    inset-inline-start: auto;
    z-index: 2;
    background: var(--bg-subtle);
    border-block-end: 1px solid var(--border-subtle);
  }

  .table-wrapper tbody td,
  .table-wrapper tfoot td {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
  }

  .table-wrapper td:nth-child(2)::before { content: var(--label-2, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(3)::before { content: var(--label-3, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(4)::before { content: var(--label-4, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(5)::before { content: var(--label-5, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(6)::before { content: var(--label-6, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(7)::before { content: var(--label-7, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(8)::before { content: var(--label-8, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(9)::before { content: var(--label-9, "") ": "; font-weight: 600; color: var(--ink-secondary); }
  .table-wrapper td:nth-child(10)::before { content: var(--label-10, "") ": "; font-weight: 600; color: var(--ink-secondary); }
}

/* --- Native Modal Dialogs (modern-web-guidance: dialog & light-dismiss-a-dialog) --- */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-md);
}

/* Never set display on dialog unconditionally — scope to dialog[open] */
dialog[open] {
  display: flex;
  flex-direction: column;
}

/* MANDATORY (both rules): prevent page scrolling under modal dialog */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgb(8 16 11 / 0.58);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-block-end: 1px solid var(--border-subtle);
}

/* Level-1 heading inside modal dialog per accessibility guidance */
.dialog-head h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.dialog-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-block-start: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 520px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- KPI Cards, ToR Cards, Export Cards --- */
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.kpi-name {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.tor-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-block-end: 14px;
}

.tor-deliverables {
  margin: 8px 0 12px;
  padding-inline-start: 20px;
  font-size: 13px;
  color: var(--ink-secondary);
}

.tor-deliverables li {
  margin-block-end: 4px;
}

.quote-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-block: 10px 12px;
}

@media (min-width: 720px) {
  .quote-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.quote-box {
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.export-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.more-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Live Toast */
.toast-bar {
  position: fixed;
  inset-block-end: calc(var(--bottom-nav-height) + 12px);
  inset-inline: 16px;
  z-index: 80;
  max-width: 480px;
  margin-inline: auto;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-header);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

.toast-bar[hidden] {
  display: none;
}

@media (min-width: 960px) {
  .toast-bar {
    inset-block-end: 20px;
    inset-inline-start: auto;
    inset-inline-end: 24px;
  }
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.text-danger {
  color: var(--danger-ink);
  font-weight: 700;
}

.text-brand {
  color: var(--brand-ink);
  font-weight: 700;
}

.text-amber {
  color: var(--amber-ink);
  font-weight: 700;
}

.alert-inline {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-block-end: 12px;
}
