/* ======= DESIGN TOKENS (RAINBOW PASTEL TONE) ======= */
:root {
  --bg-base:       #FAFAFF;      /* ขาวอมฟ้า/ม่วงสว่างๆ */
  --surface:       rgba(255,255,255,0.92);
  --surface-2:     rgba(255,255,255,0.75);
  --surface-3:     rgba(245,243,255,0.85);
  --border:        #E2E8F0;
  --border-strong: #C4B5FD;

  --text:          #1E293B;      
  --text-sub:      #64748B;
  --text-inv:      #ffffff;

  --blue:          #D8B4FE;      
  --blue-2:        #8B5CF6;      /* สีม่วงหลัก */
  --blue-glow:     rgba(139,92,246,0.15);
  --cyan:          #67E8F9;      
  --cyan-2:        #06B6D4;      /* สีฟ้าหลัก */
  --cyan-glow:     rgba(6,182,212,0.15);
  
  --green:         #0066cc;      /* สีเขียวมิ้นต์ */
  --green-2:       #0066cc;
  --danger:        #F43F5E;      /* สีชมพู/แดง */
  --danger-2:      #E11D48;

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

  --shadow-card:   0 14px 40px rgba(139,92,246,0.12), 0 2px 8px rgba(0,0,0,0.03);
  --shadow-btn:    0 8px 20px rgba(139,92,246,0.25);
  --wave-bg:       rgba(139,92,246,0.08);
}

/* ======= DARK MODE (TWILIGHT PURPLE OVERRIDE) ======= */
body.dark {
  --bg-base:       #0F0C1B;      
  --surface:       #1A162B;      
  --surface-2:     #241E3A;      
  --surface-3:     #1F1A33;      
  --border:        #42366D;      
  --border-strong: #5B4A94;      

  --text:          #E8E4FA;      
  --text-sub:      #A9A2C2;      
  --text-inv:      #FFFFFF;      

  --blue:          #A78BFA;      
  --blue-2:        #8B5CF6;      
  --blue-glow:     rgba(139,92,246,0.25);
  --cyan:          #67E8F9;      
  --cyan-2:        #06B6D4;      
  --cyan-glow:     rgba(6,182,212,0.22);
  
  --green:         #0066cc;      
  --green-2:       #0066cc;      
  --danger:        #FB7185;
  --danger-2:      #F43F5E;

  --shadow-card:   0 14px 40px rgba(124,58,237,0.15), 0 2px 8px rgba(0,0,0,0.2);
  --shadow-btn:    0 8px 20px rgba(139,92,246,0.25);
  --wave-bg:       rgba(124,58,237,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(236,72,153,0.15) 0%, transparent 65%),  /* Pink */
    radial-gradient(ellipse 55% 50% at 95% 15%,   rgba(6,182,212,0.15) 0%, transparent 60%),   /* Cyan */
    radial-gradient(ellipse 60% 55% at 10% 55%,   rgba(255,255,255,0.5) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,   rgba(139,92,246,0.15) 0%, transparent 60%),  /* Purple */
    radial-gradient(ellipse 50% 45% at 50% 50%,   rgba(59,130,246,0.1) 0%, transparent 70%);   /* Blue */
  transition: opacity 0.5s ease;
}
body.dark .bg-mesh {
  background:
    radial-gradient(ellipse 70% 60% at 5% 0%,    rgba(236,72,153,0.2) 0%, transparent 65%),
    radial-gradient(ellipse 55% 50% at 95% 15%,  rgba(6,182,212,0.2) 0%, transparent 60%),
    radial-gradient(ellipse 60% 55% at 10% 55%,  rgba(255,255,255,0.05) 0%, transparent 65%),
    radial-gradient(ellipse 65% 60% at 90% 80%,  rgba(139,92,246,0.2) 0%, transparent 60%),
    radial-gradient(ellipse 50% 45% at 50% 50%,  rgba(59,130,246,0.15) 0%, transparent 70%);
}

