/* ==========================================================================
   OneCalculator (๑เครื่องคิดเลข) — Commercial Minimal Pastel Stylesheet
   Architecture: 100dvh Zero-Overflow · 7 Pastel/Dark Themes · 60FPS Touch
   ========================================================================== */

:root {
  --font-sans: 'Inter', 'Sarabun', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-max-width: 480px;
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-pill: 999px;
  --transition-fast: 120ms cubic-bezier(0.2, 0, 0, 1);
  --transition-smooth: 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ==========================================================================
   7 THEMES: 2 Free (dark, lavender) + 5 Pro Pastels
   ========================================================================== */

/* 1. Classic Dark (Free — โหมดมืดสบายตาตามต้นฉบับ) */
html[data-theme="dark"] {
  --bg-app: #17181c;
  --bg-surface: #21232a;
  --bg-elevated: #2a2d37;
  --bg-sheet: #1e2027;
  --text-primary: #f3f4f8;
  --text-secondary: #a6aab8;
  --text-muted: #6f7485;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --shadow-float: 0 14px 38px rgba(0, 0, 0, 0.52);

  --key-num-bg: #2a2b31;
  --key-num-fg: #f3f4f8;
  --key-fn-bg: #393d52;
  --key-fn-fg: #e4e7f5;
  --key-op-bg: #393d52;
  --key-op-fg: #e8ecff;
  --key-ac-bg: #274c9e;
  --key-ac-fg: #eef4ff;
  --key-eq-bg: #dac7dc;
  --key-eq-fg: #2b1d2e;

  --magic-bg: #23252e;
  --magic-fg: #cfd4e6;
  --magic-border: rgba(255, 255, 255, 0.07);
  --accent-primary: #8ab4f8;
  --accent-primary-fg: #10203b;
  --accent-soft: rgba(138, 180, 248, 0.16);
  --danger-color: #ff7b7b;
  --pp-blue: #113f8c;
}

/* 2. Lavender Mist (Free — ขาวอมม่วงคลีนตามต้นฉบับโหมดสว่าง) */
html[data-theme="lavender"] {
  --bg-app: #f8f8fc;
  --bg-surface: #eef0f8;
  --bg-elevated: #ffffff;
  --bg-sheet: #f3f4fa;
  --text-primary: #1d1e26;
  --text-secondary: #585c6e;
  --text-muted: #888da1;
  --border-subtle: rgba(25, 28, 45, 0.08);
  --shadow-float: 0 12px 34px rgba(28, 32, 56, 0.14);

  --key-num-bg: #e7e9f0;
  --key-num-fg: #1d1e26;
  --key-fn-bg: #dde1f0;
  --key-fn-fg: #2c3148;
  --key-op-bg: #dde1f0;
  --key-op-fg: #262b42;
  --key-ac-bg: #d3e3fd;
  --key-ac-fg: #0b46a0;
  --key-eq-bg: #6f5270;
  --key-eq-fg: #ffffff;

  --magic-bg: #eceef7;
  --magic-fg: #3b4059;
  --magic-border: rgba(35, 42, 74, 0.08);
  --accent-primary: #5b4b8a;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(111, 82, 112, 0.12);
  --danger-color: #d93838;
  --pp-blue: #0e3c87;
}

/* 3. Matcha Mint (Pro Pastel) */
html[data-theme="matcha"] {
  --bg-app: #f4f9f5;
  --bg-surface: #e6f1e8;
  --bg-elevated: #ffffff;
  --bg-sheet: #ecf5ee;
  --text-primary: #1a2920;
  --text-secondary: #4c6656;
  --text-muted: #7b9685;
  --border-subtle: rgba(24, 58, 37, 0.09);
  --shadow-float: 0 12px 32px rgba(25, 58, 38, 0.13);

  --key-num-bg: #e3eee5;
  --key-num-fg: #1a2920;
  --key-fn-bg: #cfe5d4;
  --key-fn-fg: #20422b;
  --key-op-bg: #cfe5d4;
  --key-op-fg: #1d3d28;
  --key-ac-bg: #b9e3c5;
  --key-ac-fg: #114a26;
  --key-eq-bg: #3b7a57;
  --key-eq-fg: #ffffff;

  --magic-bg: #e5f1e8;
  --magic-fg: #294d36;
  --magic-border: rgba(31, 77, 48, 0.09);
  --accent-primary: #3b7a57;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(59, 122, 87, 0.13);
  --danger-color: #d63636;
  --pp-blue: #0e3c87;
}

/* 4. Sakura Peach (Pro Pastel) */
html[data-theme="sakura"] {
  --bg-app: #fdf6f7;
  --bg-surface: #f9eaee;
  --bg-elevated: #ffffff;
  --bg-sheet: #fbf0f2;
  --text-primary: #2d1b20;
  --text-secondary: #6e4c56;
  --text-muted: #9e7b85;
  --border-subtle: rgba(88, 30, 48, 0.09);
  --shadow-float: 0 12px 32px rgba(84, 28, 45, 0.13);

  --key-num-bg: #f5e5e9;
  --key-num-fg: #2d1b20;
  --key-fn-bg: #f1d4dc;
  --key-fn-fg: #592534;
  --key-op-bg: #f1d4dc;
  --key-op-fg: #592534;
  --key-ac-bg: #ffd6de;
  --key-ac-fg: #881337;
  --key-eq-bg: #c45875;
  --key-eq-fg: #ffffff;

  --magic-bg: #f8e8ec;
  --magic-fg: #663040;
  --magic-border: rgba(110, 40, 62, 0.09);
  --accent-primary: #c45875;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(196, 88, 117, 0.13);
  --danger-color: #d42c46;
  --pp-blue: #0e3c87;
}

/* 5. Butter Cream (Pro Pastel) */
html[data-theme="butter"] {
  --bg-app: #fdfbf3;
  --bg-surface: #f5efdc;
  --bg-elevated: #ffffff;
  --bg-sheet: #f9f4e6;
  --text-primary: #2c2416;
  --text-secondary: #6b5c42;
  --text-muted: #9c8c70;
  --border-subtle: rgba(74, 54, 18, 0.09);
  --shadow-float: 0 12px 32px rgba(72, 52, 16, 0.13);

  --key-num-bg: #f2ebda;
  --key-num-fg: #2c2416;
  --key-fn-bg: #eae0c2;
  --key-fn-fg: #4d3b19;
  --key-op-bg: #eae0c2;
  --key-op-fg: #4d3b19;
  --key-ac-bg: #fde49e;
  --key-ac-fg: #78350f;
  --key-eq-bg: #b7791f;
  --key-eq-fg: #ffffff;

  --magic-bg: #f4eedc;
  --magic-fg: #574420;
  --magic-border: rgba(87, 68, 32, 0.09);
  --accent-primary: #b7791f;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(183, 121, 31, 0.14);
  --danger-color: #cf3535;
  --pp-blue: #0e3c87;
}

/* 6. Baby Sky (Pro Pastel) */
html[data-theme="sky"] {
  --bg-app: #f3f8fd;
  --bg-surface: #e4effa;
  --bg-elevated: #ffffff;
  --bg-sheet: #ebf4fc;
  --text-primary: #162433;
  --text-secondary: #48617a;
  --text-muted: #7a94ad;
  --border-subtle: rgba(18, 56, 94, 0.09);
  --shadow-float: 0 12px 32px rgba(18, 54, 92, 0.13);

  --key-num-bg: #e2edf7;
  --key-num-fg: #162433;
  --key-fn-bg: #cce1f4;
  --key-fn-fg: #163d61;
  --key-op-bg: #cce1f4;
  --key-op-fg: #163d61;
  --key-ac-bg: #b8dffd;
  --key-ac-fg: #0a456e;
  --key-eq-bg: #2b6cb0;
  --key-eq-fg: #ffffff;

  --magic-bg: #e4eff9;
  --magic-fg: #21496e;
  --magic-border: rgba(24, 68, 110, 0.09);
  --accent-primary: #2b6cb0;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(43, 108, 176, 0.13);
  --danger-color: #d43535;
  --pp-blue: #0e3c87;
}

/* 7. Mocha Latte (Pro Pastel) */
html[data-theme="mocha"] {
  --bg-app: #f9f5f2;
  --bg-surface: #efe7e0;
  --bg-elevated: #ffffff;
  --bg-sheet: #f4ede7;
  --text-primary: #2a201b;
  --text-secondary: #69564b;
  --text-muted: #998579;
  --border-subtle: rgba(68, 44, 28, 0.09);
  --shadow-float: 0 12px 32px rgba(64, 40, 24, 0.14);

  --key-num-bg: #ece2da;
  --key-num-fg: #2a201b;
  --key-fn-bg: #dfd0c4;
  --key-fn-fg: #4a3325;
  --key-op-bg: #dfd0c4;
  --key-op-fg: #4a3325;
  --key-ac-bg: #dec2ac;
  --key-ac-fg: #472814;
  --key-eq-bg: #6f4e37;
  --key-eq-fg: #ffffff;

  --magic-bg: #eee5dd;
  --magic-fg: #52392b;
  --magic-border: rgba(74, 48, 32, 0.09);
  --accent-primary: #6f4e37;
  --accent-primary-fg: #ffffff;
  --accent-soft: rgba(111, 78, 55, 0.13);
  --danger-color: #cf3535;
  --pp-blue: #0e3c87;
}

/* ==========================================================================
   BASE RESET & FULLSCREEN 100dvh LOCK
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button,
input,
select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* แถบพรีวิวธีมพาสเทลชั่วคราวสำหรับผู้ใช้ฟรี */
.theme-preview-banner {
  position: fixed;
  top: calc(var(--safe-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 65;
  width: min(94vw, 450px);
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
}

.theme-preview-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ==========================================================================
   APP SHELL (พอดีจอ 100dvh บนมือถือ · กึ่งกลางสวยบนจอคอม/แท็บเล็ต)
   ========================================================================== */

.app-shell {
  position: relative;
  width: 100%;
  max-width: var(--app-max-width);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: max(var(--safe-bottom), 8px);
  padding-left: max(var(--safe-left), 12px);
  padding-right: max(var(--safe-right), 12px);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-app);
  transition: background-color var(--transition-smooth);
}

@media (min-width: 540px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, var(--bg-surface), var(--bg-app));
  }

  .app-shell {
    height: min(95dvh, 880px);
    border-radius: 32px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-float);
    overflow: hidden;
  }
}

