:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e4e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --good: #047857;
  --good-bg: #d1fae5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 18px; font-weight: 600; }

.pill {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

nav.tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

main { padding: 24px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
}

/* Expand-to-fullscreen button injected by JS onto every panel */
.expand-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  z-index: 2;
  padding: 0;
}
.expand-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.panel.expanded {
  position: fixed;
  inset: 0;
  margin: 0;
  z-index: 1000;
  border-radius: 0;
  overflow: auto;
  padding: 40px 32px 32px;
  max-width: none;
  max-height: none;
  animation: panel-expand 0.12s ease-out;
}
@keyframes panel-expand {
  from { transform: scale(0.98); opacity: 0.6; }
  to   { transform: scale(1);    opacity: 1; }
}
.panel.expanded h2 {
  font-size: 20px;
  margin-bottom: 16px;
}
.panel.expanded .hint { font-size: 14px; }
.panel.expanded .action-list {
  max-height: none;
  overflow: visible;
  font-size: 15px;
  gap: 10px;
}
.panel.expanded .action-row {
  padding: 12px 16px;
  font-size: 14px;
  grid-template-columns: 1fr auto;
  gap: 8px 24px;
}
.panel.expanded .action-row .sku { font-size: 15px; }
.panel.expanded .action-row .fc { font-size: 13px; }
.panel.expanded .action-row .primary-num { font-size: 18px; }
.panel.expanded .action-row .meta { font-size: 13px; }
.panel.expanded table { font-size: 14px; }
.panel.expanded .expand-btn {
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  font-size: 18px;
}

/* Freeze background scroll while a panel is fullscreen */
body.panel-expanded { overflow: hidden; }
body.panel-expanded > *:not(.panel.expanded) { /* nothing needed; z-index handles it */ }

.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

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

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.kpi .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi .value {
  font-size: 24px;
  font-weight: 600;
  margin-top: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar input[type="text"],
.toolbar input[type="number"],
.toolbar select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.toolbar input[type="text"] { flex: 1; min-width: 220px; }

button {
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

button:hover { background: #1d4ed8; }

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

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  height: 320px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.good { background: var(--good-bg); color: var(--good); }

#upload-form {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

#upload-result {
  margin-top: 12px;
  font-size: 13px;
}

ol.upload-steps {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
ol.upload-steps li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--bg);
}
.upload-step-title { font-size: 14px; margin-bottom: 2px; }
ol.upload-steps a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
ol.upload-steps a:hover { text-decoration: underline; }

details.upload-details {
  margin-top: 16px;
  font-size: 13px;
}
details.upload-details summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  padding: 4px 0;
}
details.upload-details ul { margin: 8px 0; }

