/* ======= DESIGN TOKENS ======= */
:root {
  --bg-base:       #FDF7FE;      /* Soft Pink/Purple Background */
  --surface:       rgba(255,255,255,0.95);
  --surface-2:     rgba(253,247,255,0.85);
  --surface-3:     rgba(250,240,255,0.9);
  --border:        rgba(216,191,230,0.4);
  --border-strong: rgba(200,162,220,0.6);

  --text:          #4B3E5B;
  --text-sub:      rgba(75,62,91,0.65);
  --text-inv:      #ffffff;

  --blue:          #D8B4E2;      /* Pastel Purple */
  --blue-2:        #AE81C9;      /* Deep Pastel Purple */
  --blue-glow:     rgba(174,129,201,0.20);
  --cyan:          #FFC4D9;      /* Pastel Pink */
  --cyan-2:        #F092B0;      /* Deep Pastel Pink */
  --cyan-glow:     rgba(240,146,176,0.20);
  
  /* สีเขียวสำหรับ ID สำเร็จ และ Progress bar (คงเดิม) */
  --green:         #00cc66;
  --green-2:       #00cc66;
  --danger:        #FF9EAA;
  --danger-2:      #E86A78;

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

  --shadow-card:   0 14px 40px rgba(174,129,201,0.12), 0 2px 8px rgba(0,0,0,0.03);
  --shadow-btn:    0 8px 20px rgba(174,129,201,0.25);
  --wave-bg:       rgba(216,191,230,0.2);
}

/* ======= DARK MODE (PASTEL OVERRIDE FOR BLACK NOIR) ======= */
body.dark {
  --bg-base:       #2A1B38;      
  --surface:       #3A264C;      
  --surface-2:     #442D59;      
  --surface-3:     #4F3566;      
  --border:        #5D4275;      
  --border-strong: #755591;      

  --text:          #FDF7FE;      
  --text-sub:      #D8B4E2;      
  --text-inv:      #2A1B38;      

  --blue:          #C299D6;      
  --blue-2:        #D8B4E2;      
  --blue-glow:     rgba(216,180,226,0.25);
  --cyan:          #E294B6;      
  --cyan-2:        #F092B0;      
  --cyan-glow:     rgba(240,146,176,0.22);
  
  --green:         #00cc66;      
  --green-2:       #00cc66;      
  --danger:        #FF9EAA;
  --danger-2:      #FFB6C1;

  --shadow-card:   0 14px 40px rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.1);
  --shadow-btn:    0 8px 20px rgba(0,0,0,0.4);
  --wave-bg:       rgba(93,66,117,0.3);
}