/* ==========================================================================
   1. TOP HEADER (ปุ่มสลับภาษาอยู่มุมบนซ้ายมือสุด)
   ========================================================================== */

.top-header {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  z-index: 20;
}

.top-header-left,
.top-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* บังคับให้ปุ่มเปลี่ยนภาษา (🌐 TH) อยู่มุมบนซ้ายมือสุดตามที่พี่เก่งต้องการ */
#btn-lang-quick {
  order: -1;
}

.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.icon-btn:active {
  transform: scale(0.9);
  background-color: var(--bg-surface);
}

.icon-btn-active {
  background-color: var(--key-fn-bg);
  color: var(--key-fn-fg);
}

.sound-mode-dot {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-primary);
}

.pill-chip-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.pill-chip-btn:active {
  transform: scale(0.93);
}

.lang-globe {
  font-size: 0.88rem;
  line-height: 1;
}

.wallet-badge-btn {
  height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: transform var(--transition-fast);
}

.wallet-badge-btn:active {
  transform: scale(0.94);
}

/* เมนูจุด 3 จุด ⋮ โค้งมนมุมขวาบน */
.dropdown-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: transparent;
}

.dropdown-menu {
  position: absolute;
  top: calc(var(--safe-top) + 48px);
  right: 12px;
  z-index: 50;
  width: min(280px, 86vw);
  padding: 8px;
  border-radius: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transform-origin: top right;
  animation: menuPopIn 150ms cubic-bezier(0.2, 0, 0, 1);
}

