/* ============================================================
   Sales App — Liquid Glass UI (iOS 27 inspired)  · 2026-10-09
   Speed rules: system fonts, no images, no web fonts, no JS.
   Real blur (backdrop-filter) only on floating chrome (bars,
   modals); content cards use translucent fills over a static
   gradient, so scrolling stays smooth on low-end phones.
   ============================================================ */
:root {
  --tint: #0a84ff;
  --tint-2: #5e5ce6;
  --danger: #ff3b30;
  --success: #1fa45a;
  --warn: #ff9f0a;
  --ink: #0b1220;
  --ink-soft: rgba(11, 18, 32, 0.62);
  --ink-faint: rgba(11, 18, 32, 0.40);
  --line: rgba(11, 18, 32, 0.08);
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --glass-edge: rgba(255, 255, 255, 0.85);
  --field: rgba(255, 255, 255, 0.72);
  --hi: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 -1px 0 rgba(255, 255, 255, 0.25);
  --shadow: 0 1px 1px rgba(11, 18, 32, 0.04), 0 8px 24px rgba(11, 18, 32, 0.07);
  --shadow-float: 0 10px 40px rgba(11, 18, 32, 0.16), 0 2px 6px rgba(11, 18, 32, 0.06);
  --r-xl: 26px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-pill: 999px;
  --blur: saturate(180%) blur(18px);
  --bg-a: #dfe9ff;
  --bg-b: #f6e8ff;
  --bg-c: #e3fbf4;
  --bg-base: #f2f4f9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f4f6fb;
    --ink-soft: rgba(244, 246, 251, 0.66);
    --ink-faint: rgba(244, 246, 251, 0.40);
    --line: rgba(255, 255, 255, 0.09);
    --glass: rgba(40, 44, 58, 0.55);
    --glass-strong: rgba(36, 40, 54, 0.78);
    --glass-edge: rgba(255, 255, 255, 0.14);
    --field: rgba(255, 255, 255, 0.07);
    --hi: inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 -1px 0 rgba(255, 255, 255, 0.03);
    --shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-float: 0 10px 40px rgba(0, 0, 0, 0.5);
    --bg-a: #1b2550; --bg-b: #3a1d4f; --bg-c: #0f3a37; --bg-base: #0b0e17;
    --success: #32d74b; --danger: #ff453a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               "Noto Sans Thai", "Sarabun", "Leelawadee UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg-base);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
/* static ambient gradient on its own layer — painted once, never repainted on scroll */
body::before {
  content: ""; position: fixed; inset: -10vmax; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40vmax 40vmax at 12% 8%, var(--bg-a), transparent 70%),
    radial-gradient(38vmax 38vmax at 92% 18%, var(--bg-b), transparent 70%),
    radial-gradient(45vmax 45vmax at 60% 100%, var(--bg-c), transparent 70%),
    var(--bg-base);
  transform: translateZ(0);
}

a { color: var(--tint); text-decoration: none; }
a:hover { opacity: 0.8; }

.container { max-width: 1120px; margin: 0 auto; padding: 18px 16px 120px; }

h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.025em; margin: 6px 0 14px; }
h2 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; color: var(--ink); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head .sub { color: var(--ink-soft); font-size: 0.92rem; margin: -10px 0 14px; }

/* ---------- Glass primitives ---------- */
.glass, .card, .stat, .flash, .modal-box, .topbar, .tabbar, .savebar {
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--hi), var(--shadow);
}
/* real blur only on floating chrome */
.topbar, .tabbar, .savebar, .modal-box {
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: var(--hi), var(--shadow-float);
}

