/* ============================================================
   ลิตาการยาง — Design System v2 (rebuilt UI)
   Light, high-contrast, outdoor-readable.
   Desktop: sidebar · Mobile (iOS/Android): bottom tab bar
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  /* Brand — rubber green */
  --green-900: #0c3b2e;
  --green-800: #10493a;
  --green-700: #166a4f;
  --green-600: #1b8a64;
  --green-500: #21a574;
  --green-100: #d8f3e6;
  --green-50:  #ecfaf3;

  /* Accent — latex amber for highlights */
  --amber-600: #b45309;
  --amber-100: #fef3c7;

  /* Semantic */
  --ink:        #1a2421;
  --ink-soft:   #4b5a54;
  --ink-faint:  #7d8c86;
  --line:       #e3e9e5;
  --line-soft:  #eef2ef;
  --bg:         #f4f6f3;
  --surface:    #ffffff;
  --surface-2:  #fafbf9;

  --danger:     #d2322e;
  --danger-bg:  #fdeceb;
  --warn:       #b45309;
  --warn-bg:    #fef3c7;
  --info:       #1d4ed8;
  --info-bg:    #e7eefc;
  --ok:         #15803d;
  --ok-bg:      #e3f5e9;

  /* Typography */
  --font: 'Prompt', 'Noto Sans Thai', -apple-system, 'Segoe UI', sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.375rem;
  --fs-xl: 1.75rem;
  --fs-num: 1.5rem;

  /* Shape & depth */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --shadow-1: 0 1px 2px rgba(12, 59, 46, .05), 0 1px 6px rgba(12, 59, 46, .04);
  --shadow-2: 0 4px 16px rgba(12, 59, 46, .08), 0 2px 4px rgba(12, 59, 46, .05);
  --shadow-3: 0 12px 36px rgba(12, 59, 46, .14);

  /* Layout */
  --sidebar-w: 232px;
  --bottombar-h: 62px;
  --content-max: 1180px;

  /* Touch */
  --tap: 48px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

img { display: block; }
/* svg ไม่ระบุขนาด → default 18px (กฎ class เฉพาะทางจะ override เอง) */
svg { display: inline-block; vertical-align: -0.2em; width: 18px; height: 18px; flex: none; }
h1 svg, h2 svg, h3 svg, label svg { width: 19px; height: 19px; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--green-100); }

