/* ======= DESIGN TOKENS ======= */
:root {
  --bg-base:       #FFFBF0;      /* Soft Yellow/Cream Background */
  --surface:       rgba(255,255,255,0.92);
  --surface-2:     rgba(255,255,255,0.75);
  --surface-3:     rgba(255,251,235,0.85);
  --border:        rgba(229,179,58,0.3);
  --border-strong: rgba(229,179,58,0.5);

  --text:          #362B14;      /* Dark Brownish-Gold for readability */
  --text-sub:      rgba(54,43,20,0.65);
  --text-inv:      #ffffff;

  --blue:          #FBE29F;      /* Pastel Gold */
  --blue-2:        #D4AF37;      /* Classic Gold */
  --blue-glow:     rgba(212,175,55,0.25);
  --cyan:          #FFD770;      /* Amber / Yellow */
  --cyan-2:        #F39C12;      /* Deep Amber */
  --cyan-glow:     rgba(243,156,18,0.22);
  
  /* สีเขียวสำหรับ ID สำเร็จ และ Progress bar (คงเดิม) */
  --green:         #00cc66;
  --green-2:       #00cc66;
  --danger:        #ff8b94;
  --danger-2:      #e06b74;

  --radius-xl:     26px;
  --radius-lg:     18px;
  --radius-md:     13px;
  --radius-sm:     9px;

  --shadow-card:   0 14px 40px rgba(212,175,55,0.08), 0 2px 8px rgba(0,0,0,0.03);
  --shadow-btn:    0 8px 20px rgba(243,156,18,0.25);
  --wave-bg:       rgba(212,175,55,0.15);
}

/* ======= DARK MODE (LUXURY DARK GOLD OVERRIDE) ======= */
body.dark {
  --bg-base:       #1A1814;      
  --surface:       #24211A;      
  --surface-2:     #2D2920;      
  --surface-3:     #26231B;      
  --border:        #5C4D2A;      
  --border-strong: #8A733F;      

  --text:          #FDF5E6;      
  --text-sub:      #C9BA9B;      
  --text-inv:      #FFFFFF;      

  --blue:          #E5B552;      
  --blue-2:        #FCE6A9;      
  --blue-glow:     rgba(229,181,82,0.25);
  --cyan:          #F5C249;      
  --cyan-2:        #FFD700;      
  --cyan-glow:     rgba(245,194,73,0.22);
  
  /* สีเขียวสำหรับ ID สำเร็จ และ Progress bar (คงเดิม) */
  --green:         #00cc66;      
  --green-2:       #00cc66;      
  --danger:        #FFB6C1;
  --danger-2:      #F08080;

  --shadow-card:   0 14px 40px rgba(229,181,82,0.15), 0 2px 8px rgba(0,0,0,0.05);
  --shadow-btn:    0 8px 20px rgba(245,194,73,0.25);
  --wave-bg:       rgba(229,181,82,0.15);
}

/* ======= RESET ======= */
*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html { scroll-behavior: smooth; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

/* ======= ICONS & SPINNER ======= */
.material-symbols-rounded {
  font-size: 1.2em;
  vertical-align: middle;
}
.css-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
}

/* ======= AURORA BACKGROUND ======= */
.bg-aurora {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg-base);
  transition: background 0.5s ease;
}

.bg-mesh {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 5% 0%,    rgba(244,208,63,0.3) 0%, transparent 65%),
    radial-gradient(ellipse 55% 50% at 95% 15%,   rgba(212,175,55,0.3) 0%, transparent 60%),
    radial-gradient(ellipse 60% 55% at 10% 55%,   rgba(255,255,255,0.6) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,   rgba(243,156,18,0.15) 0%, transparent 60%),
    radial-gradient(ellipse 50% 45% at 50% 50%,   rgba(229,179,58,0.25) 0%, transparent 70%);
  transition: opacity 0.5s ease;
}
body.dark .bg-mesh {
  background:
    radial-gradient(ellipse 70% 60% at 5% 0%,    rgba(229,181,82,0.25) 0%, transparent 65%),
    radial-gradient(ellipse 55% 50% at 95% 15%,  rgba(218,165,32,0.25) 0%, transparent 60%),
    radial-gradient(ellipse 60% 55% at 10% 55%,  rgba(255,255,255,0.1) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,  rgba(245,194,73,0.15) 0%, transparent 60%),
    radial-gradient(ellipse 50% 45% at 50% 50%,  rgba(184,134,11,0.25) 0%, transparent 70%);
}

