/* =====================================================================
   APEX TOOLS & HARDWARE — interface styles
   Brand: gold #E0A020 on near-black, sampled from the Apex flyer artwork.
   Built for a shop counter: large tap targets, high contrast, readable
   under fluorescent light and on a cheap monitor.
   ===================================================================== */

:root {
  --gold: #E0A020;
  --gold-bright: #F5B733;
  --gold-dim: #A8761420;
  --ink: #14161A;
  --ink-2: #1D2026;
  --ink-3: #262A32;
  --line: #2E333D;

  --paper: #F6F7F9;
  --card: #FFFFFF;
  --text: #14161A;
  --text-2: #5A6270;
  --text-3: #8A93A2;
  --border: #E2E6EC;

  --green: #12A150;
  --green-soft: #E6F6ED;
  --red: #D93A3A;
  --red-soft: #FDEBEB;
  --amber: #E0A020;
  --amber-soft: #FDF3E0;
  --blue: #2563EB;
  --blue-soft: #E8F0FE;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 4px 6px -2px rgba(16, 24, 40, .05), 0 12px 16px -4px rgba(16, 24, 40, .10);
  --sidebar-w: 236px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.011em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }

/* ---------- Layout ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--ink);
  color: #C9CFDA;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand img { width: 100%; max-width: 150px; display: block; }
.sidebar-brand .sub {
  font-size: .625rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 7px;
  font-weight: 600;
}

.nav { padding: 10px 0 24px; flex: 1; }
.nav-section {
  font-size: .625rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #626B7A;
  padding: 16px 18px 6px;
  font-weight: 700;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 18px;
  color: #C2C9D4;
  font-size: .875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.active {
  background: var(--ink-3);
  color: #fff;
  border-left-color: var(--gold);
  font-weight: 600;
}
.nav a .ico { width: 17px; text-align: center; opacity: .85; flex: 0 0 17px; }
.nav a .badge-count {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9px;
}

.sidebar-user {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 33px; height: 33px;
  flex: 0 0 33px;
  border-radius: 50%;
  background: var(--gold);
  color: #14161A;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .8125rem;
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .name {
  color: #fff; font-size: .8125rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .role { color: #737C8B; font-size: .6875rem; }
.sidebar-user a.signout { color: #737C8B; font-size: 1rem; padding: 4px; }
.sidebar-user a.signout:hover { color: var(--gold); }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar .page-title { font-size: 1.0625rem; font-weight: 650; }
.topbar .crumb { color: var(--text-3); font-size: .8125rem; }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.3rem; cursor: pointer; }

.content { padding: 22px 24px 56px; flex: 1; }
.content.wide { max-width: none; }

/* ---------- Cards & panels ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #FAFBFC;
  border-radius: 0 0 var(--radius) var(--radius);
}

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c5 { grid-template-columns: repeat(5, 1fr); }
.grid.sidebar-right { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* Grid items default to min-width:auto, so a wide table (the purchase items
   list, the stock valuation) refuses to shrink and shoves the sidebar off the
   screen instead of scrolling inside its own container. */
.grid > * { min-width: 0; }

/* A vertical run of cards inside one column of a grid. This needs the same
   min-width:0 treatment as .grid itself — without it the 10-column purchase
   items table forced its column wider than the cell, and the summary panel
   ended up painted on top of the table. */
.stack { display: grid; gap: 16px; min-width: 0; }
.stack > * { min-width: 0; }

