/* SUPER ACCO V3 — Design System (tokens + components). แหล่งความจริงของสี/ระยะ/มุม/เงา/ความเร็วอนิเมชัน */
:root {
  /* brand */
  --navy: #0B1F4B; --blue: #007CFF; --blue-hover: #0069D9; --blue-press: #0057B3; --cyan: #23C6FF; --light: #EFF6FF;
  /* surfaces */
  --bg: #F6F9FC; --surface: #FFFFFF; --surface-2: #F1F6FC; --border: #E2E9F3; --border-strong: #CBD7E8;
  /* text */
  --text: #0F1F3D; --text-2: #55657F; --text-3: #8795AB; --on-primary: #FFFFFF;
  /* semantic (ต้องมีข้อความกำกับเสมอ ไม่ใช้สีอย่างเดียว) */
  --success: #138A52; --success-bg: #DDF5E8; --warning: #C2641A; --warning-bg: #FFE9D2; --pending: #9A7300; --pending-bg: #FFF1BF;
  --danger: #C62828; --danger-bg: #FDE5E3; --info: #1565C0; --info-bg: #DCEBFF; --neutral: #55657F; --neutral-bg: #EAF0F7;
  /* spacing / radius / shadow / motion */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s7: 32px;
  --r-s: 8px; --r-m: 12px; --r-l: 16px; --r-xl: 20px;
  --shadow-subtle: 0 1px 2px rgba(11,31,75,.06), 0 1px 8px rgba(11,31,75,.04);
  --shadow-floating: 0 6px 18px rgba(0,124,255,.28);
  --shadow-modal: 0 -8px 30px rgba(11,31,75,.18);
  --t-fast: 140ms; --t-std: 220ms; --t-slow: 280ms; --ease: cubic-bezier(.2,.8,.2,1);
  --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --font: "Noto Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-logo: "Montserrat", "Noto Sans Thai", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] { color-scheme: light; } }
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: #E9EFF7; color: var(--text); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
#app { position: relative; max-width: 480px; margin: 0 auto; min-height: 100%; background: var(--bg); display: flex; flex-direction: column; box-shadow: 0 0 40px rgba(11,31,75,.08); }
.banner-bg { position: absolute; inset: 0 0 auto 0; height: 190px; overflow: hidden; pointer-events: none; z-index: 0; }
.banner-bg::before { content: ""; position: absolute; left: -90px; top: -110px; width: 280px; height: 220px; background: linear-gradient(135deg, rgba(35,198,255,.30), rgba(0,124,255,.10) 60%, transparent); transform: rotate(-16deg); border-radius: 40px; }
.banner-bg::after { content: ""; position: absolute; inset: 0; background: url("/app/assets/pattern.png") right -50px top -70px / 220px no-repeat; opacity: .07; mix-blend-mode: multiply; }
#view { position: relative; z-index: 1; flex: 1; padding: calc(var(--safe-t) + 10px) var(--s4) calc(var(--nav-h) + var(--safe-b) + 28px); }
#view.enter { animation: viewIn var(--t-std) var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.full #view { padding-bottom: calc(var(--s7) + 80px + var(--safe-b)); }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: var(--s2); }
.topbar h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -.2px; }
.topbar .actions { display: flex; gap: 6px; }
.iconbtn { position: relative; width: 44px; height: 44px; border: 0; background: transparent; border-radius: 50%; display: grid; place-items: center; color: var(--navy); cursor: pointer; transition: background var(--t-fast); }
.iconbtn:active { background: var(--light); transform: scale(.94); }
.iconbtn .dot { position: absolute; top: 8px; right: 9px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: #E5484D; color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.back { display: flex; align-items: center; gap: 4px; }
.fulltop { display: flex; align-items: center; gap: var(--s2); min-height: 52px; margin-bottom: var(--s2); }
.fulltop h1 { flex: 1; font-size: 20px; font-weight: 700; margin: 0; }

/* ---------- logo (CI) ---------- */
.logo { display: inline-flex; flex-direction: column; line-height: .92; font-family: var(--font-logo); font-style: italic; font-weight: 800; position: relative; padding-right: 22px; }
.logo b { font-size: 21px; color: var(--navy); letter-spacing: -.3px; }
.logo i { font-style: italic; font-size: 21px; letter-spacing: -.3px; background: linear-gradient(90deg, var(--navy) 0 18%, var(--blue) 18% 62%, var(--cyan) 62%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo svg { position: absolute; right: 0; top: -2px; width: 24px; height: 24px; }
.logo.xl b, .logo.xl i { font-size: 34px; } .logo.xl svg { width: 40px; height: 40px; right: -4px; top: -8px; } .logo.xl { padding-right: 34px; }

/* ---------- selectors / cards ---------- */
.selector { width: 100%; display: flex; align-items: center; gap: var(--s3); min-height: 48px; padding: 8px 14px; margin-bottom: var(--s2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); cursor: pointer; text-align: left; font-weight: 600; transition: background var(--t-fast), transform var(--t-fast); }
.selector:active { background: var(--light); transform: scale(.995); }
.selector .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selector small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; }
h2.sec { font-size: 18px; font-weight: 700; margin: var(--s5) 0 var(--s3); display: flex; align-items: center; justify-content: space-between; }
h2.sec a { font-size: 13px; font-weight: 600; color: var(--blue); text-decoration: none; display: inline-flex; align-items: center; min-height: 32px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); box-shadow: var(--shadow-subtle); }
.stat { display: block; width: 100%; text-align: left; padding: 12px 14px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: var(--r-m); box-shadow: var(--shadow-subtle); transition: transform var(--t-fast); position: relative; }
.stat:active { transform: scale(.98); }
.stat .lb { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -.3px; }
.stat .v small { font-size: 13px; font-weight: 600; margin-left: 3px; color: var(--text-2); }
.stat .chev { position: absolute; right: 12px; bottom: 16px; color: var(--text-3); }
.stat.warn .v { color: var(--warning); } .stat.bad .v { color: var(--danger); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: var(--r-m); border: 1px solid transparent; font-weight: 700; font-size: 15px; cursor: pointer; transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast); user-select: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blue); color: var(--on-primary); box-shadow: 0 4px 12px rgba(0,124,255,.25); }
.btn.primary:hover { background: var(--blue-hover); } .btn.primary:active { background: var(--blue-press); }
.btn.secondary { background: var(--surface); color: var(--blue); border-color: #BFD8FA; }
.btn.secondary:active { background: var(--light); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.danger { background: var(--danger); color: #fff; } .btn.danger.o { background: #fff; color: var(--danger); border-color: #F0B5B0; }
.btn.block { width: 100%; } .btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn[disabled], .btn.loading { opacity: .55; pointer-events: none; }
.btn.loading::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btnrow { display: flex; gap: var(--s3); margin: var(--s4) 0; } .btnrow .btn { flex: 1; }
.fab { position: fixed; z-index: 20; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--blue); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-floating); cursor: pointer; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); right: max(16px, calc(50% - 240px + 16px)); transition: transform var(--t-fast); }
.fab:active { transform: scale(.92); }