code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* Dashboard: positions-by-status strip */
.status-count-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.status-count {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-count-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.status-count-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.status-count.tone-danger  { border-left-color: var(--danger); }
.status-count.tone-danger  .status-count-label { color: var(--danger); }
.status-count.tone-warn    { border-left-color: var(--warn); }
.status-count.tone-warn    .status-count-label { color: var(--warn); }
.status-count.tone-good    { border-left-color: var(--good); }
.status-count.tone-good    .status-count-label { color: var(--good); }
.status-count.tone-info    { border-left-color: var(--accent); }
.status-count.tone-info    .status-count-label { color: var(--accent); }
.status-count.tone-neutral { border-left-color: var(--muted); }

/* Zone-coloured rows (SKU History latest-inventory table) */
tr.zone-row.zone-north td { background: #eff6ff; }
tr.zone-row.zone-west  td { background: #fef3c7; }
tr.zone-row.zone-south td { background: #d1fae5; }
tr.zone-row.zone-east  td { background: #fee2e2; }
tr.zone-row:hover td    { filter: brightness(0.97); }

/* Zone total rows: slightly darker tint + bold + divider line to separate
   each zone group visually */
tr.zone-summary td {
  border-top: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}
tr.zone-summary.zone-north td { background: #dbeafe; }
tr.zone-summary.zone-west  td { background: #fde68a; }
tr.zone-summary.zone-south td { background: #a7f3d0; }
tr.zone-summary.zone-east  td { background: #fecaca; }

/* Grand total row (SKU-level across every zone) — subtle dark bar with
   the inbound number highlighted since it's unique to this row */
tr.grand-summary td {
  background: #1f2937;
  color: #f9fafb;
  font-weight: 600;
  border-top: 2px solid var(--border);
}
tr.grand-summary .zone-tag {
  background: #4b5563;
  color: #f9fafb;
}
tr.grand-summary .hint { color: #d1d5db; }
tr.grand-summary .meta { color: #9ca3af; }
tr.grand-summary .trend-up { color: #34d399; }

.zone-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.zone-tag.zone-north { background: #dbeafe; color: #1d4ed8; }
.zone-tag.zone-west  { background: #fde68a; color: #92400e; }
.zone-tag.zone-south { background: #a7f3d0; color: #065f46; }
.zone-tag.zone-east  { background: #fecaca; color: #991b1b; }

/* Lead-time badge on FC / zone tiles */
.lead-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  vertical-align: middle;
}

/* Click-to-expand rows on the Critical Action tab */
tr.expandable-row { cursor: pointer; }
tr.expandable-row .exp-indicator {
  display: inline-block;
  width: 10px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 10px;
  transition: transform 0.12s ease;
}
tr.expandable-row.expanded .exp-indicator {
  transform: rotate(90deg);
  color: var(--accent);
}

tr.expansion-row > td {
  padding: 0;
  background: #f9fafb;
  border-top: none;
}
table.expansion-detail {
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}
table.expansion-detail th,
table.expansion-detail td {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  padding: 6px 12px;
}
table.expansion-detail tbody tr:last-child td { border-bottom: none; }
table.expansion-detail tr.low-cover-fc td { background: var(--warn-bg); }
table.expansion-detail tr.oos-fc      td { background: var(--danger-bg); }
table.expansion-detail tr.closed-shipment td,
tr.zone-row.closed-shipment td {
  opacity: 0.55;
  font-style: italic;
}

td.dispatch-dates {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  white-space: normal;
  max-width: 220px;
}

td.dispatch-date-cell {
  cursor: pointer;
  white-space: nowrap;
}
td.dispatch-date-cell:hover .dispatch-date-display {
  text-decoration: underline dotted;
}
td.dispatch-date-cell input.dispatch-date-input {
  font-size: inherit;
  font-family: inherit;
  padding: 1px 3px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  color: var(--text);
  width: 130px;
}

/* Replacements tab */
.replacements-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 0 14px;
}
.repl-stat {
  font-size: 13px;
  color: var(--text-secondary, #666);
}
.repl-stat strong {
  color: var(--text);
  font-size: 15px;
}
td.meta-col {
  font-size: 12px;
  color: var(--text-secondary, #888);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Customer Returns: pivot summary table */
.returns-pivot { margin: 0 0 22px; }
.returns-pivot-heading {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary, #666);
  margin: 0 0 8px;
}
.returns-pivot-wrap { overflow-x: auto; }
table.returns-pivot-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 500px;
  width: 100%;
}
table.returns-pivot-table th,
table.returns-pivot-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.returns-pivot-table th {
  background: var(--surface);
  font-weight: 600;
  text-align: left;
}
table.returns-pivot-table th.num,
table.returns-pivot-table td.num { text-align: right; }
table.returns-pivot-table tbody tr:last-child td { border-bottom: none; }
table.returns-pivot-table tbody tr:hover td { background: var(--hover-bg, #f5f5f5); }

/* Disposition badges in the detail table */
.disp-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
  background: var(--surface);
  color: var(--text-secondary, #555);
  border: 1px solid var(--border);
}
.disp-badge.disp-sellable        { background: #e6f4ea; color: #1e7e34; border-color: #b7dfbf; }
.disp-badge.disp-customer_damaged { background: #fff3cd; color: #856404; border-color: #ffc107; }
.disp-badge.disp-warehouse_damaged { background: #fde8d8; color: #b94a00; border-color: #f4a261; }
.disp-badge.disp-defective        { background: #fce4ec; color: #880e4f; border-color: #f48fb1; }
.disp-badge.disp-expired          { background: #ede7f6; color: #4527a0; border-color: #b39ddb; }

/* Critical Action: two columns side-by-side, stack on phone */
.critical-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.critical-grid table { font-size: 13px; }
.critical-grid .empty {
  text-align: center;
  color: var(--muted);
  padding: 18px;
  font-style: italic;
}
@media (max-width: 768px) {
  .critical-grid { grid-template-columns: 1fr; }
}

/* Sales Insight cards — narrative headlines at the top of the tab */
.insight-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.insight-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 110px;
}
.insight-card .insight-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.insight-card .insight-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  width: 18px;
  height: 18px;
}
.insight-card .insight-headline {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}
.insight-card .insight-detail {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.insight-card.tone-good    { border-left-color: var(--good); }
.insight-card.tone-good    .insight-title { color: var(--good); }
.insight-card.tone-warn    { border-left-color: var(--warn); }
.insight-card.tone-warn    .insight-title { color: var(--warn); }
.insight-card.tone-danger  { border-left-color: var(--danger); }
.insight-card.tone-danger  .insight-title { color: var(--danger); }
.insight-card.tone-neutral { border-left-color: var(--muted); }

/* Highlight panels on Dashboard */
.highlights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.highlight-panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.highlight-panel .hint {
  margin: -4px 0 10px;
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
}

.action-row .sku { font-weight: 600; color: var(--text); }
.action-row .fc  { color: var(--muted); font-size: 11px; }
.action-row .meta {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 11px;
}
.action-row .primary-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.action-row.empty {
  text-align: center;
  color: var(--muted);
  padding: 12px;
  border-style: dashed;
}

/* Status dots */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
}
.dot-danger { background: #ef4444; }
.dot-warn   { background: #f59e0b; }
.dot-info   { background: #3b82f6; }
.dot-good   { background: #10b981; }
.dot-muted  { background: #9ca3af; }

/* FC summary cards */
.fc-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.fc-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.fc-card:hover { border-color: var(--accent); }
.fc-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.fc-card-all {
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
  border-color: #c4b5fd;
}
.fc-card-all .fc-name { color: #5b21b6; }

.fc-card-zone.north .fc-name { color: #1d4ed8; }
.fc-card-zone.west  .fc-name { color: #b45309; }
.fc-card-zone.south .fc-name { color: #047857; }
.fc-card-zone.east  .fc-name { color: #b91c1c; }
.fc-card-zone .fc-zone-fcs {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}
.fc-card-zone .fc-zone-fcs strong { color: var(--text); font-weight: 600; }
.fc-card-zone .fc-zone-local { font-style: italic; opacity: 0.85; margin-top: 2px; }

.section-heading {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.section-heading .hint {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  margin-left: 4px;
}

/* Sortable tables */
table.sortable th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.sortable th[data-sort]:hover { color: var(--accent); }
table.sortable th[data-sort]::after {
  content: " ";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0.3;
}
table.sortable th.sort-asc::after {
  border-bottom: 5px solid currentColor;
  opacity: 1;
}
table.sortable th.sort-desc::after {
  border-top: 5px solid currentColor;
  opacity: 1;
}

.fc-card .fc-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 6px;
}
.fc-card .fc-stats {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.fc-card .fc-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.fc-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
}
.fc-pill.crit { background: var(--danger-bg); color: var(--danger); }
.fc-pill.low  { background: var(--warn-bg);   color: var(--warn); }
.fc-pill.over { background: var(--good-bg);   color: var(--good); }
.fc-pill strong { color: inherit; }

/* Trend arrows */
.trend-up   { color: #047857; }
.trend-down { color: #b91c1c; }
.trend-flat { color: var(--muted); }

/* Upload status cards on Dashboard */
.upload-status-panel { padding: 12px 16px; }
.upload-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.status-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}
.status-card .status-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-card .status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--border);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
}
.status-card .status-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.status-card .status-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.status-card.fresh { background: var(--good-bg); border-color: #a7f3d0; }
.status-card.fresh .status-icon { background: var(--good); }
.status-card.fresh .status-label { color: var(--good); }
.status-card.warn  { background: var(--warn-bg); border-color: #fde68a; }
.status-card.warn .status-icon  { background: var(--warn); }
.status-card.warn  .status-label { color: var(--warn); }
.status-card.stale { background: var(--danger-bg); border-color: #fecaca; }
.status-card.stale .status-icon { background: var(--danger); }
.status-card.stale .status-label { color: var(--danger); }

.upload-result-row {
  padding: 6px 0;
  font-size: 13px;
}

/* Urgency badges (table cells) */
.urgency {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.urgency.critical    { background: var(--danger-bg); color: var(--danger); }
.urgency.low         { background: var(--warn-bg);   color: var(--warn); }
.urgency.healthy     { background: var(--good-bg);   color: var(--good); }
.urgency.stalled     { background: #f3f4f6;          color: var(--muted); }
.urgency.overstocked { background: #e0e7ff;          color: #3730a3; }

/* ---------- Responsive: phones ---------- */
@media (max-width: 768px) {
  body { font-size: 16px; }

  header {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  header h1 { font-size: 17px; }

  /* Let the tab bar scroll horizontally instead of wrapping */
  nav.tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 0 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav.tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 12px 14px;
    font-size: 14px;
    flex-shrink: 0;
  }

  main { padding: 12px; }

  .panel { padding: 14px; }
  .panel h2 { font-size: 15px; }
  .hint { font-size: 13px; }

  /* KPI tiles: two per row on phone */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .kpi { padding: 12px; }
  .kpi .label { font-size: 11px; }
  .kpi .value { font-size: 20px; }

  /* Highlight grid collapses to single column */
  .highlights-grid { grid-template-columns: 1fr; }
  .action-list { max-height: none; }
  .action-row { font-size: 13px; padding: 10px; }
  .action-row .sku { font-size: 14px; }
  .action-row .primary-num { font-size: 14px; }

  /* Status cards on Dashboard */
  .upload-status-grid { grid-template-columns: 1fr; }
  .status-card .status-value { font-size: 20px; }

  /* FC summary tiles */
  .fc-summary-grid { grid-template-columns: 1fr; }

  /* Tables: let them scroll horizontally on small screens */
  .panel > table,
  .panel table.sortable {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }
  .panel > table thead,
  .panel > table tbody,
  .panel > table tr { display: table; width: 100%; table-layout: auto; }
  th, td { padding: 8px 10px; }

  /* Toolbars stack on mobile */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .toolbar input[type="text"],
  .toolbar input[type="number"],
  .toolbar select,
  .toolbar button {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    font-size: 15px;
  }

  button {
    padding: 10px 14px;
    font-size: 15px;
  }

  .chart-wrap { height: 260px; }

  /* Fullscreen panel feels more like the whole app on a phone */
  .panel.expanded {
    padding: 48px 14px 14px;
  }
  .panel.expanded .expand-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .expand-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  #upload-form {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #upload-form input[type="file"] {
    font-size: 14px;
  }
}

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


.btn-small {
  display: inline-block;
  padding: 4px 10px;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  color: #333;
  text-decoration: none;
  cursor: pointer;
}
.btn-small:hover { background: #e0e0e0; }

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-overlay[hidden] { display: none; }
.login-box {
  background: var(--bg, #fff);
  border-radius: 10px;
  padding: 36px 40px;
  width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.login-box h2 { margin: 0 0 20px; font-size: 20px; }
.login-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
}
.login-label input {
  padding: 8px 10px;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg, #fff);
  color: var(--text, #000);
}
#login-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent, #e47911);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
#login-btn:hover { filter: brightness(1.1); }
#login-btn:disabled { opacity: 0.6; cursor: default; }
.login-error {
  color: var(--danger, #c00);
  font-size: 13px;
  margin: 10px 0 0;
  text-align: center;
}