/* ======= 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(216,191,230,0.45) 0%, transparent 65%),
    radial-gradient(ellipse 55% 50% at 95% 15%,   rgba(255,196,217,0.4) 0%, transparent 60%),
    radial-gradient(ellipse 60% 55% at 10% 55%,   rgba(255,255,255,0.7) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,   rgba(174,129,201,0.15) 0%, transparent 60%),
    radial-gradient(ellipse 50% 45% at 50% 50%,   rgba(240,146,176,0.25) 0%, transparent 70%);
  transition: opacity 0.5s ease;
}
body.dark .bg-mesh {
  background:
    radial-gradient(ellipse 70% 60% at 5% 0%,    rgba(117,85,145,0.45) 0%, transparent 65%),
    radial-gradient(ellipse 55% 50% at 95% 15%,  rgba(145,85,117,0.4) 0%, transparent 60%),
    radial-gradient(ellipse 60% 55% at 10% 55%,  rgba(93,66,117,0.5) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,  rgba(60,38,76,0.5) 0%, transparent 60%),
    radial-gradient(ellipse 50% 45% at 50% 50%,  rgba(117,85,145,0.25) 0%, transparent 70%);
}

.blob { position: absolute; border-radius: 50%; }
.blob-1 { width: 500px; height: 500px; background: radial-gradient(circle, rgba(216,191,230,0.5) 0%, transparent 70%); top: -220px; left: -150px; animation-duration: 20s; animation-delay: 0s; }
.blob-2 { width: 380px; height: 380px; background: radial-gradient(circle, rgba(255,196,217,0.5) 0%, transparent 70%); top: 0%; right: -120px; animation-duration: 16s; animation-delay: -5s; }
.blob-3 { width: 420px; height: 420px; background: radial-gradient(circle, rgba(253,247,255,0.8) 0%, transparent 70%); top: 38%; left: -100px; animation-duration: 24s; animation-delay: -11s; }
.blob-4 { width: 320px; height: 320px; background: radial-gradient(circle, rgba(174,129,201,0.25) 0%, transparent 70%); bottom: 8%; right: -80px; animation-duration: 18s; animation-delay: -8s; }
.blob-5 { width: 260px; height: 260px; background: radial-gradient(circle, rgba(240,146,176,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(216,191,230,0.2) 0%, transparent 70%); top: 18%; left: 35%; animation-duration: 28s; animation-delay: -6s; }

/* ======= 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(216,191,230,0.25); }
.page-bg-wave path:nth-child(2) { fill: rgba(255,196,217,0.2); }
.page-bg-wave path:nth-child(3) { fill: rgba(174,129,201,0.15); }
body.dark .page-bg-wave path:nth-child(1) { fill: rgba(117,85,145,0.25); }
body.dark .page-bg-wave path:nth-child(2) { fill: rgba(145,85,117,0.2); }
body.dark .page-bg-wave path:nth-child(3) { fill: rgba(93,66,117,0.15); }

/* ======= CONTAINER ======= */
.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 22px 20px 28px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1.5px 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: 0.8;
  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, #C299D6 0%, #E294B6 100%);
  border-radius: var(--radius-lg); padding: 20px 22px 18px; margin-bottom: 22px;
  color: #2e243d; display: flex; justify-content: space-between; align-items: flex-end;
  box-shadow: 0 14px 32px rgba(194,153,214,0.3), inset 0 1px 0 rgba(255,255,255,0.5);
  cursor: pointer; user-select: none; transition: transform 0.22s ease, box-shadow 0.22s ease;
}
body.dark .balance-card {
  background: linear-gradient(135deg, #755591 0%, #915575 100%);
  color: #ffffff; box-shadow: 0 14px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.balance-card:active { transform: scale(0.97); }
.balance-card::before { content: ''; position: absolute; width: 210px; height: 210px; background: rgba(255,255,255,0.25); border-radius: 50%; top: -110px; right: -70px; }
body.dark .balance-card::before { background: rgba(255,255,255,0.15); }
.balance-card::after { content: ''; position: absolute; width: 130px; height: 130px; background: rgba(255,255,255,0.2); border-radius: 50%; bottom: -70px; left: 20px; }
body.dark .balance-card::after { background: rgba(255,255,255,0.1); }

.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(255,255,255,0.2); border-radius: 99px; padding: 2px 8px; font-size: 9px; font-weight: 700; letter-spacing: 0.3px; color: #2e243d; }
.bal-left .amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 44px; font-weight: 400; letter-spacing: -1.8px; line-height: 1; color: #2e243d !important; }
.bal-right { text-align: right; }
.bal-right .thb-label { font-size: 10px; font-weight: 700; opacity: 0.8; color: #2e243d;}
.bal-right .thb-amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 25px; font-weight: 400; letter-spacing: -0.3px; color: #2e243d !important; }

/* ======= 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, #AE81C9, #F092B0) !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, #b452cd, #cd3278) !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: var(--blue-2) !important; 
    -webkit-text-fill-color: var(--blue-2) !important; 
}
body.dark .credit-text { color: var(--text-sub) !important; -webkit-text-fill-color: var(--text-sub) !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(--blue-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(--blue-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(--blue-2); box-shadow: 0 0 0 3px var(--blue-glow); transform: translateY(-1px); }
body.dark textarea, body.dark input[type="text"], body.dark input[type="number"] { background: var(--surface-3); }
#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(--blue-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; }

/* สร้างรายการ Mass order */
.btn-blue { margin-top: 14px; background: linear-gradient(145deg, #AE81C9, #E294B6); box-shadow: 0 8px 22px rgba(174,129,201,0.3); text-shadow: 0 1px 3px rgba(174,129,201,0.4); }
body.dark .btn-blue { background: linear-gradient(145deg, #915575, #755591); box-shadow: 0 8px 22px rgba(0,0,0,0.3); }

/* สั่งใหม่ที่พลาด */
.btn-cyan { margin-top: 14px; background: linear-gradient(145deg, #E294B6, #AE81C9); box-shadow: 0 8px 22px rgba(174,129,201,0.3); text-shadow: 0 1px 3px rgba(174,129,201,0.2); }
body.dark .btn-cyan { background: linear-gradient(145deg, #755591, #915575); box-shadow: 0 8px 22px rgba(0,0,0,0.3); }

/* สั่ง Mass Order ทันที!! */
.btn-danger { background: linear-gradient(145deg, #E87A90, #D65A7A); box-shadow: 0 6px 18px rgba(232,122,144,0.4); text-shadow: 0 1px 3px rgba(180,100,100,0.3); }
body.dark .btn-danger { background: linear-gradient(145deg, #C25975, #A3405C); box-shadow: 0 6px 18px rgba(0,0,0,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(--blue-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.18); 
  border: none; 
  cursor: pointer; 
  width: 100%;
}

/* ชุดสีปุ่ม */
.btn-1000 { background: #ffb6c1; }
.btn-2000 { background: #dda0dd; }
.btn-3000 { background: #cc99ff; }
body.dark .btn-quick { text-shadow: 0 1px 2px rgba(0,0,0,0.18); }
body.dark .btn-1000 { background: #915575; }
body.dark .btn-2000 { background: #cc6699; }
body.dark .btn-3000 { background: #cc66cc; }

/* ======= 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: var(--surface); }
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(--blue-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: var(--border-strong); }
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(--blue-2); color: var(--blue-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(0,0,0,0.8); }

/* ======= 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: var(--surface-2); }
.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(--blue-2); }
.summary-item .s-val { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; color: var(--text); }

/* ======= 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(75,62,91,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.15), 0 0 0 1px rgba(255,255,255,0.2);
  white-space: nowrap;
}
body.dark #toast { background: rgba(42,27,56,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(216,191,230,0.5); background: rgba(216,191,230,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 (โหมดสว่าง) */
/* ปรับยอดรวม 3 ช่องด้านล่าง */
body:not(.dark) .summary-item:nth-child(1) .s-val { color: #8F76B0 !important; }
body:not(.dark) .summary-item:nth-child(3) .s-val { color: #9A7BC1 !important; }
body:not(.dark) .summary-item:nth-child(5) .s-val { color: #E06F92 !important; }

/* 2. กรณี Dark Mode (โหมดมืด) */
/* ปรับยอดรวม 3 ช่องด้านล่าง */
body.dark .summary-item:nth-child(1) .s-val { color: #B395D6 !important; }
body.dark .summary-item:nth-child(3) .s-val { color: #C299D6 !important; }
body.dark .summary-item:nth-child(5) .s-val { color: #F092B0 !important; }

/* ปุ่มยกเลิกในหน้าประวัติ */
.btn-cancel-sm {
    background: transparent;
    border: 1px solid #E86A78;
    color: #E86A78;
    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: #E86A78;
    color: #ffffff;
}
.btn-cancel-sm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #9A7BC1;
    color: #9A7BC1;
}