/* ═══════════════════════════════════════════════════════════════════
   ZOURÌ ADMIN — shell layout and page composition (on top of arc.css)

   Breakpoints
     ≥1200   desktop: full sidebar, 4-up metrics, two-column dashboard
     961–1199 iPad landscape / small laptop: narrower sidebar, 2-up metrics,
              low-priority table columns hidden (.hide-lg)
     721–960 iPad portrait: sidebar becomes a drawer, topbar appears
     ≤720    phone: tables turn into cards, toolbars stack
   ═══════════════════════════════════════════════════════════════════ */

:root { --sidebar-w: 248px; --topbar-h: 60px; --page-pad: var(--space-8); }

/* ── App shell ───────────────────────────────────────────────────── */
.app { min-height: 100vh; min-height: 100dvh; display: flex; }
.app[hidden] { display: none; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; width: var(--sidebar-w);
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  transition: transform var(--duration-standard) var(--ease-standard), width var(--duration-standard) var(--ease-standard);
}
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); height: var(--topbar-h); padding: 0 var(--space-5) 0 var(--space-6); border-bottom: 1px solid var(--border-subtle); flex: none; }
.sidebar-brand img { height: 22px; width: auto; }
[data-theme="dark"] .sidebar-brand img { filter: invert(1); }
.sidebar-brand .brand-text { font-family: var(--font-display); font-size: var(--text-xs); color: var(--text-muted); letter-spacing: .02em; margin-left: auto; }
.sidebar-nav { padding: var(--space-4) var(--space-3); display: grid; align-content: start; gap: 2px; flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.nav-item { display: flex; align-items: center; gap: var(--space-3); min-height: 40px; padding: 0 var(--space-3); border-radius: calc(var(--radius-control) - 4px); color: var(--text-secondary); font-size: var(--text-sm); font-weight: 500; transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard); }
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .75; }
.nav-item .count { margin-left: auto; min-width: 20px; padding: 0 6px; height: 20px; display: inline-grid; place-items: center; border-radius: var(--radius-pill); background: var(--accent-subtle); color: var(--accent-strong); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }
.nav-item .count:empty { display: none; }
@media (hover: hover) and (pointer: fine) { .nav-item:hover { background: var(--surface-muted); color: var(--foreground); } }
.nav-item[aria-current="page"] { background: var(--surface-muted); color: var(--foreground); box-shadow: inset 0 0 0 1px var(--border); }
.nav-item[aria-current="page"] svg { opacity: 1; }
.sidebar-footer { padding: var(--space-3); border-top: 1px solid var(--border-subtle); display: grid; gap: var(--space-2); flex: none; }
.account { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: calc(var(--radius-control) - 4px); min-width: 0; }
.account .avatar { width: 32px; height: 32px; flex: none; border-radius: var(--radius-pill); display: grid; place-items: center; background: var(--accent); color: var(--accent-foreground); font-size: var(--text-xs); font-weight: 500; }
.account .who { min-width: 0; display: grid; }
.account .who strong { font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .who span { color: var(--text-muted); font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .row { display: flex; gap: var(--space-2); }
.sidebar-footer .row .btn { flex: 1; min-width: 0; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; overflow-x: clip; }
.topbar { display: none; }
.page { width: 100%; max-width: 1280px; margin: 0 auto; padding: var(--space-8) var(--page-pad) var(--space-16); }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-header > div:first-child { min-width: 0; }
.page-header h1 { font-size: var(--text-2xl); }
.page-header p { margin-top: var(--space-1); color: var(--text-muted); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.page-actions .select { min-width: 120px; }

/* Toolbars above tables */
.toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar .grow { flex: 1 1 260px; min-width: 0; }
.toolbar .select { flex: 0 1 180px; min-width: 150px; }
.toolbar .toolbar-date { flex: 0 1 160px; min-width: 140px; }
.toolbar .segmented { flex: none; }
.toolbar .switch { flex: none; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-3); }
.section-title h2 { font-size: var(--text-base); font-weight: 500; }

/* Grids */
.grid-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-4); }
.grid-metrics.metrics-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-metrics.secondary { margin-bottom: var(--space-6); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-4); margin-bottom: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-4); }
.stack { display: grid; gap: var(--space-4); align-content: start; }
.metric-value { overflow-wrap: anywhere; }

