:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --success-bg: #ecfdf5;
  --danger-bg: #fef2f2;
  --radius: 8px;
  --nav-bg: #1f2430;
  --nav-text: #cbd0dc;
  --nav-text-active: #ffffff;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.navbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 52px;
}

.navbar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  margin-right: 16px;
  white-space: nowrap;
  /* Brand and .nav-right share the spare width equally, so the links sit
     in the exact middle of the bar. */
  flex: 1 1 0;
}

.navbar .nav-links {
  display: flex;
  gap: 4px;
  flex: 0 1 auto;
  justify-content: center;
  overflow-x: auto;
}

.navbar .nav-links a {
  color: var(--nav-text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  white-space: nowrap;
}

.navbar .nav-links a:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.navbar .nav-links a.active { background: rgba(255,255,255,0.14); color: #fff; }
.nav-badge {
  display: inline-block; min-width: 18px; padding: 1px 5px; margin-left: 2px; border-radius: 9px;
  background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}

.navbar .nav-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-left: 16px; flex: 1 1 0; }
.navbar .nav-right form { margin: 0; }
.navbar .nav-right button {
  background: none; border: none; color: var(--nav-text); cursor: pointer; font-size: 13px; padding: 6px 8px;
}
.navbar .nav-right button:hover { color: #fff; }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

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

.breadcrumbs { font-size: 13px; margin-bottom: 8px; color: var(--text-muted); }
.breadcrumbs a { color: var(--primary); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .breadcrumb-sep { margin: 0 6px; color: var(--border); }
.breadcrumbs .breadcrumb-current { color: var(--text); font-weight: 600; }

.page-header h1 { font-size: 20px; margin: 0; }
.page-header .actions { display: flex; gap: 8px; }
.page-header .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* "?" in a circle that shows an explanation on hover (or tap/focus on a
   phone), instead of a paragraph of explanation sitting on the page.
   Markup: <span class="help-tip" tabindex="0">?<span class="help-tip-text">…</span></span> */
.help-tip {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-left: 5px; vertical-align: middle;
  border: 1px solid var(--text-muted); border-radius: 50%;
  color: var(--text-muted); font-size: 10px; font-weight: 700; line-height: 1;
  text-transform: none; letter-spacing: 0; cursor: help;
}
.help-tip:hover, .help-tip:focus { color: var(--text); border-color: var(--text); outline: none; }
.help-tip-text {
  display: none; position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 70;
  width: max-content; max-width: min(320px, 80vw); padding: 8px 10px;
  background: #1f2937; color: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  font-size: 12.5px; font-weight: 400; line-height: 1.45; text-align: left; white-space: normal;
}
.help-tip:hover .help-tip-text, .help-tip:focus .help-tip-text { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex: 1;
  min-width: 120px;
  display: flex;
  flex-direction: column;
}
.stat-tile .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
/* Pinned to the bottom of the tile, so every value in a row lines up even
   when one tile's label wraps to two lines (it used to push just that
   tile's number down). */
/* Sized so 8 tiles (the Dashboard row) fit one line at the usual page
   width with a value like "-$2,523.51" still on one line. */
.stat-tile .value { font-size: 20px; font-weight: 700; margin-top: auto; padding-top: 4px; white-space: nowrap; }
.stat-tile .value.positive { color: var(--success); }
.stat-tile .value.negative { color: var(--danger); }

/* Sync Status page: labels here are run-type names, not short stat
   headings, so their wrapped height varies tile to tile (1-3 lines) --
   without a fixed reservation, the badge and "Sync Now" button below land
   at a different height in every tile instead of lining up as a grid. */
.stat-tile.sync-tile { display: flex; flex-direction: column; }
.stat-tile.sync-tile .label { min-height: 44px; }
.stat-tile.sync-tile .value { margin-top: 0; }
.stat-tile.sync-tile form { margin-top: auto; padding-top: 8px; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
table.data-table th, table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13.5px;
}
table.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  background: #fafafb;
}
table.data-table tr:hover td { background: #fafbff; }
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table td.center, table.data-table th.center { text-align: center; font-variant-numeric: tabular-nums; }
/* Header over a column whose cells start with a 36px thumbnail + 8px gap:
   line the header up with the text after it, not the image. */
table.data-table th.after-thumb { padding-left: 56px; }
table.data-table td.money.positive { color: var(--success); }
table.data-table td.money.negative { color: var(--danger); }
table.data-table th a.sort-link { color: inherit; text-decoration: none; }

/* Advertising, "Is everything advertised?": everything top-aligned, one
   SKU per line with its Ignore button in a column of its own. */
table.coverage-table { table-layout: fixed; min-width: 960px; }
.table-wrap:has(table.coverage-table) { overflow-x: auto; }
table.coverage-table td { vertical-align: top; }
table.coverage-table .muted { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
table.coverage-table .sku-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; }
table.coverage-table .sku-line + .sku-line { margin-top: 8px; }
table.coverage-table .sku-line a { overflow-wrap: anywhere; }
table.coverage-table .sku-line form { margin: 0; }
table.coverage-table .btn-sm, table.coverage-table .badge { white-space: nowrap; }
table.coverage-table .campaign { overflow-wrap: anywhere; }
table.coverage-table .campaign + .campaign { margin-top: 8px; }

/* Expand-in-place row preview (FBA Shipments list): a .row-toggle button
   shows/hides the hidden .preview-row right under it. */
.row-toggle {
  border: none; background: none; padding: 2px 4px; cursor: pointer;
  color: var(--text-muted); font-size: 14px; line-height: 1; transition: transform 0.15s;
}
.row-toggle:hover { color: var(--text); }
.row-toggle[aria-expanded="true"] { transform: rotate(90deg); color: var(--text); }
table.data-table tr.preview-row > td, table.data-table tr.preview-row:hover > td { background: var(--bg); padding-top: 4px; padding-bottom: 12px; }
table.data-table.preview-table { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }

.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=text], .toolbar input[type=date], .toolbar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; background: #fff;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-draft { background: #eef0f4; color: #4b5160; }
.badge-ordered { background: #e0e7ff; color: #3730a3; }
.badge-partially_received { background: #fef3c7; color: #92400e; }
.badge-received { background: var(--success-bg); color: #166534; }
.badge-cancelled { background: var(--danger-bg); color: #991b1b; }
.badge-open { background: var(--success-bg); color: #166534; }
.badge-depleted { background: #eef0f4; color: #6b7280; }
.badge-success { background: var(--success-bg); color: #166534; }
.badge-failed { background: var(--danger-bg); color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-unmatched { background: var(--danger-bg); color: #991b1b; }
.badge-reserved { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: var(--success-bg); color: #166534; }
.badge-released { background: #eef0f4; color: #6b7280; }
.badge-shipped { background: #e0e7ff; color: #3730a3; }
.badge-reconciled { background: var(--success-bg); color: #166534; }
.badge-warehouse { background: #eef0f4; color: #4b5160; }
.badge-fba { background: #e0e7ff; color: #3730a3; }
/* Hijackers: reported in Brand Registry, waiting on Amazon -- a button
   (opens the case ID dialog) dressed as a badge. */
.badge-reported { background: #e0e7ff; color: #3730a3; border: none; cursor: pointer; text-transform: none; font-family: inherit; }
.badge-reported:hover { background: #c7d2fe; }

/* Orders: Prime + faster-than-standard shipping (sales/_shipping_badges.html). */
.ship-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge-prime { background: #00a8e1; color: #fff; text-transform: none; font-style: italic; font-weight: 700; letter-spacing: .01em; }
.badge-speed-sameday, .badge-speed-nextday { background: var(--danger-bg); color: #991b1b; }
.badge-speed-secondday, .badge-speed-expedited, .badge-speed-priority { background: #fef3c7; color: #92400e; }
.badge-speed-scheduled { background: #e0e7ff; color: #3730a3; }

/* PO lines: unit cost filled in from the item's last purchase price. */
.prefill-mark { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 12px; color: var(--text-muted); white-space: nowrap; cursor: default; }
.prefill-mark[hidden] { display: none; }
.prefill-dot { width: 8px; height: 8px; border-radius: 50%; background: #f5b800; box-shadow: 0 0 0 2px #fdf0c2; flex-shrink: 0; }

.badge-running { background: #e0e7ff; color: #3730a3; display: inline-flex; align-items: center; gap: 5px; }

.spinner {
  width: 9px; height: 9px; display: inline-block;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: #f2f3f6; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* .stacked-form works on a <form> (most uses) or a plain <div> (a form
   fragment nested inside another <form>, since forms can't nest) — the
   selector matches either. */
.stacked-form .field { margin-bottom: 14px; }
.stacked-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.stacked-form input[type=text], .stacked-form input[type=number], .stacked-form input[type=date],
.stacked-form select, .stacked-form textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px;
  font-family: inherit; box-sizing: border-box;
}
.stacked-form .errorlist { color: var(--danger); font-size: 12.5px; list-style: none; padding: 0; margin: 4px 0 0; }
.stacked-form .help-text { color: var(--text-muted); font-size: 12px; margin-top: 3px; }

/* .detail-grid is also used to lay out live form fields (not just
   read-only .item/.value pairs) in several forms — without an explicit
   width, a <textarea>'s wider browser-default size can overflow its grid
   column (and the card around it) while <input>/<select> mostly get away
   with it by luck. Force every form control to fill its column. */
.detail-grid .field input, .detail-grid .field select, .detail-grid .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px;
  font-family: inherit; box-sizing: border-box;
}

/* Product search dropdown (static/js/product_search.js) */
.product-search-dropdown {
  position: absolute; top: 100%; left: 0; margin-top: 2px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14); max-height: 340px; overflow-y: auto; min-width: 260px;
}
.product-search-item { padding: 7px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-search-item:hover { background: #f2f3f6; }
.product-search-item.product-search-more, .product-search-item.product-search-create { color: var(--primary); font-weight: 500; }
.product-search-hint { padding: 6px 12px; font-size: 12px; color: var(--text-muted); font-style: italic; border-top: 1px solid var(--border); }

/* Email template shortcut ("/") picker (static/js/email_shortcut_picker.js) */
.shortcut-category-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600;
}
.shortcut-dropdown {
  position: absolute; top: 100%; left: 0; margin-top: 2px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14); max-height: 320px; overflow-y: auto; width: 320px;
}
.shortcut-group-label {
  padding: 6px 12px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600; background: var(--surface);
}
.shortcut-item { padding: 6px 12px; font-size: 13px; cursor: pointer; }
.shortcut-item:hover, .shortcut-item.is-active { background: #f2f3f6; }
.shortcut-item-label { font-family: monospace; }
.shortcut-item-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.shortcut-hint { padding: 6px 12px; font-size: 12px; color: var(--text-muted); font-style: italic; }

.formset-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.formset-table th {
  text-align: left; font-size: 12px; color: var(--text-muted); text-transform: uppercase;
  padding: 6px; border-bottom: 2px solid var(--border);
}
.formset-table td { padding: 8px 6px; vertical-align: middle; border-bottom: 1px solid var(--border); }
/* Excel-style banded rows — every other line tinted, clear separation
   between lines without needing to squint at the hairline borders alone. */
.formset-table tbody tr.formset-row:nth-child(even) { background: #f4f5fb; }
.formset-table tbody tr.formset-row:hover { background: #eceeff; }
.formset-table input, .formset-table select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 13.5px; }
.messages li.success { background: var(--success-bg); color: #166534; }
.messages li.error { background: var(--danger-bg); color: #991b1b; }
.messages li.info { background: #eef2ff; color: #3730a3; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: 13.5px; font-weight: 500; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Pill tabs: one-tap presets (e.g. Orders: FBM Unshipped / FBA Unshipped /
   Pending / All). Scroll sideways on a phone rather than wrapping. */
.pill-tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.pill-tabs::-webkit-scrollbar { display: none; }
.pill-tabs a {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.pill-tabs a:hover { text-decoration: none; color: var(--text); }
.pill-tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pill-tabs .count { background: #eef0f4; color: #4b5160; border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.pill-tabs a.active .count { background: rgba(255,255,255,0.22); color: #fff; }

/* Only shown on phones -- see the mobile block. */
.filters-toggle { display: none; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.detail-grid .item .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; }
.detail-grid .item .value { font-size: 15px; font-weight: 600; margin-top: 2px; }

.pagination { display: flex; gap: 6px; margin-top: 14px; }

.login-wrap { max-width: 360px; margin: 90px auto; }
.login-wrap h1 { text-align: center; font-size: 20px; }

/* App launcher grid */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 18px;
  max-width: 900px;
  margin: 20px auto 0;
}
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  text-align: center;
  position: relative;
}
.app-tile:hover { background: #f2f3f6; text-decoration: none; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.app-tile-badge {
  position: absolute; top: 8px; right: 8px; min-width: 20px; padding: 1px 6px; border-radius: 10px;
  background: #dc2626; color: #fff; font-size: 11.5px; font-weight: 700; line-height: 18px; text-align: center;
}
.app-tile-icon { font-size: 28px; }
.app-tile-label { font-size: 12.5px; font-weight: 500; }

/* Kanban cards */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.view-toggle a { padding: 6px 10px; font-size: 13px; color: var(--text-muted); background: var(--surface); }
.view-toggle a.active { background: var(--primary); color: #fff; }
.view-toggle a:hover { text-decoration: none; }

/* align-items: stretch is the grid default, but every card also has to be
   a flex column internally (not just display:block) for that stretched
   height to actually reach its stats block instead of leaving dead space
   below shorter cards' content — confirmed live: a 2-line-wrapping title
   (e.g. "ATS-DECAYED-MASTER-SWORD") made its card visibly taller than its
   row-mates with no fix applied, borders misaligned across the row. */
.kanban-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; align-items: stretch; }
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  display: flex;
  flex-direction: column;
}
.kanban-card:hover { box-shadow: 0 1px 6px rgba(0,0,0,0.08); text-decoration: none; }
.kanban-card-image {
  width: 100%; height: 140px; background: #f2f3f6;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 12px;
  flex-shrink: 0;
}
.kanban-card-image img { width: 100%; height: 100%; object-fit: contain; }
.kanban-card-body { padding: 10px 12px; display: flex; flex-direction: column; flex: 1; justify-content: space-between; }
.kanban-card-title { font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.kanban-card-sub { font-size: 12px; color: var(--text-muted); }
.kanban-card-stats { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12.5px; }
.kanban-card-stats-stacked { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.kanban-stat-line { display: flex; justify-content: space-between; font-size: 12px; }
.kanban-stat-line .label { color: var(--text-muted); }
.kanban-stat-line .value { font-weight: 600; }

.product-image-placeholder {
  width: 96px; height: 96px; background: #f2f3f6; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 11px;
}
.product-image { width: 96px; height: 96px; object-fit: contain; border-radius: 6px; border: 1px solid var(--border); background: #fff; }

/* History / audit trail panel */
.history-entry { padding: 10px 0; border-bottom: 1px solid var(--border); }
.history-entry:last-child { border-bottom: none; }
.history-entry .history-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.history-entry .history-change {
  font-size: 13px; margin-left: 4px; margin-bottom: 10px; padding-left: 8px;
  border-left: 2px solid var(--border);
}
.history-entry .history-change:last-child { margin-bottom: 0; }
.history-entry .history-change .field-name {
  color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em;
  margin-bottom: 2px;
}
.history-entry .history-change .old-value,
.history-entry .history-change .new-value {
  display: block; white-space: normal; word-break: break-word; margin-top: 2px;
}
.history-entry .history-change .old-value { color: var(--danger); text-decoration: line-through; opacity: 0.8; }
.history-entry .history-change .new-value { color: var(--success); font-weight: 600; }

/* ------------------------------------------------------------------
   Phones (Igor checks Dashboard / Orders / Inventory from an iPhone).
   Nothing here applies above 700px -- the desktop layout is untouched.
   ------------------------------------------------------------------ */
.navbar .nav-toggle { display: none; }

@media (max-width: 700px) {
  /* Nav: links collapse behind a menu button, opened as big tap rows. */
  .navbar { padding: 0 12px; position: relative; }
  .navbar .brand { margin-right: auto; flex: none; }
  .navbar .nav-toggle {
    display: block; background: none; border: 1px solid rgba(255,255,255,0.25); border-radius: 6px;
    color: #fff; font-size: 20px; line-height: 1; padding: 6px 10px; cursor: pointer; order: 3; margin-left: 8px;
  }
  .navbar .nav-right { margin-left: 0; order: 2; flex: none; }
  .navbar .nav-right span { display: none; }
  .navbar .nav-links {
    display: none; position: absolute; top: 52px; left: 0; right: 0; z-index: 50;
    flex-direction: column; gap: 0; background: var(--nav-bg); padding: 6px 8px 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  }
  body.nav-open .navbar .nav-links { display: flex; }
  .navbar .nav-links a { padding: 13px 12px; font-size: 16px; border-radius: 6px; }

  /* Page: use the width. */
  .page { padding: 16px 12px 40px; }
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 19px; }
  .page-header .actions { flex-wrap: wrap; }
  .card { padding: 14px; }

  /* 16px form text stops iOS Safari zooming in on every tap. Filters go
     full width instead of wrapping unevenly. */
  input, select, textarea { font-size: 16px !important; }
  .toolbar { gap: 8px; }
  .toolbar > select, .toolbar > input[type=text], .toolbar > input[type=date] { flex: 1 1 100%; }
  .toolbar > div { flex: 1 1 100%; }
  .toolbar > div input[type=text] { flex: 1; min-width: 0 !important; }
  .toolbar > label { margin-left: 0 !important; }

  /* Stat tiles: two per row, readable. */
  .stat-row { gap: 8px; }
  .stat-tile { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 12px; }
  .stat-tile .value { font-size: 19px; }

  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid .item .label { font-size: 11px; word-break: break-word; }

  /* Any table not converted to cards can at least be swiped sideways
     instead of being clipped at the screen edge. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* table.stack-mobile: each row becomes a card; each cell a
     "label ... value" line (label from the cell's data-label). A cell
     without data-label spans the card (order #, product). */
  .table-wrap:has(table.stack-mobile) { border: none; background: none; overflow: visible; }
  table.stack-mobile, table.stack-mobile tbody { display: block; background: none; }
  table.stack-mobile thead { display: none; }
  table.stack-mobile tr {
    display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 6px 12px; margin-bottom: 10px;
  }
  table.stack-mobile tr:hover td { background: none; }
  table.stack-mobile td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 7px 0; border-bottom: 1px solid var(--border); text-align: right;
  }
  table.stack-mobile td:last-child { border-bottom: none; }
  table.stack-mobile td[data-label]::before {
    content: attr(data-label); color: var(--text-muted); font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .02em; text-align: left; flex-shrink: 0;
  }
  table.stack-mobile td:not([data-label]) { display: block; text-align: left; }
}

@media (max-width: 700px) {
  /* Orders list cards: quantities stack plainly (their desktop 36px rows
     exist only to line up with product thumbnails), product names use the
     card's width, and the order # leads the card. */
  table.stack-mobile .qty-stack > div { height: auto !important; margin: 0 !important; justify-content: flex-end !important; }
  table.stack-mobile .line-title { max-width: 70vw !important; }
  table.stack-mobile td:first-child a { font-size: 15px; font-weight: 600; }

  /* Bigger tap targets for the tab pills; secondary filters fold away
     behind "More filters" so the search box sits right under the tabs. */
  .pill-tabs a { padding: 10px 16px; font-size: 15px; }
  .filters-toggle { display: inline-flex; flex: 1 1 100%; justify-content: center; }
  .toolbar:not(.filters-open) > .extra-filter { display: none !important; }
}