@keyframes menuPopIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(-6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.dropdown-item {
  width: 100%;
  padding: 11px 13px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: background-color var(--transition-fast);
}

.dropdown-item:hover,
.dropdown-item:active {
  background: var(--bg-surface);
}

.dropdown-item-highlight {
  background: var(--accent-soft);
  font-weight: 600;
}

.dropdown-icon {
  width: 22px;
  text-align: center;
  font-size: 1.02rem;
  flex-shrink: 0;
}

/* ==========================================================================
   2. DISPLAY AREA (นิพจน์ตัวใหญ่ · พรีวิวสด · ชิปรายการ · VAT · QR พร้อมเพย์)
   ========================================================================== */

.display-area {
  flex: 1 1 auto;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 4px 4px 6px;
  overflow: hidden;
}

/* แถบสถานะไมค์ฟังเสียง & กำลังสแกนบิล */
.status-pill {
  align-self: flex-end;
  max-width: 100%;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.voice-pill {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
}

.voice-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  animation: pulseDot 1s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
}

.spinner-xs {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent-primary);
  flex-shrink: 0;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill-close {
  font-size: 0.8rem;
  padding: 0 3px;
  color: var(--text-secondary);
}

/* แถบชิปรายการสินค้า (แก้ไข/ลบแล้วยอดรวมอัปเดตทันที) */
.item-chips-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 2px 0;
}

