@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=Space+Grotesk:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --font-sans: "Space Grotesk", "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
  --bg: #f4f1ea;
  --bg-contrast: #efe7da;
  --surface: #ffffff;
  --surface-muted: #fbfaf7;
  --ink: #1f2933;
  --ink-soft: #3f4c59;
  --muted: #6b7280;
  --border: #e2e0d8;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #d97706;
  --accent-soft: #f3cf93;
  --success: #16a34a;
  --danger: #b91c1c;
  --shadow: 0 16px 40px -32px rgba(17, 24, 39, 0.45);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --grid-gap: 24px;
  --glow: 0 0 0 2px rgba(15, 118, 110, 0.1), 0 20px 40px -30px rgba(15, 118, 110, 0.5);
}

.theme-oasis {
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #d97706;
  --accent-soft: #f3cf93;
}

.theme-graphite {
  --bg: #f1f4f8;
  --bg-contrast: #e4ebf4;
  --surface: #ffffff;
  --surface-muted: #f9fbfd;
  --ink: #1d2733;
  --ink-soft: #334155;
  --muted: #64748b;
  --border: #d8e1ec;
  --primary: #1d4ed8;
  --primary-strong: #1e3a8a;
  --accent: #d97706;
  --accent-soft: #f5d1a6;
  --success: #15803d;
  --danger: #b91c1c;
  --glow: 0 0 0 2px rgba(29, 78, 216, 0.1), 0 18px 40px -24px rgba(29, 78, 216, 0.35);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--ink);
  background: radial-gradient(circle at 10% 20%, var(--bg-contrast), var(--bg) 45%);
  line-height: 1.55;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.page {
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--glow);
}

/* Organization Switcher */
.org-switcher {
  position: relative;
}

.org-switcher-btn {
  display: flex;
  align-items: center;
  background: transparent;
  border: none;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}

.org-switcher-btn:hover {
  color: var(--primary);
}

.org-switcher-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 100;
  overflow: hidden;
}

.org-switcher-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.org-switcher-item:hover {
  background: var(--bg-contrast);
}

.org-switcher-item.active {
  background: var(--bg-contrast);
  color: var(--primary);
  font-weight: 500;
  cursor: default;
}

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

.org-switcher-item.manage {
  color: var(--ink-soft);
  font-size: 0.9em;
  justify-content: flex-start;
}

.org-switcher-item.manage:hover {
  color: var(--ink);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-weight: 500;
}

.nav a {
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--ink-soft);
  transition: all 0.2s ease;
}

.nav a.active,
.nav a:hover {
  background: var(--bg-contrast);
  color: var(--ink);
}

.nav-secondary {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  gap: 8px;
  font-size: 0.9rem;
}

.nav-secondary a {
  padding: 8px 14px;
  opacity: 0.7;
}

.nav-secondary a:hover,
.nav-secondary a.active {
  opacity: 1;
}

.sidebar-footer {
  padding: 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(217, 119, 6, 0.16));
  font-size: 0.92rem;
}

.content {
  padding: 32px 40px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -8px 0 24px;
}

.subnav a {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-weight: 600;
  transition: all 0.2s ease;
}

.subnav a.active,
.subnav a:hover {
  border-color: var(--primary);
  color: var(--ink);
  box-shadow: var(--glow);
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn {
  border: 0;
  cursor: pointer;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #ffffff;
  box-shadow: var(--glow);
}

.btn-secondary {
  background: var(--bg-contrast);
  color: var(--ink);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.grid {
  display: grid;
  gap: var(--grid-gap);
}

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

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

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-contrast);
  color: var(--ink-soft);
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}

