/* Copied verbatim from ja-mighty-mice r8 (bb71816 lineage): Index.html <style> then Theme.html <style>. Do not edit by hand — re-copy. */
/* Ja Mighty MICE — mobile-first UI (layout from the toritori2 app)
   Palette: navy-teal ink, PP-bag teal for actions, bag-tie yellow only for "scan here now". */
:root {
  --ink: #0F3B4C;
  --primary: #0E7C86;
  --primary-light: #3AA7B0;
  --primary-dark: #0A5E66;
  --primary-tint: #E3F2F3;
  --tie: #F2B705;
  --tie-tint: #FFF6D6;
  --bg: #EEF3F4;
  --card: #FFFFFF;
  --text: #17323D;
  --text-muted: #5B7380;
  --border: #D5E0E3;
  --success: #1F9D63;
  --success-tint: #E2F5EC;
  --danger: #D64545;
  --danger-tint: #FCE9E9;
  --warning: #C98A00;
  --warning-tint: #FFF4D6;
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-width: 248px;
  --bottom-nav-height: 64px;
  --topbar-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: 'Noto Sans Thai Looped', 'Leelawadee UI', 'Noto Sans Thai', Tahoma, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 1rem;
}

button, input, select, textarea { font-family: inherit; }

:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Top banners ---------- */

/* .freshness-banner: the cache1 "ข้อมูลเมื่อ … กำลังอัปเดต…" bar (colours set inline); it is not a storage error */
.storage-warning, .freshness-banner {
  background: var(--danger-tint);
  color: #8E2424;
  border-bottom: 2px solid var(--danger);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}
.storage-warning .btn {
  margin-top: 0.5rem; min-height: 40px; padding: 0.35rem 0.9rem; font-size: 0.9rem;
  color: #8E2424; border-color: #EBB0B0; background: white;
}

.mobile-topbar {
  position: sticky;
  top: var(--safe-top);
  z-index: 90;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--ink);
  color: white;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; }
.topbar-title .shop-name { display: block; font-size: 0.7rem; font-weight: 500; opacity: 0.8; line-height: 1.2; }
.sidebar h1 .shop-name { display: block; font-size: 0.8rem; font-weight: 500; color: rgba(255,255,255,0.75); margin-bottom: 0.15rem; }
.topbar-user:not(:empty) {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
}

/* ---------- Layout ---------- */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--ink);
  color: white;
  padding: 1.25rem 0 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  display: none;
  flex-direction: column;
}
.sidebar h1 {
  font-size: 1.15rem;
  padding: 0 1.25rem 1.1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar nav a {
  display: block;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  padding: 0.7rem 1.25rem;
  border-left: 4px solid transparent;
  transition: background 0.15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: white; }
.sidebar nav a.active {
  background: rgba(255,255,255,0.1);
  border-left-color: var(--tie);
  color: white;
  font-weight: 600;
}
.sidebar-user {
  margin-top: auto;
  padding: 1.25rem;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.85);
  border-top: 1px solid rgba(255,255,255,0.12);
}
.btn-on-dark {
  margin-top: 0.6rem;
  width: 100%;
  color: white !important;
  background: transparent !important;
  border-color: rgba(255,255,255,0.3) !important;
}
.btn-on-dark:hover { background: rgba(255,255,255,0.08) !important; }

.main-content {
  flex: 1;
  min-width: 0; /* wide tables scroll inside .table-container, never the whole page */
  margin-left: 0;
  padding: 1rem;
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1.5rem);
  max-width: 100%;
}
/* Batch 2: when the browser (or the app) scrolls a field or button into view, keep it out from under the
   sticky top bar and the fixed bottom nav. The main padding above lets the last button scroll clear of the nav. */
html {
  scroll-padding-top: calc(var(--topbar-height) + var(--safe-top) + 0.5rem);
  scroll-padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 0.75rem);
}

/* ---------- Bottom nav (phones) ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 100;
}
.bottom-nav a,
.bottom-nav .more-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0 0.4rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .more-toggle { background: none; border: none; cursor: pointer; }
.bottom-nav span.icon,
.bottom-nav .more-toggle span.icon { display: block; width: 24px; height: 24px; }
.bottom-nav svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.bottom-nav .more-toggle svg { fill: currentColor; stroke: none; }
.bottom-nav a.active,
.bottom-nav .more-toggle.active,
.bottom-nav .more-toggle[aria-expanded="true"] { color: var(--primary); font-weight: 700; }
.bottom-nav a.active::before,
.bottom-nav .more-toggle.active::before {
  content: '';
  position: absolute;
  top: 0; left: 25%; right: 25%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--tie);
}

/* "More" sheet */
.more-menu {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
  background: white;
  border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -10px 30px rgba(15,59,76,0.16);
  z-index: 150;
  padding: 0.5rem 0 0.75rem;
}
.more-menu a,
.more-menu .more-logout {
  display: block;
  width: 100%;
  min-height: 52px;
  text-align: left;
  padding: 0.9rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
}
.more-menu a.active { color: var(--primary); font-weight: 700; }
.more-menu .more-logout { color: var(--danger); border-top: 1px solid var(--border); margin-top: 0.25rem; }
.more-user { padding: 0.4rem 1.25rem 0.6rem; font-size: 0.85rem; color: var(--text-muted); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  .sidebar { display: flex; top: 0; bottom: 0; height: auto; }
  .storage-warning, .freshness-banner { margin-left: var(--sidebar-width); }
  .mobile-topbar { display: none; }
  .main-content {
    margin-left: var(--sidebar-width);
    padding: 1.75rem 2.25rem 2.5rem;
    max-width: calc(var(--sidebar-width) + 1040px);
  }
  .bottom-nav,
  .more-menu { display: none !important; }
  html { scroll-padding-top: 0; scroll-padding-bottom: 0; }
}
/* r9 (Tao): wide PC — use the width (no big empty right side); phones / tablets keep the layout above */
@media (min-width: 1280px) {
  .main-content { max-width: calc(var(--sidebar-width) + 1680px); padding-right: 2.5rem; }
}