/* Card-header action links read as buttons, with a trailing chevron */
.card-header .btn [data-icon] svg { width: 13px; height: 13px; }
@media (max-width: 480px) { .list-row .end { flex-direction: column; align-items: flex-end; gap: 4px; } }

/* Dashboard sales card */
.sales-card { margin-bottom: var(--space-4); }
.sales-card .card-header { flex-wrap: wrap; }
.sales-meta { min-height: 1.4em; margin-bottom: var(--space-3); color: var(--text-muted); font-size: var(--text-sm); }
.sales-meta strong { color: var(--foreground); }
.segmented-sm button { min-height: 32px; min-width: 0; padding: 0 var(--space-3); font-size: var(--text-xs); }
.list-body { padding-top: var(--space-2); }

/* Chart */
.chart { position: relative; width: 100%; min-height: 200px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
.chart .bar { fill: var(--series-1); transition: opacity var(--duration-fast) var(--ease-standard); }
.chart .bar.is-empty, .chart .bar.is-future { fill: var(--surface-muted); }
.chart.has-active .bar:not(.is-active) { opacity: .4; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.chart .axis-label.is-current { fill: var(--foreground); font-weight: 500; }
.chart .gridline { stroke: var(--border-subtle); stroke-width: 1; }
.chart-empty { display: grid; place-items: center; min-height: 200px; border: 1px dashed var(--border); border-radius: var(--radius-control); color: var(--text-muted); font-size: var(--text-sm); text-align: center; padding: var(--space-6); }
.chart-tip { position: absolute; z-index: 2; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); display: grid; gap: 1px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-raised); box-shadow: var(--shadow-raised); font-size: var(--text-xs); white-space: nowrap; opacity: 0; transition: opacity var(--duration-fast) var(--ease-standard); }
.chart-tip strong { font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.chart-tip.is-visible { opacity: 1; }

/* Lists in cards */
.list { display: grid; }
.list-row { display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-2) 0; border-bottom: 1px solid var(--border-subtle); min-width: 0; }
.list-row:last-child { border-bottom: 0; }
a.list-row { border-radius: 10px; transition: background var(--duration-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) { a.list-row:hover { background: var(--surface-muted); box-shadow: -8px 0 0 var(--surface-muted), 8px 0 0 var(--surface-muted); } }
.list-row .thumb { width: 40px; height: 48px; border-radius: 10px; object-fit: cover; background: var(--surface-muted); flex: none; }
.list-row .thumb-fallback { width: 40px; height: 48px; border-radius: 10px; background: var(--surface-muted); flex: none; }
.list-row .cell-stack { min-width: 0; flex: 1; display: grid; gap: 2px; }
.list-row .cell-stack strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .cell-stack span { color: var(--text-muted); font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .value { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.list-row .end { display: flex; align-items: center; gap: var(--space-3); flex: none; }
.list-row .rank { width: 18px; flex: none; color: var(--text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.list-row .badge { flex: none; }

/* Status badge map */
.status-pending       { --badge-color: var(--warning); --badge-foreground: var(--warning); --badge-background: color-mix(in oklab, var(--warning) 11%, var(--surface)); --badge-border: color-mix(in oklab, var(--warning) 27%, var(--border)); }
.status-confirmed     { --badge-color: var(--success); --badge-foreground: var(--success); --badge-background: color-mix(in oklab, var(--success) 10%, var(--surface)); --badge-border: color-mix(in oklab, var(--success) 25%, var(--border)); }
.status-in_production { --badge-color: var(--accent); --badge-foreground: var(--accent-strong); --badge-background: var(--accent-subtle); --badge-border: color-mix(in oklab, var(--accent) 24%, var(--border)); }
.status-shipped       { --badge-color: oklch(55% .12 250); --badge-foreground: oklch(45% .12 250); --badge-background: oklch(55% .12 250 / .1); --badge-border: oklch(55% .12 250 / .3); }
.status-delivered     { --badge-color: var(--success); --badge-foreground: var(--success); --badge-background: color-mix(in oklab, var(--success) 14%, var(--surface)); --badge-border: color-mix(in oklab, var(--success) 30%, var(--border)); }
.status-cancelled     { --badge-color: var(--danger); --badge-foreground: var(--danger); --badge-background: color-mix(in oklab, var(--danger) 10%, var(--surface)); --badge-border: color-mix(in oklab, var(--danger) 26%, var(--border)); }
.status-refunded      { --badge-color: var(--text-secondary); --badge-foreground: var(--text-secondary); --badge-background: var(--surface-muted); --badge-border: var(--border); }
[data-theme="dark"] .status-shipped { --badge-foreground: oklch(80% .1 250); --badge-color: oklch(80% .1 250); }

/* Tables — shared tweaks on top of arc.css */
.table .cell-stack { max-width: 260px; }
.stock-cell { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.stock-cell .save { display: none; }
.stock-cell[data-dirty="true"] .save { display: inline-flex; }

/* Order dialog */
.order-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--space-6); }
.order-items .row { display: grid; grid-template-columns: minmax(0, 1fr) 48px 110px 110px; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle); }
.order-items .row.head { color: var(--text-muted); font-size: var(--text-xs); padding: 0 0 var(--space-2); }
.order-items .row > :not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.order-items .product { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.order-items .product img, .order-items .product .thumb-fallback { width: 44px; height: 54px; border-radius: 10px; object-fit: cover; background: var(--surface-muted); flex: none; }
.order-items .product div { min-width: 0; display: grid; gap: 2px; }
.order-items .product strong { overflow-wrap: anywhere; }
.order-items .product span { color: var(--text-muted); font-size: var(--text-xs); }
.totals { display: grid; gap: var(--space-2); padding-top: var(--space-4); }
.totals div { display: flex; justify-content: space-between; gap: var(--space-3); color: var(--text-secondary); }
.totals div strong { color: var(--foreground); font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals .grand { padding-top: var(--space-2); border-top: 1px solid var(--border); font-size: var(--text-base); color: var(--foreground); }
.detail-list { display: grid; gap: var(--space-3); }
.detail-list div { display: grid; gap: 2px; }
.detail-list span { color: var(--text-muted); font-size: var(--text-xs); }
.detail-list strong { font-weight: 400; overflow-wrap: anywhere; }
.detail-block { padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-muted); line-height: 1.6; overflow-wrap: anywhere; }
.status-editor { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.status-editor .select { flex: 1 1 180px; }
.timeline { display: flex; gap: var(--space-2) var(--space-3); flex-wrap: wrap; margin-top: var(--space-3); }
.timeline span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: var(--text-xs); }
.timeline span::before { content: ''; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border-strong); }
.timeline span.is-done { color: var(--text-secondary); } .timeline span.is-done::before { background: var(--success); border-color: var(--success); }
.timeline span.is-current { color: var(--foreground); } .timeline span.is-current::before { background: var(--accent); border-color: var(--accent); }

/* Inventory editor */
.variant-editor { display: grid; gap: var(--space-3); }
.variant-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 110px minmax(0, 120px); gap: var(--space-3); align-items: center; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-control); }
.variant-row input[type="color"] { width: 44px; height: 36px; border: 1px solid var(--border-strong); border-radius: 12px; padding: 2px; background: var(--surface); cursor: pointer; }
.variant-row .input { min-height: var(--control-height-sm); border-radius: calc(var(--radius-control) - 3px); }
.inline-note { color: var(--text-muted); font-size: var(--text-xs); }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 44fr) minmax(0, 56fr); background: var(--background); }
.login-visual { position: relative; overflow: hidden; background: var(--neutral-10); display: flex; flex-direction: column; justify-content: space-between; padding: var(--space-10); color: oklch(97% 0.004 70); }
.login-visual > picture { position: absolute; inset: 0; }
.login-visual img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center; opacity: 0; transition: opacity var(--duration-considered) var(--ease-standard); }
.login-visual img.is-loaded { opacity: 1; }
.login-visual::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, oklch(15% 0.01 70 / .35), oklch(15% 0.01 70 / .75)); }
.login-visual > :not(picture) { position: relative; z-index: 1; }
.login-visual .visual-logo { position: relative; z-index: 1; height: 26px; width: auto; align-self: flex-start; inset: auto; opacity: 1; object-fit: contain; }
.login-visual h2 { font-size: clamp(var(--text-2xl), 3.2vw, var(--text-4xl)); font-weight: 400; letter-spacing: var(--tracking-display); max-width: 14ch; }
.login-visual p { margin-top: var(--space-4); color: oklch(97% 0.004 70 / .72); max-width: 36ch; }
.login-form { display: grid; place-items: center; padding: var(--space-10) var(--space-6); }
.login-card { width: 100%; max-width: 380px; animation: content-fade-in var(--duration-considered) var(--ease-enter) both, content-rise-in var(--duration-spring) var(--ease-spring) both; }
.login-card h1 { font-size: var(--text-2xl); }
.login-card > p { margin: var(--space-2) 0 var(--space-8); color: var(--text-muted); }
.login-card .form-grid { gap: var(--space-5); }
.login-note { margin-top: var(--space-6); color: var(--text-muted); font-size: var(--text-xs); text-align: center; }
.login-error { display: none; gap: var(--space-2); margin-bottom: var(--space-5); padding: var(--space-3) var(--space-4); border: 1px solid color-mix(in oklab, var(--danger) 26%, var(--border)); border-radius: var(--radius-control); background: color-mix(in oklab, var(--danger) 8%, var(--surface)); color: var(--danger); font-size: var(--text-sm); }
.login-error.is-visible { display: flex; }
.wake-notice { display: none; margin-top: var(--space-3); color: var(--text-muted); font-size: var(--text-xs); text-align: center; }
.wake-notice.is-visible { display: block; }