.badge {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.badge.status {
  background: var(--bg-contrast);
  color: var(--ink-soft);
}

.badge.status.invoiced {
  background: rgba(245, 158, 11, 0.2);
  color: rgb(245, 158, 11);
}

.badge.status.received {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.badge.status.lost {
  background: rgba(185, 28, 28, 0.12);
  color: var(--danger);
}

.badge.status.written {
  background: rgba(100, 116, 139, 0.16);
  color: #475569;
}

.badge.warning {
  background: rgba(217, 119, 6, 0.12);
  color: var(--accent);
}

.badge.danger {
  background: rgba(185, 28, 28, 0.12);
  color: var(--danger);
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-contrast);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0;
  max-width: 100%;
}

.progress-bar.success {
  background: linear-gradient(90deg, var(--success), var(--primary));
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

.chart {
  height: 220px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: repeating-linear-gradient(
    120deg,
    rgba(15, 118, 110, 0.08),
    rgba(15, 118, 110, 0.08) 12px,
    transparent 12px,
    transparent 24px
  );
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}

.table th {
  color: var(--muted);
  font-weight: 600;
}

.pill {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
}

.pill.filter {
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s ease;
}

.pill.filter:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.pill.filter.active {
  border-color: var(--primary);
  box-shadow: var(--glow);
}

.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.pill.invoiced::before {
  background: rgb(245, 158, 11);
}

.pill.received::before {
  background: var(--success);
}

.pill.lost::before {
  background: var(--danger);
}

.pill.written::before {
  background: #64748b;
}

.form {
  display: grid;
  gap: 16px;
}

.form label {
  font-size: 0.9rem;
  font-weight: 600;
}

.form-control {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

/* Autocomplete Dropdown */
.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow-y: auto;
  z-index: 100;
  margin-top: 4px;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: var(--surface-muted);
}

.autocomplete-item.autocomplete-create {
  background: var(--bg);
  font-weight: 500;
}

.autocomplete-item.autocomplete-create:hover {
  background: var(--bg-contrast);
}

.panel {
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.45);
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  width: min(720px, 100%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  transform: translateY(8px);
  transition: transform 0.2s ease;
}

.modal.open .modal-panel {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-close {
  border: 0;
  background: var(--bg-contrast);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 700;
  cursor: pointer;
}

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

.link {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

.stagger > * {
  animation: fadeUp 0.6s ease both;
}

.stagger > *:nth-child(2) {
  animation-delay: 0.08s;
}

.stagger > *:nth-child(3) {
  animation-delay: 0.16s;
}

.stagger > *:nth-child(4) {
  animation-delay: 0.24s;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-secondary {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .content {
    padding: 24px;
  }

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

@media (max-width: 860px) {
  /* High specificity to win cascade - force single column */
  .grid.grid-3,
  .grid.grid-2,
  section.grid-3,
  section.grid-2,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr !important;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Utility classes */
.capitalize {
  text-transform: capitalize;
}

/* Alert component */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.alert.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

.alert ul {
  margin: 0;
  padding-left: 20px;
}

.alert li {
  margin: 4px 0;
}

/* Checkbox row for forms */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.checkbox-row label {
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 0;
}

/* Checkbox group (touch-friendly multi-select) */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 160px;
  overflow-y: auto;
}

.checkbox-group .checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 0;
  transition: background-color 0.15s;
}

.checkbox-group .checkbox-item:hover {
  background: var(--bg-contrast);
}

.checkbox-group .checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  margin: 0;
}

/* Responsive table wrapper */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive .table {
  min-width: auto;
}

/* Multi-select chips (mobile-friendly alternative) */
.chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 44px;
}

.chip-select .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  font-size: 13px;
}

.chip-select .chip button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}

/* Improved empty state */
.empty-state {
  text-align: center;
  padding: 32px 16px;
}

.empty-state p {
  color: var(--muted);
  margin-bottom: 16px;
}

/* Tabs component - matches subnav style */
.tabs {
  width: 100%;
}

.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.tab-btn {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  border-color: var(--primary);
  color: var(--ink);
}

.tab-btn.active {
  border-color: var(--primary);
  color: var(--ink);
  box-shadow: var(--glow);
}

.tab-content {
  animation: fadeIn 0.3s ease;
}

.tab-content:not(.active) {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Progress bar */
.progress {
  width: 100%;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* Widget grid */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--grid-gap);
}

.widget-grid .widget-large {
  grid-column: span 2;
}

@media (max-width: 860px) {
  .widget-grid {
    grid-template-columns: 1fr;
  }

  .widget-grid .widget-large {
    grid-column: span 1;
  }
}

/* Widget cards */
.widget-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.widget-card.widget-hidden {
  opacity: 0.6;
}

.widget-ghost {
  opacity: 0.4;
  background: var(--bg-contrast);
}

.widget-chosen {
  box-shadow: var(--glow);
}

.widget-drag {
  opacity: 0.9;
}

.widget-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--surface-muted);
  border-radius: 6px;
  cursor: grab;
  transition: background 0.2s ease;
}

.widget-handle:hover {
  background: var(--bg-contrast);
}

.widget-handle:active {
  cursor: grabbing;
}

.widget-content {
  margin-top: 16px;
}

.widget-disabled {
  opacity: 0.5;
}

/* Toggle switch */
.widget-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.widget-toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
}

.widget-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  transition: 0.2s;
  border-radius: 24px;
}