.blob { position: absolute; border-radius: 50%; }
.blob-1 { width: 500px; height: 500px; background: radial-gradient(circle, rgba(244,208,63,0.4) 0%, transparent 70%); top: -220px; left: -150px; animation-duration: 20s; animation-delay: 0s; }
.blob-2 { width: 380px; height: 380px; background: radial-gradient(circle, rgba(212,175,55,0.4) 0%, transparent 70%); top: 0%; right: -120px; animation-duration: 16s; animation-delay: -5s; }
.blob-3 { width: 420px; height: 420px; background: radial-gradient(circle, rgba(255,245,204,0.5) 0%, transparent 70%); top: 38%; left: -100px; animation-duration: 24s; animation-delay: -11s; }
.blob-4 { width: 320px; height: 320px; background: radial-gradient(circle, rgba(243,156,18,0.2) 0%, transparent 70%); bottom: 8%; right: -80px; animation-duration: 18s; animation-delay: -8s; }
.blob-5 { width: 260px; height: 260px; background: radial-gradient(circle, rgba(229,179,58,0.25) 0%, transparent 70%); top: 55%; left: 20%; animation-duration: 22s; animation-delay: -14s; }
.blob-6 { width: 220px; height: 220px; background: radial-gradient(circle, rgba(218,165,32,0.2) 0%, transparent 70%); top: 18%; left: 35%; animation-duration: 28s; animation-delay: -6s; }

body.dark .blob-1 { background: radial-gradient(circle, rgba(229,181,82,0.3) 0%, transparent 70%); }
body.dark .blob-2 { background: radial-gradient(circle, rgba(218,165,32,0.3) 0%, transparent 70%); }
body.dark .blob-3 { background: radial-gradient(circle, rgba(184,134,11,0.3) 0%, transparent 70%); }
body.dark .blob-4 { background: radial-gradient(circle, rgba(245,194,73,0.2) 0%, transparent 70%); }
body.dark .blob-5 { background: radial-gradient(circle, rgba(255,215,0,0.15) 0%, transparent 70%); }
body.dark .blob-6 { background: radial-gradient(circle, rgba(218,165,32,0.2) 0%, transparent 70%); }

/* ======= BODY ======= */
body, button, input, textarea, select {
  font-family: 'Kanit', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background: transparent;
  min-height: 100vh;
  color: var(--text);
  padding: 18px 14px 50px;
  overflow-x: hidden;
  transition: color 0.3s ease;
  position: relative;
}

.page-bg-wave {
  position: fixed;
  bottom: 0; left: 0;
  width: 100%;
  z-index: -1;
  line-height: 0;
  pointer-events: none;
}
.page-bg-wave svg { display: block; width: 100%; height: 20vh; min-height: 150px; }
.page-bg-wave path { transition: fill 0.45s ease; }
.page-bg-wave path:nth-child(1) { fill: rgba(244,208,63,0.15); }
.page-bg-wave path:nth-child(2) { fill: rgba(212,175,55,0.15); }
.page-bg-wave path:nth-child(3) { fill: rgba(243,156,18,0.1); }
body.dark .page-bg-wave path:nth-child(1) { fill: rgba(229,181,82,0.15); }
body.dark .page-bg-wave path:nth-child(2) { fill: rgba(218,165,32,0.15); }
body.dark .page-bg-wave path:nth-child(3) { fill: rgba(184,134,11,0.1); }