/* ---------- Top bar (floating pill) ---------- */
.topbar {
  position: sticky; top: 10px; z-index: 50;
  max-width: 1120px; margin: 10px auto 0; width: calc(100% - 20px);
  border-radius: var(--r-pill);
  padding: 6px 6px 6px 18px;
  display: flex; align-items: center; gap: 12px;
}
.topbar .brand { color: var(--ink); font-weight: 800; font-size: 1.02rem; letter-spacing: -0.02em; margin-right: auto; white-space: nowrap; }
.topbar .nav { display: flex; align-items: center; gap: 2px; }
.topbar .nav a {
  color: var(--ink-soft); font-size: 0.9rem; font-weight: 600;
  padding: 8px 13px; border-radius: var(--r-pill); white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.topbar .nav a:hover { color: var(--ink); background: var(--line); opacity: 1; }
.topbar .nav a.active { color: var(--ink); background: var(--field); box-shadow: var(--hi), 0 1px 4px rgba(0,0,0,0.08); }
.topbar .user {
  display: inline-flex; align-items: center; gap: 8px; color: var(--ink-soft);
  font-size: 0.86rem; font-weight: 600; padding: 6px 12px 6px 6px; border-radius: var(--r-pill);
}
.topbar .user:hover { background: var(--line); opacity: 1; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center;
  background: linear-gradient(135deg, var(--tint), var(--tint-2)); color: #fff; font-weight: 800; font-size: 0.85rem;
  text-transform: uppercase;
}

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar { display: none; }
@media (max-width: 820px) {
  .topbar .nav { display: none; }
  .topbar { padding: 6px 6px 6px 16px; }
  .tabbar {
    display: flex; position: fixed; z-index: 60;
    left: 50%; transform: translateX(-50%);
    bottom: calc(10px + env(safe-area-inset-bottom));
    border-radius: var(--r-pill); padding: 6px; gap: 2px;
    max-width: calc(100% - 20px); overflow-x: auto; scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    min-width: 62px; padding: 6px 10px; border-radius: var(--r-pill);
    color: var(--ink-soft); font-size: 0.68rem; font-weight: 600; white-space: nowrap;
  }
  .tabbar a .ic { font-size: 1.2rem; line-height: 1.2; }
  .tabbar a.active { color: var(--tint); background: var(--field); box-shadow: var(--hi); }
  h1 { font-size: 1.5rem; }
}

/* ---------- Flash ---------- */
.flash { border-radius: var(--r-md); padding: 10px 16px; margin: 4px 0 16px; font-size: 0.93rem; font-weight: 500; border-left: 4px solid var(--tint); }
.flash p { margin: 3px 0; }

/* ---------- Cards ---------- */
.card { border-radius: var(--r-lg); padding: 18px; margin-bottom: 16px; }
.card > h2:first-child { margin-top: 0; }
.card.table-wrap { padding: 6px; }
.card.table-wrap > h2 { padding: 12px 12px 0; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 960px) { .grid-2 { grid-template-columns: 380px 1fr; } }
.grid-2 > .card { margin-bottom: 0; }
.section { margin-bottom: 16px; }

/* ---------- Stat tiles ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 760px) { .cards { grid-template-columns: repeat(4, 1fr); } }
.stat { border-radius: var(--r-lg); padding: 14px 16px 16px; position: relative; overflow: hidden; }
.stat .label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--tint)); }
.stat:nth-child(2) { --dot: var(--warn); }
.stat:nth-child(3) { --dot: var(--tint-2); }
.stat:nth-child(4) { --dot: var(--success); }
.stat .value { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .value.good { color: var(--success); }
.stat .value.bad { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--glass-edge);
  background: var(--field);
  color: var(--ink);
  border-radius: var(--r-pill);
  padding: 9px 18px;
  font-family: inherit; font-size: 0.93rem; font-weight: 600; line-height: 1.3;
  cursor: pointer; text-align: center; white-space: nowrap;
  box-shadow: var(--hi), 0 1px 3px rgba(11, 18, 32, 0.06);
  transition: transform 0.12s ease, background 0.2s, box-shadow 0.2s;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--glass-strong); opacity: 1; }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, #3a9bff, var(--tint)); border-color: rgba(255,255,255,0.35); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), 0 6px 16px rgba(10, 132, 255, 0.35);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.danger.solid {
  background: linear-gradient(180deg, #ff6259, var(--danger)); color: #fff; border-color: rgba(255,255,255,0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 6px 16px rgba(255, 59, 48, 0.3);
}
.btn.small { padding: 5px 12px; font-size: 0.84rem; }
.btn.block { display: flex; width: 100%; margin-top: 12px; padding: 13px 18px; }
.btn.icon { padding: 9px 12px; }

/* ---------- Toolbar / segmented ---------- */
.month-nav, .toolbar { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.seg {
  display: inline-flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--glass); border: 1px solid var(--glass-edge); border-radius: var(--r-pill);
  box-shadow: var(--hi), var(--shadow);
}
.seg .btn { background: transparent; border-color: transparent; box-shadow: none; padding: 7px 12px; }
.seg .btn:hover { background: var(--field); }
.seg input[type="month"], .seg input[type="date"], .month-nav input[type="month"], .month-nav input[type="date"] {
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1.2; color: var(--ink);
  padding: 7px 12px; border: 0; border-radius: var(--r-pill);
  background: var(--field); box-shadow: var(--hi);
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .toolbar .seg { width: 100%; justify-content: space-between; }
  .toolbar .actions { width: 100%; }
  .toolbar .actions .btn { flex: 1 1 auto; }
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(11, 18, 32, 0.28);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box { border-radius: var(--r-xl); max-width: 420px; width: 100%; padding: 26px; animation: pop 0.22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
.modal-box h2 { margin: 0 0 10px; color: var(--danger); font-size: 1.15rem; }
.modal-box p { margin: 0 0 8px; color: var(--ink-soft); }
.modal-box .warn-date { font-weight: 700; color: var(--ink); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; margin-top: 0; }

/* ---------- Forms ---------- */
.form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 0.88rem; color: var(--ink-soft); }
.form input, .form select, .form textarea {
  display: block; width: 100%; margin-top: 6px; padding: 11px 14px;
  font-size: 16px; font-family: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--field);
  box-shadow: inset 0 1px 2px rgba(11,18,32,0.05);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tint) !important; box-shadow: 0 0 0 4px rgba(10,132,255,0.18) !important; }