/* ---------- Stat tiles ---------- */

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat .label {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-3);
  font-weight: 650;
}
.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 5px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .value.sm { font-size: 1.2rem; }
.stat .meta { font-size: .75rem; color: var(--text-2); margin-top: 3px; }
.stat .meta.up { color: var(--green); }
.stat .meta.down { color: var(--red); }
.stat.accent { border-top: 3px solid var(--gold); }
.stat.good  { border-top: 3px solid var(--green); }
.stat.bad   { border-top: 3px solid var(--red); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.tbl th {
  text-align: left;
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #FAFBFC;
  white-space: nowrap;
}
table.tbl td {
  padding: 10px 14px;
  border-bottom: 1px solid #EFF2F5;
  vertical-align: middle;
}
table.tbl tbody tr:hover { background: #FAFBFC; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl .center { text-align: center; }
table.tbl tfoot td {
  padding: 11px 14px;
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: #FAFBFC;
}
table.tbl.compact td, table.tbl.compact th { padding: 7px 11px; }

.mono { font-family: var(--mono); font-size: .8125em; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

.thumb {
  width: 38px; height: 38px;
  border-radius: 6px;
  object-fit: cover;
  background: #F0F2F5;
  border: 1px solid var(--border);
  flex: 0 0 38px;
}
.thumb.lg { width: 64px; height: 64px; flex-basis: 64px; }
.thumb-ph {
  display: grid; place-items: center;
  color: var(--text-3); font-size: .9rem;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .6875rem;
  font-weight: 650;
  white-space: nowrap;
  line-height: 1.6;
}
.badge.green { background: var(--green-soft); color: #0B6B36; }
.badge.red   { background: var(--red-soft);   color: #A32020; }
.badge.amber { background: var(--amber-soft); color: #8A5F0B; }
.badge.blue  { background: var(--blue-soft);  color: #1E429F; }
.badge.grey  { background: #EEF1F5;           color: #55606F; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: .875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: #F4F6F8; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #14161A;
}
.btn.primary:hover { background: var(--gold-bright); border-color: var(--gold-bright); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.dark:hover { background: var(--ink-3); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { opacity: .9; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.success:hover { opacity: .9; }
.btn.sm { padding: 5px 10px; font-size: .8125rem; }
.btn.lg { padding: 12px 22px; font-size: 1rem; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #EEF1F5; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: .8125rem;
  font-weight: 650;
  margin-bottom: 5px;
  color: #39414E;
}
.field .hint { font-size: .75rem; color: var(--text-3); margin-top: 4px; }
.field.req label::after { content: " *"; color: var(--red); }

/* ---------- Searchable product picker (combobox) ---------- */

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.combo-item { padding: 8px 11px; font-size: .875rem; cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--amber-soft); }
.combo-item + .combo-item { border-top: 1px solid #F0F2F5; }

input[type=text], input[type=number], input[type=password], input[type=email],
input[type=date], input[type=datetime-local], input[type=search], input[type=tel],
select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9375rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
input[readonly], input:disabled, select:disabled {
  background: #F4F6F8; color: var(--text-2); cursor: not-allowed;
}
textarea { resize: vertical; min-height: 74px; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%238A93A2' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 32px;
}
input.num-input { text-align: right; font-variant-numeric: tabular-nums; }

.form-row { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
.form-row.c3 { grid-template-columns: repeat(3, 1fr); }
.form-row.c4 { grid-template-columns: repeat(4, 1fr); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: .875rem;
  user-select: none;
}
.check input { width: auto; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--gold); }

.switch-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #FAFBFC;
  cursor: pointer;
}
.switch-card.on { border-color: var(--gold); background: var(--amber-soft); }

/* ---------- Flash messages ---------- */

.flashes { margin-bottom: 16px; display: grid; gap: 9px; }
.flash {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid;
  display: flex;
  align-items: center;
  gap: 9px;
}
.flash.success { background: var(--green-soft); border-color: #A6E3C1; color: #0B6B36; }
.flash.danger  { background: var(--red-soft);   border-color: #F3B7B7; color: #A32020; }
.flash.warning { background: var(--amber-soft); border-color: #F0D191; color: #8A5F0B; }
.flash.info    { background: var(--blue-soft);  border-color: #B9CEFA; color: #1E429F; }

/* ---------- Empty & misc ---------- */

.empty { padding: 46px 20px; text-align: center; color: var(--text-3); }
.empty .icon { font-size: 2.1rem; opacity: .4; margin-bottom: 10px; }
.empty p { margin: 0 0 4px; font-size: .9375rem; }

.page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head .spacer { flex: 1; }
.page-head p.sub { margin: 3px 0 0; color: var(--text-2); font-size: .875rem; }

.filters {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 148px; }
.filters .grow { flex: 1; min-width: 210px; }
.filters .filter-check { margin-left: auto; padding-bottom: 8px; }

.pagination {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  padding: 15px;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 500;
}
.pagination .current { background: var(--gold); border-color: var(--gold); color: #14161A; font-weight: 700; }
.pagination .disabled { opacity: .4; pointer-events: none; }

.progress { height: 6px; background: #EEF1F5; border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--gold); border-radius: 4px; }
.progress.good > span { background: var(--green); }
.progress.bad > span { background: var(--red); }

hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: .875rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 15px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--gold); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16, 20, 26, .55);
  display: none;
  place-items: center;
  z-index: 200;
  padding: 20px;
}
.modal-backdrop.open { display: grid; }
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 780px; }
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal-head .spacer { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 9px; justify-content: flex-end;
  background: #FAFBFC;
  border-radius: 0 0 12px 12px;
}
.close-x {
  background: none; border: 0; font-size: 1.35rem;
  color: var(--text-3); cursor: pointer; line-height: 1; padding: 0 4px;
}

/* =====================================================================
   RESPONSIVE
   The shop uses this on a counter PC, a tablet on the shelves during a
   stock take, and the owner's phone. Those are genuinely different jobs,
   so the layout changes shape rather than just shrinking.
   ===================================================================== */

/* Nothing may push the page sideways. A single wide table escaping its
   container makes every screen scroll horizontally, which on a phone reads
   as "the app is broken". */
html, body { max-width: 100%; overflow-x: hidden; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 26, .5);
  z-index: 55;
}
.sidebar-backdrop.open { display: block; }

/* ---------- Tablet ---------- */

@media (max-width: 1100px) {
  .grid.c4, .grid.c5 { grid-template-columns: repeat(2, 1fr); }
  .grid.sidebar-right { grid-template-columns: 1fr; }
}

/* ---------- Sidebar collapses ---------- */

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    width: 270px;
    flex-basis: 270px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .menu-toggle {
    display: grid;
    place-items: center;
    width: 40px; height: 40px;
    margin-left: -8px;
    border-radius: var(--radius-sm);
    flex: 0 0 40px;
  }
  .menu-toggle:active { background: #EEF1F5; }
  .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
  .form-row, .form-row.c3, .form-row.c4 { grid-template-columns: 1fr; }
  .content { padding: 16px 14px 48px; }
  .topbar { padding: 10px 14px; gap: 10px; }
}

/* ---------- Phone ---------- */

@media (max-width: 760px) {

  /* Topbar: the title must not wrap into two lines and shove the page down.
     Actions move onto their own row so buttons keep a usable width. */
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .topbar .page-title {
    font-size: .9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52vw;
  }
  .topbar .crumb {
    font-size: .6875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52vw;
  }
  .topbar .btn { padding: 7px 11px; font-size: .8125rem; }

  /* Stat tiles: two across and shorter. Four full-width tiles meant nearly a
     thousand pixels of scrolling before any actual content appeared. */
  .grid.c5, .grid.c4, .grid.c3, .grid.c2 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 11px 12px; }
  .stat .label { font-size: .5625rem; letter-spacing: .05em; }
  .stat .value { font-size: 1.0625rem; margin-top: 3px; }
  .stat .value.sm { font-size: .9375rem; }
  .stat .meta { font-size: .625rem; line-height: 1.35; }

  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.0625rem; }
  .card-head { padding: 12px 14px; gap: 8px; }
  .card-body { padding: 14px; }
  .content { padding: 12px 10px 64px; }

  /* Filters become one field per row — side-by-side selects at 375px are
     too narrow to read the selected option. But a full stack of them pushes
     the actual results a screen and a half down, so they collapse behind a
     toggle and the results stay the first thing you see. */
  .filters { gap: 10px; }
  .filters .field, .filters .grow { width: 100%; flex: 1 1 100%; min-width: 0; }
  .filters input, .filters select { min-width: 0; width: 100%; }
  .filters > .btn { width: 100%; }

  /* Preset chips (Today / This week / This month …) share rows rather than
     taking a full-width row each — six stacked buttons was half a screen
     before the figures started. */
  .filters .btn-row { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .filters .btn-row .btn { width: auto; padding: 9px 6px; font-size: .75rem; }

  /* Checkbox filters get their own full-width row rather than being pushed
     to the right edge, where the label wraps away from its box. */
  .filters .check { width: 100%; flex: 1 1 100%; }
  .filters .filter-check { margin-left: 0; padding-bottom: 0; }

  .filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 12px;
  }
  .filters.collapsible { display: none; }
  .filters.collapsible.open { display: flex; }

  .btn-row .btn { flex: 1 1 auto; }
  .page-head { gap: 10px; }

  /* ----- Tables become cards -----
     A hardware sales table has 8 columns; at 375px that is either an
     unreadable squeeze or a horizontal scroll that hides the invoice number
     and the amount at the same time. Each row becomes a labelled block
     instead. Labels come from the table's own <thead>, injected by app.js,
     so this works for every table in the system without touching templates. */
  table.tbl.stackable { display: block; }
  table.tbl.stackable thead { display: none; }
  table.tbl.stackable tbody { display: block; }

  table.tbl.stackable > tbody > tr {
    display: block;
    padding: 12px 14px;
    border-bottom: 8px solid var(--paper);
    background: #fff;
  }
  table.tbl.stackable > tbody > tr:hover { background: #fff; }

  table.tbl.stackable > tbody > td,
  table.tbl.stackable > tbody > tr > td {
    display: flex;
    align-items: baseline;
    /* flex-start plus an auto margin on the label, rather than space-between:
       a cell like "60 pcs" is two child nodes, and space-between would fling
       the number and its unit to opposite edges of the row. */
    justify-content: flex-start;
    gap: 6px;
    padding: 3px 0;
    border: 0;
    text-align: right;
    white-space: normal;
  }
  table.tbl.stackable > tbody > tr > td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-size: .6875rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
    flex: 0 0 auto;
    margin-right: auto;
    padding-right: 12px;
  }
  /* Columns with no header (thumbnail, action buttons) get no label and sit
     on their own line. */
  table.tbl.stackable > tbody > tr > td:not([data-label]) {
    justify-content: flex-start;
    text-align: left;
  }
  table.tbl.stackable > tbody > tr > td:not([data-label])::before { display: none; }

  /* The first labelled cell is the row's identity — give it prominence
     rather than making it one line among equals. */
  table.tbl.stackable > tbody > tr > td.row-title {
    display: block;
    text-align: left;
    font-size: .9375rem;
    padding-bottom: 7px;
    margin-bottom: 5px;
    border-bottom: 1px solid #EFF2F5;
  }
  table.tbl.stackable > tbody > tr > td.row-title::before { display: none; }

  /* Action buttons in a stacked row sit together at the bottom. */
  table.tbl.stackable > tbody > tr > td.row-actions {
    justify-content: flex-start;
    gap: 6px;
    padding-top: 9px;
    flex-wrap: wrap;
  }
  table.tbl.stackable > tbody > tr > td.row-actions .btn { flex: 0 0 auto; }

  /* Cells whose only content is a placeholder dash. In a table the column
     still needs to line up; in a card it is a wasted line. */
  table.tbl.stackable > tbody > tr > td.empty-cell { display: none; }

  table.tbl.stackable tfoot { display: block; }
  table.tbl.stackable tfoot tr { display: block; padding: 12px 14px; }
  table.tbl.stackable tfoot td {
    display: flex; justify-content: space-between; gap: 14px;
    border: 0; padding: 3px 0; text-align: right;
  }
  table.tbl.stackable tfoot td::before {
    content: attr(data-label);
    color: var(--text-3); font-size: .6875rem; font-weight: 650;
    text-transform: uppercase; text-align: left;
  }
  table.tbl.stackable tfoot td:empty { display: none; }

  /* Tables that genuinely read better as tables keep their shape and simply
     scroll — the profit & loss statement is only two columns. */
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Modals become bottom sheets: reachable with a thumb, and the close
     control stays on screen when the keyboard opens. */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal-backdrop.open { display: flex; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
    animation: sheet-up .2s ease;
  }
  .modal-foot { border-radius: 0; position: sticky; bottom: 0; }
  .modal-foot .btn { flex: 1 1 auto; }

  .kv { grid-template-columns: 1fr auto; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tabs a { white-space: nowrap; }
  .pagination { padding: 12px 8px; }
}

@keyframes sheet-up {
  from { transform: translateY(14px); opacity: .6; }
  to   { transform: translateY(0);    opacity: 1; }
}

@media (max-width: 400px) {
  /* Tiles stay two across even on a small phone — "TSh 48,276,000" still
     fits at this size, and dropping to one column is what made the dashboard
     a thousand pixels of scrolling in the first place. */
  .stat { padding: 10px; }
  .stat .value { font-size: .9375rem; }
  .stat .value.sm { font-size: .875rem; }
  .topbar .page-title { max-width: 44vw; }
  .content { padding: 10px 8px 64px; }
}

/* ---------- Touch devices ----------
   Sized for a finger rather than a mouse. Applies on tablets too, which are
   often wide enough to miss the phone breakpoints entirely. */

@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.sm { min-height: 36px; }
  .qty-btn { width: 38px; height: 38px; flex-basis: 38px; font-size: 1.1rem; }
  .nav a { padding: 12px 18px; }
  select, input[type=text], input[type=number], input[type=password],
  input[type=email], input[type=date], input[type=search], input[type=tel],
  textarea {
    /* Safari zooms the whole page when a focused input is under 16px.
       That zoom does not undo itself, so the cashier is left on a
       magnified page mid-sale. */
    font-size: 16px;
    min-height: 44px;
  }
  textarea { min-height: 80px; }
  table.tbl td, table.tbl th { padding-top: 12px; padding-bottom: 12px; }
  .check { padding: 4px 0; }
}

/* ---------- Print ---------- */

@media print {
  .sidebar, .sidebar-backdrop, .topbar, .no-print, .btn, .filters,
  .pagination { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; }
  .card { border: 0; box-shadow: none; }
  body { background: #fff; font-size: 12px; }
  html, body { overflow-x: visible; }
}
