:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --border: #e5e7eb;
  --hover: #f3f4f6;
  --accent: #111827;
  --accent-text: #ffffff;
  --focus: #9ca3af;
  --error: #b42318;
  --withdraw-bg: #fdecec;
  --withdraw-text: #b42318;
  --withdraw-border: #f6caca;
  --deposit-bg: #ecfdf3;
  --deposit-text: #067647;
  --deposit-border: #abefc6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 8px 24px rgba(17, 24, 39, 0.06);
}

/* Dark theme: follows the device unless the user picked light / dark (data-theme on <html>, set by js/ui.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0c0f;
    --card: #15171c;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --faint: #6b7280;
    --border: #262a31;
    --hover: #1d2027;
    --accent: #f3f4f6;
    --accent-text: #111827;
    --focus: #6b7280;
    --error: #f97066;
    --withdraw-bg: rgba(240, 68, 56, 0.14);
    --withdraw-text: #fda29b;
    --withdraw-border: rgba(240, 68, 56, 0.35);
    --deposit-bg: rgba(18, 183, 106, 0.14);
    --deposit-text: #75e0a7;
    --deposit-border: rgba(18, 183, 106, 0.35);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0c0f;
  --card: #15171c;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --faint: #6b7280;
  --border: #262a31;
  --hover: #1d2027;
  --accent: #f3f4f6;
  --accent-text: #111827;
  --focus: #6b7280;
  --error: #f97066;
  --withdraw-bg: rgba(240, 68, 56, 0.14);
  --withdraw-text: #fda29b;
  --withdraw-border: rgba(240, 68, 56, 0.35);
  --deposit-bg: rgba(18, 183, 106, 0.14);
  --deposit-text: #75e0a7;
  --deposit-border: rgba(18, 183, 106, 0.35);
  --shadow: none;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 16px;
}
.card.wide { max-width: 440px; padding: 24px; }

h1 { margin: 0; font-size: 1.25rem; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { margin: -10px 0 4px; color: var(--muted); font-size: 0.9rem; }

label { display: grid; gap: 6px; font-size: 0.85rem; font-weight: 500; color: var(--muted); }

input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--hover); }

.field { display: grid; gap: 6px; }

/* Password field with show/hide button */
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-field .toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  color: var(--faint);
  border-radius: 6px;
}
.password-field .toggle:hover { color: var(--text); background: var(--hover); }
.password-field .toggle svg { width: 18px; height: 18px; }
.password-field .toggle .icon-hide { display: none; }
.password-field .toggle[aria-pressed="true"] .icon-show { display: none; }
.password-field .toggle[aria-pressed="true"] .icon-hide { display: block; }

button {
  font: inherit;
  font-weight: 550;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
button:hover { opacity: 0.9; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: wait; }
button.link { background: none; color: var(--muted); padding: 0; font-weight: 500; }
button.link:hover { color: var(--text); opacity: 1; }

button.secondary { background: none; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--hover); opacity: 1; }

.error { color: var(--error); margin: 0; font-size: 0.875rem; }
.success { color: var(--muted); margin: 0; font-size: 0.875rem; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

dialog {
  width: min(380px, calc(100% - 32px));
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
}
dialog .card { max-width: none; }
dialog::backdrop { background: rgba(17, 24, 39, 0.35); }

.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.875rem; }
/* 24-hour date + time (Page.dateTime24): date box + HH:MM box on one line */
.dt24 { display: flex; gap: 6px; min-width: 0; }
.dt24 input[type=date] { flex: 1 1 auto; min-width: 0; }
.dt24 input.t24, input.t24 { width: 5.2em; padding-left: 6px; padding-right: 6px; flex: 0 0 auto; text-align: center; font-variant-numeric: tabular-nums; }
.badge {
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

/* Vertical menu */
.menu { display: grid; gap: 4px; }
.menu-group {
  margin: 12px 0 4px;
  padding: 0 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}
.menu-group:first-child { margin-top: 0; }
.menu a,
.menu .menu-item {
  width: 100%;
  text-align: left;
  background: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  transition: background 0.12s;
}
.menu a::after,
.menu .menu-item::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--faint);
  border-top: 1.5px solid var(--faint);
  transform: rotate(45deg);
  flex: none;
}
.menu a:hover, .menu .menu-item:hover { background: var(--hover); opacity: 1; }
.menu a:hover::after, .menu .menu-item:hover::after { border-color: var(--text); }
.menu a small, .menu .menu-item small { display: block; color: var(--muted); font-weight: 400; font-size: 0.8rem; }