/* ======= CONTAINER ======= */
.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 22px 20px 28px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fadeUp 0.5s cubic-bezier(0.16,1,0.3,1) both;
  position: relative;
  overflow: hidden;
}
.container::before {
  content: ''; position: absolute; inset: 0;
  background-color: var(--border-strong);
  
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Ctext x='50%25' y='50%25' font-size='20' text-anchor='middle' dominant-baseline='central' fill='black'%3E♱%3C/text%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Ctext x='50%25' y='50%25' font-size='20' text-anchor='middle' dominant-baseline='central' fill='black'%3E♱%3C/text%3E%3C/svg%3E");
  
  -webkit-mask-size: 40px 40px;
  mask-size: 40px 40px;
  opacity: 1.0;
  pointer-events: none; 
  z-index: 0;
}
.container > * { position: relative; z-index: 1; }

.wave-wrap { margin: 0px -20px -1px -20px; line-height: 0; overflow: hidden; }
.wave-wrap svg { display: block; width: calc(100% + 1.3px); height: 55px; }
.wave-wrap path { fill: var(--wave-bg); transition: fill 0.3s ease; }
.bottom-section { margin: 0 -20px -28px -20px; padding: 0px 20px 28px 20px; background: var(--wave-bg); transition: background 0.3s ease; }

/* ======= BALANCE CARD ======= */
.balance-card {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #FDEB71 0%, #F8D800 50%, #D4AF37 100%);
  border-radius: var(--radius-lg); padding: 20px 22px 18px; margin-bottom: 22px;
  color: #4A3C15; display: flex; justify-content: space-between; align-items: flex-end;
  box-shadow: 0 14px 32px rgba(212,175,55,0.4), inset 0 1px 0 rgba(255,255,255,0.7);
  cursor: pointer; user-select: none; transition: transform 0.22s ease, box-shadow 0.22s ease;
}
body.dark .balance-card {
  background: linear-gradient(135deg, #FCE6A9 0%, #DAA520 50%, #B8860B 100%);
  color: #1A1814; box-shadow: 0 14px 32px rgba(218,165,32,0.4), inset 0 1px 0 rgba(255,255,255,0.7);
}
.balance-card:active { transform: scale(0.97); }
.balance-card::before { content: ''; position: absolute; width: 210px; height: 210px; background: rgba(255,255,255,0.3); border-radius: 50%; top: -110px; right: -70px; }
body.dark .balance-card::before { background: rgba(255,255,255,0.3); }
.balance-card::after { content: ''; position: absolute; width: 130px; height: 130px; background: rgba(255,255,255,0.25); border-radius: 50%; bottom: -70px; left: 20px; }
body.dark .balance-card::after { background: rgba(255,255,255,0.25); }

.bal-left .bal-label { font-size: 11px; font-weight: 700; opacity: 0.9; letter-spacing: 0.2px; margin-bottom: 7px; display: flex; align-items: center; gap: 7px; }
.bal-left .bal-label .rate-pill { background: rgba(74,60,21,0.15); border-radius: 99px; padding: 2px 8px; font-size: 9px; font-weight: 700; letter-spacing: 0.3px; }
body.dark .bal-left .bal-label .rate-pill { background: rgba(26,24,20,0.15); }
.bal-left .amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 42px; font-weight: 400; letter-spacing: -1.8px; line-height: 1; }
.bal-right { text-align: right; }
.bal-right .thb-label { font-size: 10px; font-weight: 700; opacity: 0.8; }
.bal-right .thb-amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 25px; font-weight: 400; letter-spacing: -0.3px; }