/* ---------- Cards & headings ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.9rem;
  color: var(--ink);
  line-height: 1.3;
}
.card .card { margin-bottom: 0.75rem; }
.section-title { font-size: 1.05rem; font-weight: 700; color: var(--ink); margin: 1.25rem 0 0.25rem; }

.stat-card { text-align: center; padding: 1rem 0.5rem; }
.stat-card > div:first-child { line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-card > div:last-child { color: var(--text-muted); font-size: 0.9rem; }

.card-product { background: var(--primary-tint); border-color: #C3E2E4; }
.card-product strong:first-child { font-size: 1.05rem; color: var(--ink); }
.card-confirm { background: var(--success-tint); border-color: #B9E3CD; line-height: 1.8; }

.data-warning { border: 2px solid var(--danger); background: var(--danger-tint); }
.data-warning h2 { color: #8E2424; }

.grid { display: grid; gap: 0.75rem; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-3 .card { margin-bottom: 0; }
@media (max-width: 400px) {
  .grid-3 { gap: 0.5rem; }
  .stat-card > div:first-child { font-size: 1.6rem !important; }
  .stat-card > div:last-child { font-size: 0.8rem; }
}
@media (min-width: 640px) {
  .grid { gap: 1rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem; /* 16px+ keeps iPhone from zooming on focus */
  background: white;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,124,134,0.18);
}

/* The scan field: the one loud element */
.barcode-input {
  font-size: 1.15rem;
  font-weight: 600;
  min-height: 56px;
  padding: 0.85rem 1rem;
  border: 2px solid var(--ink);
  background-color: white;
  letter-spacing: 0.02em;
}
.barcode-input:focus {
  border-color: var(--tie);
  box-shadow: 0 0 0 4px rgba(242,183,5,0.3);
  background-color: var(--tie-tint);
}
.scan-input {
  padding-left: 3rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230F3B4C' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 6v12M7 6v12M10 6v12M13 6v12M16 6v12M20 6v12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.9rem center;
  background-size: 22px;
}

/* r7 scan box (เบิกออกงาน / คืนของ): big field (wedge scanner; r8: no camera), one result line coloured by kind, newest rows on top.
   No max-height scroller inside (r6b-2: a nested scroll box painted twice on Android). */