/* Settings */
.settings-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-6); padding: var(--space-5) 0; border-bottom: 1px solid var(--border-subtle); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .copy { max-width: 46ch; min-width: 0; }
.settings-row .copy strong { display: block; font-weight: 500; margin-bottom: 2px; }
.settings-row .copy span { color: var(--text-muted); font-size: var(--text-sm); }
.settings-row .control { flex: none; display: flex; align-items: center; gap: var(--space-3); }
.settings-row .control .input { width: 120px; }

/* Utilities */
.muted { color: var(--text-muted); }
.right { text-align: right; }
.mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.flex { display: flex; align-items: center; gap: var(--space-2); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.m-only { display: none; }
.loading-rows { padding: var(--space-5); display: grid; gap: var(--space-3); }

/* ════════════════════════════════════════════════════════════════════
   iPad landscape / small laptops (≤1199px)
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 1199px) {
  :root { --sidebar-w: 224px; --page-pad: var(--space-6); }
  .grid-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table .hide-lg { display: none; }
  .table .cell-stack { max-width: 200px; }
  .toolbar .grow { flex-basis: 100%; }
  #inventoryTable .cell-stack strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
  #inventoryTable .edit-label { display: none; }
}

/* ════════════════════════════════════════════════════════════════════
   iPad portrait (≤960px): drawer navigation
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 960px) {
  :root { --sidebar-w: 280px; }
  .sidebar { transform: translateX(-100%); box-shadow: none; visibility: hidden; transition: transform var(--duration-standard) var(--ease-standard), visibility 0s linear var(--duration-standard); }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-floating); visibility: visible; transition: transform var(--duration-standard) var(--ease-standard), visibility 0s; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 29; background: oklch(10% 0 0 / .4); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: overlay-in var(--duration-standard) var(--ease-enter) both; }
  .sidebar-backdrop[hidden] { display: none; }
  .main { margin-left: 0; }
  .topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: var(--space-3); height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--space-4) 0; background: color-mix(in oklab, var(--background) 86%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
  .topbar img { height: 18px; justify-self: end; }
  [data-theme="dark"] .topbar img { filter: invert(1); }
  .topbar .title { font-weight: 500; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .order-grid { grid-template-columns: 1fr; }
  .table .hide-md { display: none; }

  .login { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-visual { min-height: 280px; padding: var(--space-8); }
  .login-visual h2 { font-size: var(--text-2xl); max-width: 22ch; }
  .login-visual p { display: none; }
}

/* ════════════════════════════════════════════════════════════════════
   Phones (≤720px): tables become cards with a sort strip on top
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  .table.table-cards { min-width: 0; display: block; }
  .table-cards tbody { display: block; }
  .table-cards thead { display: block; border-bottom: 1px solid var(--border); }
  .table-cards thead tr { display: flex; gap: var(--space-2); overflow-x: auto; padding: var(--space-3); scrollbar-width: none; }
  .table-cards thead tr::-webkit-scrollbar { display: none; }
  .table-cards th { display: none; }
  .table-cards th[data-sort]:not(.hide-sm, .hide-md, .hide-lg) { display: block; flex: none; height: auto; padding: 0; border: 0; background: transparent; }
  .table-cards th[data-sort] button { height: 32px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-pill); font-size: var(--text-xs); flex-direction: row !important; justify-content: center !important; color: var(--text-secondary); }
  .table-cards th[aria-sort="ascending"] button, .table-cards th[aria-sort="descending"] button { background: var(--surface-muted); border-color: var(--border-strong); color: var(--foreground); }
  .table-cards th[data-sort] .sort-icon { width: 12px; height: 12px; }

  .table-cards tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--space-3); row-gap: 6px; align-items: center; padding: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
  .table-cards tbody tr:last-child { border-bottom: 0; }
  .table.table-cards td { display: block; height: auto; padding: 0; border: 0; min-width: 0; text-align: left; background: transparent; }
  .table.table-cards td[data-end] { justify-self: end; text-align: right; }
  .table-cards td[colspan] { grid-column: 1 / -1; }
  .table-cards td[data-label]::before { content: attr(data-label) " "; color: var(--text-muted); font-size: var(--text-xs); }
  .table-cards .hide-sm, .table-cards .hide-md, .table-cards .hide-lg { display: none !important; }
  .table-cards .cell-stack { max-width: none; }
  .table-cards .cell-stack.inline-sm { display: flex; gap: 6px; align-items: baseline; }
  .table-cards .cell-stack.inline-sm strong { font-weight: 400; color: var(--text-secondary); font-size: var(--text-xs); }
  @media (hover: hover) and (pointer: fine) { .table-cards tbody tr.is-clickable:hover { background: var(--surface-muted); } }

  /* Orders: ID + status / customer + total / date */
  #ordersTable tbody tr { grid-template-areas: "order status" "customer total" "date date"; }
  #ordersTable td[data-cell="order"]    { grid-area: order; }
  #ordersTable td[data-cell="status"]   { grid-area: status; }
  #ordersTable td[data-cell="customer"] { grid-area: customer; }
  #ordersTable td[data-cell="total"]    { grid-area: total; }
  #ordersTable td[data-cell="date"]     { grid-area: date; }

  /* Inventory: product + edit / colour + price / stock + status */
  #inventoryTable tbody tr { grid-template-areas: "product actions" "colour price" "stock status"; row-gap: var(--space-3); }
  #inventoryTable td[data-cell="product"] { grid-area: product; }
  #inventoryTable td[data-cell="actions"] { grid-area: actions; }
  #inventoryTable td[data-cell="colour"]  { grid-area: colour; }
  #inventoryTable td[data-cell="price"]   { grid-area: price; }
  #inventoryTable td[data-cell="stock"]   { grid-area: stock; }
  #inventoryTable td[data-cell="status"]  { grid-area: status; }
  #inventoryTable .stock-cell { justify-content: flex-start; }

  /* Newsletter: email + delete / source + date */
  #newsletterTable tbody tr { grid-template-areas: "email actions" "source date"; }
  #newsletterTable td[data-cell="email"]   { grid-area: email; overflow-wrap: anywhere; }
  #newsletterTable td[data-cell="actions"] { grid-area: actions; }
  #newsletterTable td[data-cell="source"]  { grid-area: source; }
  #newsletterTable td[data-cell="date"]    { grid-area: date; justify-self: end; color: var(--text-secondary); font-size: var(--text-xs); }

  /* Customers: name + spent / location + orders / last order */
  #customersTable tbody tr { grid-template-areas: "name spent" "location orders" "last last"; }
  #customersTable td[data-cell="name"]     { grid-area: name; }
  #customersTable td[data-cell="spent"]    { grid-area: spent; }
  #customersTable td[data-cell="location"] { grid-area: location; }
  #customersTable td[data-cell="orders"]   { grid-area: orders; }
  #customersTable td[data-cell="last"]     { grid-area: last; color: var(--text-secondary); font-size: var(--text-xs); }

  .table-footer { flex-wrap: wrap; justify-content: center; gap: var(--space-2); padding: var(--space-3); }
}