.blob { position: absolute; border-radius: 50%; }
.blob-1 { width: 500px; height: 500px; background: radial-gradient(circle, rgba(236,72,153,0.3) 0%, transparent 70%); top: -220px; left: -150px; animation-duration: 20s; animation-delay: 0s; }
.blob-2 { width: 380px; height: 380px; background: radial-gradient(circle, rgba(6,182,212,0.3) 0%, transparent 70%); top: 0%; right: -120px; animation-duration: 16s; animation-delay: -5s; }
.blob-3 { width: 420px; height: 420px; background: radial-gradient(circle, rgba(139,92,246,0.3) 0%, transparent 70%); top: 38%; left: -100px; animation-duration: 24s; animation-delay: -11s; }
.blob-4 { width: 320px; height: 320px; background: radial-gradient(circle, rgba(59,130,246,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(217,70,239,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(16,185,129,0.15) 0%, transparent 70%); top: 18%; left: 35%; animation-duration: 28s; animation-delay: -6s; }

body.dark .blob-1 { background: radial-gradient(circle, rgba(236,72,153,0.25) 0%, transparent 70%); }
body.dark .blob-2 { background: radial-gradient(circle, rgba(6,182,212,0.25) 0%, transparent 70%); }
body.dark .blob-3 { background: radial-gradient(circle, rgba(139,92,246,0.3) 0%, transparent 70%); }
body.dark .blob-4 { background: radial-gradient(circle, rgba(59,130,246,0.15) 0%, transparent 70%); }
body.dark .blob-5 { background: radial-gradient(circle, rgba(217,70,239,0.2) 0%, transparent 70%); }
body.dark .blob-6 { background: radial-gradient(circle, rgba(16,185,129,0.15) 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(139,92,246,0.1); }
.page-bg-wave path:nth-child(2) { fill: rgba(6,182,212,0.1); }
.page-bg-wave path:nth-child(3) { fill: rgba(236,72,153,0.08); }
body.dark .page-bg-wave path:nth-child(1) { fill: rgba(139,92,246,0.15); }
body.dark .page-bg-wave path:nth-child(2) { fill: rgba(6,182,212,0.15); }
body.dark .page-bg-wave path:nth-child(3) { fill: rgba(236,72,153,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 (RAINBOW GRADIENT) ======= */
.balance-card {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #D946EF 0%, #8B5CF6 50%, #0EA5E9 100%); /* Pink -> Purple -> Blue */
  border-radius: var(--radius-lg); padding: 20px 22px 18px; margin-bottom: 22px;
  color: #000099; display: flex; justify-content: space-between; align-items: flex-end;
  box-shadow: 0 14px 32px rgba(139,92,246,0.35), inset 0 1px 0 rgba(255,255,255,0.3);
  cursor: pointer; user-select: none; transition: transform 0.22s ease, box-shadow 0.22s ease;
}
body.dark .balance-card {
  background: linear-gradient(135deg, #C026D3 0%, #7C3AED 50%, #0284C7 100%);
  color: #000099; box-shadow: 0 14px 32px rgba(124,58,237,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
}
.balance-card:active { transform: scale(0.97); }
.balance-card::before { content: ''; position: absolute; width: 210px; height: 210px; background: rgba(255,255,255,0.15); border-radius: 50%; top: -110px; right: -70px; }
body.dark .balance-card::before { background: rgba(255,255,255,0.1); }
.balance-card::after { content: ''; position: absolute; width: 130px; height: 130px; background: rgba(255,255,255,0.1); border-radius: 50%; bottom: -70px; left: 20px; }
body.dark .balance-card::after { background: rgba(255,255,255,0.05); }

.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: #000099; }
.bal-left .amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 44px; font-weight: 400; letter-spacing: -1.8px; line-height: 1; color: #000099 !important; }
.bal-right { text-align: right; }
.bal-right .thb-label { font-size: 10px; font-weight: 700; opacity: 0.8; color: #000099;}
.bal-right .thb-amount { font-family: 'Bebas Neue', sans-serif !important; font-size: 25px; font-weight: 400; letter-spacing: -0.3px; color: #000099 !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, #EC4899, #8B5CF6, #06B6D4) !important; /* Pink to Purple to Cyan */
  -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; background-clip: text !important;
}
body.dark .gradient-text {
  background: linear-gradient(to right, #fc2a97, #4288f7, #22D3EE) !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: #8B82A5 !important; 
    -webkit-text-fill-color: #8B82A5 !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 #DDD6FE; border-radius: 99px; padding: 10px 16px;
  background: var(--surface-2); color: #8B5CF6; font-weight: 800; font-size: 12px; cursor: pointer; font-family: inherit; letter-spacing: 0.2px;
  
  /* 1. แก้ไข Transition ให้ไวขึ้น (เปลี่ยนจาก 0.2s เป็น 0.05s) ให้ตอบสนองติดนิ้วทันที */
  transition: transform 0.05s ease, background-color 0.1s ease; 
  
  /* 2. เพิ่มคำสั่งนี้เพื่อปิดดีเลย์ 300ms บนมือถือ (บอกมือถือว่าปุ่มนี้ห้ามซูม ให้กดเลย) */
  touch-action: manipulation; 
  
  -webkit-tap-highlight-color: transparent; 
  user-select: none; 
  outline: none;
  -webkit-appearance: none;
}

/* 3. ล้างสถานะโฟกัส (Focus) ไม่ให้สีค้างเวลาแตะเสร็จ */
.theme-toggle-btn:focus {
  outline: none;
}

body.dark .theme-toggle-btn { background: #1A162B; border-color: #5B4A94; color: #A78BFA; }
.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); }
.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(--blue-2); /* ขอบสีม่วง/ฟ้าสลับกัน */
  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 { border-color: #A855F7; } /* พื้นที่วางลิงก์ขอบม่วง */
input { border-color: #06B6D4; } /* ช่องใส่ ID/Rate ขอบฟ้า */

textarea::placeholder, input::placeholder { color: var(--text-sub); font-weight: 600; }
textarea:focus, input:focus { border-color: #0EA5E9; box-shadow: 0 0 0 3px rgba(14,165,233,0.2); transform: translateY(-1px); }
body.dark textarea, body.dark input[type="text"], body.dark input[type="number"] { background: #1A162B; }
#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: #000099; } /* สีเขียวอมฟ้า */
body.dark .link-count { color: #000099; }

/* ======= 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); }
.config-field { flex: 1; }
.config-field > .config-label { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 8px; opacity: 0.9; }

/* แยกสี Label ใน Config Card (ชมพู กับ ฟ้า) */
.config-field:nth-child(1) > .config-label { color: #EC4899; }
.config-field:nth-child(2) > .config-label { color: #06B6D4; }
body.dark .config-field:nth-child(1) > .config-label { color: #F472B6; }
body.dark .config-field:nth-child(2) > .config-label { color: #22D3EE; }

/* ======= 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, #9D6BFF, #6B8AFF); box-shadow: 0 8px 22px rgba(107,138,255,0.3); text-shadow: 0 1px 3px rgba(138,107,255,0.4); }
body.dark .btn-blue { background: linear-gradient(145deg, #9370DB, #6495ED); box-shadow: 0 8px 22px rgba(100,149,237,0.3); text-shadow: 0 1px 3px rgba(147,112,219,0.4); }

.btn-cyan { margin-top: 14px; background: linear-gradient(145deg, #D4C3FF, #A3C4FF); box-shadow: 0 8px 22px rgba(163,196,255,0.4); text-shadow: 0 1px 3px rgba(196,163,255,0.2); }
body.dark .btn-cyan { background: linear-gradient(145deg, #87CEFA, #d8bfd8); box-shadow: 0 8px 22px rgba(135,206,250,0.4); text-shadow: 0 1px 3px rgba(221,160,221,0.2); }

.btn-danger { background: linear-gradient(145deg, #FB7185, #E11D48); box-shadow: 0 6px 18px rgba(244,63,94,0.4); text-shadow: 0 1px 3px rgba(180,100,100,0.3); }
body.dark .btn-danger { background: linear-gradient(145deg, #FDA4AF, #F43F5E); box-shadow: 0 6px 18px rgba(251,113,133,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); 
}
.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); }

.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%;
}

/* ชุดสีปุ่ม Quick Fill (แดง, ม่วง, ฟ้า) */
.btn-1000 { background: #ff66cc; } /* Red/Pink */
.btn-2000 { background: #9999ff; } /* Purple */
.btn-3000 { background: #99ccff; } /* Blue */
body.dark .btn-quick { text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
body.dark .btn-1000 { background: #b03060; }
body.dark .btn-2000 { background: #9333EA; }
body.dark .btn-3000 { background: #0284C7; }

/* ======= TABLE ======= */
.table-container { margin-top: 16px; overflow: hidden; border-radius: var(--radius-lg); border: 1.5px solid var(--border); background: var(--surface); }
body.dark .table-container { background: #1A162B; border-color: var(--border); }
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); }
td { padding: 12px 9px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; text-align: center; vertical-align: middle; }
body.dark td { border-bottom-color: #42366D; }
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); color: var(--blue); }
.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); }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #10B981, #34D399); 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(0,0,0,0.3); z-index: 2; }

/* ======= 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); text-align: center; }
body.dark .summary-card { background: #241E3A; border-color: var(--border); }
.sum-divider { width: 1px; height: 36px; background: var(--border); 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(--text-sub); margin-bottom: 5px; }
.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(30,41,59,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(30,41,59,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(139,92,246,0.5); background: rgba(139,92,246,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);
  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);
  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);
}
.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); 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); border-radius: 99px;
  padding: 10px 16px; color: var(--blue-2); font-weight: 700; font-size: 12px; cursor: pointer;
  margin: 0; transition: all 0.2s;
  
  /* --- เพิ่มส่วนนี้เพื่อให้แตะบนมือถือได้เนียนๆ ไม่ติดบัคสีค้าง --- */
  -webkit-tap-highlight-color: transparent; 
  user-select: none; 
}

/* --- เพิ่มส่วนนี้สำหรับโหมดมืด ให้สีเข้าคู่กับปุ่มข้างๆ --- */
body.dark .btn-history-toggle {
  background: #1A162B; 
  border-color: #5B4A94; 
  color: #A78BFA; 
}

/* --- เพิ่มเอฟเฟกต์ยุบตัวตอนเอานิ้วกด (แทนที่ :hover ที่ลบทิ้งไป) --- */
.btn-history-toggle:active { 
  transform: scale(0.92); 
}

/* --- ปรับสีส่วนแสดงผลทั้งหมด (Balance + Summary) ให้ตรงกับรูปเป๊ะ --- */
/* ปรับยอดเงินด้านบน (การ์ด Balance) เป็นสีขาวเสมอเพื่อให้อ่านง่ายบนพื้นหลัง Gradient แบบรูป */
.bal-left .amount, .bal-right .thb-amount, .bal-right .thb-label { color: #000099 !important; }

/* 1. กรณี Light Mode (โหมดสว่าง) */
/* ปรับยอดรวม 3 ช่องด้านล่าง */
body:not(.dark) .summary-item:nth-child(1) .s-val { color: #8B5CF6 !important; } /* ม่วง */
body:not(.dark) .summary-item:nth-child(3) .s-val { color: #F43F5E !important; } /* ชมพู/แดง */
body:not(.dark) .summary-item:nth-child(5) .s-val { color: #10B981 !important; } /* เขียว */

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

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