:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --sidebar: #111827;
  --sidebar-muted: #9ca3af;
  --sidebar-active: #1f2937;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eff6ff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --border: #e5e7eb;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(17, 24, 39, .04);
  --shadow: 0 4px 12px rgba(17, 24, 39, .06), 0 12px 32px rgba(17, 24, 39, .05);
  --shadow-lg: 0 8px 24px rgba(17, 24, 39, .08), 0 24px 56px rgba(17, 24, 39, .06);
  --focus: 0 0 0 4px rgba(37, 99, 235, .14);
  /* Typography scale */
  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;
  --text-3xl: 2.375rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.7;
  --surface-hover: #f3f4f6;
  --surface-alt: #f1f5f9;
}

[data-theme="dark"] {
  --bg: #0b0b12;
  --surface: #14141d;
  --surface-soft: #14141d;
  --sidebar: #08080c;
  --sidebar-muted: #7a7a8a;
  --sidebar-active: #1c1c28;
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --primary-soft: #1a1a2e;
  --text: #e6e6ed;
  --muted: #7a7a8a;
  --line: #28283a;
  --border: #28283a;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow: 0 4px 12px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .45);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .55), 0 24px 56px rgba(0, 0, 0, .45);
  --focus: 0 0 0 4px rgba(59, 130, 246, .25);
  --surface-hover: #1e1e2c;
  --surface-alt: #1a1a2a;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  color-scheme: light;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #c1c1c1 #f1f1f1;
}

html[data-theme="dark"] {
  color-scheme: dark;
  scrollbar-color: #3a3a4e #1e1e2c;
}

/* ── Scrollbar (Webkit) ── */
html::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
html::-webkit-scrollbar-track {
  background: #f1f1f1;
}
html::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}
html::-webkit-scrollbar-thumb:hover {
  background: #a1a1a1;
}
html[data-theme="dark"]::-webkit-scrollbar-track {
  background: #1e1e2c;
}
html[data-theme="dark"]::-webkit-scrollbar-thumb {
  background: #3a3a4e;
  border-radius: 4px;
}
html[data-theme="dark"]::-webkit-scrollbar-thumb:hover {
  background: #4a4a5e;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

.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;
}

button,
input,
textarea,
select {
  font: inherit;
  min-width: 0;
}

button { border: 0; }

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input::placeholder,
textarea::placeholder { color: #9ca3af; }

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

select {
  color: var(--text);
  color-scheme: light;
  appearance: auto;
  background-color: var(--surface);
}

select option {
  background: var(--surface);
  color: var(--text);
}

/* ── Autofill override ── */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
  border: 1px solid var(--line);
}

/* ── Checkbox & Radio ── */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
  color-scheme: light;
  min-height: 0;
  width: auto;
  box-shadow: none;
}
[data-theme="dark"] input[type="checkbox"],
[data-theme="dark"] input[type="radio"] {
  color-scheme: dark;
}

/* ── Number input ── */
input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 0.7;
  height: 28px;
  cursor: pointer;
}
[data-theme="dark"] input[type="number"]::-webkit-inner-spin-button,
[data-theme="dark"] input[type="number"]::-webkit-outer-spin-button {
  filter: invert(0.85);
}

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

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

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafb;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.muted,
.product-card span {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.btn,
button.btn {
  display: inline-flex;
  width: auto;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--primary);
  color: #ffffff;
  padding: 10px 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(37, 99, 235, .22);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease, color .18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: var(--primary-strong);
  box-shadow: 0 16px 32px rgba(37, 99, 235, .28);
}

.btn:focus-visible,
.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn.ghost,
.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.btn.ghost:hover,
.btn.secondary:hover {
  color: var(--primary);
  border-color: #bfdbfe;
  background: var(--primary-soft);
  box-shadow: var(--shadow);
}

.btn.small {
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13px;
}

.danger-btn,
.btn.danger {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
  box-shadow: 0 10px 22px rgba(220, 38, 38, .20);
}

.danger-btn:hover,
.btn.danger:hover {
  background: #b91c1c;
  color: #ffffff;
  box-shadow: 0 16px 32px rgba(220, 38, 38, .25);
}