.form .btn { margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-form { display: inline; }
.inline-form label { font-size: 0.9rem; font-weight: 500; margin-right: 8px; }
.inline-form input, .inline-form select {
  font-size: 15px; font-family: inherit; padding: 7px 12px; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--field); margin: 0 4px;
}
.check { display: flex; align-items: center; gap: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  color: var(--ink-faint); font-weight: 700; font-size: 0.74rem; letter-spacing: 0.04em; text-transform: uppercase;
  background: transparent; border-bottom: 1px solid var(--line);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover td { background: rgba(10, 132, 255, 0.05); }
tbody td:first-child { border-radius: 10px 0 0 10px; }
tbody td:last-child { border-radius: 0 10px 10px 0; }
tfoot td { font-weight: 700; }
tr.inactive td { color: var(--ink-faint); }
td a { font-weight: 600; }

/* ---------- Search ---------- */
.search {
  width: 100%; font-size: 16px; font-family: inherit; color: var(--ink);
  padding: 11px 16px 11px 40px; margin: 0 0 14px;
  border: 1px solid var(--glass-edge); border-radius: var(--r-pill);
  background: var(--glass) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E") no-repeat 15px center;
  box-shadow: var(--hi), var(--shadow);
}

/* ---------- Entry table ---------- */
.entry-table input[type="text"], .entry-table input[type="number"] {
  width: 96px; font-size: 16px; font-family: inherit; padding: 8px 10px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; text-align: right; background: var(--field);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.entry-table input.note { width: 160px; text-align: left; }
.entry-table td.ro, .entry-table th.ro { color: var(--ink-faint); font-size: 0.84rem; }
.entry-table th[data-sort] { cursor: pointer; user-select: none; }
.entry-table th[data-sort]:hover { color: var(--tint); }
.entry-table tbody td:first-child { font-weight: 600; position: sticky; left: 0; background: var(--glass-strong); z-index: 1; }
.sort-ind { color: var(--tint); font-size: 0.75rem; }
.profit-pos { color: var(--success); font-weight: 700; }
.profit-neg { color: var(--danger); font-weight: 700; }
.by { font-size: 11px; color: var(--ink-faint); margin-top: 2px; font-weight: 400; }

/* sticky save bar */
.savebar {
  position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
  display: flex; gap: 10px; align-items: center;
  border-radius: var(--r-pill); padding: 6px; margin-top: 14px;
}
.savebar .btn { flex: 1; margin: 0; }
.savebar .btn.danger { flex: 0 0 auto; }
@media (max-width: 820px) { .savebar { bottom: calc(84px + env(safe-area-inset-bottom)); } }

/* ---------- P&L ---------- */
.pnl { width: 100%; }
.pnl td { text-align: right; }
.pnl td:first-child { text-align: left; color: var(--ink); }
.pnl tr.sub td:first-child { padding-left: 24px; color: var(--ink-soft); font-size: 0.88rem; }
.pnl tr.sub td { font-size: 0.88rem; color: var(--ink-soft); }
.pnl tr.total td { font-size: 1.08rem; font-weight: 800; border-top: 1px solid var(--ink-faint); border-bottom: 0; }
.pnl tr.total td:first-child { border-radius: 0; }

/* ---------- Login ---------- */
.login-wrap { max-width: 400px; margin: 12vh auto 0; text-align: center; }
.login-wrap .logo {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22px; display: grid; place-items: center;
  font-size: 2rem; background: var(--glass-strong); border: 1px solid var(--glass-edge); box-shadow: var(--hi), var(--shadow-float);
}
.login-wrap h1 { margin-bottom: 4px; }
.login-wrap .muted { color: var(--ink-soft); margin: 0 0 22px; }
.login-wrap .card { padding: 26px; text-align: left; border-radius: var(--r-xl);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); background: var(--glass-strong); }
.login-wrap .btn { width: 100%; padding: 13px; margin-top: 6px; }

/* ---------- Misc ---------- */
.badge { display: inline-block; padding: 3px 11px; border-radius: var(--r-pill); font-size: 0.76rem; font-weight: 700; }
.badge.on { background: rgba(31, 164, 90, 0.14); color: var(--success); }
.badge.off { background: var(--line); color: var(--ink-soft); }
.muted { color: var(--ink-soft); }

/* ---------- Accessibility / perf fallbacks ---------- */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar, .tabbar, .savebar, .modal-box, .login-wrap .card { background: var(--glass-strong); }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass: var(--bg-base); --glass-strong: var(--bg-base); }
  .topbar, .tabbar, .savebar, .modal-box, .login-wrap .card { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { body::before, .topbar, .tabbar, .savebar, .toolbar { display: none !important; } .card { box-shadow: none; } }

/* ---------- Mobile refinements ---------- */
@media (max-width: 600px) {
  .pnl td:first-child { white-space: normal; }
  .pnl td { padding: 10px 8px; }
  .toolbar .actions .btn.icon { flex: 0 0 auto; }
  .entry-table input[type="number"] { width: 74px; padding: 8px 6px; }
  .entry-table input.note { width: 120px; }
  .entry-table tbody td:first-child { max-width: 128px; white-space: normal; }
  .card { padding: 14px; }
}

/* ============================================================
   Liquid Glass motion layer · 2026-10-09
   Only transform / opacity are animated (GPU-composited).
   Everything switches off under prefers-reduced-motion.
   ============================================================ */
:root { --spring: cubic-bezier(.34, 1.56, .64, 1); --ease-out: cubic-bezier(.22, 1, .36, 1); }

/* page-to-page morph (Chrome/Edge 126+, Safari 18.2+); others just navigate normally */
@view-transition { navigation: auto; }
.topbar { view-transition-name: topbar; }
.tabbar { view-transition-name: tabbar; }
::view-transition-old(root) { animation: vt-out .18s ease both; }
::view-transition-new(root) { animation: vt-in .32s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; transform: scale(.985); filter: blur(4px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px) scale(1.01); filter: blur(6px); } }