/* ════════════════════════════════════════════════════════════════════
   Small phones (≤640px)
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root { --page-pad: var(--space-4); }
  .page { padding-top: var(--space-5); padding-bottom: calc(var(--space-12) + env(safe-area-inset-bottom)); }

  .page-header { flex-direction: column; align-items: stretch; gap: var(--space-3); margin-bottom: var(--space-5); }
  .page-header h1 { font-size: var(--text-xl); }
  .page-actions { width: 100%; flex-wrap: nowrap; }
  .page-actions > .btn:not(.btn-icon), .page-actions > .select { flex: 1 1 0; min-width: 0; }

  .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .toolbar > * { min-width: 0 !important; }
  .toolbar .grow, .toolbar .segmented, .toolbar .switch, .toolbar .span-2-sm { grid-column: 1 / -1; }
  .toolbar .segmented { width: 100%; }
  .toolbar .segmented button { flex: 1 1 0; min-width: 0; }

  .grid-metrics { gap: var(--space-3); }
  .metric { padding: var(--space-4); border-radius: var(--radius-panel); }
  .metric-top { gap: var(--space-2); margin-bottom: var(--space-3); }
  .metric-top span { min-width: 0; font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .metric-top small { padding: 2px 6px; font-size: 11px; }
  .metric-value { font-size: clamp(1.25rem, 6.2vw, 1.75rem); }
  .metric.is-compact .metric-value { font-size: clamp(1.125rem, 5.6vw, 1.5rem); }
  .metric p { margin-top: var(--space-2); font-size: var(--text-xs); }

  .card { border-radius: var(--radius-panel); }
  .card-header { flex-wrap: wrap; padding: var(--space-4) var(--space-4) 0; }
  .card-body { padding: var(--space-4); }
  .list-body { padding-top: var(--space-1); }
  .side-stack { grid-template-columns: 1fr; }
  .sales-card .segmented { width: 100%; }
  .sales-card .segmented button { flex: 1; }

  .order-items .row { grid-template-columns: minmax(0, 1fr) auto; }
  .order-items .row > :nth-child(2), .order-items .row > :nth-child(3) { display: none; }
  .m-only { display: inline; }

  .variant-row { grid-template-columns: 44px minmax(0, 1fr); }
  .variant-row > :nth-child(3) { grid-column: 2; }
  .variant-row > :nth-child(4) { grid-column: 1 / -1; text-align: left; }
  .variant-row > :nth-child(4):empty, .variant-row > :nth-child(4):has(.inline-note:empty) { display: none; }

  .settings-row { flex-direction: column; gap: var(--space-3); }
  .settings-row .control { width: 100%; }
  .settings-row .control .input { flex: 1; width: auto; }

  .login-visual { display: none; }
  .login-form { place-items: start center; padding: calc(var(--space-12) + env(safe-area-inset-top)) var(--space-5) var(--space-8); }
}

@media (max-width: 480px) {
  .dialog-footer { gap: var(--space-2); }
  .dialog-footer .btn { flex: 1 1 auto; }
  .dialog-footer .left { order: 3; flex-basis: 100%; margin-right: 0; }
}