/* ---------- chips / badges ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; margin: 0 -4px; scrollbar-width: none; } .chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; transition: background var(--t-fast), color var(--t-fast); }
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 600; }
.chip.sm { min-height: 32px; font-size: 13px; padding: 0 12px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.4; }
.badge.success { background: var(--success-bg); color: var(--success); } .badge.warning { background: var(--warning-bg); color: var(--warning); } .badge.pending { background: var(--pending-bg); color: var(--pending); }
.badge.danger { background: var(--danger-bg); color: var(--danger); } .badge.info { background: var(--info-bg); color: var(--info); } .badge.neutral { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- list ---------- */
.list { display: flex; flex-direction: column; gap: var(--s2); }
.item { display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); box-shadow: var(--shadow-subtle); cursor: pointer; transition: transform var(--t-fast), background var(--t-fast); min-height: 64px; }
.item:active { transform: scale(.99); background: var(--surface-2); }
.item .ic { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--light); color: var(--blue); display: grid; place-items: center; }
.item .tx { flex: 1; min-width: 0; } .item .t1 { font-weight: 700; font-size: 15px; } .item .t2 { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .rt { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; } .item .amt { font-weight: 700; font-size: 17px; }
.item .chev { color: var(--text-3); flex: none; }
.rows { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); overflow: hidden; box-shadow: var(--shadow-subtle); }
.row { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 52px; padding: 8px 14px; background: transparent; border: 0; border-bottom: 1px solid var(--border); text-align: left; cursor: pointer; font-weight: 600; }
.row:last-child { border-bottom: 0; } .row:active { background: var(--surface-2); } .row .ic { color: var(--blue); width: 28px; display: grid; place-items: center; } .row .grow { flex: 1; } .row small { display: block; color: var(--text-3); font-weight: 400; font-size: 12px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); box-shadow: var(--shadow-subtle); cursor: pointer; text-align: center; min-height: 104px; transition: transform var(--t-fast); }
.tile:active { transform: scale(.97); background: var(--surface-2); } .tile .ic { color: var(--blue); } .tile .t1 { font-weight: 700; font-size: 15px; } .tile .t2 { color: var(--text-3); font-size: 12px; }
.tile[disabled] { opacity: .5; pointer-events: none; }
.progress { height: 8px; border-radius: 4px; background: var(--neutral-bg); overflow: hidden; } .progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); border-radius: 4px; transition: width var(--t-slow) var(--ease); } .progress.full i { background: var(--danger); }