.num, .tnum { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* Scrollbars (desktop) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c9d4ce; border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
* { scrollbar-width: thin; scrollbar-color: #c9d4ce transparent; }

/* ============================================================
   APP SHELL
   ============================================================ */
#app { min-height: 100dvh; }

.shell { display: flex; min-height: 100dvh; }

/* ----- Brand logo (ใช้ทั้ง header + login) ----- */
.brand-logo {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, var(--green-500), var(--green-700));
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.1rem; color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 3px 10px rgba(12,59,46,.28);
}
.brand-name { font-weight: 700; font-size: 1.0625rem; line-height: 1.15; color: var(--ink); white-space: nowrap; }
.brand-name span { color: var(--green-600); }
.brand-sub { font-size: var(--fs-xs); color: var(--ink-faint); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ----- Top header + แถบ pill เลื่อนแนวนอน (ทุกขนาดจอ) ----- */
.appwrap { min-height: 100dvh; display: flex; flex-direction: column; }

.topshell {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(165%) blur(18px); -webkit-backdrop-filter: saturate(165%) blur(18px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: var(--content-max); margin: 0 auto;
  padding: 11px 20px 9px;
}
.appbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.appbar-titles { min-width: 0; }
.appbar-logout {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 40px; padding: 0 14px; border-radius: 11px;
  color: var(--ink-soft); font-size: var(--fs-sm); font-weight: 500;
  border: 1px solid var(--line); background: var(--surface);
  transition: all .15s ease; cursor: pointer;
}
.appbar-logout:hover { border-color: #f3b9b7; color: var(--danger); background: var(--danger-bg); }
.appbar-logout svg { width: 17px; height: 17px; }

.pillnav {
  display: flex; gap: 8px; align-items: center;
  max-width: var(--content-max); margin: 0 auto;
  padding: 2px 16px 12px;
  overflow-x: auto; scroll-behavior: smooth;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  cursor: grab; -webkit-user-select: none; user-select: none;
}
.pillnav::-webkit-scrollbar { display: none; }
.pillnav.dragging { cursor: grabbing; scroll-behavior: auto; }
.pillnav.dragging .pill { pointer-events: none; }
.pill {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 0 18px; border-radius: 999px; white-space: nowrap;
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-soft);
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
  cursor: pointer;
}
.pill svg { width: 17px; height: 17px; color: var(--ink-faint); transition: color .18s ease; }
.pill:hover { border-color: var(--green-500); color: var(--green-700); background: var(--green-50); }
.pill:hover svg { color: var(--green-600); }
.pill:active { transform: scale(.96); }
.pill.active {
  background: linear-gradient(135deg, var(--green-700), var(--green-600));
  border-color: transparent; color: #fff;
  box-shadow: 0 5px 16px rgba(22, 106, 79, .34);
}
.pill.active svg { color: #fff; }

/* ----- Main content ----- */
.main {
  flex: 1; min-width: 0; width: 100%;
  max-width: var(--content-max); margin: 0 auto;
  padding: 22px 24px calc(56px + env(safe-area-inset-bottom));
}
.main-inner { width: 100%; min-width: 0; }

/* กัน grid/flex item ขยายเกิน container (min-width:auto ของ grid) */
.layout-2col > *, .main-inner > *, .section-gap > * { min-width: 0; }
.layout-2col { min-width: 0; max-width: 100%; }

/* Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; }
.page-head .sub { color: var(--ink-faint); font-size: var(--fs-sm); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: var(--fs-md); font-weight: 600; display: flex; align-items: center; gap: 9px; }
.card-head h2 svg { width: 19px; height: 19px; color: var(--green-600); }
.card-head .hint { font-size: var(--fs-xs); color: var(--ink-faint); }

/* ----- Stat cards ----- */
.stats { display: grid; gap: 12px; margin-bottom: 18px; }
.stats.cols-2 { grid-template-columns: repeat(2, 1fr); }
.stats.cols-3 { grid-template-columns: repeat(3, 1fr); }
.stats.cols-4 { grid-template-columns: repeat(4, 1fr); }
.stat {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 16px 18px;
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
}
.stat .s-label { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-faint); display: flex; align-items: center; gap: 6px; }
.stat .s-label svg { width: 14px; height: 14px; }
.stat .s-value { font-size: var(--fs-num); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.15; }
.stat .s-sub { font-size: var(--fs-xs); color: var(--ink-faint); }
.stat.tone-green  { background: linear-gradient(135deg, var(--green-50), #fff 70%); border-color: var(--green-100); }
.stat.tone-green .s-value { color: var(--green-800); }
.stat.tone-red    { background: linear-gradient(135deg, var(--danger-bg), #fff 70%); border-color: #f6d2d1; }
.stat.tone-red .s-value { color: var(--danger); }
.stat.tone-amber  { background: linear-gradient(135deg, var(--warn-bg), #fff 70%); border-color: #f3e0b0; }
.stat.tone-amber .s-value { color: var(--amber-600); }
.stat.tone-blue   { background: linear-gradient(135deg, var(--info-bg), #fff 70%); border-color: #cfdcf7; }
.stat.tone-blue .s-value { color: var(--info); }
.stat.hero {
  background: linear-gradient(135deg, var(--green-800), var(--green-600));
  border: none; color: #fff;
}
.stat.hero .s-label { color: #bfe6d2; }
.stat.hero .s-value { color: #fff; }
.stat.hero .s-sub { color: #a8d9c2; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border-radius: 12px; font-weight: 500; font-size: var(--fs-base);
  border: 1px solid transparent;
  transition: filter .15s ease, transform .1s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap; user-select: none;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green-700); color: #fff; box-shadow: 0 2px 8px rgba(22,106,79,.3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink-soft); }
.btn-secondary:hover { border-color: var(--green-600); color: var(--green-700); background: var(--green-50); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #fadbda; }
.btn-ghost { color: var(--ink-soft); min-height: 38px; padding: 0 12px; border-radius: 10px; }
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn-lg { min-height: 50px; font-size: var(--fs-md); border-radius: 14px; padding: 0 26px; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: var(--fs-sm); border-radius: 9px; }
.btn-icon { min-width: 38px; min-height: 38px; padding: 0; border-radius: 10px; }
.btn-block { width: 100%; }

/* ----- Forms ----- */
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(12, 1fr); }
.fg-3 { grid-column: span 3; } .fg-4 { grid-column: span 4; }
.fg-6 { grid-column: span 6; } .fg-8 { grid-column: span 8; }
.fg-12 { grid-column: span 12; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label {
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-soft);
  display: flex; align-items: center; gap: 5px;
}
.field > label .req { color: var(--danger); }

.control {
  position: relative; display: flex; align-items: center;
}
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 16px; /* prevents iOS zoom */
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  appearance: none; -webkit-appearance: none;
}
.input:hover { border-color: #c6d2cb; }
.input:focus {
  outline: none; border-color: var(--green-600);
  box-shadow: 0 0 0 3.5px rgba(27,138,100,.16);
}
.input::placeholder { color: #a7b4ae; }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--ink-soft); }
textarea.input { min-height: 76px; resize: vertical; }

/* unit suffix inside control */
.control .unit {
  position: absolute; right: 14px;
  font-size: var(--fs-sm); color: var(--ink-faint); pointer-events: none;
  background: inherit;
}
.control.has-unit .input { padding-right: 52px; }

/* select arrow */
.control.is-select::after {
  content: ""; position: absolute; right: 14px; width: 10px; height: 10px;
  border-right: 2px solid var(--ink-faint); border-bottom: 2px solid var(--ink-faint);
  transform: rotate(45deg) translateY(-3px); pointer-events: none;
}
.control.is-select select { padding-right: 38px; }

/* computed/readonly display field */
.computed {
  min-height: var(--tap); display: flex; align-items: center; justify-content: space-between;
  background: var(--green-50); border: 1.5px dashed var(--green-100);
  border-radius: var(--r-md); padding: 10px 14px;
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--green-800);
}
.computed .c-unit { font-size: var(--fs-xs); font-weight: 400; color: var(--ink-faint); }
.computed.tone-red { background: var(--danger-bg); border-color: #f6d2d1; color: var(--danger); }
.computed.tone-amber { background: var(--warn-bg); border-color: #f3e0b0; color: var(--amber-600); }

/* segmented control */
.segmented {
  display: inline-flex; background: var(--line-soft); border-radius: 12px; padding: 3px; gap: 2px;
}
.segmented button {
  min-height: 38px; padding: 0 16px; border-radius: 9px;
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-soft);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.segmented button.active { background: var(--surface); color: var(--green-800); box-shadow: var(--shadow-1); font-weight: 600; }

/* chip-select (สาขา ฯลฯ) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 16px; border-radius: 99px;
  border: 1.5px solid var(--line); background: var(--surface);
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--green-500); color: var(--green-700); }
.chip.active { background: var(--green-700); border-color: var(--green-700); color: #fff; box-shadow: 0 2px 8px rgba(22,106,79,.25); }

/* autocomplete dropdown */
.autocomplete { position: relative; }
.ac-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-2);
  max-height: 264px; overflow-y: auto; padding: 5px;
}
.ac-item {
  padding: 11px 12px; border-radius: 9px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: var(--fs-base);
}
.ac-item:hover, .ac-item.hl { background: var(--green-50); }
.ac-item .ac-meta { font-size: var(--fs-xs); color: var(--ink-faint); }

/* ----- Tables (desktop) → cards (mobile) ----- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0 0 var(--r-lg) var(--r-lg); }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.tbl thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  font-weight: 500; color: var(--ink-faint); text-align: left;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-size: var(--fs-xs);
}
.tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tbody tr { transition: background .12s ease; }
.tbl tbody tr:hover { background: var(--green-50); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .t-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl th.t-num { text-align: right; }
.tbl .t-actions { text-align: right; white-space: nowrap; }
.tbl tfoot td {
  padding: 12px 14px; background: var(--surface-2); font-weight: 600;
  border-top: 2px solid var(--line); font-variant-numeric: tabular-nums;
}

/* ----- แถวสรุปท้ายตารางสรุปยางวันนี้ ----- */
.tbl-pivot tfoot td { border-top: 1px solid var(--line-soft); background: transparent; }
.tbl-pivot tfoot tr:first-child td { border-top: 2px solid var(--line); }
.sum-row td:first-child { font-weight: 600; }
.sum-label { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; }
.sum-dot { width: 9px; height: 9px; border-radius: 99px; flex: none; box-shadow: 0 0 0 3px rgba(0,0,0,.03); }
.sum-row .t-num b { font-size: 0.9375rem; font-weight: 700; }
.sum-dash { color: #c4cfca; font-weight: 400; }

.sum-weight { background: linear-gradient(90deg, var(--green-50), transparent 55%); }
.sum-weight .sum-dot { background: var(--green-600); }
.sum-weight .t-num b { color: var(--green-700); }

.sum-money { background: linear-gradient(90deg, var(--info-bg), transparent 55%); }
.sum-money .sum-dot { background: var(--info); }
.sum-money .t-num b { color: var(--info); }

.sum-avg { background: linear-gradient(90deg, var(--warn-bg), transparent 55%); }
.sum-avg .sum-dot { background: var(--amber-600); }
.sum-avg .t-num b { color: var(--amber-600); }

/* compact table (มือถือ) — แถวสลับสี ตัวเลขชิดขวา อ่านเทียบง่าย */
.tbl-compact { font-size: 0.75rem; }
.tbl-compact thead th { padding: 9px 8px; font-size: 0.625rem; }
.tbl-compact tbody td { padding: 10px 8px; }
.tbl-compact tbody tr:nth-child(even) { background: var(--surface-2); }
.tbl-compact tfoot td { padding: 11px 8px; font-size: 0.75rem; }
.tbl-compact .badge { padding: 1px 8px; font-size: 0.625rem; }
.tbl-compact .badge .dot { width: 5px; height: 5px; }
.tbl-compact .btn-icon { min-width: 34px; min-height: 34px; border-radius: 8px; }
.tbl-compact .btn-icon svg { width: 15px; height: 15px; }
.tbl-compact .t-actions { white-space: nowrap; padding-left: 2px; padding-right: 8px; }
.t-sub {
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap;
  font-size: 0.625rem; color: var(--ink-faint); font-weight: 400; margin-top: 3px;
}

/* denom chips — ป้ายแบงค์/เหรียญแบบมีสี (ใช้ใน ยอดเงินยกมา + ประวัติการนับเงิน) */
.denom-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.denom-chip {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 4px 10px; border-radius: 9px;
  font-size: 0.6875rem; font-weight: 600; line-height: 1.1;
}
.denom-chip i { font-style: normal; font-weight: 500; opacity: 0.72; font-size: 0.625rem; }
.denom-chip b { font-variant-numeric: tabular-nums; }

/* ยอดเงินยกมา — การ์ดไล่สีเขียว */
.carry-panel {
  background: linear-gradient(135deg, var(--green-50), #fff 78%);
  border: 1px solid var(--green-100); border-radius: var(--r-md);
  padding: 13px 15px; margin-bottom: 14px;
}
.carry-panel .carry-total { color: var(--green-800); font-size: 1.1rem; }

/* ===== หน้าสรุปจำนวนเงิน — โทนการ์ดมีสี ===== */
/* ไทล์แบงค์ในยอดเงินยกมา */
.denom-tiles { display: flex; gap: 6px; }
.denom-tile {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: 10px; padding: 7px 3px; text-align: center;
}
.denom-tile .lbl { font-size: 0.6rem; font-weight: 600; margin-bottom: 2px; white-space: nowrap; }
.denom-tile .cnt { font-size: 1.05rem; font-weight: 700; color: var(--ink); }

/* ช่องกรอกแบงค์แบบการ์ด (label บน + ตัวเลขใหญ่ชิดขวา) */
.denom-input {
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); padding: 9px 13px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.denom-input:focus-within { border-color: var(--green-600); box-shadow: 0 0 0 3.5px rgba(27,138,100,.16); }
.denom-input label { display: block; font-size: 0.6875rem; font-weight: 600; margin-bottom: 2px; }
.denom-input input {
  width: 100%; border: 0; outline: none; background: transparent; padding: 0;
  font-size: 1.2rem; font-weight: 600; text-align: right; color: var(--ink);
  font-variant-numeric: tabular-nums; min-height: 26px;
}
.denom-input input::placeholder { color: #c4cfca; }

/* กล่องยอดรวมทั้งสิ้น */
.cash-total {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--green-50), var(--green-100));
  border: 1px solid var(--green-100); border-radius: var(--r-md); padding: 15px 18px;
}
.cash-total .label { font-weight: 600; color: var(--green-800); }
.cash-total .val { font-size: 1.5rem; font-weight: 700; color: var(--green-700); }

/* การ์ดประวัติการนับเงิน */
.cash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 13px; }
.cash-rec {
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: 15px 16px;
}
.cash-rec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cash-rec-date { font-weight: 600; font-size: 0.9375rem; }
.cash-rec-amount { font-size: 1.35rem; font-weight: 700; color: var(--green-800); }
.denom-cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.denom-cell {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  padding: 8px 11px; border-radius: 9px; font-size: 0.75rem;
}
.denom-cell .lbl { color: var(--ink-soft); font-weight: 500; }
.denom-cell .cnt { font-weight: 700; color: var(--ink); }
.denom-cell .cnt.text-faint { font-weight: 500; color: var(--ink-faint); }
.cash-rec-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 13px; }
@media (max-width: 700px) { .cash-grid { grid-template-columns: 1fr; } }

/* metric grid — แผ่นสเปกตัวเลขแบบเส้นบาง (ใช้ในการ์ดรายการส่งยาง) */
.metric-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  margin-top: 11px; background: var(--line); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line);
}
.metric-grid > div {
  background: var(--surface); padding: 8px 12px; min-width: 0;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.metric-grid span { font-size: 0.6875rem; color: var(--ink-faint); white-space: nowrap; flex: none; }
.metric-grid b { font-size: 0.8125rem; font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; }
/* ช่องค่าคู่ (2 ราคา): ป้ายบน ค่าล่าง เต็มความกว้างช่อง */
.metric-grid > div.stack { flex-direction: column; align-items: stretch; gap: 1px; }
.metric-grid > div.stack b { text-align: left; white-space: normal; }

/* ไฮไลต์การ์ดที่ถูกเลือก (checkbox) */
.rec.row-selected { border-color: var(--green-500); background: var(--green-50); box-shadow: 0 0 0 1px var(--green-500); }

/* แถบ "เลือกทั้งหมด" ใต้หัวข้อรายการ */
.selectall-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px; border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink-soft); cursor: pointer;
}
.selectall-bar:hover { color: var(--green-700); }
.selectall-count { margin-left: auto; font-size: var(--fs-xs); color: var(--green-700); font-weight: 600; }
@media (max-width: 960px) { .selectall-bar { padding: 11px 16px; } }

/* record cards (mobile list) */
.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 13px 14px;
  box-shadow: var(--shadow-1);
}
.rec .rec-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rec .rec-title { font-weight: 600; font-size: var(--fs-base); }
.rec .rec-amount { font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-md); color: var(--green-800); white-space: nowrap; }
.rec .rec-amount.neg { color: var(--danger); }
.rec .rec-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 7px; font-size: var(--fs-xs); color: var(--ink-faint); }
.rec .rec-meta b { color: var(--ink-soft); font-weight: 500; }
.rec .rec-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line-soft); }
.rec .rec-foot .rec-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.rec .rec-acts { display: flex; gap: 6px; }

/* ----- Badges ----- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: 500;
  border-radius: 99px; padding: 3px 10px; white-space: nowrap;
}
.badge-green { background: var(--ok-bg); color: var(--ok); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-amber { background: var(--warn-bg); color: var(--warn); }
.badge-blue { background: var(--info-bg); color: var(--info); }
.badge-gray { background: var(--line-soft); color: var(--ink-soft); }
.badge-purple { background: #f1e9fc; color: #7c3aed; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-teal { background: #ccfbf1; color: #0f766e; }
.badge-cyan { background: #cffafe; color: #0e7490; }
.badge-indigo { background: #e0e7ff; color: #4338ca; }
.badge-rose { background: #ffe4e6; color: #be123c; }
.badge .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }

/* ----- สถานะยางที่จัดส่ง — แยกสีให้ชัดเจน ----- */
.badge-st { font-weight: 600; padding: 3px 11px; }
.badge-waiting  { background: var(--warn-bg); color: var(--warn); box-shadow: inset 0 0 0 1px #f1d79a; }   /* รอส่ง — เหลืองอำพันอ่อน */
.badge-shipping { background: var(--info); color: #fff; }                                                   /* กำลังจัดส่ง — น้ำเงินทึบ เด่นชัด */
.badge-shipping .dot { background: #fff; }
.badge-done     { background: var(--ok-bg); color: var(--ok); box-shadow: inset 0 0 0 1px #b5e3c4; }        /* ส่งแล้ว — เขียว */

/* checkbox */
.cbx {
  width: 20px; height: 20px; flex: none;
  accent-color: var(--green-600); cursor: pointer;
  border-radius: 6px;
}
tr.row-selected { background: var(--green-50) !important; }

/* ----- Filter bar ----- */
.filterbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.filterbar .input, .filterbar select.input { min-height: 42px; }
.filterbar .control { min-width: 0; }
.search-box { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-faint); pointer-events: none; }
.search-box .input { padding-left: 38px; min-height: 42px; }

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(16, 36, 28, .5);
  display: grid; place-items: center; padding: 18px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  transform: translateY(14px) scale(.98); transition: transform .22s cubic-bezier(.32,.72,.27,1);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal .m-head { padding: 20px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal .m-head h3 { font-size: var(--fs-md); font-weight: 600; }
.modal .m-body { padding: 16px 22px; }
.modal .m-foot { padding: 0 22px 20px; display: flex; gap: 10px; justify-content: flex-end; }
.modal.modal-lg { max-width: 760px; }

@media (max-width: 640px) {
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal {
    max-width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 92dvh;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(40px);
  }
  .modal .m-foot { flex-direction: column-reverse; }
  .modal .m-foot .btn { width: 100%; min-height: 50px; }
}

/* ----- Toast ----- */
.toasts {
  position: fixed; z-index: 90; display: flex; flex-direction: column; gap: 8px;
  top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(92vw, 400px); pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff;
  border-radius: var(--r-md); padding: 13px 16px;
  font-size: var(--fs-sm); box-shadow: var(--shadow-3);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn .25s cubic-bezier(.32,.72,.27,1);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.ok svg { color: #5ee2a0; }
.toast.err { background: #5c1513; }
.toast.err svg { color: #ff9d9a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.97); } to { opacity: 1; transform: none; } }
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ----- Empty / loading states ----- */
.empty {
  text-align: center; padding: 44px 20px; color: var(--ink-faint);
}
.empty svg { width: 44px; height: 44px; margin: 0 auto 10px; opacity: .4; }
.empty .e-title { font-weight: 500; color: var(--ink-soft); margin-bottom: 3px; }
.empty .e-sub { font-size: var(--fs-sm); }

.skeleton {
  background: linear-gradient(90deg, var(--line-soft) 25%, #f7f9f6 50%, var(--line-soft) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm); min-height: 16px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.spinner {
  width: 20px; height: 20px; border-radius: 99px;
  border: 2.5px solid var(--green-100); border-top-color: var(--green-600);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Login ----- */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 22px;
  background:
    radial-gradient(800px 420px at 85% -10%, rgba(33,165,116,.16), transparent 60%),
    radial-gradient(700px 400px at -10% 110%, rgba(180,83,9,.07), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-3); border: 1px solid var(--line-soft);
  padding: 34px 28px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}
.login-card .brand-logo { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 16px; font-size: 1.6rem; }
.login-card h1 { font-size: var(--fs-lg); font-weight: 600; margin-bottom: 4px; }
.login-card .sub { color: var(--ink-faint); font-size: var(--fs-sm); margin-bottom: 26px; }
.role-btns { display: flex; flex-direction: column; gap: 12px; }
.role-btn {
  display: flex; align-items: center; gap: 14px; text-align: left;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 16px; transition: all .15s ease; min-height: 72px;
}
.role-btn:hover { border-color: var(--green-500); background: var(--green-50); }
.role-btn .r-icon {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
}
.role-btn .r-icon svg { width: 22px; height: 22px; }
.role-btn.admin .r-icon { background: var(--green-100); color: var(--green-700); }
.role-btn.employee .r-icon { background: var(--info-bg); color: var(--info); }
.role-btn b { display: block; font-size: var(--fs-base); font-weight: 600; }
.role-btn span { font-size: var(--fs-xs); color: var(--ink-faint); }

/* ----- Util ----- */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mt-4 { margin-top: 26px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.text-faint { color: var(--ink-faint); } .text-soft { color: var(--ink-soft); }
.text-green { color: var(--green-700); } .text-red { color: var(--danger); }
.text-sm { font-size: var(--fs-sm); } .text-xs { font-size: var(--fs-xs); }
.w-600 { font-weight: 600; } .w-500 { font-weight: 500; }
.hide { display: none !important; }
.section-gap { display: flex; flex-direction: column; gap: 18px; }

.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* desktop/mobile visibility helpers */
.only-mobile { display: none !important; }
.only-desktop { display: revert; }

/* ============================================================
   ใบเสร็จความร้อน — ใช้ทั้งพรีวิว (.receipt-paper) และตอนพิมพ์ (#lr-receipt)
   ============================================================ */
.rc { color: #000; font-family: var(--font); font-size: 12.5px; line-height: 1.5; }
.rc-center { text-align: center; }
.rc-shop { font-size: 17px; font-weight: 700; letter-spacing: .01em; }
.rc-sub { font-size: 11px; }
.rc-title { font-weight: 600; margin: 3px 0 5px; }
.rc-line { border-top: 1px solid #000; margin: 5px 0; }
.rc-line.dash { border-top-style: dashed; }
.rc-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.rc-row > span:last-child, .rc-row b { text-align: right; font-variant-numeric: tabular-nums; }
.rc-row b { font-weight: 700; }
.rc-total { font-size: 15px; font-weight: 700; }
.rc-foot { font-size: 11px; }

/* พรีวิวในโมดัล */
.receipt-opts { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.receipt-preview-scroll {
  display: flex; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r-md);
  padding: 16px; max-height: 56vh; overflow: auto;
}
.receipt-paper { background: #fff; box-shadow: 0 2px 14px rgba(12,59,46,.16); padding: 12px 13px; border-radius: 2px; }
#lr-receipt { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 960px) {
  .main { padding: 16px 14px calc(32px + env(safe-area-inset-bottom)); }
  .only-mobile { display: revert !important; }
  .only-desktop { display: none !important; }

  .appbar { padding: 10px 16px 8px; }
  .brand-logo { width: 38px; height: 38px; border-radius: 11px; font-size: 1rem; }
  .pillnav { padding: 2px 14px 11px; }

  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 1.1875rem; }

  .stats.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .stats.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .stats { gap: 8px; }
  .stat { padding: 12px 11px; border-radius: var(--r-md); gap: 3px; }
  .stat .s-value { font-size: 1.05rem; }
  .stat .s-label { font-size: 0.625rem; }
  .stat .s-sub { font-size: 0.625rem; }

  .card { border-radius: var(--r-md); }
  .card-pad { padding: 16px; }
  .card-head { padding: 13px 16px; flex-wrap: wrap; }
  .card-head h2 { flex: 1 1 auto; min-width: 0; }
  /* กลุ่มปุ่ม/ช่องในหัวการ์ด ห่อลงบรรทัดใหม่เต็มความกว้างบนมือถือ */
  .card-head > .row { flex-wrap: wrap; }

  .form-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .fg-3, .fg-4, .fg-6 { grid-column: span 1; }
  .fg-8, .fg-12 { grid-column: span 2; }
  .fg-m-full { grid-column: span 2 !important; }

  /* chips (สาขา/กอง) บนมือถือ: แถวเดียวเลื่อนแนวนอน — ฟอร์มสั้นลง */
  .chips {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 3px; scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }

  /* dropdown ชื่อลูกค้ากว้างพอแม้ช่องเป็นครึ่งคอลัมน์ */
  .ac-menu { min-width: min(250px, 88vw); }

  .filterbar { gap: 8px; }
  .search-box { max-width: none; }

  /* sticky submit on mobile forms */
  .submit-bar {
    position: sticky; bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 20; padding-top: 6px;
  }
  .submit-bar .btn { width: 100%; min-height: 52px; border-radius: 16px; box-shadow: 0 8px 24px rgba(22,106,79,.32); }
}

@media (max-width: 640px) {
  /* ส่วนหัว: เหลือไอคอนออกจากระบบอย่างเดียว ประหยัดพื้นที่ */
  .appbar-logout { padding: 0; min-width: 40px; justify-content: center; }
  .appbar-logout .logout-text { display: none; }
}

@media (max-width: 380px) {
  .stats.cols-2, .stats.cols-4 { grid-template-columns: 1fr 1fr; }
  .stats.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .stats.cols-3 .stat .s-value { font-size: 0.9375rem; }
  /* ฟอร์มคง 2 คอลัมน์แม้จอเล็ก — แค่ลดช่องไฟ */
  .form-grid { gap: 10px; }
}

/* iOS specifics */
@supports (-webkit-touch-callout: none) {
  .input, select.input { font-size: 16px !important; }
}

/* Android / coarse pointers: bigger targets */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 46px; }
  .btn-icon { min-width: 42px; min-height: 42px; }
  .tbl tbody td { padding-top: 13px; padding-bottom: 13px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Print */
@media print {
  .topshell, .btn, .filterbar, .submit-bar, .appbar-logout { display: none !important; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; border: 1px solid #ddd; }
  .main { margin: 0; padding: 0; }
}