/* ======= APP TITLE ======= */
.app-title { font-family: 'Carter One',sans-serif !important; text-align: center; margin: 0 auto 14px auto; font-size: 1.8rem; font-weight: 700; letter-spacing: -0.5px; width: fit-content; display: block; }
.gradient-text {
  background: linear-gradient(to right, #F39C12, #D4AF37) !important;
  -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; background-clip: text !important;
}
body.dark .gradient-text {
  background: linear-gradient(to right, #FFD700, #E5B552) !important;
  -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; background-clip: text !important;
}

.credit-text {
    font-family: 'Kanit',sans-serif !important;
    position: absolute;
    bottom: -8px; 
    right: 15px;   
    white-space: nowrap; 
    font-size: 12px; 
    font-weight: 600;
    letter-spacing: 0;
    color: #B8860B !important; 
    -webkit-text-fill-color: #B8860B !important; 
}
body.dark .credit-text {
    color: #DAA520 !important; 
    -webkit-text-fill-color: #DAA520 !important;
}

/* ======= THEME TOGGLE ======= */
.theme-toggle { display: flex; justify-content: center; gap: 12px; margin-bottom: 20px; }
.theme-toggle-btn {
  display: flex; align-items: center; justify-content: center; flex: 1; gap: 6px; border: 1.5px solid var(--border-strong); border-radius: 99px; padding: 10px 16px;
  background: var(--surface-2); color: var(--blue-2); font-weight: 800; font-size: 12px; cursor: pointer; transition: all 0.2s ease; font-family: inherit; letter-spacing: 0.2px;
}
body.dark .theme-toggle-btn { color: var(--cyan-2); }
.theme-toggle-btn:hover { background: var(--blue-glow); }
.theme-toggle-btn:active { transform: scale(0.92); }
.theme-toggle-btn .material-symbols-rounded { font-size: 16px; }

/* ======= SECTION LABEL ======= */
.sec-label { display: flex; align-items: center; gap: 6px; margin-bottom: 9px; margin-top: 20px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.9px; color: var(--blue-2); }
body.dark .sec-label { color: var(--cyan-2); }
.sec-label .material-symbols-rounded { font-size: 16px; }

/* ======= TEXTAREA / INPUT ======= */
textarea, input[type="text"], input[type="number"] {
  width: 100%; border-radius: var(--radius-md); padding: 13px 15px; font-size: 13px; font-weight: 600; outline: none; border: 1.5px solid var(--border-strong);
  background: var(--surface-3); color: var(--text); transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s; font-family: inherit; -webkit-appearance: none; appearance: none;
}
textarea::placeholder, input::placeholder { color: var(--text-sub); font-weight: 600; }
textarea:focus, input:focus { border-color: var(--cyan-2); box-shadow: 0 0 0 3px var(--cyan-glow); transform: translateY(-1px); }
body.dark textarea, body.dark input[type="text"], body.dark input[type="number"] { background: #24211A; }
#serviceId, #serviceRate, [id^="qty_"] { text-align: center; font-weight: 700; }
.link-count { margin-top: 7px; text-align: right; font-size: 11px; font-weight: 700; color: var(--text-sub); }

/* ======= CONFIG CARD ======= */
.config-card { margin-top: 14px; padding: 15px 16px; border-radius: var(--radius-lg); display: flex; gap: 12px; background: var(--surface-2); border: 1.5px solid var(--border-strong); }
.config-field { flex: 1; }
.config-field > .config-label { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.7px; color: var(--blue-2); margin-bottom: 8px; opacity: 0.9; }
body.dark .config-field > .config-label { color: var(--cyan-2); }

/* ======= BUTTONS ======= */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; outline: none; border-radius: 16px; padding: 15px; font-size: 16px; font-weight: 800; cursor: pointer; transition: transform 0.2s cubic-bezier(0.175,0.885,0.32,1.275), filter 0.15s, box-shadow 0.2s;
  position: relative; overflow: hidden; color: white; font-family: inherit; letter-spacing: 0.1px;
}
.btn::before { content: ''; position: absolute; inset: 0 0 50% 0; background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 100%); border-radius: inherit; pointer-events: none; }
@media (hover: hover) { .btn:hover { transform: translateY(-2px); filter: brightness(1.04); } }
.btn:active { transform: scale(0.95) translateY(1px) !important; filter: brightness(1.05); transition: 0.07s !important; }

/* เปลี่ยนจากสีฟ้าเป็นสีทอง/เหลืองเข้ม เพื่อให้ตัวหนังสือสีขาวอ่านชัด */
.btn-blue { margin-top: 14px; background: linear-gradient(145deg, #ffcc33, #ffcc66); box-shadow: 0 8px 22px rgba(212,175,55,0.3); text-shadow: 0 1px 3px rgba(150,100,0,0.4); }
body.dark .btn-blue { background: linear-gradient(145deg, #E5B552, #DAA520); box-shadow: 0 8px 22px rgba(218,165,32,0.3); text-shadow: 0 1px 3px rgba(184,134,11,0.4); }

.btn-cyan { margin-top: 14px; background: linear-gradient(145deg, #ffcc33, #ffcc66); box-shadow: 0 8px 22px rgba(243,156,18,0.4); text-shadow: 0 1px 3px rgba(200,100,0,0.2); }
body.dark .btn-cyan { background: linear-gradient(145deg, #F5C249, #F39C12); box-shadow: 0 8px 22px rgba(245,194,73,0.4); text-shadow: 0 1px 3px rgba(210,130,0,0.2); }

.btn-danger { background: linear-gradient(145deg, #ffb3ba, #ffdfba); box-shadow: 0 6px 18px rgba(255,179,186,0.4); text-shadow: 0 1px 3px rgba(180,100,100,0.3); }
body.dark .btn-danger { background: linear-gradient(145deg, #FFB6C1, #F08080); box-shadow: 0 6px 18px rgba(255,182,193,0.4); text-shadow: 0 1px 3px rgba(240,128,128,0.3); }

/* ======= QUICK FILL ======= */
.quick-fill-card { 
  margin-top: 14px; 
  padding: 14px; 
  border-radius: var(--radius-lg); 
  background: var(--surface-2); 
  border: 1.5px solid var(--border-strong); 
}
.quick-fill-title { 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  gap: 4px; 
  font-size: 10px; 
  font-weight: 900; 
  text-transform: uppercase; 
  letter-spacing: 0.8px; 
  color: var(--blue-2); 
  margin-bottom: 10px; 
}
body.dark .quick-fill-title { color: var(--cyan-2); }

/* --- บังคับให้ 1 แถวมี 4 ช่อง พอปุ่มที่ 5 จะปัดตกมาแถว 2 อัตโนมัติ --- */
.quick-fill-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr); 
  gap: 8px; 
}

.btn-quick { 
  padding: 10px 4px; 
  font-size: 11.5px; 
  font-weight: 800; 
  border-radius: var(--radius-md); 
  letter-spacing: 0px; 
  color: #fff; 
  text-shadow: 0 1px 2px rgba(0,0,0,0.25); 
  border: none; 
  cursor: pointer; 
  width: 100%;
}

/* ชุดสีปุ่ม */
.btn-1000 { background: #F4D03F; }
.btn-2000 { background: #F4D03F; }
.btn-3000 { background: #F4D03F; }
body.dark .btn-quick { text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
body.dark .btn-1000 { background: #B8860B; }
body.dark .btn-2000 { background: #B8860B; }
body.dark .btn-3000 { background: #B8860B; }

/* ======= TABLE ======= */
.table-container { margin-top: 16px; overflow: hidden; border-radius: var(--radius-lg); border: 1.5px solid var(--border-strong); background: var(--surface); }
body.dark .table-container { background: #24211A; }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--blue-glow); }
th { padding: 12px 9px; font-size: 12px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase; color: var(--blue-2); }
body.dark th { color: var(--cyan-2); }
td { padding: 12px 9px; border-bottom: 1px solid var(--border-strong); font-size: 13px; font-weight: 600; text-align: center; vertical-align: middle; }
body.dark td { border-bottom-color: #5C4D2A; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: var(--blue-glow); }
.btn-check-all { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1.5px solid var(--blue-2); border-radius: 8px; padding: 4px 9px; background: transparent; color: var(--blue-2); font-size: 11px; font-weight: 700; cursor: pointer; font-family: inherit; transition: all 0.18s; letter-spacing: 0.2px; }
body.dark .btn-check-all { border-color: var(--cyan-2); color: var(--cyan-2); }
.btn-check-all:hover { background: var(--blue-glow); }
.btn-check-all:active { transform: scale(0.9); }
.btn-check-all .material-symbols-rounded { font-size: 14px; }
.status-box { margin-top: 5px; padding-top: 3px; text-align: left; }
.status-txt { font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.status-txt .material-symbols-rounded { font-size: 13px; }

/* ======= PROGRESS BAR (คงเดิมทั้งหมด ตามบรีฟว่าสีเขียวต้องไม่เปลี่ยน) ======= */
.progress-container { width: 100%; background: var(--surface-2); border-radius: 99px; margin-top: 14px; height: 20px; position: relative; overflow: hidden; display: none; border: 1.5px solid var(--border-strong); }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #11998e, #38ef7d); border-radius: 99px; transition: width 0.3s ease; }
.progress-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: white; text-shadow: 0 1px 3px rgba(100,100,100,0.5); z-index: 2; }
body.dark .progress-text { text-shadow: 0 1px 3px rgba(100,100,100,0.5); }

/* ======= ACTION BUTTONS ROW ======= */
.action-row { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }
.btn-retry-sm { width: auto; padding: 10px 24px; font-size: 12px; border-radius: var(--radius-md); margin-top: 0 !important; }

/* ======= SUMMARY CARD ======= */
.summary-card { margin-top: 0px; display: flex; justify-content: space-around; align-items: center; padding: 16px; border-radius: var(--radius-lg); background: var(--surface-2); border: 1.5px solid var(--border-strong); text-align: center; }
body.dark .summary-card { background: #26231B; }
.sum-divider { width: 1px; height: 36px; background: var(--border-strong); border-radius: 99px; flex-shrink: 0; }
.summary-item .s-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--blue-2); margin-bottom: 5px; }
body.dark .summary-item .s-label { color: var(--text-sub); }
.summary-item .s-val { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; color: var(--text); }
.summary-item.accent .s-val { color: var(--cyan-2); }
body.dark .summary-item.accent .s-val { color: var(--cyan-2); }

/* ======= TOAST ======= */
#toast {
  display: flex; align-items: center; gap: 8px;
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(120px); opacity: 0; visibility: hidden;
  background: rgba(54,43,20,0.95); color: white; padding: 12px 22px; border-radius: 14px;
  font-size: 13px; font-weight: 700; z-index: 999;
  transition: all 0.4s cubic-bezier(0.175,0.885,0.32,1.275);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.07);
  white-space: nowrap;
}
body:not(.dark) #toast { background: rgba(54,43,20,0.95); }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

/* ======= ANIMATIONS ======= */
@keyframes fadeUp { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }
@keyframes rowSliceIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.animated-row { animation: rowSliceIn 0.32s cubic-bezier(0.16,1,0.3,1) both; }

.container > *:nth-child(1)  { animation: fadeIn 0.4s ease 0.05s backwards; }
.container > *:nth-child(2)  { animation: fadeIn 0.4s ease 0.10s backwards; }
.container > *:nth-child(3)  { animation: fadeIn 0.4s ease 0.15s backwards; }
.container > *:nth-child(4)  { animation: fadeIn 0.4s ease 0.20s backwards; }
.container > *:nth-child(5)  { animation: fadeIn 0.4s ease 0.25s backwards; }
.container > *:nth-child(6)  { animation: fadeIn 0.4s ease 0.28s backwards; }
.container > *:nth-child(7)  { animation: fadeIn 0.4s ease 0.31s backwards; }
.container > *:nth-child(8)  { animation: fadeIn 0.4s ease 0.34s backwards; }
.container > *:nth-child(9)  { animation: fadeIn 0.4s ease 0.37s backwards; }
.container > *:nth-child(10) { animation: fadeIn 0.4s ease 0.40s backwards; }

@keyframes flashPulse { 0% { box-shadow: 0 0 0 4px rgba(212,175,55,0.5); background: rgba(212,175,55,0.25); } 100% { box-shadow: none; } }
.flash-pulse { animation: flashPulse 0.5s ease-out; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ======= HISTORY MODAL ======= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px);
  z-index: 1000; display: none; justify-content: center; align-items: center;
  opacity: 0; transition: opacity 0.3s ease; padding: 20px;
}
.modal-overlay.show { display: flex; opacity: 1; }
.history-modal {
  background: var(--surface); border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-xl); width: 100%; max-width: 500px; max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-card); transform: translateY(20px); transition: transform 0.3s ease;
}
.modal-overlay.show .history-modal { transform: translateY(0); }
.history-header {
  padding: 16px 20px; border-bottom: 1.5px solid var(--border-strong);
  display: flex; justify-content: space-between; align-items: center; background: var(--surface-2);
}
.history-header h3 { font-size: 16px; font-weight: 700; color: var(--blue-2); margin: 0; }
.btn-close {
  background: transparent; border: none; color: var(--text-sub); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: color 0.2s;
  width: 40px; 
  height: 40px;
}
.btn-close .material-symbols-rounded {
  font-size: 28px !important; 
}
.btn-close:hover { color: var(--danger); }
.history-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.batch-card {
  background: var(--surface-3); border: 1.5px solid var(--border);
  border-radius: var(--radius-md); padding: 12px; margin-bottom: 12px;
}
.batch-header {
  display: flex; justify-content: space-between; font-size: 11px; font-weight: 700;
  color: var(--text); margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--border-strong);
}
.batch-item { font-size: 11px; color: var(--text-sub); display: flex; justify-content: space-between; margin-bottom: 4px; }
.batch-item a { color: inherit; text-decoration: underline; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch-id { color: var(--green-2); font-weight: 700; }

.btn-history-toggle {
  display: flex; align-items: center; justify-content: center; flex: 1; gap: 6px;
  background: var(--surface-2); border: 1.5px solid var(--border-strong); border-radius: 99px;
  padding: 10px 16px; color: var(--blue-2); font-weight: 700; font-size: 12px; cursor: pointer;
  margin: 0; transition: all 0.2s;
}
.btn-history-toggle:hover { background: var(--blue-glow); }

/* --- ปรับสีส่วนแสดงผลทั้งหมด (Balance + Summary) --- */

/* 1. กรณี Light Mode (โหมดสว่าง) */
/* ปรับยอดเงินด้านบน ให้กลมกลืนกับพื้นหลังสีทอง */
body:not(.dark) .bal-left .amount,
body:not(.dark) .bal-right .thb-amount { color: #4A3C15 !important; }

/* ปรับยอดรวม 3 ช่องด้านล่าง */
body:not(.dark) .summary-item:nth-child(1) .s-val { color: #D4AF37 !important; }
body:not(.dark) .summary-item:nth-child(3) .s-val { color: #E5B33A !important; }
body:not(.dark) .summary-item:nth-child(5) .s-val { color: #F39C12 !important; }

/* 2. กรณี Dark Mode (โหมดมืด) */
/* ปรับยอดเงินด้านบน */
body.dark .bal-left .amount,
body.dark .bal-right .thb-amount { color: #FFF8E7 !important; }

/* ปรับยอดรวม 3 ช่องด้านล่าง */
body.dark .summary-item:nth-child(1) .s-val { color: #FFD700 !important; }
body.dark .summary-item:nth-child(3) .s-val { color: #FCE6A9 !important; }
body.dark .summary-item:nth-child(5) .s-val { color: #F5C249 !important; }

/* ปุ่มยกเลิกในหน้าประวัติ (ยังคงเป็นสีแดงตามเดิม) */
.btn-cancel-sm {
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 10px;
    font-family: 'Kanit', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-cancel-sm:hover:not(:disabled) {
    background: #ef4444;
    color: #ffffff;
}
.btn-cancel-sm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #64748b;
    color: #64748b;
}