.scan-box { border: 2px solid var(--tie); background: var(--tie-tint); border-radius: var(--radius); padding: 0.8rem; margin: 0.6rem 0 1rem; }
.scan-label { display: block; font-weight: 700; color: var(--ink); margin-bottom: 0.4rem; }
.scan-row-input { display: flex; gap: 0.5rem; }
.scan-row-input .scan-input { flex: 1 1 auto; min-width: 0; font-size: 1.25rem; }
.scan-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.scan-count { margin-left: auto; font-size: 1.05rem; color: var(--ink); }
.scan-count strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.scan-warn-n { color: #8E2424; font-weight: 700; }
.scan-msg { margin-top: 0.5rem; min-height: 2.6rem; padding: 0.55rem 0.8rem; border-radius: var(--radius); font-weight: 700; font-size: 1.05rem; border-left: 6px solid transparent; overflow-wrap: anywhere; }
.scan-msg:empty { display: none; }
.scan-ok { background: var(--success-tint); color: #145F3D; border-left-color: var(--success); }
.scan-dup { background: var(--warning-tint); color: #6B4E00; border-left-color: var(--warning); }
.scan-bad { background: var(--danger-tint); color: #8E2424; border-left-color: var(--danger); }
.scan-warns { list-style: none; margin: 0.35rem 0 0; padding: 0; font-size: 0.88rem; }
.scan-warns li { padding: 0.15rem 0.5rem; border-left: 3px solid var(--danger); margin-top: 2px; color: #8E2424; }
.scan-warns li.scan-warn-dup { border-left-color: var(--warning); color: #6B4E00; }
.scan-list { list-style: none; margin: 0.5rem 0 0; padding: 0; background: var(--card, #fff); border-radius: var(--radius); }
.scan-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
.scan-row:first-child { background: var(--success-tint); }
.scan-no { flex: none; min-width: 2rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.scan-what { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.scan-empty, .scan-more { padding: 0.5rem 0.6rem; }
.scan-more summary { cursor: pointer; font-weight: 600; color: var(--primary-dark); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #17824F; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger-soft { background: var(--danger-tint); color: #A12F2F; }
.btn-outline { background: white; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary-light); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0.35rem 0.9rem; font-size: 0.9rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Status messages ---------- */
.status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-weight: 500;
  border-left: 4px solid;
}
.status-success { background: var(--success-tint); color: #145F3D; border-color: var(--success); }
.status-error { background: var(--danger-tint); color: #8E2424; border-color: var(--danger); }
.status-warning { background: var(--warning-tint); color: #6B4E00; border-color: var(--warning); }
.status-info { background: var(--primary-tint); color: var(--primary-dark); border-color: var(--primary); }
/* 10-minute repeat warning (owner order 25 Oct): not .status, so a save's own status does not remove it. Sticky under
   the top bar: after a save the page stays where the scanner box / bill line is, and the warning stays in view
   (below the bar and the product dropdowns, z-index 70). */
.recent-dup-warning { position: sticky; top: calc(var(--topbar-height) + var(--safe-top) + 4px); z-index: 70; padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 500; border: 1px solid var(--warning); border-left: 4px solid var(--warning); background: var(--warning-tint); color: #6B4E00; overflow-wrap: anywhere; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); }
@media (min-width: 768px) { .recent-dup-warning { top: 4px; } }
/* LINE card: the reply of the last button, inside the card (not .status: showStatus removes the first .status) */
.line-summary-notice { padding: 0.75rem 1rem; border-radius: var(--radius); margin: 0.75rem 0; font-weight: 500; border-left: 4px solid; }

/* ---------- Tables ---------- */
.table-container {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 0.7rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #F3F7F8; font-weight: 600; color: var(--ink); font-size: 0.85rem; white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: #F7FAFA; }
.history-detail { min-width: 14rem; white-space: normal; }

/* Phones: each table row becomes a card with labelled values */
@media (max-width: 640px) {
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody { display: block; }
  .responsive-table tr {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.6rem;
    background: white;
  }
  .responsive-table tbody tr:hover { background: white; }
  .responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.2rem 0;
    border: none;
    text-align: right;
    white-space: normal;
  }
  .responsive-table td[data-label]::before {
    content: attr(data-label) ":";   /* r9 (Tao): "ทีม: ทีมเอ" — a separator even where flex gap is not supported */
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: left;
    flex-shrink: 0;
    margin-right: 0.5rem;
  }
  .responsive-table td[data-label=""]::before { content: none; margin: 0; }
  /* the card title line (block, not flex): "ชิ้น: TST_R5-2" */
  .responsive-table td.cell-title[data-label]::before { content: attr(data-label) ": "; margin-right: 0.35rem; font-weight: 400; }
  .responsive-table td.cell-title {
    order: -2;
    display: block;
    text-align: left;
    font-weight: 700;
    font-size: 1rem;
    color: var(--ink);
    padding-bottom: 0.35rem;
  }
  .responsive-table td.cell-title[data-label]::before { margin-right: 1rem; }   /* r9: block cell has no flex gap — same 1rem as other rows */
  .responsive-table td.cell-total { border-top: 1px dashed var(--border); margin-top: 0.25rem; padding-top: 0.4rem; }
  .responsive-table td.history-detail {
    display: block;
    text-align: left;
    min-width: 0;
    background: #F3F7F8;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    margin: 0.3rem 0;
    font-size: 0.9rem;
  }
  .responsive-table td[colspan] { display: block; text-align: center; color: var(--text-muted); }
  .responsive-table td.history-detail { order: -1; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-kg { background: var(--primary-tint); color: var(--primary-dark); }
.badge-bundle { background: var(--success-tint); color: #145F3D; }
.badge-low { background: var(--danger-tint); color: #A12F2F; }
.badge-ok { background: var(--success-tint); color: #145F3D; }

.tx-type { font-weight: 600; }
.tx-receive { color: var(--success); }
.tx-transfer { color: var(--primary); }
.tx-issue { color: var(--ink); }
.tx-adjust { color: var(--warning); }

/* ---------- Issue cart ---------- */
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item small { font-size: 0.95rem; color: var(--primary-dark); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Quantity panel ---------- */
.qty-module {
  background: #F6F9FA;
  padding: 1rem;
  border-radius: var(--radius);
  margin: 0.75rem 0 1rem;
  border: 1px solid var(--border);
}
.qty-module small { display: block; margin-top: 0.25rem; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,59,76,0.55);
  z-index: 199;
}
.login-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 2rem);
  max-width: 400px;
  z-index: 200;
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(15,59,76,0.3);
}
.login-mark {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--ink);
  display: grid;
  place-items: center;
  margin-bottom: 0.9rem;
}
.login-mark svg {
  width: 28px; height: 28px;
  fill: none; stroke: var(--tie); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.login-note { margin-bottom: 1rem; color: var(--text-muted); font-size: 0.9rem; }
.login-error { margin: 0.75rem 0 0; padding: 0.6rem 0.8rem; border-radius: var(--radius); border-left: 4px solid var(--danger); background: var(--danger-tint); color: #8E2424; font-weight: 500; }
#login-retry { margin-top: 0.5rem; }

/* ---------- In-page confirm (used inside Google Apps Script frames) ---------- */
.confirm-backdrop {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15,59,76,0.55);
  display: grid; place-items: center; padding: 1rem;
}
.confirm-card {
  background: white; border-radius: var(--radius-lg); padding: 1.25rem;
  width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(15,59,76,0.3);
  /* v18 (REVIEW-V18C M1): a long message scrolls inside the card; the buttons always stay on screen */
  display: flex; flex-direction: column; max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
}
.confirm-message { white-space: pre-line; margin-bottom: 1rem; color: var(--ink); line-height: 1.6;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.confirm-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; flex: none; }
.confirm-actions .btn { flex: 1 1 120px; }

/* ---------- Stock units, count page, minimum stock ---------- */
.sack-eq { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }
.card-note { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.92rem; }
.field-hint { color: var(--text-muted); font-size: 0.9rem; margin: 0.5rem 0; }
.login-hint { display: block; color: var(--text-muted); font-size: 0.8rem; margin-top: 0.4rem; }
.login-link { display: block; margin: 0.9rem auto 0; padding: 0.3rem 0.5rem; background: none; border: 0; color: var(--text-muted); font-size: 0.85rem; text-decoration: underline; cursor: pointer; }
.dev-setup { margin: 1rem 0 0; }
.dev-setup summary { cursor: pointer; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.6rem; }
.dev-log-wrap { max-height: 50vh; overflow: auto; }
.dev-log-table td { vertical-align: top; }
input.min-input, input.count-input { width: 7.5rem; min-height: 44px; display: inline-block; vertical-align: middle; }
.count-diff { font-weight: 700; font-variant-numeric: tabular-nums; }
.diff-same { color: var(--success); }
.diff-more { color: var(--primary); }
.diff-less { color: var(--danger); }
.diff-invalid { color: var(--danger); font-weight: 600; }
tr.count-row-active { background: var(--tie-tint) !important; outline: 2px solid var(--tie); }
@media (max-width: 640px) {
  .responsive-table td input.min-input, .responsive-table td input.count-input { width: 7rem; }
}

.low-alert { border: 2px solid var(--danger); background: var(--danger-tint); color: #8E2424; }
.low-alert p { margin-top: 0.25rem; font-size: 0.92rem; }

/* ---------- Helpers ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.card-confirm .flex { flex-wrap: wrap; }
.card-confirm .flex .btn { flex: 1 1 140px; }

/* ---------- Staff list (Admin) ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
input.staff-name { width: 100%; max-width: 22rem; min-height: 44px; }
.staff-active-label { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; white-space: nowrap; }
.staff-active-label input { width: 1.2rem; height: 1.2rem; font-size: 16px; }
input.staff-name { font-size: 16px; }

/* ---------- Google Sheets saving overlay ---------- */
.busy-overlay { position: fixed; inset: 0; z-index: 3000; display: none; align-items: center; justify-content: center;
  background: rgba(15, 59, 76, 0.35); }
.busy-card { display: flex; align-items: center; gap: 0.75rem; background: var(--card, #fff); color: var(--text, #17323D);
  padding: 1rem 1.25rem; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.18); font-weight: 600; max-width: 90vw; }
.busy-spinner { width: 1.4rem; height: 1.4rem; border-radius: 50%; border: 3px solid var(--primary-tint, #E3F2F3);
  border-top-color: var(--primary, #0E7C86); animation: busy-spin 0.8s linear infinite; flex: none; }
@keyframes busy-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .busy-spinner { animation-duration: 2.4s; } }

/* ---------- Product search (scan or type) ---------- */
.product-search { position: relative; }
/* v16c: tall enough to scroll through every product; above the form below it, under the sticky top bar (90). */
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 80; list-style: none; margin: 4px 0 0; padding: 4px;
  background: var(--card, #fff); border: 1px solid var(--border, #D5E0E3); border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 59, 76, 0.14); max-height: 50vh; overflow-y: auto; overscroll-behavior: contain; }
.suggest-empty { padding: 0.6rem 0.75rem; color: var(--text-muted, #5B7380); cursor: default; }
.field-hint { margin: 0.3rem 0 0; font-size: 0.82rem; color: var(--text-muted, #5B7380); }
.suggest-item { padding: 0.6rem 0.75rem; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-height: 44px; }
.suggest-item:hover, .suggest-item.active { background: var(--primary-tint, #E3F2F3); }
.suggest-name { font-weight: 600; color: var(--text, #17323D); }
.suggest-meta { font-size: 0.8rem; color: var(--text-muted, #5B7380); }
#pin-card h3 { margin: 1rem 0 0.6rem; font-size: 1.02rem; }

/* Admin import (Excel / CSV) preview */
.import-status { margin: 0.75rem 0 0.5rem; }
.import-title { font-size: 1rem; margin: 1rem 0 0.4rem; }
.import-bad { color: var(--danger); font-weight: 600; }
.import-ok { color: var(--success, #1F9D63); font-weight: 600; }
.import-file-error { background: var(--danger-tint); border: 1px solid var(--danger); border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.5rem 0; }
.import-file-errors, .import-row-errors { color: var(--danger); margin: 0.25rem 0 0.25rem 1.1rem; }
.import-warnings { color: var(--warning); margin: 0.25rem 0 0.25rem 1.1rem; }
.import-row-errors { margin: 0; padding-left: 1rem; font-size: 0.85rem; }
.import-table-wrap { max-height: 60vh; overflow: auto; }
.import-table tr.import-row-error td { background: var(--danger-tint); }
@media (min-width: 768px) {
  .import-table { min-width: 1100px; }
  .import-table td { white-space: nowrap; vertical-align: top; }
  .import-table td.import-result { white-space: normal; min-width: 280px; }
  .import-table td.cell-title { white-space: normal; min-width: 200px; }
}
#import-confirm[disabled] { opacity: 0.5; cursor: not-allowed; }
#import-file, #bill-file { font-size: 1rem; max-width: 100%; min-height: 48px; } /* 16px+: no iPhone zoom */

/* ---------- v17: easier to use (desktop first; phones only need to stay readable) ---------- */
.login-shop { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin: -0.4rem 0 0.4rem; }
.forgot-pin { margin-top: 0.75rem; font-size: 0.88rem; color: var(--text-muted); text-align: center; }
.login-card { max-height: calc(100vh - 2rem); overflow-y: auto; }

/* 1-2-3 hints at the top of receive / transfer / issue */
.step-hints { list-style: none; counter-reset: step; display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem;
  margin: -0.25rem 0 1rem; padding: 0.6rem 0.8rem; background: var(--primary-tint); border-radius: var(--radius); color: var(--ink); font-size: 0.95rem; }
.step-hints li { counter-increment: step; display: flex; align-items: baseline; gap: 0.4rem; }
.step-hints li::before { content: counter(step); flex: none; display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem;
  border-radius: 50%; background: var(--primary); color: white; font-weight: 700; font-size: 0.85rem; }

/* Dashboard: big shortcut buttons */
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.quick-btn { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0.15rem;
  min-height: 72px; padding: 0.8rem 1rem; border: 1.5px solid var(--border); border-left: 6px solid var(--primary);
  border-radius: var(--radius); background: white; color: var(--ink); text-align: left; cursor: pointer; font-family: inherit; }
.quick-btn:hover { background: var(--primary-tint); border-color: var(--primary-light); }
.quick-label { font-size: 1.15rem; font-weight: 700; }
.quick-sub { font-size: 0.82rem; color: var(--text-muted); }
.quick-receive { border-left-color: var(--success); }
.quick-issue { border-left-color: var(--ink); }
.quick-transfer { border-left-color: var(--primary); }
.quick-stock { border-left-color: var(--tie); }
.quick-report { border-left-color: var(--primary-light); }

/* Dashboard: green / yellow / red status */
.stat-num { font-size: 2.2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-card.stat-red .stat-num { color: var(--danger); }
.stat-card.stat-yellow .stat-num { color: var(--warning); }
.stat-card.stat-green .stat-num { color: var(--success); }
.stat-card.stat-red.stat-on { background: var(--danger-tint); border: 2px solid var(--danger); }
.stat-card.stat-yellow.stat-on { background: var(--warning-tint); border: 2px solid var(--warning); }
.stat-card.stat-green { background: var(--success-tint); }
.dash-totals { margin-top: 0.75rem; color: var(--text-muted); font-size: 0.92rem; }
.dash-totals strong { color: var(--ink); }
.status-dot { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.45rem; vertical-align: middle; }
.dot-red { background: var(--danger); }
.dot-yellow { background: var(--warning); }
.dot-green { background: var(--success); }
.badge-st-red { background: var(--danger-tint); color: #A12F2F; }
.badge-st-yellow { background: var(--warning-tint); color: #6B4E00; }
.badge-st-green { background: var(--success-tint); color: #145F3D; }
.low-alert strong { font-size: 1.1rem; }
.near-line { margin-top: 0.75rem; color: #6B4E00; }
.ok-line { color: #145F3D; font-weight: 600; }

/* One loud confirm button per action page */
.btn-main { min-height: 56px; font-size: 1.15rem; padding: 0.8rem 1.6rem; font-weight: 700; }
.card-confirm .flex .btn-main { flex: 2 1 200px; }

/* Desktop / PC: larger text, fields and buttons (1024px and wider) */
@media (min-width: 1024px) {
  html { font-size: 106.25%; }               /* 17px */
  .sidebar nav a { padding: 0.8rem 1.25rem; font-size: 1.02rem; }
  .card { padding: 1.4rem 1.5rem; }
  .card h2 { font-size: 1.45rem; }
  .btn { min-height: 52px; }
  .btn-sm { min-height: 42px; }
  .btn-main { min-height: 62px; font-size: 1.25rem; }
  .barcode-input { font-size: 1.3rem; min-height: 62px; }
  input[type="text"], input[type="number"], input[type="password"], input[type="search"], select { min-height: 52px; font-size: 1.05rem; }
  .status { font-size: 1.05rem; padding: 0.9rem 1.1rem; }
  table { font-size: 0.98rem; }
  .quick-grid { grid-template-columns: repeat(5, 1fr); gap: 0.9rem; }
  .quick-btn { min-height: 96px; padding: 1rem 1.1rem; }
  .quick-label { font-size: 1.35rem; }
  .stat-num { font-size: 2.8rem; }
  .step-hints { font-size: 1.02rem; }
  .login-card { max-width: 440px; }
}
@media (min-width: 1600px) {
  html { font-size: 112.5%; }               /* 18px on wide screens (1920) */
}
@media (min-width: 640px) and (max-width: 1023px) {
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 400px) {
  .stat-num { font-size: 1.7rem; }
  .quick-btn { min-height: 64px; padding: 0.6rem 0.75rem; }
  .quick-label { font-size: 1.05rem; }
}
@media print {
  html { font-size: 100% !important; }
}


/* ---------- Ja Mighty MICE additions ---------- */
input[type="date"], input[type="tel"], input[type="email"] {
  width: 100%; min-height: 48px; padding: 0.7rem 0.9rem; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 1rem; background: white; color: var(--text);
}
.page-head { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.page-head h2 { margin: 0; font-size: 1.3rem; color: var(--ink); }
.filters { display: grid; gap: 0.6rem; grid-template-columns: 1fr; margin-bottom: 0.9rem; }
@media (min-width: 640px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr; } }
.filters .form-group { margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.b { display: inline-block; padding: 0.12rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.b-free, .b-done { background: var(--success-tint); color: #145F3D; }
.b-out { background: var(--primary-tint); color: var(--primary-dark); }
.b-repair, .b-draft { background: var(--warning-tint); color: #6B4E00; }
.b-lost, .b-lock { background: var(--danger-tint); color: #A12F2F; }
/* r8 store check */
.store-check { margin-top: 0.75rem; }
.store-sign { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; margin-top: 0.75rem; }
.store-sign .btn { min-height: 52px; font-size: 1.05rem; }
.store-text { flex: 1 1 16rem; margin: 0; font-weight: 600; color: var(--danger, #A12F2F); }
.store-signed { margin: 0.5rem 0; }
.store-codes { max-height: none; }
.b-cancel { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #F3F7F8; border: 1px solid var(--border); display: inline-grid; place-items: center; font-size: 0.7rem; color: var(--text-muted); text-align: center; overflow: hidden; vertical-align: middle; }
.thumb-lg { width: 120px; height: 120px; font-size: 0.85rem; }
.pick-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
/* r6b-2: phones get no nested scroller — a 46vh scroll box inside the scrolling page painted/stitched twice on Android
   (เบิกออกงาน showed the จำนวน/buttons/list block twice, overlapping). The list flows with the page; the save box sticks. */
@media (max-width: 767px) {
  .pick-list { max-height: none; overflow: visible; }
  .sticky-confirm { position: sticky; bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 0.5rem); z-index: 5; box-shadow: 0 -4px 14px rgba(15, 59, 76, 0.12); }
}
.pick-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.pick-row:last-child { border-bottom: none; }
.pick-row input { width: 1.3rem; height: 1.3rem; flex: none; min-height: 0; }
.pick-row small { color: var(--text-muted); }
.pick-row.on { background: var(--primary-tint); }
.muted { color: var(--text-muted); }
.sig { margin: 1.5rem 0 0; padding: 0.9rem 0.5rem 0; border-top: 1px solid var(--border); text-align: center; color: var(--text-muted); font-size: 0.85rem; }
.login-card .sig { margin-top: 1rem; padding-top: 0.7rem; }
#toast-host { position: fixed; left: 0; right: 0; top: calc(var(--topbar-height) + var(--safe-top) + 8px); z-index: 4000; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; pointer-events: none; padding: 0 0.75rem; }
@media (min-width: 768px) { #toast-host { top: 12px; left: var(--sidebar-width); } }
#toast-host .status { margin: 0; pointer-events: auto; box-shadow: 0 6px 20px rgba(15,59,76,0.2); max-width: 560px; width: 100%; }
#save-bar { position: fixed; z-index: 90; right: 0.75rem; bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 0.6rem); max-width: calc(100% - 1.5rem); padding: 0.5rem 0.9rem; border-radius: 999px; background: var(--ink); color: white; font-size: 0.85rem; box-shadow: 0 6px 20px rgba(15,59,76,0.3); display: none; align-items: center; gap: 0.6rem; }
@media (min-width: 768px) { #save-bar { bottom: 1rem; } }
#save-bar.show { display: flex; }
#save-bar.bad { background: var(--danger); }
#save-bar button { background: white; color: var(--ink); border: 0; border-radius: 999px; padding: 0.15rem 0.7rem; font-weight: 600; cursor: pointer; }
.dlg-field { margin-bottom: 0.8rem; }
.dlg-field label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.92rem; }
.dlg-err { color: #8E2424; background: var(--danger-tint); border-left: 4px solid var(--danger); padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); margin-bottom: 0.6rem; }
.confirm-card.wide { max-width: 560px; }
.confirm-card .confirm-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-bottom: 1rem; }
.confirm-card h3 { color: var(--ink); margin-bottom: 0.6rem; font-size: 1.15rem; }
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: 0.25rem 0.8rem; font-size: 0.95rem; }
.kv dt { color: var(--text-muted); }
.kv dt::after { content: ":"; }
.qr-img { width: 140px; height: 140px; background: white; border: 1px solid var(--border); border-radius: 8px; }
.warn-box { border: 2px solid var(--danger); background: var(--danger-tint); color: #8E2424; border-radius: var(--radius); padding: 0.7rem 0.9rem; margin: 0.6rem 0; }
.path-list { margin: 0.4rem 0 0 1.2rem; font-size: 0.92rem; }
#qr-sheet { display: none; }
@media print {
  body.print-qr .sidebar, body.print-qr .bottom-nav, body.print-qr .more-menu, body.print-qr .mobile-topbar, body.print-qr .main-content,
  body.print-qr .login-card, body.print-qr .login-overlay, body.print-qr .confirm-backdrop, body.print-qr #save-bar, body.print-qr #toast-host { display: none !important; }
  /* everything except the QR sheet: .app-container (min-height 100vh) left in the flow printed a blank first page */
  body.print-qr > *:not(#qr-sheet) { display: none !important; }
  html, body.print-qr { min-height: 0 !important; height: auto !important; margin: 0 !important; padding: 0 !important; }
  body.print-qr { background: white; }
  body.print-qr #qr-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; }
  #qr-sheet .qr-label { border: 0.3mm solid #444; padding: 2mm; text-align: center; break-inside: avoid; font-size: 8pt; color: #000; }
  #qr-sheet .qr-label img { width: 30mm; height: 30mm; }
  body.print-report .sidebar, body.print-report .bottom-nav, body.print-report .more-menu, body.print-report .mobile-topbar,
  body.print-report .no-print, body.print-report #save-bar, body.print-report #toast-host, body.print-report button { display: none !important; }
  body.print-report .main-content { margin: 0; padding: 0; max-width: none; }
  body.print-report .app-container { display: block; }
  body.print-report .table-container { overflow: visible; }
  body.print-report table { font-size: 9pt; }
  body.print-report .responsive-table thead { display: table-header-group; }
  body.print-report .responsive-table tr { display: table-row; }
  body.print-report .responsive-table td { display: table-cell; }
  body.print-report .responsive-table td[data-label]::before { content: none; }
  .sig { color: #000; }
}

/* Ja Mighty MICE theme layer. Variables intentionally override Index.html's palette without editing it. */
html[data-theme="light"] {
  color-scheme: light;
  --ink: #0F3B4C;
  --primary: #0E7C86;
  --primary-light: #3AA7B0;
  --primary-dark: #0A5E66;
  --primary-tint: #E3F2F3;
  --tie: #F2B705;
  --tie-tint: #FFF6D6;
  --bg: #EEF3F4;
  --card: #FFFFFF;
  --text: #17323D;
  --text-muted: #526B78;
  --border: #CFDDE1;
  --success: #16804F;
  --success-tint: #E2F5EC;
  --danger: #C93636;
  --danger-tint: #FCE9E9;
  --warning: #946300;
  --warning-tint: #FFF4D6;
  --theme-raised: #FFFFFF;
  --theme-table-head: #E9F0F2;
  --theme-hover: #F1F6F7;
  --theme-shadow: 0 2px 10px rgba(15,59,76,.08);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #B7E5E8;
  --primary: #55C4CB;
  --primary-light: #82D8DE;
  --primary-dark: #2BA3AC;
  --primary-tint: #203D43;
  --tie: #F2C94C;
  --tie-tint: #443B20;
  --bg: #10191D;
  --card: #19262B;
  --text: #E5EFF1;
  --text-muted: #B0C2C7;
  --border: #3A5058;
  --success: #48C887;
  --success-tint: #193B2D;
  --danger: #FF7777;
  --danger-tint: #45282B;
  --warning: #F1C35B;
  --warning-tint: #42371E;
  --theme-raised: #213137;
  --theme-table-head: #26383E;
  --theme-hover: #223238;
  --theme-shadow: 0 4px 18px rgba(0,0,0,.32);
}
html[data-theme] body { background: var(--bg); color: var(--text); }
html[data-theme] .mobile-topbar,
html[data-theme] .sidebar { background: #102F3A; color: #F5FBFC; }
html[data-theme] .mobile-topbar { border-bottom: 1px solid rgba(255,255,255,.12); }
html[data-theme] .sidebar nav a { color: #D9E9EC; }
html[data-theme] .sidebar nav a:hover,
html[data-theme] .sidebar nav a.active { color: #fff; }
html[data-theme] .bottom-nav,
html[data-theme] .more-menu { background: var(--theme-raised); color: var(--text); border-color: var(--border); }
html[data-theme] .bottom-nav a,
html[data-theme] .bottom-nav .more-toggle { color: var(--text-muted); }
html[data-theme] .card,
html[data-theme] .busy-card,
html[data-theme] .suggest-list { background: var(--card); color: var(--text); border-color: var(--border); box-shadow: var(--theme-shadow); }
html[data-theme] .card h2,
html[data-theme] .section-title,
html[data-theme] .form-group label,
html[data-theme] .card-product strong:first-child,
html[data-theme] .responsive-table td.cell-title { color: var(--ink); }
html[data-theme] .card-product { background: var(--primary-tint); border-color: var(--border); color: var(--text); }
html[data-theme] .card-confirm,
html[data-theme] .stat-card.stat-green { background: var(--success-tint); border-color: var(--border); color: var(--text); }
html[data-theme] .data-warning,
html[data-theme] .low-alert,
html[data-theme] .warn-box,
html[data-theme] .stat-card.stat-red.stat-on { background: var(--danger-tint); border-color: var(--danger); color: var(--text); }
html[data-theme] .stat-card.stat-yellow.stat-on { background: var(--warning-tint); border-color: var(--warning); color: var(--text); }
html[data-theme] .data-warning h2,
html[data-theme] .login-error,
html[data-theme] .dlg-err,
html[data-theme] .confirm-message,
html[data-theme] .confirm-card h3 { color: var(--text); }
html[data-theme] .near-line { color: var(--warning); }
html[data-theme] .ok-line { color: var(--success); }
html[data-theme] .qty-module,
html[data-theme] .thumb { background: var(--theme-hover); color: var(--text-muted); border-color: var(--border); }
html[data-theme] .quick-btn { background: var(--card); color: var(--ink); border-color: var(--border); }
html[data-theme] .quick-btn:hover { background: var(--primary-tint); }
html[data-theme] .login-mark { background: var(--primary-tint); }
html[data-theme] .b-free, html[data-theme] .b-done, html[data-theme] .badge-bundle, html[data-theme] .badge-ok, html[data-theme] .badge-st-green { background: var(--success-tint); color: var(--success); }
html[data-theme] .b-out, html[data-theme] .badge-kg { background: var(--primary-tint); color: var(--primary-dark); }
html[data-theme] .b-repair, html[data-theme] .b-draft, html[data-theme] .badge-st-yellow { background: var(--warning-tint); color: var(--warning); }
html[data-theme] .b-lost, html[data-theme] .b-lock, html[data-theme] .badge-low, html[data-theme] .badge-st-red, html[data-theme] .btn-danger-soft { background: var(--danger-tint); color: var(--danger); }
html[data-theme="dark"] .btn-primary, html[data-theme="dark"] .btn-success, html[data-theme="dark"] .btn-danger,
html[data-theme="dark"] .step-hints li::before { color: #0B1519; }
html[data-theme="dark"] .btn-success:hover { background: #6FDDA3; }
html[data-theme="dark"] #save-bar { background: var(--theme-raised); color: var(--text); border: 1px solid var(--border); }
html[data-theme="dark"] #save-bar.bad { background: var(--danger-tint); border-color: var(--danger); }
html[data-theme="dark"] #save-bar button { background: var(--primary); color: #0B1519; }
html[data-theme="dark"] .scan-input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23B7E5E8' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 6v12M7 6v12M10 6v12M13 6v12M16 6v12M20 6v12'/%3E%3C/svg%3E"); }
html[data-theme="dark"] .qr-img { background: #fff; }
html[data-theme] input,
html[data-theme] select,
html[data-theme] textarea,
html[data-theme] .btn-outline,
html[data-theme] .bc-qty { background-color: var(--theme-raised); color: var(--text); border-color: var(--border); }
html[data-theme] input::placeholder,
html[data-theme] textarea::placeholder { color: var(--text-muted); opacity: 1; }
html[data-theme] select option { background: var(--theme-raised); color: var(--text); }
html[data-theme] .barcode-input { background-color: var(--theme-raised); border-color: var(--primary-light); }
html[data-theme] .barcode-input:focus { background-color: var(--tie-tint); }
html[data-theme="dark"] .scan-box { background: var(--theme-raised); }
html[data-theme="dark"] .scan-ok { color: #8BE3B5; }
html[data-theme="dark"] .scan-dup, html[data-theme="dark"] .scan-warns li.scan-warn-dup { color: #F3D27A; }
html[data-theme="dark"] .scan-bad, html[data-theme="dark"] .scan-warns li, html[data-theme="dark"] .scan-warn-n { color: #F4A3A3; }
html[data-theme] th { background: var(--theme-table-head); color: var(--text); }
html[data-theme] td { border-color: var(--border); }
html[data-theme] tbody tr:hover { background: var(--theme-hover); }
@media (max-width: 640px) {
  html[data-theme] .responsive-table tr,
  html[data-theme] .responsive-table tbody tr:hover { background: var(--card); }
  html[data-theme] .responsive-table td.history-detail { background: var(--theme-table-head); }
}
html[data-theme] .status-success,
html[data-theme] .status-error,
html[data-theme] .status-warning,
html[data-theme] .status-info,
html[data-theme] .recent-dup-warning,
html[data-theme] .bc-warning,
html[data-theme] .storage-warning,
html[data-theme] .freshness-banner,
html[data-theme] .line-summary-notice { color: var(--text); }
html[data-theme] .status-success { background: var(--success-tint); }
html[data-theme] .status-error,
html[data-theme] .storage-warning,
html[data-theme] .freshness-banner { background: var(--danger-tint); border-color: var(--danger); }
html[data-theme] .status-warning,
html[data-theme] .recent-dup-warning,
html[data-theme] .bc-warning { background: var(--warning-tint); border-color: var(--warning); }
html[data-theme] .status-info { background: var(--primary-tint); }
html[data-theme] .login-overlay,
html[data-theme] .busy-overlay,
html[data-theme] .confirm-backdrop { background: rgba(0,0,0,.72); }
html[data-theme] .modal,
html[data-theme] [role="dialog"],
html[data-theme] .login-card,
html[data-theme] .confirm-card { background-color: var(--card); color: var(--text); border-color: var(--border); }
html[data-theme] footer { color: var(--text-muted); border-color: var(--border); }
/* ---- round 3: gaps found when auditing every view/dialog/state (hard-coded colours in Index.html) ---- */
html[data-theme] .storage-warning .btn { background: var(--theme-raised); color: var(--text); border-color: var(--danger); }
html[data-theme] .btn-outline:hover { background: var(--theme-hover); border-color: var(--primary-light); }
html[data-theme] .btn-danger-soft:hover { background: var(--danger-tint); }
html[data-theme] .login-error, html[data-theme] .dlg-err { background: var(--danger-tint); border-color: var(--danger); }
html[data-theme] .sack-eq, html[data-theme] .field-hint, html[data-theme] .card-note, html[data-theme] .login-note,
html[data-theme] .login-hint, html[data-theme] .login-shop, html[data-theme] .forgot-pin, html[data-theme] .dash-totals { color: var(--text-muted); }
html[data-theme] .dash-totals strong, html[data-theme] .page-head h2, html[data-theme] .confirm-message { color: var(--ink); }
html[data-theme] .step-hints { background: var(--primary-tint); color: var(--ink); }
html[data-theme] .import-table tr.import-row-error td { background: var(--danger-tint); }
html[data-theme] tr.count-row-active { background: var(--tie-tint) !important; }
html[data-theme] .more-menu .more-logout { color: var(--danger); }
html[data-theme] .more-menu a.active, html[data-theme] .bottom-nav a.active, html[data-theme] .bottom-nav .more-toggle.active,
html[data-theme] .bottom-nav .more-toggle[aria-expanded="true"] { color: var(--primary); }
html[data-theme] .suggest-item:hover, html[data-theme] .suggest-item.active { background: var(--primary-tint); }
html[data-theme] .busy-spinner { border-color: var(--primary-tint); border-top-color: var(--primary); }
html[data-theme] .qr-fail { display: inline-grid; place-items: center; background: var(--theme-hover); color: var(--text-muted); font-size: .8rem; text-align: center; }
html[data-theme] hr, html[data-theme] .tab-bar, html[data-theme] details { border-color: var(--border); }
html[data-theme] a:not(.btn) { color: var(--primary); }
html[data-theme] .sidebar nav a, html[data-theme] .sidebar-user { color: #D9E9EC; }
html[data-theme] .sidebar nav a:hover, html[data-theme] .sidebar nav a.active { color: #fff; }
html[data-theme="dark"] .sidebar nav a.active { border-left-color: var(--tie); }
html[data-theme="dark"] img.thumb { background: #fff; }
html[data-theme="dark"] .card, html[data-theme="dark"] .confirm-card, html[data-theme="dark"] .login-card { box-shadow: var(--theme-shadow); }
/* ---- phones (390px): nothing may push the page sideways; long text wraps; dialogs fit above the bottom nav ---- */
@media (max-width: 480px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .main-content > *, .card, .card > * { min-width: 0; max-width: 100%; }
  .filters { grid-template-columns: minmax(0, 1fr); }
  .filters > * { min-width: 0; }
  .page-head { gap: .5rem; }
  .page-head .btn, .page-head .row-actions { max-width: 100%; }
  .topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-user:not(:empty) { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kv { grid-template-columns: minmax(0, 6.5rem) minmax(0, 1fr); }
  .kv dd, .kv dt, td, th { overflow-wrap: anywhere; }
  .confirm-backdrop { padding: .5rem; padding-bottom: calc(.5rem + var(--bottom-nav-height) + var(--safe-bottom)); align-items: start; }
  .confirm-card { max-height: calc(100dvh - var(--bottom-nav-height) - var(--safe-bottom) - 1rem); max-width: 100%; padding: 1rem; margin-top: auto; margin-bottom: auto; }
  .confirm-card .confirm-body { overflow-x: auto; overflow-wrap: anywhere; }
  .confirm-actions .btn { flex: 1 1 100px; min-width: 0; padding-left: .6rem; padding-right: .6rem; }
  .login-card { max-height: calc(100dvh - 1.5rem); padding: 1.1rem; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qr-img { width: 120px; height: 120px; }
  .thumb-lg { max-width: 100%; }
  #toast-host { left: .5rem; right: .5rem; }
  #save-bar { right: .5rem; max-width: calc(100% - 1rem); }
}
/* ---- print always light, whatever the screen theme ---- */
@media print {
  html[data-theme="dark"] {
    color-scheme: light;
    --ink: #0F3B4C; --primary: #0E7C86; --primary-light: #3AA7B0; --primary-dark: #0A5E66; --primary-tint: #E3F2F3;
    --tie: #F2B705; --tie-tint: #FFF6D6; --bg: #FFFFFF; --card: #FFFFFF; --text: #000000; --text-muted: #333333; --border: #BBBBBB;
    --success: #16804F; --success-tint: #E2F5EC; --danger: #C93636; --danger-tint: #FCE9E9; --warning: #946300; --warning-tint: #FFF4D6;
    --theme-raised: #FFFFFF; --theme-table-head: #EEEEEE; --theme-hover: #F5F5F5; --theme-shadow: none;
  }
  html[data-theme] body, html[data-theme] .card, html[data-theme] .main-content { background: #fff !important; color: #000 !important; box-shadow: none !important; }
  html[data-theme] th { background: #eee; color: #000; }
  html[data-theme="dark"] .btn-primary, html[data-theme="dark"] .btn-success, html[data-theme="dark"] .btn-danger { color: #fff; }
  html[data-theme] #qr-sheet, html[data-theme] #qr-sheet .qr-label { background: #fff !important; color: #000 !important; }
  .qr-img, #qr-sheet img { background: #fff; }
}
/* Toggle: phones (<768px) = a button inside the top bar (never over the bottom nav, footer or save bar);
   desktop = small fixed button in the top-right corner (the sidebar is on the left, no bottom nav there). */
.mice-theme-toggle {
  display: grid; place-items: center;
  width: 40px; height: 40px; min-width: 40px; min-height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--theme-raised); color: var(--text);
  font: 600 20px/1 system-ui, sans-serif; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mice-theme-toggle:hover { border-color: var(--primary); color: var(--primary); }
.mice-theme-toggle:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }
.mobile-topbar .mice-theme-toggle {
  position: absolute; top: 50%; right: 0.6rem; transform: translateY(-50%);
  width: 36px; height: 36px; min-width: 36px; min-height: 36px;
  background: #1E5666; border-color: rgba(255,255,255,.55); color: #fff;
}
html[data-theme] .mobile-topbar { padding-right: 3.4rem; }
body > .mice-theme-toggle {
  position: fixed; z-index: 200; top: max(10px, env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  box-shadow: 0 3px 12px rgba(0,0,0,.24);
}
@media (max-width: 767px) { body > .mice-theme-toggle { display: none; } }
.login-card .login-theme-toggle { position: absolute; top: 0.75rem; right: 0.75rem; z-index: 1; }
@media print { .mice-theme-toggle { display: none !important; } }