/* ---------- search / forms ---------- */
.search { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 14px; background: #E8EEF6; border-radius: 24px; margin-bottom: var(--s3); color: var(--text-3); }
.search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 15px; color: var(--text); min-width: 0; }
.field { margin-bottom: var(--s3); } .field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; } .field label .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-m); background: var(--surface); outline: none; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.textarea { min-height: 76px; resize: vertical; } .input:focus, .select:focus, .textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,124,255,.18); }
.field.err .input, .field.err .select { border-color: var(--danger); } .field .errmsg { color: var(--danger); font-size: 12px; margin-top: 4px; } .field .hint { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: #C5D0E0; border: 0; cursor: pointer; transition: background var(--t-fast); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--t-fast); }
.switch[aria-checked="true"] { background: var(--blue); } .switch[aria-checked="true"]::after { transform: translateX(20px); }
.setrow { display: flex; align-items: center; gap: var(--s3); padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface); } .setrow:last-child { border-bottom: 0; } .setrow .grow { flex: 1; } .setrow small { display: block; color: var(--text-3); font-size: 12px; }
.seg { display: flex; background: var(--neutral-bg); border-radius: var(--r-m); padding: 3px; gap: 3px; } .seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--text-2); cursor: pointer; } .seg button.on { background: #fff; color: var(--blue); box-shadow: var(--shadow-subtle); }

/* ---------- document form ---------- */
.itemrow { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); padding: 10px 12px; margin-bottom: var(--s2); }
.itemrow .top { display: flex; align-items: center; gap: 8px; } .itemrow .top .input { min-height: 44px; } .itemrow .sub { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 8px; margin-top: 8px; } .itemrow .sub .input { min-height: 42px; padding: 8px; }
.totals { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); padding: 10px 14px; margin: var(--s3) 0; } .totals .tr { display: flex; justify-content: space-between; align-items: center; min-height: 34px; color: var(--text-2); font-size: 14px; } .totals .tr.neg b { color: var(--danger); }
.totals .grand { display: flex; justify-content: space-between; align-items: center; background: var(--light); margin: 8px -14px -10px; padding: 14px; border-radius: 0 0 var(--r-m) var(--r-m); font-size: 17px; font-weight: 700; } .totals .grand b { font-size: 24px; color: var(--navy); }
.stickybar { position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; padding: 10px var(--s4) calc(10px + var(--safe-b)); background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--border); display: flex; gap: var(--s3); }
.stickybar .btn { flex: 1; }
.paper { background: #fff; border: 1px solid var(--border); border-radius: var(--r-s); box-shadow: var(--shadow-subtle); overflow: hidden; }
.paperwrap { overflow: auto; background: #DCE4EF; padding: 10px; border-radius: var(--r-m); }
.paperwrap iframe { border: 0; background: #fff; display: block; transform-origin: top left; width: 794px; height: 1123px; }
.zoombar { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }

/* ---------- sheet / dialog / toast ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(11,31,75,.42); animation: fade var(--t-std) var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; max-height: 92vh; display: flex; flex-direction: column; background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-modal); padding: 8px var(--s4) calc(var(--s4) + var(--safe-b)); animation: sheetIn var(--t-slow) var(--ease); touch-action: pan-y; }
.sheet.closing { animation: sheetOut var(--t-std) var(--ease) forwards; } .scrim.closing { animation: fadeOut var(--t-std) forwards; }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } } @keyframes sheetOut { to { transform: translateY(100%); } } @keyframes fadeOut { to { opacity: 0; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #CFD8E6; margin: 4px auto 8px; }
.sheet .shead { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); } .sheet .shead h3 { margin: 0; font-size: 18px; font-weight: 700; }
.sheet .sbody { overflow-y: auto; flex: 1; padding-bottom: var(--s2); }
.dialog { position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, calc(100vw - 40px)); background: #fff; border-radius: var(--r-l); padding: var(--s5); box-shadow: var(--shadow-modal); animation: pop var(--t-std) var(--ease); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.96); } to { opacity: 1; transform: translate(-50%, -50%); } }
.dialog h3 { margin: 0 0 6px; font-size: 17px; } .dialog p { margin: 0 0 var(--s4); color: var(--text-2); font-size: 14px; white-space: pre-line; } .dialog .btnrow { margin: 0; }
.toasts { position: fixed; z-index: 60; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 88%; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-modal); animation: toastIn var(--t-std) var(--ease); } .toast.err { background: var(--danger); } .toast.ok { background: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- bottom nav (3 tabs) ---------- */
.nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; height: calc(var(--nav-h) + var(--safe-b)); padding: 6px 12px var(--safe-b); display: flex; gap: 6px; background: #fff; border-top: 1px solid var(--border); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; border-radius: 14px; color: var(--text-2); text-decoration: none; font-size: 12px; font-weight: 600; min-height: 52px; transition: background var(--t-fast), color var(--t-fast); }
.nav a.on { background: #E8F2FF; color: var(--blue); } .nav a:active { transform: scale(.97); }

/* ---------- states ---------- */
.skel { background: linear-gradient(90deg, #E8EEF6 25%, #F3F7FB 37%, #E8EEF6 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-m); } @keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.empty { text-align: center; padding: 28px 16px; color: var(--text-2); } .empty img { width: 108px; height: auto; mix-blend-mode: multiply; margin-bottom: 4px; } .empty h3 { margin: 4px 0; color: var(--text); font-size: 17px; } .empty p { margin: 0 0 var(--s4); font-size: 14px; }
.notice { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r-m); font-size: 13px; margin: var(--s3) 0; background: var(--info-bg); color: var(--info); } .notice.warn { background: var(--warning-bg); color: var(--warning); } .notice.bad { background: var(--danger-bg); color: var(--danger); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; } .kv:last-child { border-bottom: 0; } .kv span:first-child { color: var(--text-2); }
.qrbox { display: grid; place-items: center; padding: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--r-l); } .qrbox canvas, .qrbox img { width: 220px; height: 220px; image-rendering: pixelated; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 110px; padding-top: 6px; } .bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: flex-end; height: 100%; } .bars .b i { width: 100%; background: linear-gradient(180deg, var(--cyan), var(--blue)); border-radius: 6px 6px 0 0; min-height: 3px; } .bars .b span { font-size: 11px; color: var(--text-3); }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 14px; } .timeline .ev { position: relative; padding: 4px 0 10px; font-size: 13px; } .timeline .ev::before { content: ""; position: absolute; left: -20px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; } .timeline small { color: var(--text-3); display: block; }
.hero-mascot { display: flex; align-items: center; gap: 12px; } .hero-mascot img { width: 72px; mix-blend-mode: multiply; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (min-width: 481px) { body { padding: 0; } }