/* entrance: content floats up like glass settling */
.container > * { animation: rise .55s var(--ease-out) both; }
.container > *:nth-child(2) { animation-delay: .04s; }
.container > *:nth-child(3) { animation-delay: .08s; }
.container > *:nth-child(4) { animation-delay: .12s; }
.container > *:nth-child(5) { animation-delay: .16s; }
.container > *:nth-child(n+6) { animation-delay: .2s; }
.cards .stat { animation: pop-in .6s var(--spring) both; }
.cards .stat:nth-child(2) { animation-delay: .06s; }
.cards .stat:nth-child(3) { animation-delay: .12s; }
.cards .stat:nth-child(4) { animation-delay: .18s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.94); } }
.topbar { animation: drop .6s var(--spring) both; }
@keyframes drop { from { opacity: 0; transform: translateY(-16px) scale(.96); } }
@media (max-width: 820px) {
  .tabbar { animation: lift .6s var(--spring) .1s both; }
  @keyframes lift { from { opacity: 0; transform: translate(-50%, 24px) scale(.94); } to { transform: translateX(-50%); } }
}

/* specular light: a soft highlight that follows the pointer / finger */
.stat, .seg, .btn, .login-wrap .card, .modal-box { position: relative; isolation: isolate; }
.topbar, .tabbar, .savebar { isolation: isolate; }
.login-wrap .card { overflow: hidden; }
.stat::after, .topbar::after, .tabbar::after, .savebar::after, .seg::after, .btn::after, .login-wrap .card::after, .modal-box::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(160px circle at var(--mx, 50%) var(--my, -40%), rgba(255,255,255,.55), transparent 60%);
  opacity: 0; transition: opacity .35s ease;
}
.stat:hover::after, .topbar:hover::after, .tabbar:hover::after, .savebar:hover::after, .seg:hover::after,
.btn:hover::after, .login-wrap .card:hover::after, .lit::after { opacity: 1; }
@media (prefers-color-scheme: dark) {
  .stat::after, .topbar::after, .tabbar::after, .savebar::after, .seg::after, .btn::after, .login-wrap .card::after, .modal-box::after {
    background: radial-gradient(160px circle at var(--mx, 50%) var(--my, -40%), rgba(255,255,255,.14), transparent 60%);
  }
}
/* glass rim sheen that sweeps once on load */
.stat::before, .login-wrap .card::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.55) 48%, transparent 60%);
  transform: translateX(-120%); animation: sweep 1.4s var(--ease-out) .5s both;
}
@keyframes sweep { to { transform: translateX(120%); } }