/* ------------------------------------------------------------------ */
/* Data pages                                                          */
/* ------------------------------------------------------------------ */
.page {
  max-width: 1920px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: grid;
  gap: 16px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar .title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar a.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 6px 10px 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
.topbar a.back:hover { color: var(--text); }
.topbar a.back .bk-phone, body.m-phone .topbar a.back .bk-desk { display: none; }
body.m-phone .topbar a.back .bk-phone { display: inline; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1 1 200px; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
.toolbar .grow input { width: 100%; }
.toolbar .spacer { flex: 1; }

select {
  width: 100%;
  font: inherit;
  padding: 9px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--hover); }
textarea {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  resize: vertical;
  min-height: 70px;
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-width: 0; padding: 0; margin: 0; flex: none; accent-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 190px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* Always-visible scrollbars on tables: macOS hides them until you scroll, so a mouse without a side wheel could not
   reach the right-hand columns (Members). Styling them makes Chrome / Safari draw them all the time. */
.table-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.table-wrap::-webkit-scrollbar-track, .table-wrap::-webkit-scrollbar-corner { background: var(--card); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--muted); opacity: .6; border-radius: 6px; border: 3px solid var(--card); }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.data th, table.data td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: var(--hover); }
/* Keep the first column (e.g. member code) in view while scrolling sideways */
table.data.sticky-first td:first-child { position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: 1px 0 0 var(--border); }
table.data.sticky-first th:first-child { left: 0; z-index: 2; box-shadow: 1px 0 0 var(--border); }
table.data.sticky-first tbody tr:hover td:first-child { background: var(--hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .muted { color: var(--faint); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

button.small { padding: 5px 10px; font-size: 0.8rem; }
button.icon { padding: 5px 9px; }

/* On/off chip (confirm status) */
button.chip {
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.chip:hover { color: var(--text); opacity: 1; }
button.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
/* "รอโอน": planned time set (amber); red once the time has passed */
button.chip.due { margin-left: 4px; }
button.chip.due.on { background: color-mix(in srgb, #f59e0b 20%, var(--card)); color: color-mix(in srgb, #b45309 70%, var(--text)); border-color: color-mix(in srgb, #f59e0b 45%, var(--card)); }
button.chip.due.late { background: color-mix(in srgb, #ef4444 16%, var(--card)); color: color-mix(in srgb, #b91c1c 75%, var(--text)); border-color: color-mix(in srgb, #ef4444 45%, var(--card)); opacity: 1; font-weight: 600; }

a.tag { text-decoration: none; cursor: pointer; }
a.tag:hover { text-decoration: underline; }
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.strong { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
/* Withdrawals stand out in soft red so staff take care with them */
.tag.withdraw { background: var(--withdraw-bg); color: var(--withdraw-text); border-color: var(--withdraw-border); font-weight: 600; }

/* Segmented control (deposit / withdrawal) */
.segmented { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--border); border-radius: 8px; padding: 3px; gap: 3px; background: var(--bg); }
.segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 7px 16px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
}
.segmented label:has(input:checked) { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08); }

/* Forms in pages and dialogs */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid > * { min-width: 0; } /* a wide field (date + time) shrinks instead of spilling over the next one */
.section-title { margin: 6px 0 0; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); }
.hint { margin: 0; color: var(--faint); font-size: 0.8rem; font-weight: 400; }

dialog.wide { width: min(760px, calc(100% - 32px)); }
dialog .card { max-height: calc(100vh - 32px); overflow: auto; }
.actions .left { margin-right: auto; }
button.danger { background: none; color: var(--error); border: 1px solid var(--border); }
button.danger:hover { background: var(--hover); opacity: 1; }

.result {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.result div { display: grid; gap: 2px; font-size: 0.8rem; color: var(--muted); }
.result strong { color: var(--text); font-size: 1rem; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* Admin previewing the screens as staff */
.view-staff-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin: 10px 0; padding: 8px 12px; border-radius: 8px;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; font-size: 0.9rem; font-weight: 500;
}

/* Notice banner (e.g. approvals waiting) */
.notice {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}
.notice:hover { opacity: 0.9; }

/* ------------------------------------------------------------------ */
/* Soft colours: deposit / withdrawal, banks, webs, menu icons         */
/* ------------------------------------------------------------------ */
.tag.deposit { background: var(--deposit-bg); color: var(--deposit-text); border-color: var(--deposit-border); font-weight: 600; }
.tag.web {
  background: color-mix(in srgb, var(--c) 14%, var(--card));
  color: color-mix(in srgb, var(--c) 75%, var(--text));
  border-color: color-mix(in srgb, var(--c) 35%, var(--card));
  font-weight: 600;
}
.bank-chip { display: inline-flex; align-items: center; gap: 7px; }
.bank-chip::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, var(--card));
}

.menu .ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-right: 12px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--c) 16%, var(--card));
  color: color-mix(in srgb, var(--c) 75%, var(--text));
}
.menu a > span:not(.ico), .menu .menu-item > span:not(.ico) { flex: 1; }

/* Number cells edited directly in the Transactions table */
input.cell-input {
  width: 110px;
  min-width: 100px;
  padding: 5px 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  border-color: transparent;
  background: var(--bg);
}
input.cell-input:hover { border-color: var(--border); }
input.cell-input:focus { background: var(--card); }
input.cell-input.saving { opacity: 0.5; }

/* Approval status tags and row buttons */
.tag.pending { background: color-mix(in srgb, #f59e0b 20%, var(--card)); color: color-mix(in srgb, #b45309 70%, var(--text)); border-color: color-mix(in srgb, #f59e0b 45%, var(--card)); font-weight: 600; }
.tag.slip-tag { margin-top: 4px; white-space: nowrap; font-size: 0.75rem; }
.tag.bad { background: color-mix(in srgb, #ef4444 16%, var(--card)); color: color-mix(in srgb, #b91c1c 75%, var(--text)); border-color: color-mix(in srgb, #ef4444 45%, var(--card)); font-weight: 600; }
.tag.rejected { color: var(--muted); text-decoration: line-through; }
td.actions-cell { white-space: nowrap; }
td.actions-cell button + button { margin-left: 6px; }

/* Summary cards (Bank Statement) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { display: grid; gap: 4px; padding: 12px 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.stat small { color: var(--muted); font-size: 0.75rem; }
.stat strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stat .in, table.data td.in { color: var(--deposit-text); }
.stat .out, table.data td.out { color: var(--withdraw-text); }

/* Type tabs: deposit green, withdrawal pastel red, credit transfer blue */
.segmented label:has(input[value="deposit"]:checked) { background: var(--deposit-bg); color: var(--deposit-text); box-shadow: inset 0 0 0 1px var(--deposit-border); }
.segmented label:has(input[value="withdrawal"]:checked) { background: var(--withdraw-bg); color: var(--withdraw-text); box-shadow: inset 0 0 0 1px var(--withdraw-border); }
.segmented label:has(input[value="transfer"]:checked) { background: color-mix(in srgb, #2563eb 14%, var(--card)); color: color-mix(in srgb, #1d4ed8 75%, var(--text)); box-shadow: inset 0 0 0 1px color-mix(in srgb, #2563eb 35%, var(--card)); }

/* Transactions: selects and links inside table cells */
select.cell-select { width: auto; min-width: 90px; max-width: 220px; padding: 4px 8px; font-size: 0.8rem; }
td.web-cell { white-space: nowrap; }
td.web-cell select + a.ag-link { margin-left: 6px; }
a.ag-link { text-decoration: none; font-weight: 600; }
a.ag-link .tag.web { cursor: pointer; }

/* Transactions: compact table that fits a desktop screen without scrolling sideways */
table.data.compact th, table.data.compact td { padding: 6px 8px; }
table.data.compact input.cell-input { width: 96px; min-width: 84px; padding: 4px 6px; }
table.data.compact select.cell-select { min-width: 0; max-width: 128px; }
table.data .sub { color: var(--muted); font-size: 0.78rem; }
table.data th .sub { font-size: 0.7rem; font-weight: 500; }
table.data td.confirm-cell { white-space: nowrap; }
table.data td.confirm-cell > div + div { margin-top: 4px; }
table.data.compact tr.row-deposit td:first-child { box-shadow: inset 3px 0 0 var(--deposit-border); }
table.data.compact tr.row-withdraw td:first-child { box-shadow: inset 3px 0 0 var(--withdraw-border); }
table.data.compact tr.row-adjust td:first-child { box-shadow: inset 3px 0 0 var(--muted); }

/* Theme switch button in the top bar */
button.theme-btn { padding: 4px 8px; min-width: 0; font-size: 0.9rem; line-height: 1; }

/* Bank Statement: reported but not confirmed yet */
table.data tr.pending-row td { color: var(--faint); }
table.data tr.pending-row td strong, table.data tr.pending-row td.in, table.data tr.pending-row td.out { color: var(--faint); font-weight: 400; }
table.data tr.pending-row .tag:not(:last-child) { opacity: 0.6; }

/* Transactions: withdrawal new balance / credit, click to copy the difference */
.copy-diff { cursor: copy; border-bottom: 1px dashed currentColor; }
.copy-diff:hover { color: var(--text); }
a.bank-link { color: inherit; text-decoration: none; }
a.bank-link:hover { text-decoration: underline; }

/* Home menu: sections stacked on phones; cards in columns on a computer */
.menu-section { display: grid; gap: 4px; }
.menu-section + .menu-section .menu-group { margin-top: 12px; }
.notices { display: grid; gap: 8px; }
.notices:not(:has(.notice:not([hidden]))) { display: none; }
@media (min-width: 960px) {
  .home-view { place-items: start center; padding: 40px 32px; }
  .card.home { width: min(100%, 1680px); max-width: none; padding: 28px 32px; gap: 20px; }
  .card.home > header h1 { font-size: 1.5rem; }
  .home .notices { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .home .menu { display: block; columns: 3 300px; column-gap: 16px; }
  .home .menu-section {
    break-inside: avoid;
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  .home .menu-section + .menu-section .menu-group { margin-top: 0; }
  .home .menu-group { margin: 2px 0 6px; }
}
@media (min-width: 1400px) {
  .home .menu { columns: 4 300px; }
  .home .menu a, .home .menu .menu-item { font-size: 1.05rem; padding-block: 12px; }
}
/* Large monitors: scale the whole UI up a little */
@media (min-width: 1700px) { body { font-size: 16px; } }
@media (min-width: 2200px) { body { font-size: 17px; } .page { max-width: 2200px; } }
button.link-btn { background: none; border: 0; padding: 0 4px; min-width: 0; color: var(--muted); font-size: 0.85rem; cursor: pointer; }
button.link-btn:hover { color: var(--text); background: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 40% { background: color-mix(in srgb, #facc15 40%, transparent); } }
/* Loading: spinner + soft pulse so it is clear the page is working */
.empty.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
.empty.loading::before {
  content: ''; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--text); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.55; } }
/* ± for the balance cell on phones (number keypads have no minus key) */
.sign-btn { display: none; }
@media (pointer: coarse) {
  .sign-btn { display: inline-block; min-width: 0; padding: 4px 8px; margin-right: 4px; font-size: 0.9rem; }
}
.follow-tag { display: block; margin-top: 2px; font-size: 0.75rem; }
/* Transactions: the account name may wrap to 2 lines so the table fits the screen */
table.data.compact .bank-chip { white-space: normal; max-width: 140px; line-height: 1.25; }

/* 🔔 unfinished work, top bar of every page */
.bell {
  position: relative; display: inline-flex; align-items: center; text-decoration: none;
  font-size: 1.1rem; line-height: 1; padding: 4px; margin-right: 8px; filter: grayscale(1); opacity: 0.5;
}
.bell.on { filter: none; opacity: 1; }
.bell.on .bell-count {
  position: absolute; top: -6px; right: -10px; min-width: 18px; padding: 2px 5px; border-radius: 999px;
  background: #dc2626; color: #fff; font-size: 0.7rem; font-weight: 700; text-align: center;
}
.bell.on { animation: bell-ring 1.2s ease-in-out 2; }
@keyframes bell-ring { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-12deg); } 60% { transform: rotate(8deg); } 80% { transform: rotate(-4deg); } }
.bell-mute { font-size: 0.9rem; text-decoration: none; padding: 2px; }

/* Transactions: the "ถอน" tag opens the check-before-transfer popup */
button.tag-button { cursor: pointer; font: inherit; font-size: 0.75rem; padding: 1px 8px; }
button.tag-button:hover { filter: brightness(0.95); text-decoration: underline; }
.pay-body { display: grid; gap: 12px; }
.pay-line { display: grid; gap: 2px; }
.pay-line > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pay-amount { font-size: 1.5rem; color: var(--withdraw-text); }
.pay-account { font-size: 1.25rem; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; }

/* Transactions: web cell shows the AG login on hover */
.hover-wrap { position: relative; display: inline-flex; align-items: center; }
.hover-pop { display: none; position: fixed; z-index: 30; padding: 8px 10px;
  gap: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  white-space: nowrap; text-align: left; }
.hover-wrap:hover .hover-pop, .hover-wrap:focus-within .hover-pop { display: grid; }
.hover-pop a { font-weight: 600; text-decoration: none; }
/* Transactions: credit guide = new credit of the previous row (same code + web) */
.credit-guide { font-size: 0.72rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.credit-guide.off { color: #dc2626; font-weight: 600; }
.svc-time { font-size: 0.72rem; white-space: nowrap; cursor: help; font-weight: 600; }
.svc-time.fast { color: #16a34a; }
.svc-time.mid { color: #d97706; }
.svc-time.slow { color: #dc2626; }
.svc-time.open { font-weight: 400; font-style: italic; }
input.cell-input.credit-off, td.credit-off { color: #dc2626; }
input.cell-input.credit-off { border-color: #dc2626; }
.hover-pop.web-pop { min-width: 190px; }

/* 📲 Web Push settings */
.push-btn { font-size: 0.95rem; text-decoration: none; padding: 2px; filter: grayscale(1); opacity: 0.55; }
.push-btn.on { filter: none; opacity: 1; }
.push-dialog .card { max-width: 420px; display: grid; gap: 10px; }
.push-topics { display: grid; gap: 6px; }

/* LINE chat (js/linechat.js): 💬 button + panel on every staff page; --c = the OA's colour */
.lc-bubble { position: fixed; right: 16px; bottom: 16px; z-index: 50; width: 56px; height: 56px; border-radius: 50%; padding: 0;
  font-size: 1.6rem; background: #06c755; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); touch-action: none; user-select: none; }
.lc-bubble.dragging { cursor: grabbing; opacity: 0.85; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35); }
.lc-bubble.on { animation: bell-ring 1.2s ease-in-out 2; }
.lc-badge { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: #dc2626; color: #fff; font-size: 0.75rem; font-weight: 700; line-height: 22px; }
.lc-panel { position: fixed; right: 16px; bottom: 84px; z-index: 50;
  width: min(760px, calc(100vw - 32px)); height: min(600px, calc(100vh - 100px)); display: flex; flex-direction: column;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
.lc-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.lc-head .lc-quota { margin-left: auto; font-size: 0.75rem; }
.lc-close { font-size: 1.1rem; text-decoration: none; }
.lc-body { flex: 1; display: flex; min-height: 0; }
.lc-side { width: 300px; display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.lc-filters { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap; }
.lc-filter { padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; background: transparent; color: var(--text);
  border: 1px solid var(--c, var(--border)); }
.lc-filter.on { background: var(--c, var(--accent)); color: #fff; border-color: transparent; }
.lc-list { flex: 1; overflow-y: auto; }
.lc-empty { padding: 16px; }
.lc-item { width: 100%; display: flex; gap: 10px; align-items: center; padding: 9px 10px; text-align: left; border-radius: 0;
  background: transparent; color: var(--text); border-left: 4px solid var(--c); border-bottom: 1px solid var(--border); font-weight: 400; }
.lc-item:hover, .lc-item.active { background: color-mix(in srgb, var(--c) 10%, transparent); }
.lc-item.waiting strong { font-weight: 700; }
.lc-item-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.lc-item-top { display: flex; gap: 6px; align-items: center; }
.lc-item-top strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }
.lc-item-top small { color: var(--muted); font-size: 0.72rem; }
.lc-item-text { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-item.waiting .lc-item-text { color: var(--text); }
.lc-oa { color: #fff; font-size: 0.68rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.lc-avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid transparent;
  display: inline-grid; place-items: center; color: #fff; font-weight: 700; }
.lc-unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #dc2626; color: #fff; font-size: 0.72rem; line-height: 20px; text-align: center; }
.lc-dot { width: 10px; height: 10px; border-radius: 50%; background: #dc2626; }
.lc-chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.lc-pick { margin: auto; }
.lc-chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #fff; background: var(--c); }
.lc-chat-head .lc-back { color: #fff; font-size: 1.5rem; text-decoration: none; padding: 0 4px; }
.lc-chat-name { flex: 1; min-width: 0; display: grid; }
.lc-chat-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-chat-name small { opacity: 0.85; font-size: 0.72rem; }
.lc-act { padding: 4px 8px; font-size: 0.75rem; background: rgba(255, 255, 255, 0.2); color: #fff; border: 1px solid rgba(255, 255, 255, 0.5); }
.lc-msgs-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.lc-bottom { position: absolute; right: 14px; bottom: 12px; width: 38px; height: 38px; padding: 0; border-radius: 50%;
  background: var(--card); color: var(--text); border: 1px solid var(--border); box-shadow: 0 2px 8px rgb(0 0 0 / .18); font-size: 1.1rem; }
.lc-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
  background: color-mix(in srgb, var(--c) 6%, var(--card)); }
.lc-older { align-self: center; font-size: 0.8rem; }
.lc-day, .lc-system { align-self: center; font-size: 0.72rem; color: var(--muted); padding: 2px 10px; border-radius: 999px; background: var(--card); }
.lc-msg { display: grid; gap: 2px; max-width: 78%; }
.lc-msg.in { justify-self: start; align-self: flex-start; }
.lc-msg.out { align-self: flex-end; justify-items: end; }
.lc-msg small { font-size: 0.68rem; color: var(--muted); }
.lc-bubble-msg { padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; line-height: 1.45; }
.lc-msg.in .lc-bubble-msg { background: var(--card); border: 1px solid var(--border); border-top-left-radius: 4px; }
.lc-msg.out .lc-bubble-msg { background: var(--c); color: #fff; border-top-right-radius: 4px; }
.lc-msg.out .lc-bubble-msg a { color: #fff; }
.lc-msg.media .lc-bubble-msg { padding: 0; background: transparent; border: 0; }
.lc-sticker { width: 110px; height: auto; }
.lc-image { max-width: 220px; max-height: 260px; border-radius: 12px; cursor: zoom-in; background: var(--border); min-width: 60px; min-height: 60px; }
.lc-compose { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--border); align-items: flex-end; }
.lc-input { flex: 1; resize: none; min-height: 40px; max-height: 120px; font: inherit; }
.lc-send { color: #fff; padding: 10px 16px; }
/* Narrow screens: full screen, list or conversation (not both) */
@media (max-width: 720px) {
  .lc-root.open .lc-bubble { display: none; }
  .lc-panel { inset: 0; width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .lc-head { position: relative; padding-top: 16px; touch-action: none; }
  .lc-grip { position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--border); }
  .lc-side { width: 100%; border-right: 0; }
  .lc-root.in-chat .lc-side, .lc-root:not(.in-chat) .lc-chat { display: none; }
  .lc-chat-head .lc-back { display: inline; }
}
@media (min-width: 721px) {
  .lc-chat-head .lc-back { display: none; }
}
@media (min-width: 721px) { .lc-grip { display: none; } }
/* Computer: drag the top bar to move the window (with the bubble), the corner grip to resize (js/linechat.js) */
.lc-resize { display: none; }
@media (min-width: 721px) {
  .lc-head { cursor: grab; user-select: none; touch-action: none; }
  .lc-head.dragging { cursor: grabbing; }
  .lc-panel.resizing { user-select: none; }
  .lc-resize { display: block; position: absolute; width: 24px; height: 24px; z-index: 2; touch-action: none; }
  .lc-resize::after { content: ''; position: absolute; inset: 3px; border: 0 solid #06c755; opacity: 0.75; }
  .lc-resize:hover::after { opacity: 1; }
  .lc-resize.tl { top: 0; left: 0; cursor: nwse-resize; } .lc-resize.tl::after { border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 13px; }
  .lc-resize.tr { top: 0; right: 0; cursor: nesw-resize; } .lc-resize.tr::after { border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 13px; }
  .lc-resize.bl { bottom: 0; left: 0; cursor: nesw-resize; } .lc-resize.bl::after { border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 13px; }
  .lc-resize.br { bottom: 0; right: 0; cursor: nwse-resize; } .lc-resize.br::after { border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 13px; }
}
@media print { .lc-root { display: none; } }

/* ⚡ answers used often */
.lc-quick-btn { flex: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; background: transparent; color: var(--muted);
  border: 1px solid var(--border); font-size: 1rem; }
.lc-quick-btn.on { background: var(--c); color: #fff; border-color: var(--c); }
.lc-pic { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px; border-top: 1px solid var(--border); }
.lc-pic img { max-width: 120px; max-height: 120px; border-radius: 8px; object-fit: contain; background: var(--border); }
.lc-pic .hint { flex: 1; min-width: 120px; }
.lc-quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; max-height: 140px; overflow-y: auto;
  border-top: 1px solid var(--border); }
.lc-quick[hidden] { display: none; }
.lc-quick-item { display: inline-flex; align-items: center; }
.lc-chip { padding: 5px 12px; border-radius: 16px; font-size: 0.82rem; background: var(--card); color: var(--c);
  border: 1px solid var(--c); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc-chip:disabled { opacity: 0.7; }
.lc-chip.add { border-style: dashed; color: var(--muted); border-color: var(--border); }
.lc-chip-x { padding: 0 6px; margin-left: 2px; background: transparent; color: #dc2626; border: 0; font-size: 0.9rem; }
.lc-quick-edit { font-size: 0.8rem; margin-left: auto; }

.copy-code { cursor: copy; }
.lc-search-wrap { padding: 8px 8px 0; }
.lc-search-wrap .lc-search { width: 100%; box-sizing: border-box; }
.cash-slip { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* Sub menu between related pages (Bonus Tier / VIP Tier) */
.subtabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 12px; background: var(--hover); border-radius: 12px; width: fit-content; max-width: 100%; overflow-x: auto; }
.subtabs a { padding: 6px 14px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.subtabs a[aria-current="page"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.vip-tag { margin-left: 6px; color: #fff; font-size: 0.72rem; padding: 0 6px; }
.vip-dot { display: inline-block; width: 10px; height: 10px; margin-left: 6px; border-radius: 50%; vertical-align: middle; }
.pot-tag { background: #ede9fe; color: #5b21b6; }
.more-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 12px; flex-wrap: wrap; }
/* Autobot (LINE chat) */
/* Autobot / Autopilot switches (home page) */
.bot-switches { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.bot-switch { padding: 6px 14px; font-size: 0.85rem; font-weight: 600; border-radius: 999px; background: #e5e7eb; color: #374151; border: 1px solid #d1d5db; }
.bot-switch.readonly { cursor: default; }
.bot-switch.autobot.on { background: #16a34a; color: #fff; border-color: #15803d; }
.bot-switch.autopilot.on { background: #dc2626; color: #fff; border-color: #b91c1c; animation: pilot-blink 1s steps(2, start) infinite; }
@keyframes pilot-blink { 50% { background: #7f1d1d; border-color: #7f1d1d; } }
@media (prefers-reduced-motion: reduce) { .bot-switch.autopilot.on { animation: none; } }
.lc-botcard { margin: 0 8px 6px; padding: 8px 10px; border: 1px solid #86efac; background: #f0fdf4; border-radius: 10px; display: grid; gap: 6px; font-size: 0.82rem; color: #14532d; position: relative; }
.lc-botcard.muted { border-color: var(--border); background: transparent; color: var(--muted, #6b7280); display: flex; align-items: center; gap: 8px; }
.lc-botcard.error { border-color: #fca5a5; background: #fef2f2; color: #991b1b; display: flex; gap: 8px; }
.lc-aicard:not(.muted):not(.error) { border-color: #93c5fd; background: #eff6ff; color: #1e3a8a; }
.lc-aicard.esc:not(.muted):not(.error) { border-color: #fcd34d; background: #fffbeb; color: #78350f; }
.lc-aitext { white-space: pre-wrap; padding: 6px 8px; border-radius: 8px; background: var(--bg, #fff); color: var(--text, #111827); }
.lc-aibtns { display: flex; gap: 6px; align-items: center; }
.lc-aibtns .link { margin-left: auto; }
.lc-bothead { display: flex; align-items: center; gap: 8px; }
.lc-botclose { margin-left: auto; }
.lc-botconf { font-size: 0.72rem; padding: 0 6px; border-radius: 999px; background: #dcfce7; }
.lc-botconf.low { background: #fef3c7; color: #92400e; }
.lc-botrow { display: flex; gap: 8px; align-items: flex-start; }
.lc-botslip { width: 56px; height: 76px; object-fit: cover; border-radius: 6px; cursor: zoom-in; flex: none; background: #e5e7eb; }
.lc-botfields { display: flex; flex-wrap: wrap; gap: 4px; }
.lc-botfields input, .lc-botfields select { padding: 3px 6px; font-size: 0.8rem; width: auto; min-width: 0; }
.lc-botfields select:last-of-type { max-width: 100%; }
.lc-botall { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; }
.lc-botwarn { font-size: 13px; color: #b45309; background: #fef3c7; border-radius: 6px; padding: 4px 8px; margin: 4px 0; }
.lc-botask { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.lc-botask span { margin-right: auto; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .lc-botcard:not(.muted):not(.error) { background: #052e16; color: #bbf7d0; border-color: #166534; }
  .lc-aicard:not(.muted):not(.error) { background: #172554; color: #bfdbfe; border-color: #1e40af; }
  .lc-aicard.esc:not(.muted):not(.error) { background: #451a03; color: #fde68a; border-color: #92400e; }
}

/* Multi-select dropdown with checkboxes (half_summary status filter) */
.multi-pick { position: relative; }
.multi-pick > summary {
  list-style: none; cursor: pointer; min-width: 160px; padding: 10px 32px 10px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); position: relative;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.multi-pick > summary::-webkit-details-marker { display: none; }
.multi-pick > summary::after { content: '▾'; position: absolute; right: 12px; color: var(--muted); }
.multi-pick[open] > summary { border-color: var(--focus); box-shadow: 0 0 0 3px var(--hover); }
.multi-list {
  position: absolute; z-index: 20; right: 0; top: calc(100% + 4px); min-width: 220px; padding: 6px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.multi-list label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--text); font-weight: 400; }
.multi-list label:hover { background: var(--hover); }
.multi-list input[type=checkbox] { width: auto; min-width: 0; margin: 0; padding: 0; }
.multi-list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.multi-actions { display: flex; gap: 6px; padding: 6px 2px 2px; border-top: 1px solid var(--border); margin-top: 4px; }
.multi-actions button { flex: 1; padding: 6px 8px; font-size: 0.85rem; }
/* Sideways scrollbar above a table (js/crud.js), always drawn */
.hscroll-top { overflow-x: auto; overflow-y: hidden; height: 14px; margin-bottom: 4px; }
.hscroll-top::-webkit-scrollbar { height: 12px; }
.hscroll-top::-webkit-scrollbar-track { background: var(--card); border-radius: 6px; }
.hscroll-top::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 6px; border: 3px solid var(--card); }
.hscroll-top::-webkit-scrollbar-thumb:hover { background: var(--text); }

/* 🔔 popup list */
.bell-pop { position: fixed; z-index: 1000; min-width: 260px; max-width: calc(100vw - 16px); padding: 6px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); }
.bell-pop-title { padding: 8px 10px 6px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.bell-pop a { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.bell-pop a:hover { background: var(--hover); }
.bell-pop a .grow { flex: 1; }
.bell-pop a strong { min-width: 24px; padding: 2px 8px; border-radius: 999px; background: #dc2626; color: #fff; font-size: 0.8rem; text-align: center; }

/* Announcements page (announcement.html): the 16:9 picture as the customer form shows it */
.ann-pic { width: 100%; max-width: 480px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.ann-thumb { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; display: block; }
/* Autopilot #bot-topup: the bot is topping this deposit up (Transactions) */
.tag.topup-busy { background: #dc2626; color: #fff; font-weight: 700; animation: pulse 1s ease-in-out infinite; }

/* Bot switchboard (Bot Log) */
.switchboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.sb-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 8px; align-content: start; }
.sb-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sb-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; opacity: 0.75; }
.sb-row.on { opacity: 1; }
.sb-row button { min-width: 64px; }
.bot-buttons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.bot-buttons button.bad { color: var(--danger, #b91c1c); }
.checks-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 4px 16px; }
.checks-grid > div { display: grid; gap: 4px; align-content: start; }

/* ------------------------------------------------------------------ */
/* Phone layer (js/mobile.js, user 2026-11-11): only below 720 px; a computer looks as before                     */
/* ------------------------------------------------------------------ */
.m-tabbar, .m-table-toggle, .m-view-toggle, .menu .ico .m-svg { display: none; }
html.m-nozoom { touch-action: pan-x pan-y; }
/* phone view: the page never slides sideways (wide tables scroll inside their own box) */
html.m-nozoom, html.m-nozoom body { overflow-x: hidden; max-width: 100%; }
@media (max-width: 720px) {
  body.m-phone { --m-bar: 0px; padding-bottom: calc(var(--m-bar) + env(safe-area-inset-bottom)); }
  /* iPhone zooms into a box with text under 16 px: keep every box at 16 px */
  body.m-phone input, body.m-phone select, body.m-phone textarea { font-size: 16px; }
  body.m-phone .page { padding: 12px 10px 24px; gap: 12px; }
  /* a grid item is never wider than the screen (a long select / text no longer widens the whole page: the sub tabs
     then stopped scrolling, Promotion โบนัสฝาก 2026-11-22) */
  body.m-phone .page > * { min-width: 0; }
  body.m-phone button, body.m-phone .menu a { touch-action: manipulation; }
  body.m-phone button.small { padding: 8px 12px; }
  body.m-phone .toolbar input, body.m-phone .toolbar select { min-width: 0; flex: 1 1 140px; }
  body.m-phone .toolbar > button { flex: 0 0 auto; }
  /* never wider than the screen (Samsung S24 Ultra = 384px: a long account name in the bank <select> made the page
     437px wide; iPhone Pro Max = 440px hid it). Grid / flex children may shrink below their content. */
  body.m-phone .page, body.m-phone .page > main, body.m-phone .page > main > * { min-width: 0; max-width: 100%; }
  body.m-phone .page > main[style*="grid"], body.m-phone .page > main.grid { grid-template-columns: minmax(0, 1fr); }
  body.m-phone .toolbar > * { min-width: 0; max-width: 100%; }
  body.m-phone .toolbar select { text-overflow: ellipsis; }
  body.m-cards table.data.m-ready tbody, body.m-cards table.data.m-ready tfoot,
  body.m-cards table.data.m-ready tr { grid-template-columns: minmax(0, 1fr); min-width: 0; }
  body.m-cards table.data.m-ready td { min-width: 0; overflow-wrap: anywhere; }
  body.m-phone .form-grid { grid-template-columns: 1fr; }
  body.m-phone dialog { width: calc(100vw - 16px); max-width: none; padding: 0; }
  body.m-phone dialog .card { padding: 18px 16px; max-height: calc(100dvh - 24px); }
  body.m-phone .actions { flex-wrap: wrap; }
  body.m-phone .actions button { flex: 1 1 auto; min-height: 44px; }
  body.m-phone .toast { bottom: calc(var(--m-bar) + 16px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
  body.m-phone .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  body.m-phone .stat { padding: 10px 12px; min-width: 0; }
  body.m-phone .stat strong { font-size: 1.05rem; overflow-wrap: anywhere; }
  body.m-phone .subtabs { width: 100%; }
  body.m-phone .hscroll-top { display: none; }
  body.m-phone .sticky-save { bottom: calc(var(--m-bar) + env(safe-area-inset-bottom)); }

  /* top bar: title + icons; the staff name goes (the badge stays) */
  body.m-phone .topbar { gap: 6px; }
  body.m-phone .topbar h1 { font-size: 1.05rem; }
  /* the icons row sits under the title, left-aligned (it used to hug the right edge when it wrapped) */
  body.m-phone .topbar .who { gap: 8px; flex: 1 1 100%; flex-wrap: wrap; justify-content: flex-start; margin-left: 0; }
  body.m-phone .topbar .who > span:not(.badge) { display: none; }
  .m-table-toggle { font-size: 1.15rem; padding: 2px 6px; }
  body.m-phone .m-table-toggle { display: inline-block; }
  /* 🖥 มุมมองเก่า / 📱 มุมมองมือถือ: on every narrow screen, in both views */
  body.m-narrow .m-view-toggle { display: inline-block; font-size: 0.8rem; white-space: nowrap; padding: 2px 4px; }

  /* bottom bar */
  body.m-phone .m-tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--m-bar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
  }
  .m-tabbar a { display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); text-decoration: none;
    font-size: 0.68rem; font-weight: 600; -webkit-tap-highlight-color: transparent; }
  .m-tabbar a .m-ico { display: grid; place-items: center; }
  .m-tabbar a .m-ico svg { width: 24px; height: 24px; }
  .m-tabbar a[aria-current="page"] { color: var(--text); }
  .m-tabbar a[aria-current="page"] .m-ico { color: #2563eb; }
  body.m-phone .lc-bubble { bottom: calc(var(--m-bar) + 14px + env(safe-area-inset-bottom)); right: 12px; width: 52px; height: 52px; }
  body.m-phone .lc-panel { z-index: 60; }

  /* home: icon tiles, 4 per row */
  body.m-phone .home-view.center { padding: 12px 10px; place-items: start stretch; }
  body.m-phone .card.home { padding: 16px 12px; gap: 14px; }
  body.m-phone .home-view.center > .card.home { min-width: 0; width: 100%; max-width: 100%; }
  body.m-phone .card.home > header.row { flex-wrap: wrap; gap: 6px 10px; min-width: 0; }
  body.m-phone .card.home > header .who { flex-wrap: wrap; justify-content: flex-end; gap: 6px 8px; min-width: 0; margin-left: auto; }
  body.m-phone .card.home > header .who > #who-name { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.m-phone .bot-switches > * { max-width: 100%; white-space: normal; }
  body.m-phone .home .menu { gap: 14px; }
  body.m-phone .home .menu-section { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px 2px; }
  body.m-phone .home .menu-section > .menu-group { grid-column: 1 / -1; margin: 0 0 2px; padding: 0 4px; }
  body.m-phone .home .menu a, body.m-phone .home .menu .menu-item {
    flex-direction: column; justify-content: flex-start; gap: 5px; padding: 8px 1px; text-align: center; border-radius: 12px; }
  /* app-style tile: the section colour (--c) as a soft gradient, white line icon */
  body.m-phone .home .menu .ico { width: 50px; height: 50px; margin: 0; border-radius: 15px; font-size: 1.05rem;
    background: linear-gradient(150deg, color-mix(in srgb, var(--c) 72%, #fff), var(--c)); color: #fff;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--c) 35%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
  body.m-phone .home .menu .ico[data-m] { font-size: 0; }
  body.m-phone .home .menu .ico .m-svg { display: block; width: 24px; height: 24px; stroke-width: 1.9; }
  body.m-phone .home .menu a:active .ico, body.m-phone .home .menu .menu-item:active .ico { transform: scale(0.94); }
  body.m-phone .home .menu a:hover, body.m-phone .home .menu .menu-item:hover { background: transparent; }
  body.m-phone .home .menu [data-m-label] > span:not(.ico) { display: none; }
  body.m-phone .home .menu a::after, body.m-phone .home .menu .menu-item::after {
    width: auto; height: auto; border: 0; transform: none; content: ""; }
  body.m-phone .home .menu [data-m-label]::after {
    content: attr(data-m-label); font-size: 0.68rem; line-height: 1.2; font-weight: 600; color: var(--text);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  body.m-phone .home .menu :not([data-m-label]) > span:not(.ico) small { display: none; }
  body.m-phone .home .menu :not([data-m-label]) > span:not(.ico) { font-size: 0.72rem; }

  /* tables as cards (☰ in the top bar = the wide table again) */
  body.m-cards .table-wrap:has(> table.data.m-ready), body.m-cards .table-wrap:has(> div > table.data.m-ready) {
    max-height: none !important; overflow: visible !important; background: transparent; border: 0; }
  body.m-cards table.data.m-ready { display: block; font-size: 0.9rem; }
  body.m-cards table.data.m-ready thead { display: none; }
  body.m-cards table.data.m-ready tbody, body.m-cards table.data.m-ready tfoot { display: grid; gap: 8px; }
  body.m-cards table.data.m-ready tfoot { margin-top: 8px; }
  body.m-cards table.data.m-ready tr { display: grid; padding: 8px 12px; background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow); }
  body.m-cards table.data.m-ready tfoot tr { background: var(--hover); }
  /* a cell = label (left column) + everything inside it stacked on the right */
  body.m-cards table.data.m-ready td { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); column-gap: 12px;
    align-items: center; justify-items: end; padding: 5px 0;
    border: 0; border-bottom: 1px dashed var(--border); text-align: right; min-width: 0; position: static; box-shadow: none;
    background: transparent; white-space: normal; overflow-wrap: anywhere; }
  body.m-cards table.data.m-ready td:last-child { border-bottom: 0; }
  body.m-cards table.data.m-ready td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 30; justify-self: start;
    text-align: left; color: var(--muted); font-size: 0.78rem; font-weight: 500; overflow-wrap: normal; }
  body.m-cards table.data.m-ready td > * { grid-column: 2; }
  body.m-cards table.data.m-ready td[data-label=""]::before { content: none; }
  body.m-cards table.data.m-ready td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
  body.m-cards table.data.m-ready td[data-label=""] > * { grid-column: 1; }
  body.m-cards table.data.m-ready td:empty { display: none; }
  /* first cell = the card's title */
  body.m-cards table.data.m-ready td:first-child { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px;
    justify-content: flex-start; text-align: left; font-size: 1rem; font-weight: 600; padding-bottom: 7px; }
  body.m-cards table.data.m-ready td:first-child::before { content: none; }
  body.m-cards table.data.m-ready td.m-wide { display: block; text-align: left; }
  body.m-cards table.data.m-ready td.m-wide::before { content: none; }
  body.m-cards table.data.m-ready tr:hover td { background: transparent; }
  body.m-cards table.data.m-ready td > * { max-width: 100%; }
  /* boxes in a card: one size for all (the value column's full width, same height), not sized by their text */
  body.m-cards table.data.m-ready td input:not([type=checkbox]):not([type=radio]), body.m-cards table.data.m-ready td select,
  body.m-cards table.data.m-ready td textarea {
    justify-self: stretch; width: 100%; min-width: 0; max-width: none; height: 42px; padding: 8px 10px; font-size: 16px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg); text-align: right; box-sizing: border-box; }
  body.m-cards table.data.m-ready td textarea { height: auto; min-height: 42px; text-align: left; }
  body.m-cards table.data.m-ready td select { text-align: left; }
  /* ± and the balance box on one line */
  body.m-cards table.data.m-ready td:has(> .sign-btn) { grid-template-columns: minmax(0, 40%) auto minmax(0, 1fr); }
  body.m-cards table.data.m-ready td:has(> .sign-btn) > * { grid-column: 3; }
  body.m-cards table.data.m-ready td:has(> .sign-btn) > .sign-btn { grid-column: 2; grid-row: 1; height: 42px; margin: 0; }
  body.m-cards table.data.m-ready td.actions-cell { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
  body.m-cards table.data.m-ready td.actions-cell::before { margin-right: auto; }
  body.m-cards table.data.m-ready td.actions-cell button { min-height: 40px; }
  body.m-cards table.data.m-ready tr.flash { outline: 2px solid #facc15; }

  /* edge swipe hint (iPhone app) */
  .m-swipe { position: fixed; top: 50%; left: 8px; z-index: 100; width: 44px; height: 44px; margin-top: -22px; border-radius: 50%;
    display: grid; place-items: center; font-size: 1.8rem; background: var(--card); color: var(--text); border: 1px solid var(--border);
    box-shadow: var(--shadow); pointer-events: none; }
  .m-swipe.right { left: auto; right: 8px; }
  .m-swipe.go { background: var(--accent); color: var(--accent-text); }
}

/* ------------------------------------------------------------------ */
/* Side menu (js/page.js sideMenu): computers only, « / » folds it to icons */
/* ------------------------------------------------------------------ */
.side-menu { display: none; }
@media (min-width: 721px) {
  body.has-side { --side-w: 212px; padding-left: var(--side-w); }
  body.has-side.side-fold { --side-w: 56px; }
  .side-menu {
    display: flex; flex-direction: column; gap: 2px; position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 50;
    background: var(--card); border-right: 1px solid var(--border); padding: 10px 8px 24px; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; transition: width 0.15s ease;
  }
  .side-fold-btn {
    flex: none; width: 28px; height: 28px; padding: 0; border-radius: 8px; border: 1px solid var(--border); background: var(--card);
    color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer;
  }
  .side-fold-btn:hover { color: var(--text); background: var(--hover); }
  .side-fold-btn .when-fold, .side-fold .side-fold-btn .when-open { display: none; }
  .side-fold .side-fold-btn .when-fold { display: inline; }
  /* folded: icons only, the name shows on hover (title) */
  .side-fold .side-menu { padding-left: 6px; padding-right: 6px; }
  .side-fold .side-menu .lbl, .side-fold .side-head { display: none; }
  .side-fold .side-menu a { justify-content: center; padding: 6px 0; }
  .side-fold .side-top { flex-direction: column; }
  .side-fold .side-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
  body.has-side.m-phone { padding-left: 0; }
}
/* items: computers (left column) and phones (drawer, js/mobile.js setDrawer) */
.side-top { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.side-top .side-home { flex: 1; }
.side-group { display: grid; gap: 1px; margin-top: 8px; }
.side-head { font-size: 0.7rem; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 8px; white-space: nowrap; }
.side-menu a {
  display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 8px; color: var(--text); text-decoration: none;
  font-size: 0.85rem; white-space: nowrap; min-width: 0;
}
.side-menu a:hover { background: var(--hover); }
.side-menu a.cur { background: var(--hover); font-weight: 600; box-shadow: inset 3px 0 0 var(--c, var(--accent)); }
.side-menu .ico {
  flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; font-size: 0.78rem; font-weight: 700;
  color: #fff; background: var(--c);
}
.side-menu .lbl { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 720px) {
  body.m-phone .side-menu {
    display: flex; flex-direction: column; gap: 2px; position: fixed; inset: 0 auto 0 0; width: min(290px, 84vw); z-index: 1000;
    background: var(--card); border-right: 1px solid var(--border); box-shadow: var(--shadow); overflow-y: auto; overflow-x: hidden;
    padding: calc(12px + env(safe-area-inset-top)) 10px calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-105%); visibility: hidden; transition: transform 0.2s ease, visibility 0.2s;
  }
  body.m-phone.m-side-open .side-menu { transform: none; visibility: visible; }
  body.m-phone .side-fold-btn { display: none; }
  body.m-phone .side-menu a { padding: 9px 8px; font-size: 0.95rem; }
  body.m-phone .side-menu .ico { width: 28px; height: 28px; }
  .m-side-backdrop { position: fixed; inset: 0; z-index: 999; background: rgb(0 0 0 / 0.45); opacity: 0; pointer-events: none;
    transition: opacity 0.2s; }
  body.m-phone.m-side-open .m-side-backdrop { opacity: 1; pointer-events: auto; }
  body.m-phone.m-side-open { overflow: hidden; }
}
@media print { .side-menu { display: none !important; } body.has-side { padding-left: 0 !important; } }

/* ------------------------------------------------------------------ */
/* Page change without the white flash; the side menu stays put       */
/* ------------------------------------------------------------------ */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 120ms; }
.side-menu { view-transition-name: side-menu; }
@media (prefers-reduced-motion: reduce) { ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none; } }

/* ------------------------------------------------------------------ */
/* Loading bar + box (js/auth.js track): 3 s+ = box, 20 s+ = slow     */
/* ------------------------------------------------------------------ */
.net-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 2000; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, transparent, #22c55e, transparent); background-size: 40% 100%; background-repeat: no-repeat;
  transition: opacity 0.2s; }
.net-bar.on { opacity: 1; animation: net-run 1.1s linear infinite; }
@keyframes net-run { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.net-box { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 2000; display: flex; align-items: center;
  gap: 10px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 24px); padding: 8px 14px; border-radius: 12px;
  background: var(--card); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 0.85rem; }
.net-box small { color: var(--muted); }
.net-box.slow { border-color: #f59e0b; background: color-mix(in srgb, #f59e0b 12%, var(--card)); }
body.m-phone .net-box { bottom: calc(20px + env(safe-area-inset-bottom)); }
@media (prefers-reduced-motion: reduce) { .net-bar.on { animation: none; background: #22c55e; } }

/* back to top (js/ui.js) — above the 💬 bubble (right 16, bottom 16, 56px) */
.to-top { position: fixed; right: 26px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 45; width: 36px; height: 36px;
  padding: 0; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--text);
  box-shadow: var(--shadow); font-size: 1.1rem; line-height: 1; cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.to-top.show { opacity: 0.9; transform: none; pointer-events: auto; }
.to-top:hover { opacity: 1; }
@media print { .to-top { display: none; } }