.icon-btn {
  width: 42px;
  min-width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, color .18s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  color: var(--primary);
  border-color: #bfdbfe;
  box-shadow: var(--shadow);
}

/* ── Theme toggle ── */
.theme-toggle {
  font-size: 1.25rem;
  line-height: 1;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
.theme-toggle:hover {
  color: var(--warning);
  border-color: #fde68a;
  background: var(--surface);
}
[data-theme="dark"] .theme-toggle:hover {
  color: var(--warning);
  border-color: #713f12;
}

.panel,
.form-card,
.auth-card,
.product-card,
.metric,
.hero-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.panel:hover,
.form-card:hover,
.metric:hover,
.product-card:hover {
  transform: translateY(-2px);
  border-color: #d1d5db;
  box-shadow: var(--shadow);
}

.panel {
  min-width: 0;
  padding: 26px;
}

.panel.wide { grid-row: span 2; }

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

.panel-head h2,
.form-card h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.app-shell {
  display: block;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 280px;
  max-width: calc(100vw - 32px);
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px 16px;
  overflow-y: auto;
  background: var(--sidebar);
  color: #f9fafb;
  border-right: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 8px 0 28px rgba(17, 24, 39, .18);
}

.brand {
  color: var(--primary);
  font-weight: 850;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 10px 12px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 850;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  box-shadow: 0 12px 28px rgba(37, 99, 235, .35);
}

.sidebar a:not(.brand) {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 11px;
  color: var(--sidebar-muted);
  font-size: 14px;
  font-weight: 650;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.sidebar a:not(.brand):hover {
  transform: translateX(2px);
  color: #ffffff;
  background: rgba(255, 255, 255, .08);
}

.sidebar a.active {
  color: #ffffff;
  background: var(--sidebar-active);
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, .07);
  color: #d1d5db;
  font-size: 14px;
  font-weight: 850;
}

.sidebar a.active .nav-icon,
.sidebar a:hover .nav-icon {
  background: rgba(37, 99, 235, .22);
  color: #ffffff;
}

.nav-section-label {
  list-style: none;
  padding: 16px 12px 4px;
  color: rgba(255, 255, 255, .35);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.workspace {
  min-width: 0;
  padding: 28px;
  margin-left: 280px;
  transition: margin .22s ease;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  min-height: 76px;
  margin: -28px -28px 32px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1.15;
  font-weight: 850;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-grid.advanced {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 24px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 12px;
  color: var(--text);
  font-size: 29px;
  line-height: 1;
  font-weight: 850;
}

.metric.success strong { color: var(--success); }
.metric.danger strong { color: var(--danger); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, .9fr);
  gap: 18px;
  align-items: start;
}

.split-grid,
.detail-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.feed-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.feed-row:last-child { border-bottom: 0; }

.feed-row small {
  color: var(--muted);
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  color: #1d4ed8;
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.status-badge.success,
.status-badge.approved,
.status-badge.won,
.status-badge.paid {
  color: #166534;
  background: #dcfce7;
}

.status-badge.warning,
.status-badge.partial,
.status-badge.tracking,
.status-badge.sent {
  color: #92400e;
  background: #fef3c7;
}

.status-badge.danger,
.status-badge.rejected,
.status-badge.lost,
.status-badge.overdue,
.status-badge.cancelled {
  color: #991b1b;
  background: #fee2e2;
}

.toast-stack {
  position: fixed;
  right: 18px;
  top: 92px;
  z-index: 50;
  display: grid;
  gap: 10px;
}

.toast {
  padding: 13px 15px;
  border-radius: var(--radius);
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  transition: opacity .2s ease, transform .2s ease;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  border: 1px dashed #d1d5db;
  border-radius: var(--radius);
  background: var(--surface-soft);
  text-align: center;
}

.action-menu {
  position: relative;
  width: max-content;
  overflow: visible;
}

.action-menu summary {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #ffffff;
  padding: 7px 11px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  list-style: none;
}

.action-menu summary::-webkit-details-marker { display: none; }

.action-menu[open] summary {
  color: var(--primary);
  border-color: #bfdbfe;
}

.action-menu > div {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 9999;
  min-width: 160px;
  display: grid;
  gap: 2px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  box-shadow: var(--shadow-lg);
}

.action-menu a,
.action-menu button {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.action-menu a:hover,
.action-menu button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.action-menu form {
  margin: 0;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 24, 39, .48);
}

.confirm-modal[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow-lg);
}

.confirm-dialog h2,
.confirm-dialog p {
  margin: 0;
}

.confirm-dialog p {
  color: var(--muted);
  line-height: 1.6;
}

canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

.chart-frame {
  position: relative;
  width: 100%;
  min-width: 0;
  height: clamp(260px, 36vw, 380px);
  max-height: 420px;
  overflow: hidden;
}

.chart-frame-small {
  height: clamp(240px, 28vw, 320px);
  max-height: 350px;
}

.chart-frame canvas {
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  max-height: 100%;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
}

.section,
.page-hero,
.card-grid,
.form-page,
.metric-row,
.detail-grid {
  padding: 56px 6vw;
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 0 6vw;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.site-nav nav {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.hero {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  align-items: center;
  gap: 34px;
  padding: 7vh 6vw;
}

.hero-copy h1,
.page-hero h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(42px, 7vw, 86px);
  line-height: .98;
  letter-spacing: 0;
  font-weight: 800;
}

.hero-copy p,
.page-hero p {
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.hero-panel { padding: 28px; }
.hero-panel h2 { font-size: 30px; line-height: 1.15; }

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.product-card { padding: 20px; }
.product-card h3 { min-height: 54px; }

.metric-row,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.metric-row div,
.detail-grid div {
  display: grid;
  gap: 4px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.metric-row strong,
.detail-grid strong {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.metric-row span,
.metric-row a,
.detail-grid span,
.detail-grid a {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.metric-row .status-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
}

.form-page {
  display: grid;
  grid-template-columns: minmax(0, .75fr) minmax(320px, 1fr);
  gap: 28px;
  align-items: start;
}

.form-card { display: grid; gap: 24px; padding: 28px; }

.searchbar,
.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.searchbar input,
.filters select { flex: 1; }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 6vw;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.customer-portal-footer {
  display: grid;
  grid-template-columns: minmax(240px, .65fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: stretch;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.customer-portal-footer h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.customer-portal-footer iframe {
  width: 100%;
  height: clamp(220px, 30vw, 320px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #e5e7eb;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

body.sidebar-collapsed .workspace {
  margin-left: 0;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(17, 24, 39, .42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

@media (min-width: 1280px) {
  .workspace {
    padding: 32px;
  }

  .topbar {
    margin: -32px -32px 32px;
    padding: 18px 32px;
  }
}

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

  .panel.wide {
    grid-row: auto;
  }
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
  }

  body:not(.sidebar-collapsed) .sidebar {
    transform: translateX(0);
  }

  body:not(.sidebar-collapsed) .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .workspace {
    margin-left: 0;
    padding: 22px;
  }

  .topbar {
    margin: -22px -22px 22px;
    padding: 16px 22px;
  }

  .hero,
  .form-page,
  .split-grid,
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .topbar-actions .btn {
    min-height: 38px;
    padding-inline: 12px;
  }
}

@media (max-width: 768px) {
  .panel,
  .form-card,
  .auth-card,
  .metric {
    border-radius: 12px;
    padding: 18px;
  }

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

  .quick-actions,
  .form-actions,
  .filters,
  .searchbar {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-actions .btn,
  .form-actions .btn,
  .filters .btn,
  .searchbar .btn {
    width: 100%;
  }

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

@media (max-width: 640px) {
  .workspace { padding: 16px; }
  .topbar {
    margin: -16px -16px 16px;
    padding: 14px 16px;
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }
  .topbar h1 { font-size: 24px; }
  .metric-grid,
  .metric-grid.advanced { grid-template-columns: 1fr; }
  .topbar-actions {
    width: 100%;
  }
  .topbar-actions .icon-btn {
    margin-right: auto;
  }
  .topbar-actions .btn {
    flex: 1;
  }
  .site-nav { align-items: flex-start; flex-direction: column; padding: 16px 5vw; }
  .hero,
  .section,
  .page-hero,
  .card-grid,
  .form-page,
  .metric-row,
  .detail-grid {
    padding-left: 5vw;
    padding-right: 5vw;
  }
  .hero-copy h1,
  .page-hero h1 { font-size: 42px; }
  .footer { flex-direction: column; align-items: flex-start; }
  .customer-portal-footer { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .workspace { padding: 12px; }
  .topbar {
    margin: -12px -12px 12px;
    padding: 12px;
  }
  .topbar-actions .btn {
    width: calc(50% - 5px);
    flex: 1 1 calc(50% - 5px);
  }
}

/* === TYPOGRAPHY UTILITIES === */
.label-sm { font-size: 13px; font-weight: 500; color: var(--muted); display: block; }
.value-lg { font-size: 20px; font-weight: 700; color: var(--text); display: block; }
.card-title { font-size: 20px; font-weight: 700; line-height: 1.3; }
.card-body { font-size: 15px; line-height: 1.6; color: var(--muted); }
.page-title { font-size: 28px; font-weight: 800; line-height: 1.2; }
.section-title { font-size: 22px; font-weight: 700; line-height: 1.3; }

/* Action cell - must allow dropdown to overflow */
td.actions-cell,
th.actions-cell {
  position: relative;
  overflow: visible;
}

/* Info card — title + description with proper spacing */
.info-card {
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}
.info-card .feature-title {
  display: block;
  margin: 0 0 12px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.info-card .feature-description {
  display: block;
  margin: 0;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.8;
  color: #64748b;
}
.info-card strong,
.info-card span {
  display: none;
}
.info-card .status-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
}
.info-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

/* ── Theme transition (applied briefly during theme switch) ── */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 220ms ease !important,
              border-color 220ms ease !important,
              color 220ms ease !important,
              box-shadow 220ms ease !important;
}

/* ── Dark mode element overrides ── */
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: var(--surface);
  color: var(--text);
  color-scheme: dark;
}
[data-theme="dark"] select option {
  background: var(--surface);
  color: var(--text);
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--muted);
}
[data-theme="dark"] th {
  background: var(--surface);
  color: var(--muted);
}
[data-theme="dark"] .btn.ghost,
[data-theme="dark"] .btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
[data-theme="dark"] .btn.ghost:hover,
[data-theme="dark"] .btn.secondary:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: #93c5fd;
}
[data-theme="dark"] .icon-btn {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
[data-theme="dark"] .icon-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}
[data-theme="dark"] .topbar {
  background: rgba(20, 20, 29, .88);
}
[data-theme="dark"] .toast {
  background: var(--surface);
}
[data-theme="dark"] .action-menu summary {
  background: var(--surface);
  border-color: var(--line);
}
[data-theme="dark"] .action-menu > div {
  background: var(--surface);
}
[data-theme="dark"] .action-menu a,
[data-theme="dark"] .action-menu button {
  background: transparent;
  color: var(--text);
}
[data-theme="dark"] .action-menu a:hover,
[data-theme="dark"] .action-menu button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}
[data-theme="dark"] .confirm-dialog {
  background: var(--surface);
}
[data-theme="dark"] .empty-state {
  border-color: var(--line);
}
[data-theme="dark"] .site-nav {
  background: rgba(20, 20, 29, .92);
}
[data-theme="dark"] .metric-row div,
[data-theme="dark"] .detail-grid div {
  background: var(--surface);
}
[data-theme="dark"] .info-card {
  background: var(--surface);
}
[data-theme="dark"] .info-card .feature-description {
  color: var(--muted);
}
[data-theme="dark"] .sidebar-overlay {
  background: rgba(0, 0, 0, .55);
}
[data-theme="dark"] .confirm-modal {
  background: rgba(0, 0, 0, .6);
}
[data-theme="dark"] .btn.danger:hover {
  background: #dc2626;
}
[data-theme="dark"] .customer-portal-footer iframe {
  background: var(--surface);
}