/* liquid press: squish + spring back */
.btn, .tabbar a, .topbar .nav a { transition: transform .45s var(--spring), background .2s, box-shadow .25s, color .2s; }
@media (hover: hover) { .btn:hover { transform: translateY(-1px); } }
.btn:active, .tabbar a:active, .topbar .nav a:active { transform: scale(.94); transition-duration: .1s; }
.btn.primary:hover { box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 10px 24px rgba(10,132,255,.42); }
.btn .ripple {
  position: absolute; border-radius: 50%; pointer-events: none; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  background: rgba(255,255,255,.6); transform: scale(0); animation: ripple .6s var(--ease-out) forwards;
}
.btn { overflow: hidden; }
@keyframes ripple { to { transform: scale(26); opacity: 0; } }

/* active tab: blob morphs in */
.tabbar a.active, .topbar .nav a.active { animation: blob .55s var(--spring) both; }
@keyframes blob { from { transform: scale(.7); opacity: .4; } }

/* stats lift gently on hover (desktop) */
@media (hover: hover) {
  .stat { transition: transform .45s var(--spring), box-shadow .3s; }
  .stat:hover { transform: translateY(-3px) scale(1.01); box-shadow: var(--hi), var(--shadow-float); }
}

/* modal: glass expands from a droplet */
.modal-overlay.open { animation: fade .2s ease both; }
.modal-overlay.open .modal-box { animation: droplet .5s var(--spring) both; }
@keyframes fade { from { opacity: 0; } }
@keyframes droplet { from { opacity: 0; transform: scale(.82) translateY(12px); border-radius: 48px; } }