.widget-toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.widget-toggle-input:checked + .widget-toggle-slider {
  background-color: var(--primary);
}

.widget-toggle-input:checked + .widget-toggle-slider:before {
  transform: translateX(20px);
}

/* Widget controls */
.widget-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.widget-size-btn {
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.widget-hidden-card {
  opacity: 0.5;
  border-style: dashed;
}

/* Table responsive wrapper */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-contrast);
  color: var(--muted);
}

.tag-success {
  background: rgba(22, 163, 74, 0.15);
  color: var(--success);
}

/* ========================================
   MOBILE RESPONSIVE ENHANCEMENTS
   ======================================== */

/* Tablet breakpoint */
@media (max-width: 768px) {
  /* Force all grids to single column - HIGH SPECIFICITY to win cascade */
  .grid.grid-3,
  .grid.grid-2,
  section.grid-3,
  section.grid-2,
  .grid-3,
  .grid-2,
  .grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Also target by attribute for inline styles */
  [class*="grid-3"],
  [class*="grid-2"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Force inline grids to single column */
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns: repeat(2"],
  [style*="grid-template-columns:repeat(2"] {
    grid-template-columns: 1fr !important;
  }

  /* Topbar */
  .topbar .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .topbar .actions .btn {
    flex: 1;
    min-width: 100px;
    text-align: center;
  }

  /* Tab nav */
  .tab-nav {
    gap: 8px;
  }

  .tab-btn {
    padding: 10px 12px;
    min-height: 44px;
  }

  /* Subnav */
  .subnav a {
    padding: 10px 14px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Modal */
  .modal-panel {
    width: 95%;
    max-width: none;
    margin: 16px;
    max-height: calc(100vh - 32px);
  }

  /* Form controls - 16px prevents iOS zoom */
  .form-control {
    min-height: 44px;
    font-size: 16px;
  }

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

  /* Buttons */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  .btn-secondary {
    min-height: 40px;
  }

  /* Table actions */
  .table-row-action {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .table-row-action .btn {
    min-width: 70px;
    padding: 8px 12px;
  }

  /* Card header */
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  /* KPI cards */
  .kpi-value {
    font-size: 1.8rem;
    word-break: break-word;
  }

  /* Content padding */
  .content {
    padding: 20px 16px 32px;
  }

  /* Filter forms - force stacking */
  .form [style*="display: flex"][style*="gap"] {
    flex-direction: column !important;
  }

  .form [style*="display: flex"] > div[style*="min-width"] {
    min-width: 100% !important;
    width: 100% !important;
  }

  .form [style*="display: flex"] > div[style*="flex: 1"] {
    flex: none !important;
    width: 100% !important;
  }
}

/* Mobile phone breakpoint */
@media (max-width: 480px) {
  /* All inline grids stack to single column */
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns: repeat(2"],
  [style*="grid-template-columns:repeat(2"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Page title size */
  .page-title {
    font-size: 1.5rem;
  }

  /* Topbar stacking */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .topbar .actions {
    flex-direction: column;
  }

  .topbar .actions .btn {
    width: 100%;
  }

  /* Sidebar mobile - horizontal scroll nav */
  .sidebar {
    padding: 12px 16px;
    gap: 12px;
    overflow-x: auto;
  }

  .logo {
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  .nav {
    gap: 8px;
  }

  .nav a {
    padding: 10px 12px;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  /* Cards - better mobile padding */
  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .card-title {
    font-size: 1rem;
  }

  /* KPI cards - compact mobile layout */
  .kpi {
    gap: 10px;
  }

  .kpi-value {
    font-size: 1.4rem;
    line-height: 1.2;
  }

  .kpi-meta {
    font-size: 0.8rem;
    gap: 6px;
  }

  .kpi-meta .badge {
    font-size: 0.7rem;
    padding: 3px 8px;
  }

  /* Card inside grid - make them look better */
  .grid .card,
  .grid-2 .card,
  .grid-3 .card {
    margin-bottom: 0;
  }

  /* Dashboard stat boxes */
  [style*="display: grid"] > div[style*="text-align: center"] {
    padding: 12px !important;
  }

  [style*="display: grid"] > div[style*="text-align: center"] > div[style*="font-size: 1.5rem"] {
    font-size: 1.2rem !important;
  }

  /* Modal full-screen on mobile */
  .modal-panel {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  .modal-header {
    flex-shrink: 0;
  }

  .modal-panel .form {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 100px; /* Space for sticky actions */
  }

  .modal-panel .actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding: 16px;
    margin: 0 -16px -16px;
    border-top: 1px solid var(--border);
    flex-direction: column;
    gap: 8px;
  }

  .modal-panel .actions .btn {
    width: 100%;
  }

  /* Table mobile layout */
  .table thead {
    display: none;
  }

  .table tbody tr {
    display: block;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }

  .table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid var(--border);
  }

  .table tbody td:last-child {
    border-bottom: none;
    padding-top: 12px;
  }

  .table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--ink-soft);
    font-size: 0.85rem;
  }

  .table-row-action {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
  }

  /* Empty state */
  .empty-state {
    padding: 24px 16px;
  }

  /* List items */
  .list li {
    padding: 12px 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .list li span:last-child {
    font-size: 1.1rem;
    font-weight: 600;
  }

  /* Progress bars */
  .progress {
    height: 20px;
  }

  /* Form layouts */
  .form > div {
    margin-bottom: 16px;
  }

  /* Filter section improvements */
  [style*="display: flex"][style*="gap: 12px"] {
    flex-direction: column !important;
  }

  /* Legend items wrap better */
  [style*="display: flex"][style*="gap: 16px"][style*="font-size: 0.8"] {
    flex-wrap: wrap;
  }

  /* Pagination mobile */
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .pagination a,
  .pagination span {
    min-width: 40px;
    min-height: 40px;
    padding: 8px;
  }
}

/* Fix for iOS Safari - prevent zoom on input focus */
@media screen and (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Ensure touch targets are large enough */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .nav a,
  .tab-btn,
  .subnav a {
    min-height: 44px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
  }
}

/* =====================================================
   MOBILE BOTTOM TAB BAR
   ===================================================== */
.mobile-tab-bar {
  display: none;
}

@media (max-width: 768px) {
  /* Hide sidebar on mobile */
  .sidebar {
    display: none !important;
  }

  /* Full width content on mobile */
  .layout.page {
    grid-template-columns: 1fr !important;
  }

  /* Show bottom tab bar */
  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
    justify-content: space-around;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  }

  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.2s;
    min-width: 60px;
  }

  .mobile-tab svg {
    width: 22px;
    height: 22px;
  }

  .mobile-tab.active {
    color: var(--primary);
  }

  .mobile-tab:hover {
    color: var(--primary);
  }

  /* Add padding to content for bottom bar */
  .content {
    padding-bottom: 100px !important;
  }
}

/* =====================================================
   FINAL MOBILE GRID OVERRIDE - HIGHEST PRIORITY
   This MUST be at the end of the file to win cascade
   ===================================================== */
@media (max-width: 900px) {
  /* All grid variants - maximum specificity */
  section.grid.grid-4,
  section.grid.grid-3,
  section.grid.grid-2,
  section.grid-4,
  section.grid-3,
  section.grid-2,
  .grid.grid-4,
  .grid.grid-3,
  .grid.grid-2,
  .grid-4,
  .grid-3,
  .grid-2 {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Also catch grids with stagger class */
  .grid.grid-3.stagger,
  .grid.grid-2.stagger,
  .grid-3.stagger,
  .grid-2.stagger {
    grid-template-columns: 1fr !important;
  }

  /* Override any inline grid styles */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* =====================================================
   MARKETING / LANDING PAGE STYLES
   ===================================================== */

.marketing-page {
  background: radial-gradient(circle at 10% 20%, var(--bg-contrast), var(--bg) 45%);
}

/* Marketing Header */
.marketing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 0;
  max-width: 1200px;
  margin: 0 auto;
}

.marketing-nav {
  display: flex;
  gap: 32px;
  font-weight: 500;
}

.marketing-nav a {
  color: var(--ink-soft);
  transition: color 0.2s;
}

.marketing-nav a:hover {
  color: var(--ink);
}

.marketing-header-actions {
  display: flex;
  gap: 12px;
}

/* Hero Section */
.marketing-hero {
  padding: 0 24px 80px;
}

.hero-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  align-items: center;
  max-width: 1200px;
  margin: 48px auto 0;
}

.hero-copy {
  max-width: 560px;
}

.eyebrow {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.hero-copy h1 {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 24px;
  letter-spacing: -0.02em;
}

.hero-copy .lead {
  font-size: 1.2rem;
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 32px;
}

.hero-cta {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.btn-large {
  padding: 14px 28px;
  font-size: 1rem;
}

.trust-line {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Hero Visual - Mock Dashboard */
.hero-visual {
  display: flex;
  justify-content: center;
}

.mock-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 400px;
}

.mock-card {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border);
}

.mock-card.wide {
  grid-column: span 2;
}

.mock-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mock-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.mock-dot.accent {
  background: var(--accent);
}

.mock-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.mock-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.mock-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-contrast);
  color: var(--ink-soft);
}

.mock-badge.success {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.mock-progress {
  height: 8px;
  background: var(--bg-contrast);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.mock-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
}

.mock-progress-label {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Social Proof */
.marketing-proof {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 32px 24px;
}

.proof-content {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto;
}

.proof-item {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.proof-divider {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}

/* Features Section */
.marketing-features {
  padding: 80px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 48px;
}

.section-header h2 {
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.section-subtitle {
  color: var(--muted);
  font-size: 1.1rem;
  margin: 0;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.feature-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 24px 48px -24px rgba(17, 24, 39, 0.25);
}

.feature-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.1), rgba(15, 118, 110, 0.05));
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  color: var(--primary);
}

.feature-icon.accent {
  background: linear-gradient(135deg, rgba(217, 119, 6, 0.1), rgba(217, 119, 6, 0.05));
  color: var(--accent);
}

.feature-card h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 12px;
}

.feature-card p {
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.6;
}

/* Value Section */
.marketing-value {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 80px 24px;
}

.value-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  align-items: center;
}

.value-copy h2 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 16px;
  line-height: 1.3;
}

.value-copy p {
  color: var(--ink-soft);
  font-size: 1.1rem;
  margin: 0;
  line-height: 1.6;
}

.value-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.stat-card {
  text-align: center;
  padding: 24px 16px;
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Steps Section */
.marketing-steps {
  padding: 80px 24px;
  max-width: 800px;
  margin: 0 auto;
}

.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.step-item {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.step-number {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--glow);
}

.step-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.step-content p {
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.6;
}

/* CTA Section */
.marketing-cta {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  padding: 80px 24px;
  text-align: center;
}

.cta-content {
  max-width: 600px;
  margin: 0 auto;
}

.cta-content h2 {
  color: white;
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 16px;
}

.cta-content > p {
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.1rem;
  margin: 0 0 32px;
  line-height: 1.6;
}

.cta-content .btn-primary {
  background: white;
  color: var(--primary-strong);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.cta-content .btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.cta-note {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  margin: 24px 0 0;
}

/* Footer */
.marketing-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 64px 24px 32px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 64px;
}

.footer-brand p {
  color: var(--muted);
  margin: 16px 0 0;
}

.footer-links {
  display: flex;
  gap: 64px;
}

.footer-column h4 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 16px;
}

.footer-column a {
  display: block;
  color: var(--ink-soft);
  margin-bottom: 12px;
  transition: color 0.2s;
}

.footer-column a:hover {
  color: var(--ink);
}

.footer-bottom {
  max-width: 1200px;
  margin: 48px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.footer-bottom p {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* Marketing Responsive */
@media (max-width: 900px) {
  .hero-content {
    grid-template-columns: 1fr;
    gap: 48px;
    text-align: center;
  }

  .hero-copy {
    max-width: 100%;
  }

  .hero-copy h1 {
    font-size: 2.2rem;
  }

  .hero-cta {
    justify-content: center;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }

  .value-content {
    grid-template-columns: 1fr;
    gap: 48px;
    text-align: center;
  }

  .value-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .footer-content {
    grid-template-columns: 1fr;
    gap: 48px;
  }
}

@media (max-width: 600px) {
  .marketing-header {
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
  }

  .marketing-nav {
    display: none;
  }

  .hero-copy h1 {
    font-size: 1.8rem;
  }

  .hero-cta {
    flex-direction: column;
  }

  .btn-large {
    width: 100%;
  }

  .mock-dashboard {
    max-width: 100%;
  }

  .proof-content {
    flex-direction: column;
    gap: 16px;
  }

  .proof-divider {
    display: none;
  }

  .section-header h2 {
    font-size: 1.6rem;
  }

  .value-stats {
    grid-template-columns: 1fr;
  }

  .step-item {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .footer-links {
    flex-direction: column;
    gap: 32px;
  }
}

/* =====================================================
   UTILITY CLASSES
   ===================================================== */

.hidden {
  display: none !important;
}

/* Health score weight validation */
.weight-valid {
  background: rgba(22, 163, 74, 0.15) !important;
  color: var(--success) !important;
}

.weight-invalid {
  background: rgba(185, 28, 28, 0.15) !important;
  color: var(--danger) !important;
}