.item-chips-list {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}

.item-chips-list::-webkit-scrollbar {
  display: none;
}

.item-chip {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 8px 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.77rem;
  white-space: nowrap;
}

.item-chip-name {
  color: var(--text-secondary);
  max-width: 95px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-chip-val {
  font-weight: 700;
  color: var(--text-primary);
}

.item-chip-del {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  background: rgba(127, 127, 127, 0.14);
}

.item-chips-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.chip-tool-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* นิพจน์ตัวใหญ่ชิดขวา เลื่อนซ้าย-ขวาได้ */
.expression-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  text-align: right;
}

.expression-scroll::-webkit-scrollbar {
  display: none;
}

.expression-display {
  display: inline-block;
  min-width: 100%;
  text-align: right;
  font-size: clamp(2.35rem, 9.2vw, 3.55rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: var(--text-primary);
  user-select: text;
  transition: font-size 120ms ease;
}

.expression-display.expr-medium {
  font-size: clamp(1.85rem, 7.2vw, 2.7rem);
}

.expression-display.expr-long {
  font-size: clamp(1.45rem, 5.6vw, 2.1rem);
}

/* ผลลัพธ์พรีวิวสดก่อนกด = */
.preview-row {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.result-preview {
  font-size: clamp(1.25rem, 4.8vw, 1.7rem);
  font-weight: 500;
  color: var(--text-secondary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* แถบสรุปแยก 3 ยอด VAT */
.vat-summary-bar {
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.vat-summary-cols {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.vat-col {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.vat-col-lbl {
  font-size: 0.66rem;
  color: var(--text-muted);
}

.vat-col-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.vat-summary-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.vat-copy-btn {
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  font-size: 0.71rem;
  font-weight: 600;
}

.vat-close-btn {
  font-size: 0.76rem;
  color: var(--text-muted);
  padding: 2px 4px;
}

/* แถบคิดเงินทอนด่วน 1-Tap + ปุ่ม 📲 QR รับเงิน */
.quick-change-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 2px;
}

.quick-change-scroll {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-change-scroll::-webkit-scrollbar {
  display: none;
}

.quick-change-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.banknote-buttons {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.banknote-chip {
  height: 27px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.banknote-chip:active {
  transform: scale(0.93);
  background: var(--key-fn-bg);
}

.banknote-custom {
  color: var(--text-secondary);
}

.promptpay-trigger-btn {
  flex: 0 0 auto;
  height: 29px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  background: var(--key-ac-bg);
  color: var(--key-ac-fg);
  font-size: 0.76rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform var(--transition-fast);
}

.promptpay-trigger-btn:active {
  transform: scale(0.93);
}

.change-result-banner {
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
}

.change-close-btn {
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 0 4px;
}

/* ==========================================================================
   3. SIGNATURE 4-ACTION ROW (ตรงแนว 4 คอลัมน์เหนือ AC, ( ), %, ÷ เป๊ะ)
   ========================================================================== */

.magic-actions-row {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 4px 2px 8px;
}

.magic-btn {
  height: 38px;
  border-radius: var(--radius-pill);
  background: var(--magic-bg);
  border: 1px solid var(--magic-border);
  color: var(--magic-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 6px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.magic-btn:active {
  transform: scale(0.93);
  background: var(--key-fn-bg);
}

.magic-btn.listening {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444;
}

.magic-icon {
  flex-shrink: 0;
}

.magic-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   4. KEYPAD 4x5 (ปุ่มทรงกลมขนาดใหญ่ กดติดนิ้ว 60FPS + ป๊อปอัป VAT ด่วน)
   ========================================================================== */

.keypad-wrapper {
  position: relative;
  flex: 0 0 58%;
  max-height: 470px;
  min-height: 300px;
  padding: 2px 2px 4px;
  display: flex;
  flex-direction: column;
}

.keypad-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.calc-key {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-pill);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.45rem, 5.8vw, 1.95rem);
  font-weight: 500;
  line-height: 1;
  will-change: transform;
  transition: transform 85ms cubic-bezier(0.2, 0, 0, 1), filter 120ms ease;
}

.calc-key:active,
.calc-key.key-pressed {
  transform: scale(0.92);
  filter: brightness(1.09);
}

.key-num {
  background-color: var(--key-num-bg);
  color: var(--key-num-fg);
}

.key-fn {
  background-color: var(--key-fn-bg);
  color: var(--key-fn-fg);
}

.key-op {
  background-color: var(--key-op-bg);
  color: var(--key-op-fg);
  font-size: clamp(1.65rem, 6.4vw, 2.15rem);
}

.key-ac {
  background-color: var(--key-ac-bg);
  color: var(--key-ac-fg);
  font-size: clamp(1.3rem, 5.2vw, 1.7rem);
  font-weight: 600;
}

.key-equals {
  background-color: var(--key-eq-bg);
  color: var(--key-eq-fg);
  font-size: clamp(1.75rem, 6.6vw, 2.25rem);
  font-weight: 600;
}

/* ป้ายบอกใบ้เล็กๆ VAT บนปุ่ม % */
.key-percent {
  gap: 2px;
}

.key-sub-hint {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  opacity: 0.62;
  line-height: 1;
}

/* ป๊อปอัปคิด/ถอด VAT ด่วนเมื่อกดค้างปุ่ม % */
.vat-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 52;
  background: rgba(0, 0, 0, 0.22);
}

.vat-longpress-popup {
  position: absolute;
  top: -126px;
  right: 4px;
  z-index: 55;
  width: min(270px, 84vw);
  padding: 10px;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: menuPopIn 140ms ease-out;
}

.vat-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.vat-gear-btn {
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  font-size: 0.74rem;
  font-weight: 600;
}

.vat-action-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

.vat-action-btn:active {
  transform: scale(0.97);
}

.vat-action-btn strong {
  font-size: 0.92rem;
  color: var(--text-primary);
}

.vat-action-btn small {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.vat-add {
  border-left: 3px solid var(--accent-primary);
}

.vat-remove {
  border-left: 3px solid var(--key-eq-bg);
}

/* ปรับสัดส่วนอัตโนมัติสำหรับหน้าจอความสูงน้อย (เช่น จอแนวนอนหรือมือถือขนาดกะทัดรัด) */
@media (max-height: 670px) {
  .top-header {
    height: 42px;
  }
  .magic-btn {
    height: 33px;
  }
  .keypad-wrapper {
    flex-basis: 56%;
    min-height: 255px;
  }
  .keypad-grid {
    gap: 7px;
  }
  .expression-display {
    font-size: clamp(1.95rem, 8vw, 2.7rem);
  }
}

/* ==========================================================================
   5. PULL-DOWN HISTORY DRAWER (ลิ้นชักประวัติแบบดึงลงตามต้นฉบับ)
   ========================================================================== */

.history-backdrop {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.history-drawer {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--bg-sheet);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: max(var(--safe-bottom), 10px);
  transform: translateY(-104%);
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.history-drawer.open {
  transform: translateY(0);
  pointer-events: auto;
}

.history-drawer-topbar {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.history-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-list-container {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px;
  user-select: text;
}

.history-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.history-empty-icon {
  font-size: 2.3rem;
  margin-bottom: 10px;
  opacity: 0.75;
}

.history-group {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.history-date-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.history-item {
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.history-item-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-badges {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.history-note-badge,
.history-img-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.history-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.history-mini-btn {
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  font-size: 0.71rem;
  color: var(--text-secondary);
}

.history-expr {
  font-size: 1.08rem;
  color: var(--text-secondary);
  text-align: right;
  word-break: break-all;
  cursor: pointer;
}

.history-res {
  font-size: 1.62rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  cursor: pointer;
}

/* ส่วนท้ายของลิ้นชักแสดงนิพจน์ปัจจุบันพร้อมแถบจับรูดขึ้น */
.history-drawer-footer {
  flex: 0 0 auto;
  padding: 8px 18px 10px;
  background: var(--bg-app);
  border-top: 1px solid var(--border-subtle);
  cursor: grab;
}

.sheet-drag-pill {
  width: 38px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: var(--radius-pill);
  background: var(--text-muted);
  opacity: 0.55;
}

.history-current-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.drawer-current-expr {
  font-size: 1.9rem;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-current-preview {
  font-size: 1.1rem;
  color: var(--text-secondary);
  text-align: right;
  min-height: 20px;
}

/* ==========================================================================
   MODALS, FORMS & SHARED BUTTONS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  padding: 16px;
  background: rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  width: min(440px, 100%);
  max-height: 88dvh;
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 170ms cubic-bezier(0.2, 0, 0, 1);
}

.modal-compact {
  width: min(360px, 100%);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.modal-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 4px 0;
}

.section-subtitle {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.helper-note {
  margin: 0;
  font-size: 0.77rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input,
.form-select {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.92rem;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent-primary);
}

.form-input-lg {
  height: 48px;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: right;
}

.form-range {
  width: 100%;
  accent-color: var(--accent-primary);
}

.input-inline-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.privacy-local-badge {
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 0.76rem;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* Shared Buttons */
.btn-pill-xs {
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 600;
}

.btn-accent {
  background: var(--key-ac-bg);
  color: var(--key-ac-fg);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-tonal {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.btn-tonal-sm {
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary-full,
.btn-tonal-full {
  width: 100%;
  height: 46px;
  border-radius: 14px;
  font-size: 0.92rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform var(--transition-fast);
}

.btn-primary-full {
  background: var(--key-eq-bg);
  color: var(--key-eq-fg);
}

.btn-tonal-full {
  background: var(--key-ac-bg);
  color: var(--key-ac-fg);
}

.btn-primary-full:active,
.btn-tonal-full:active {
  transform: scale(0.98);
}

.modal-dual-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-primary-half,
.btn-tonal-half,
.btn-danger-outline {
  height: 43px;
  padding: 0 10px;
  border-radius: 13px;
  font-size: 0.84rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary-half {
  background: var(--key-eq-bg);
  color: var(--key-eq-fg);
}

.btn-tonal-half {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.btn-danger-outline {
  border: 1px solid var(--danger-color);
  color: var(--danger-color);
}

.btn-link-xs,
.btn-link-sm {
  color: var(--accent-primary);
  font-weight: 600;
  text-decoration: none;
}

.btn-link-xs {
  font-size: 0.75rem;
}

.btn-link-sm {
  font-size: 0.8rem;
}

.mt-8 {
  margin-top: 6px;
}

/* ==========================================================================
   LANGUAGE GRID (10 ภาษา) & THEME GRID (7 ธีม)
   ========================================================================== */

.lang-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.lang-option-btn {
  padding: 9px 11px;
  border-radius: 14px;
  background: var(--bg-surface);
  border: 1.5px solid transparent;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.lang-option-btn.active {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
}

.lang-flag {
  font-size: 1.3rem;
  line-height: 1;
}

.lang-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.lang-native {
  font-size: 0.85rem;
  font-weight: 700;
}

.lang-sub {
  font-size: 0.69rem;
  color: var(--text-muted);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.theme-card {
  padding: 11px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.theme-card.active {
  border-color: var(--accent-primary);
}

.theme-swatches {
  display: flex;
  align-items: center;
  gap: 5px;
}

.theme-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(127, 127, 127, 0.22);
}

.theme-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.theme-card-title {
  font-size: 0.82rem;
  font-weight: 700;
}

.theme-card-badge {
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  font-size: 0.66rem;
  font-weight: 700;
  background: var(--accent-soft);
}

/* ==========================================================================
   PROMPTPAY QR PAYMENT CARD (ความคมชัดสูง สแกนติดไว)
   ========================================================================== */

.qr-card-visual {
  border-radius: 20px;
  background: #ffffff;
  color: #161b26;
  border: 1px solid rgba(0, 0, 0, 0.1);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.qr-card-banner {
  background: linear-gradient(135deg, #0d3b85, #1857b8);
  color: #ffffff;
  padding: 10px 14px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.qr-card-content {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.qr-shop-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0d264c;
  text-align: center;
}

.qr-target-id {
  font-size: 0.78rem;
  color: #5a6578;
}

.qr-canvas-frame {
  padding: 10px;
  border-radius: 14px;
  background: #ffffff;
  border: 2px solid #e6ecf5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#qr-canvas {
  display: block;
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
}

.qr-amount-box {
  margin-top: 4px;
  padding: 6px 18px;
  border-radius: var(--radius-pill);
  background: #f0f5ff;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-amount-lbl {
  font-size: 0.68rem;
  color: #4b5c78;
}

.qr-amount-val {
  font-size: 1.45rem;
  font-weight: 800;
  color: #0d3b85;
}

.qr-expr-note {
  font-size: 0.73rem;
  color: #6b7688;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-wakelock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.73rem;
  color: var(--text-secondary);
}

.qr-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ==========================================================================
   CAMERA SCANNER & RECEIPT VIEWER
   ========================================================================== */

.modal-camera-card {
  width: min(460px, 100%);
}

.camera-viewport-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 58dvh;
  background: #000000;
  overflow: hidden;
}

.camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide-frame {
  position: absolute;
  inset: 10%;
  border: 1px dashed rgba(255, 255, 255, 0.45);
  border-radius: 16px;
  pointer-events: none;
}

.guide-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: #ffffff;
  border-style: solid;
}

.guide-corner.tl { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-top-left-radius: 12px; }
.guide-corner.tr { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-top-right-radius: 12px; }
.guide-corner.bl { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-bottom-left-radius: 12px; }
.guide-corner.br { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-bottom-right-radius: 12px; }

.camera-hint-overlay {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.62);
  color: #ffffff;
  font-size: 0.74rem;
  white-space: nowrap;
}

.camera-controls-bar {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
}

.camera-shutter-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid var(--text-primary);
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shutter-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--text-primary);
}

.receipt-viewer-summary {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-surface);
  text-align: right;
}

.receipt-image-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  max-height: 260px;
  display: flex;
  justify-content: center;
  background: #000000;
}

.receipt-viewer-img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
}

/* ==========================================================================
   WALLET (฿120 LIFETIME + TOPUP) & SOUND / BYOK SETTINGS
   ========================================================================== */

.wallet-balance-card {
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.wallet-balance-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.plan-pill {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--key-ac-bg);
  color: var(--key-ac-fg);
  font-size: 0.72rem;
  font-weight: 700;
}

.no-expiry-tag {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.wallet-balance-number strong {
  font-size: 1.55rem;
  font-weight: 800;
  margin-right: 6px;
}

.wallet-balance-number span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.pricing-card {
  position: relative;
  padding: 14px;
  border-radius: 18px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pricing-hero {
  border-color: var(--accent-primary);
}

.pricing-badge {
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  font-size: 0.71rem;
  font-weight: 700;
}

.pricing-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pricing-header-row h4 {
  margin: 0;
  font-size: 0.98rem;
}

.pricing-sku-sub {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.pricing-amount {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
}

.pricing-features {
  margin: 0;
  padding-left: 4px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  line-height: 1.38;
}

.wallet-footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
}

/* Switches & BYOK Accordion */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-row strong {
  font-size: 0.86rem;
}

.switch-toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 25px;
  border-radius: var(--radius-pill);
  background: var(--key-fn-bg);
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.switch-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 160ms ease;
}

.switch-toggle:checked {
  background: var(--accent-primary);
}

.switch-toggle:checked::after {
  transform: translateX(19px);
}

.byok-details {
  border-radius: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 10px 12px;
}

.byok-summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
}

.byok-content {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.byok-status-msg {
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 18px;
}

.byok-steps-list {
  margin: 0;
  padding-left: 16px;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ==========================================================================
   HELP TIPS & TOAST NOTIFICATIONS
   ========================================================================== */

.help-cards-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.help-tip-item {
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bg-surface);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.help-tip-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.help-tip-item strong {
  font-size: 0.85rem;
  display: block;
  margin-bottom: 2px;
}

.help-tip-item p {
  margin: 0;
  font-size: 0.77rem;
  line-height: 1.42;
  color: var(--text-secondary);
}

.help-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.app-version-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.toast-container {
  position: fixed;
  bottom: calc(max(var(--safe-bottom), 14px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: min(90vw, 400px);
}

.toast-item {
  padding: 9px 15px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--bg-app);
  font-size: 0.81rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  animation: toastFadeIn 180ms ease-out;
}

@keyframes toastFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
/* ==========================================================================
   V1.1 UPGRADES: Clean Top Header · TTS Speed Slider · BYOK Lock & Guide
   ========================================================================== */

.top-header {
  gap: 4px;
}

.top-header-left,
.top-header-right {
  gap: 2px;
}

.top-header .icon-btn {
  width: 34px;
  height: 34px;
}

.emoji-header-btn {
  font-size: 1.02rem;
  line-height: 1;
}

.top-header .promptpay-trigger-btn {
  height: 31px;
  padding: 0 10px;
  font-size: 0.74rem;
}

@media (max-width: 375px) {
  .top-header .icon-btn {
    width: 31px;
    height: 31px;
  }
  .pill-chip-btn {
    padding: 0 8px;
    font-size: 0.73rem;
  }
  .top-header .promptpay-trigger-btn {
    padding: 0 8px;
    font-size: 0.71rem;
  }
}

/* ป้ายแสดงวิธีคิดโจทย์ภาษาธรรมชาติจากไมค์ AI */
.ai-formula-note {
  align-self: flex-end;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* กล่องปรับความเร็วเสียงขาน ช้า-ไว */
.tts-speed-box {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tts-speed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tts-speed-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--text-primary);
  font-size: 0.75rem;
}

.tts-speed-ends {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* กล่องแนะนำ API Key ส่วนตัว & ระบบล็อกช่องคีย์ในรุ่นฟรี */
.byok-recommend-box {
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.byok-recommend-box strong {
  font-size: 0.82rem;
  color: var(--text-primary);
}

.byok-recommend-box p {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.byok-recommend-box.highlight-alert {
  border: 1.5px solid var(--accent-primary);
}

.byok-lock-banner {
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1.5px dashed var(--accent-primary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.byok-lock-title {
  font-size: 0.81rem;
  font-weight: 700;
  color: var(--text-primary);
}

.byok-controls-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.byok-controls-wrap.is-locked {
  opacity: 0.45;
  pointer-events: none;
  filter: grayscale(0.4);
}

.byok-ext-link,
.api-link-btn {
  text-decoration: none;
}

.byok-steps-clean {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.byok-steps-clean p {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* การ์ดคู่มือ API Key ในหน้าคู่มือการใช้ */
.api-guide-card {
  padding: 13px 14px;
  border-radius: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.api-guide-heading {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
}

.api-guide-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.api-guide-steps p {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.46;
  color: var(--text-secondary);
}
/* ==========================================================================
   FIX V1.1.2: PromptPay QR Modal Full Visibility (No Bottom Clipping)
   ========================================================================== */

.modal-qr-card {
  max-height: 92dvh;
}

.qr-modal-body {
  padding: 12px 16px 16px;
  gap: 10px;
}

.qr-card-visual {
  flex-shrink: 0;
}

.qr-card-banner {
  padding: 8px 12px;
}

.qr-card-content {
  padding: 12px 14px 16px;
  gap: 5px;
}

.qr-canvas-frame {
  padding: 8px;
}

#qr-canvas {
  width: clamp(164px, 25dvh, 210px);
  height: clamp(164px, 25dvh, 210px);
}

.qr-amount-box {
  margin-top: 4px;
  padding: 7px 20px 9px;
}

.qr-amount-val {
  font-size: 1.42rem;
  line-height: 1.25;
}

.qr-expr-note:empty {
  display: none;
}

.qr-wakelock-row,
.qr-card-actions {
  flex-shrink: 0;
}

#btn-edit-pp-from-card {
  white-space: nowrap;
  flex-shrink: 0;
}