/* flash message slides in like a notification */
.flash { animation: notif .6s var(--spring) both; }
@keyframes notif { from { opacity: 0; transform: translateY(-12px) scale(.96); } }

/* living ambient light — desktop only, so blurred bars on phones never re-render per frame */
@media (min-width: 821px) and (hover: hover) {
  body::before { animation: drift 28s ease-in-out infinite alternate; will-change: transform; }
  @keyframes drift {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    50%  { transform: translate3d(-3vmax, 2vmax, 0) scale(1.06); }
    100% { transform: translate3d(2vmax, -2vmax, 0) scale(1.03); }
  }
}

/* rows ease in on search filter */
.prow { transition: opacity .2s; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  .stat::before, .login-wrap .card::before { display: none; }
}

/* ============================================================
   Responsive pass · 2026-10-09 — phone / tablet / desktop
   ============================================================ */
/* tab bar: every item fits on one line, no sideways scrolling */
@media (max-width: 820px) {
  .tabbar { width: min(560px, calc(100% - 16px)); overflow: visible; justify-content: space-between; }
  .tabbar a { flex: 1 1 0; min-width: 0; padding: 6px 2px; font-size: 0.66rem; }
  .tabbar a .ic { font-size: 1.15rem; }
}
@media (max-width: 380px) { .tabbar a { font-size: 0.6rem; } }

/* tablet (601–1023): two-column dashboard only when there's room */
@media (min-width: 601px) and (max-width: 959px) {
  .container { padding-left: 20px; padding-right: 20px; }
}

/* phones */
@media (max-width: 600px) {
  .container { padding: 14px 12px 130px; }
  h1 { font-size: 1.35rem; margin-bottom: 12px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .card.table-wrap { padding: 4px; }
  th, td { padding: 10px 8px; }
  thead th { font-size: 0.68rem; }
  /* table first column stays visible while swiping numbers */
  .card.table-wrap table:not(.pnl) tbody td:first-child,
  .card.table-wrap table:not(.pnl) thead th:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--glass-strong);
  }
  .entry-table .by { display: none; }
  .entry-table tbody td:first-child { max-width: 110px; font-size: 0.86rem; }
  .entry-table input[type="number"] { width: 68px; }
  .seg { width: 100%; justify-content: space-between; }
  .seg input[type="month"], .seg input[type="date"] { flex: 1; min-width: 0; text-align: center; }
  .seg .inline-form { flex: 1; display: flex; }
  .stat .value { font-size: 1.3rem; }
  .stat { padding: 12px 14px; }
  .modal-actions { flex-direction: column-reverse; }
  .topbar .user { padding-right: 8px; }
}

/* wide tables: soft fade hint that they scroll sideways */
.table-wrap { scrollbar-width: thin; }

/* large desktops: use the space */
@media (min-width: 1440px) { .container, .topbar { max-width: 1280px; } }

/* safe areas (iPhone notch / home bar, landscape) */
@supports (padding: max(0px)) {
  .container { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  @media (max-width: 600px) { .container { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); } }
}
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1.4fr; }
@media (max-width: 760px) { .form-row.cols-3 { grid-template-columns: 1fr; } }
.form input[type="file"] { padding: 9px; cursor: pointer; }
.form input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; margin-right: 12px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--glass-edge); border-radius: var(--r-pill); background: var(--glass-strong); color: var(--tint);
}
.form label.check { display: flex; align-items: flex-start; gap: 10px; color: var(--ink); font-weight: 500; }
.form label.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--tint); box-shadow: none; padding: 0; }
@media (max-width: 600px) { .card.table-wrap table:not(.pnl) tbody td[colspan] { position: static; } }

/* ============================================================
   Dashboard layout v3 · 2026-10-09 — P&L as a flow card, tables full width
   ============================================================ */
.pnl2 { padding: 18px 20px 16px; }
.pnl2-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pnl2-head h2 { margin: 0; }
.pnl2-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pnl2-meta span { font-size: .8rem; font-weight: 600; color: var(--ink-soft); padding: 4px 10px; border-radius: var(--r-pill); background: var(--glass-strong); border: 1px solid var(--glass-edge); font-variant-numeric: tabular-nums; }
.pnl2-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 10px; }
.pnl2-flow.staff { grid-template-columns: 1fr 1fr; }
.pnl2-flow .kpi { min-width: 0; padding: 12px 14px; border-radius: var(--r-md, 14px); background: var(--glass-strong); border: 1px solid var(--glass-edge); }
.pnl2-flow .k-label { font-size: .78rem; font-weight: 600; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pnl2-flow .k-val { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pnl2-flow .k-val.good { color: var(--success); } .pnl2-flow .k-val.bad { color: var(--danger); } .pnl2-flow .k-val.warn { color: var(--warn); }
.pnl2-flow .op { font-size: 1.3rem; font-weight: 700; color: var(--ink-faint); }
.pnl2-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; margin: 16px 0 6px; background: var(--glass-strong); }
.pnl2-bar span { min-width: 4px; }
.pnl2-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); column-gap: 28px; }
.pnl2-list li { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid rgba(127,127,127,.14); font-size: .9rem; min-width: 0; }
.pnl2-list li i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.pnl2-list li .l { flex: 1; min-width: 0; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pnl2-list li .l small { color: var(--ink-soft); font-size: .76rem; }
.pnl2-list li .v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pnl2-list li .pct { width: 40px; text-align: right; font-size: .76rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.pnl2-list li.zero { opacity: .5; }
.pnl2-list li.zero .v { font-weight: 500; }
/* full-width tables: numbers right-aligned, roomy on desktop */
.card.table-wrap table th:not(:first-child), .card.table-wrap table td:not(:first-child) { text-align: right; }
@media (max-width: 760px) {
  .pnl2 { padding: 16px 14px 12px; }
  .pnl2-flow { grid-template-columns: 1fr 1fr; }
  .pnl2-flow .op { display: none; }
  .pnl2-flow .kpi:last-child { grid-column: 1 / -1; }
  .pnl2-flow .k-val { font-size: 1.25rem; }
  .pnl2-list { grid-template-columns: 1fr; }
}
@media (min-width: 760px) { .cards { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }
.pnl2-flow.staff .kpi:last-child { grid-column: auto; }

/* ============================================================
   Entry page v2 · 2026-10-09 — chips, live totals, phone cards
   ============================================================ */
.entry-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.entry-tools .search { flex: 1 1 260px; margin: 0; }
.chips { display: flex; gap: 6px; padding: 4px; border-radius: var(--r-pill); background: var(--glass); border: 1px solid var(--glass-edge); }
.chip { font: inherit; font-size: .84rem; font-weight: 600; color: var(--ink-soft); border: 0; background: transparent; padding: 7px 12px; border-radius: var(--r-pill); cursor: pointer; white-space: nowrap; transition: background .25s, color .25s; }
.chip b { font-weight: 700; font-variant-numeric: tabular-nums; margin-left: 2px; opacity: .7; }
.chip.on { background: var(--glass-strong); color: var(--tint); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.entry-table tr.prow.filled td.pname { box-shadow: inset 3px 0 0 var(--tint); }
.entry-table input::placeholder { color: var(--ink-faint); }
.savebar { align-items: center; }
.sb-sum { display: grid; grid-template-columns: auto auto; column-gap: 10px; row-gap: 0; align-items: baseline; padding: 0 6px; flex: 0 0 auto; }
.sb-l { font-size: .72rem; font-weight: 600; color: var(--ink-soft); }
.sb-v { font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }

/* phones: every product becomes a card, inputs in a 2×2 grid */
@media (max-width: 760px) {
  .entry-tools .chips { width: 100%; justify-content: space-between; }
  .chip { flex: 1; padding: 8px 4px; font-size: .8rem; }
  .card.table-wrap:has(.entry-table) { background: transparent; border: 0; box-shadow: none; padding: 0; overflow: visible; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .entry-table, .entry-table tbody { display: block; width: 100%; }
  .entry-table thead { display: none; }
  .entry-table tr.prow {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 10px; padding: 12px 12px 14px;
    border-radius: var(--r-lg); background: var(--glass-strong); border: 1px solid var(--glass-edge); box-shadow: var(--hi), 0 4px 14px rgba(15,23,42,.06);
  }
  .entry-table tr.prow.filled { border-color: color-mix(in srgb, var(--tint) 45%, transparent); }
  .entry-table tr.prow td { display: block; padding: 0; border: 0; background: none !important; position: static !important; max-width: none !important; text-align: left !important; }
  .entry-table tr.prow td.pname { grid-column: 1 / -1; font-size: 1rem; font-weight: 700; box-shadow: none !important; display: flex; align-items: center; gap: 8px; }
  .entry-table tr.prow.filled td.pname::after { content: "กรอกแล้ว"; margin-left: auto; font-size: .7rem; font-weight: 700; color: var(--tint); background: color-mix(in srgb, var(--tint) 12%, transparent); padding: 3px 8px; border-radius: var(--r-pill); }
  .entry-table tr.prow td[data-l]::before { content: attr(data-l); display: block; font-size: .72rem; font-weight: 600; color: var(--ink-soft); margin: 0 0 4px 2px; }
  .entry-table tr.prow td input[type="number"], .entry-table tr.prow td input.note { width: 100% !important; font-size: 16px; padding: 10px 12px; text-align: right; }
  .entry-table tr.prow td input.note { text-align: left; }
  .entry-table tr.prow td.notecell { grid-column: 1 / -1; }
  .entry-table tr.prow td.ro { font-size: .95rem; font-weight: 700; color: var(--ink); padding-left: 2px; }
  .entry-table tr.prow td.costcell { color: var(--ink-soft); font-weight: 600; }
  .entry-table tr.prow td.ro.profit-pos { color: var(--success); }
  .entry-table tr.prow td.ro.profit-neg { color: var(--danger); }
  .entry-table tr:not(.prow) td { display: block; }
  .savebar .btn.primary { font-size: .92rem; }
}
@media (max-width: 380px) { .sb-sum { grid-template-columns: auto; } .sb-l { display: none; } }
.entry-tools .search { -webkit-appearance: none; appearance: none; }
/* compact phone cards: 4 numbers on one row, note + cost + profit on the next */
@media (max-width: 760px) {
  .entry-table tr.prow { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 8px; padding: 10px 10px 12px; }
  .entry-table tr.prow td input[type="number"], .entry-table tr.prow td input.note { padding: 9px 8px; border-radius: 10px; }
  .entry-table tr.prow td.notecell { grid-column: span 2; }
  .entry-table tr.prow td.ro { align-self: end; padding-bottom: 9px; font-size: .9rem; }
  .entry-table tr.prow td[data-l]::before { font-size: .68rem; margin-bottom: 3px; white-space: nowrap; }
}
@media (max-width: 760px) { .entry-table tr.prow:not(:has(.ro)) td.notecell { grid-column: 1 / -1; } }
@media (min-width: 761px) and (max-width: 1100px) {
  .entry-table input[type="number"] { width: 78px; }
  .entry-table input.note { width: 110px; }
}
