import React from 'react';
import * as ReactDOM from 'react-dom/client';

    const { useState, useMemo, useEffect, useCallback } = React;

    // ==========================================
    // 🖼️ COMPONENTS: ไอคอน SVG ทั้งหมดของเว็บ
    // ==========================================
    // ✏️ [แก้ได้] ไอคอนแต่ละตัวด้านล่าง สามารถเปลี่ยน SVG path ได้เลย
    // หรือจะเพิ่มไอคอนใหม่ก็ทำแบบเดียวกัน: const IconXxx = ({size=24, className=""}) => <svg .../>
    const IconPlus = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>;
    const IconHome = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>;
    const IconSearch = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>;
    const IconClock = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" className={className}><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>;
    const IconCheck = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="4" strokeLinecap="round" strokeLinejoin="round" className={className}><polyline points="20 6 9 17 4 12"></polyline></svg>;
    const IconFileText = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>;
    const IconCalendar = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg>;
    const IconLoader = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>;
    const IconEye = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg>;
    const IconEyeOff = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>;
    const IconImage = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>;
    const IconList = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line><line x1="3" y1="18" x2="3.01" y2="18"></line></svg>;
    const IconChevronLeft = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><polyline points="15 18 9 12 15 6"></polyline></svg>;
    const IconChevronRight = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" className={className}><polyline points="9 18 15 12 9 6"></polyline></svg>;
    const IconTrash = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>;
    const IconFacebook = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"></path></svg>;
    const IconLine = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"></path></svg>;
    const IconTiktok = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><path d="M9 12a4 4 0 1 0 4 4V4a5 5 0 0 0 5 5"></path></svg>;
    const IconInstagram = ({size=24, className=""}) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}><rect x="2" y="2" width="20" height="20" rx="5" ry="5"></rect><circle cx="12" cy="12" r="4"></circle><circle cx="17.5" cy="6.5" r="1" fill="currentColor" stroke="none"></circle></svg>;

    // ==========================================
    // 🎨 ตัวแปรสีหลัก (COLORS Object) — แก้ที่นี่ที่เดียว สีเปลี่ยนทั้งเว็บ!
    // ==========================================
    // ✏️ [แก้ได้] เปลี่ยนค่า HEX สี ตามต้องการ
    // - blue, pink, purple, orange = สีพื้นหลังการ์ดและ section ต่าง ๆ (โทนอ่อน)
    // - bg = สีพื้นหลังหน้าเว็บทั้งหมด
    // - white = สีขาวที่ใช้ใน border / background elements
    // - textMain = สีข้อความหลัก และสีปุ่มหลัก
    // - textSoft = สีข้อความรอง
    // - pinkDeep, blueDeep, purpleDeep, orangeDeep = สีเข้มสำหรับข้อความ/ไอคอน accent
    //
    // 🎨 สีการ์ดและ UI elements ที่เคยเป็นสีขาวตายตัว — ตอนนี้แก้ได้ที่นี่!
    // - cardWhite = สีพื้นหลังการ์ดหลัก (Header, ProgressFlower, CompactStats, ฯลฯ)
    // - cardBorder = สีขอบการ์ด
    // - cardInner = สีพื้นหลังภายในการ์ด (badge, ปุ่ม, วงกลม, input)
    // - cloudWhite = สีก้อนเมฆ
    // - modalBg = สีพื้นหลัง modal
    // - navBarBg = สีพื้นหลัง Navigation Bar ล่าง
    // - profileBorder = สีขอบรูปโปรไฟล์
    // - buttonBg = สีพื้นหลังปุ่มต่าง ๆ (ปุ่ม check, doing, badge)
    // - dividerColor = สีเส้นแบ่ง
    // - emptyStateBg = สีพื้นหลังเมื่อไม่มีข้อมูล
    // - calendarBg = สีพื้นหลังปฏิทิน
    // - searchInputBg = สีพื้นหลังช่องค้นหา
    // - filterBarBg = สีพื้นหลังแถบ filter
    // - bannerOverlayBg = สีพื้นหลังปุ่มบนแบนเนอร์
    const COLORS = {
      blue: '#B8D8FF',       // สีพื้น section บน (ฟ้าสด)
      pink: '#FFB3D9',       // สี blob พื้นหลัง (top-left) (ชมพูสด)
      purple: '#D4AAFF',     // สี blob พื้นหลัง (กลาง) (ม่วงสด)
      orange: '#FFE0A8',     // สีพื้น NEXT QUEUE section (เหลืองส้มสด)
      bg: '#E8000D',         // ⭐ สีพื้นหลังทั้งเพจ
      white: '#FFD6E8',      // สีใช้แทน white ใน border บางจุด
      textMain: '#E8000D',   // ⭐ สีหลักของข้อความและปุ่มหลัก (แดงสด)
      textSoft: '#FF3344',   // สีข้อความรอง
      pinkDeep: '#E8000D',   // สี accent เข้ม (ปุ่ม, badge)
      blueDeep: '#CC0000',   // สี accent เข้ม (title, icon)
      purpleDeep: '#E8000D', // สี accent เข้ม (label, text)
      orangeDeep: '#FF2233', // สี accent เข้ม (NEXT QUEUE label)
      cardBg: '#ffffff',     // ⭐ สีพื้นหลังการ์ดงาน (todo/doing)
      cardBgDone: '#f9f9f9', // ⭐ สีพื้นหลังการ์ดงาน (done)

      // 🎨 [แก้ได้] สีการ์ดและ UI elements — เปลี่ยนที่นี่ที่เดียว!
      cardWhite: '#ffffff',       // ⭐ สีพื้นหลังการ์ดหลัก (Header, ProgressFlower, CompactStats)
      cardBorder: '#FFE0EC',      // ⭐ สีขอบการ์ดทั่วไป (ชมพูอ่อน)
      cardInner: '#ffffff',       // ⭐ สีพื้นหลังภายในการ์ด (badge, วงกลม, input, ปุ่มเล็ก)
      cloudWhite: '#ffffff',      // ⭐ สีก้อนเมฆ
      modalBg: '#ffffff',         // ⭐ สีพื้นหลัง modal (เพิ่มงาน, login, เปลี่ยนรูป ฯลฯ)
      navBarBg: '#ffffff',        // ⭐ สีพื้นหลัง Navigation Bar ล่าง
      profileBorder: '#FFB3D9',   // ⭐ สีขอบรูปโปรไฟล์ (ชมพูสด)
      buttonBg: '#ffffff',        // ⭐ สีพื้นหลังปุ่มต่าง ๆ (check, doing, badge, tag)
      dividerColor: '#FFB3D9',    // ⭐ สีเส้นแบ่ง (ชมพูสด)
      emptyStateBg: '#ffffff',    // ⭐ สีพื้นหลังเมื่อไม่มีข้อมูล (empty state border)
      calendarBg: '#ffffff',      // ⭐ สีพื้นหลังปฏิทิน
      searchInputBg: '#ffffff',   // ⭐ สีพื้นหลังช่องค้นหา
      filterBarBg: '#ffffff',     // ⭐ สีพื้นหลังแถบ filter
      bannerOverlayBg: '#ffffff', // ⭐ สีพื้นหลังปุ่มบนแบนเนอร์
    };

    // ==========================================
    // ☁️ COMPONENT: FluffyCloud (ก้อนเมฆตกแต่ง)
    // ==========================================
    // ✏️ [แก้ได้] ลบ <FluffyCloud .../> ออกจาก DynamicBackground ถ้าไม่ต้องการเมฆ
    // หรือเพิ่ม/ลด scale และ opacity เพื่อปรับขนาดและความเข้ม
    const FluffyCloud = React.memo(({ top, left, right, bottom, scale = 1, opacity = 0.7, delay = '0s', reverse = false }) => (
      <div className="absolute pointer-events-none drop-shadow-sm z-0" style={{ top, left, right, bottom, opacity, transform: `scale(${scale})` }}>
        <div className={reverse ? 'animate-float-reverse' : 'animate-float'} style={{ animationDelay: delay }}>
          <div className="relative w-40 h-16">
            {/* ✏️ [แก้ได้] สีก้อนเมฆ — แก้ที่ COLORS.cloudWhite */}
            <div className="absolute bottom-0 left-4 w-32 h-10 rounded-full" style={{ backgroundColor: `${COLORS.cloudWhite}e6` }}></div>
            <div className="absolute bottom-2 left-2 w-14 h-14 rounded-full" style={{ backgroundColor: `${COLORS.cloudWhite}e6` }}></div>
            <div className="absolute bottom-5 left-10 w-16 h-16 rounded-full" style={{ backgroundColor: `${COLORS.cloudWhite}e6` }}></div>
            <div className="absolute bottom-1 right-2 w-14 h-14 rounded-full" style={{ backgroundColor: `${COLORS.cloudWhite}e6` }}></div>
          </div>
        </div>
      </div>
    ));

    // ==========================================
    // 🌅 COMPONENT: DynamicBackground (พื้นหลังเคลื่อนไหว)
    // ==========================================
    // ✏️ [แก้ได้] ปรับ blob สี และตำแหน่งเมฆด้านล่าง
    // - ลบ <FluffyCloud .../> ถ้าไม่ต้องการก้อนเมฆ
    // - เปลี่ยน COLORS.pink / COLORS.blue / COLORS.purple ในส่วน blob
    // - ปรับ opacity / blur เพื่อให้ดูเบาหรือเข้มขึ้น
    const DynamicBackground = React.memo(() => (
      <div className="fixed inset-0 overflow-hidden pointer-events-none z-0">
        {/* Blob ชมพูสด ซ้ายบน */}
        <div className="absolute top-[5%] left-[-15%] w-80 h-80 rounded-full blur-[80px] opacity-50 animate-float" style={{ backgroundColor: '#FFB3D9' }}></div>
        {/* Blob ฟ้าสด ขวาบน */}
        <div className="absolute top-[0%] right-[-10%] w-64 h-64 rounded-full blur-[90px] opacity-40 animate-float-reverse" style={{ backgroundColor: '#A8DAFF' }}></div>
        {/* Blob ม่วงสด กลาง */}
        <div className="absolute top-[35%] right-[5%] w-56 h-56 rounded-full blur-[80px] opacity-35 animate-float" style={{ backgroundColor: '#C8A8FF' }}></div>
        {/* Blob เหลืองสด ล่างซ้าย */}
        <div className="absolute bottom-[15%] left-[-5%] w-72 h-72 rounded-full blur-[100px] opacity-40 animate-float-reverse" style={{ backgroundColor: '#FFE066' }}></div>
        {/* Blob เขียวมิ้นต์ ล่างขวา */}
        <div className="absolute bottom-[5%] right-[-10%] w-64 h-64 rounded-full blur-[90px] opacity-35 animate-float" style={{ backgroundColor: '#A8FFDA' }}></div>
        {/* Blob ส้มอ่อน กลางล่าง */}
        <div className="absolute top-[60%] left-[20%] w-48 h-48 rounded-full blur-[70px] opacity-30 animate-float-reverse" style={{ backgroundColor: '#FFCC88' }}></div>
      </div>
    ));

    // ==========================================
    // 🔝 COMPONENT: Header (ส่วนหัวเว็บ)
    // ==========================================
    // ✏️ [แก้ได้] ในนี้แก้ได้หลายจุด:
    // - ชื่อแอป: แก้ "LILAC" เป็นชื่ออื่นได้ใน .split('') (ตัวอักษรจะ animate ทีละตัว)
    // - Tagline: แก้ "Check Q" เป็นข้อความอื่น
    // - อีโมจิเริ่มต้น: แก้ 🐰 เป็นอีโมจิอื่นเมื่อยังไม่มีรูปโปรไฟล์
    const Header = React.memo(({ isAdmin, setIsAdmin, setShowAuthModal, handleImageUpload, profileImage }) => (
      <div className="px-5 pt-6 pb-2 relative z-10">
        {/* ✏️ [แก้ได้] สีพื้นหลัง Header card — แก้ที่ COLORS.cardWhite */}
        <div className="backdrop-blur-md rounded-[32px] p-4 shadow-xl shadow-[#CC0000]/20 flex items-center justify-between h-20 relative overflow-hidden group" style={{ backgroundColor: COLORS.cardWhite, borderWidth: '1px', borderColor: `${COLORS.cardBorder}80` }}>
          <div className="absolute left-6 top-1/2 -translate-y-1/2 w-24 h-8 bg-[#FF69B4]/40 blur-xl rounded-full"></div>
          <div className="flex flex-col justify-center ml-2 relative z-10">
            <div className="flex items-center gap-1">
             <h1 className="text-2xl font-black italic tracking-tighter flex">
  {/* ✏️ [แก้ได้] เปลี่ยนชื่อแอปที่นี่ */}
  {"blossom.in.nails".split('').map((char, index) => (
    <span 
      key={index} 
      className={`bg-gradient-to-br from-[#E8000D] to-[#FF69B4] bg-clip-text text-transparent drop-shadow-sm inline-block animate-text-wave pb-2 ${char === ' ' ? 'w-2.5' : 'pr-[1.5px]'}`}
      style={{ animationDelay: `${index * 0.1}s` }}
    >
      {char}
    </span>
  ))}
</h1>
              {/* ✏️ [แก้ได้] ปุ่ม Admin/Guest badge — ถ้าไม่ต้องการแสดงให้ลบ <button> นี้ออก */}
              {/* ✏️ [แก้ได้] สีพื้นหลัง badge — แก้ที่ COLORS.buttonBg */}
              <button onClick={() => isAdmin ? setIsAdmin(false) : setShowAuthModal(true)} className={`px-1.5 py-0.5 ml-1 rounded-full text-[7px] font-black uppercase tracking-widest border shadow-sm transition-all active:scale-95`} style={{ backgroundColor: isAdmin ? `${COLORS.buttonBg}99` : `${COLORS.buttonBg}cc`, color: isAdmin ? '#CC0000' : '#9ca3af', borderColor: isAdmin ? '#FFB3B3' : '#e5e7eb' }}>
                {isAdmin ? 'Admin' : 'Guest'}
              </button>
            </div>
            <div className="flex items-center gap-1.5 opacity-70">
              <div className="w-3 h-[1px]" style={{ backgroundColor: COLORS.pinkDeep }}></div>
              {/* ✏️ [แก้ได้] Tagline ใต้ชื่อแอป */}
              <p className="text-[8px] font-black tracking-[0.5em] uppercase" style={{ color: COLORS.purpleDeep }}>Check Q</p>
            </div>
          </div>
          {/* รูปโปรไฟล์มุมขวา — Admin กดได้เพื่ออัปโหลดรูป */}
          {/* ✏️ [แก้ได้] สีขอบและพื้นหลังรูปโปรไฟล์ — แก้ที่ COLORS.profileBorder, COLORS.cardInner */}
          <div onClick={isAdmin ? handleImageUpload : undefined} className={`w-16 h-16 rounded-[1.25rem] flex items-center justify-center relative overflow-hidden transition-transform ${isAdmin ? 'cursor-pointer hover:scale-105 active:scale-95' : ''}`} style={{ backgroundColor: COLORS.cardInner, borderWidth: '2px', borderColor: COLORS.profileBorder }}>
            {profileImage ? (
              <img src={profileImage} alt="Profile" className="w-full h-full object-cover" />
            ) : (
              <>
                <div className="absolute inset-0 opacity-40" style={{ background: `linear-gradient(to top right, ${COLORS.pink}, ${COLORS.blue})` }}></div>
                {/* ✏️ [แก้ได้] อีโมจิ default เมื่อยังไม่มีรูปโปรไฟล์ */}
                <span className="text-2xl relative z-10 select-none">🐰</span>
              </>
            )}
          </div>
        </div>
      </div>
    ));

    // ==========================================
    // 🌸 COMPONENT: ProgressFlower (ดอกไม้ความคืบหน้า)
    // ==========================================
    // ✏️ [แก้ได้] ในนี้แก้ได้:
    // - ป้ายชื่อ: แก้ "ความสำเร็จวันนี้" เป็นข้อความอื่น
    // - สีกลีบดอก: แก้ fill="#E2CEF3" เป็นสีอื่น
    // - สีเกสร: แก้ fill="#fffae7" เป็นสีอื่น
    // - อีโมจิ particle: แก้ 💜 🪻 เป็นอีโมจิอื่น
    const ProgressFlower = React.memo(({ progress, todayTasksLength, doneToday, triggerFlowerBounce, isBouncing }) => {
      const bloomScale = Math.max(0.2, progress / 100);
      const isFullBloom = progress === 100 && todayTasksLength > 0;
      const petals = [0, 72, 144, 216, 288].map(angle => {
        const rad = (angle * Math.PI) / 180;
        return { cx: 50 + 15 * Math.sin(rad), cy: 50 - 15 * Math.cos(rad), r: 18 };
      });

      return (
        // ✏️ [แก้ได้] สีพื้นหลังการ์ดดอกไม้ — แก้ที่ COLORS.cardWhite, COLORS.cardBorder
        <div onClick={triggerFlowerBounce} className={`backdrop-blur-sm rounded-[28px] p-3 flex flex-col items-center justify-center shadow-lg shadow-[#CC0000]/20 h-full relative overflow-hidden transition-all duration-300 cursor-pointer ${isBouncing ? 'scale-95' : 'hover:scale-[1.02]'}`} style={{ backgroundColor: COLORS.cardWhite, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
          {/* ✏️ [แก้ได้] ป้ายชื่อบนการ์ด */}
          <div className="absolute top-2 left-3 text-[8px] font-black text-purpleDeep uppercase tracking-tighter opacity-70" style={{ color: COLORS.purpleDeep }}>ความสำเร็จวันนี้</div>
          <div className="relative w-full h-20 flex items-center justify-center mt-2">
            {progress > 0 && (
              <div className="absolute inset-0 pointer-events-none">
                  {/* ✏️ [แก้ได้] สี particle ที่ลอยออกมาจากดอกไม้ */}
                  <div className="absolute top-1/2 left-1/4 w-1.5 h-1.5 bg-[#E8000D] rounded-full animate-float-particle-1 opacity-70"></div>
                  <div className="absolute top-2/3 right-1/4 w-2 h-2 bg-[#C8A8FF] rounded-full animate-float-particle-2 opacity-70"></div>
                  <div className="absolute top-1/3 right-1/3 w-1.5 h-1.5 bg-[#FFE066] rounded-full animate-float-particle-3 opacity-70"></div>
                  <div className="absolute top-1/4 left-1/2 w-1 h-1 bg-[#FF69B4] rounded-full animate-float-particle-1 opacity-60" style={{ animationDelay: '0.8s' }}></div>
                  <div className="absolute bottom-1/4 left-1/3 w-1 h-1 bg-[#A8DAFF] rounded-full animate-float-particle-2 opacity-60" style={{ animationDelay: '1.2s' }}></div>
              </div>
            )}
            <svg viewBox="0 0 100 100" className="w-20 h-20 overflow-visible">
              <g transform="translate(50, 50)">
                  <g className="animate-breathe">
                    <g transform={`scale(${bloomScale})`} className="transition-transform duration-1000 cubic-bezier(0.34, 1.56, 0.64, 1)">
                      <g transform="translate(-50, -50)">
                        {/* ✏️ [แก้ได้] สีกลีบดอก — เปลี่ยน fill="#E2CEF3" */}
                        {petals.map((p, i) => (
                          <circle key={i} cx={p.cx} cy={p.cy} r={p.r} fill={['#FF6B9D','#FF9E44','#FFE066','#6DD5A0','#6EB5FF'][i % 5]} opacity="0.95" className="transition-all duration-700"/>
                        ))}
                        {/* ✏️ [แก้ได้] สีเกสรดอก — เปลี่ยน fill="#fffae7" */}
                        <circle cx="50" cy="50" r="14" fill="#fffae7" className="transition-all duration-700" />
                        {/* หน้าสัตว์เมื่อทำครบ 100% */}
                        {isFullBloom && (
                          <g transform="translate(50, 50)" className="animate-fade-in">
                            <path d="M -5 -1 Q -3 -3 -1 -1" fill="none" stroke="#1E3A5F" strokeWidth="1.2" strokeLinecap="round" />
                            <path d="M 1 -1 Q 3 -3 5 -1" fill="none" stroke="#1E3A5F" strokeWidth="1.2" strokeLinecap="round" />
                            <path d="M -1.5 2 Q 0 4 1.5 2" fill="none" stroke="#1E3A5F" strokeWidth="1.2" strokeLinecap="round" />
                            <ellipse cx="-6" cy="1" rx="1.5" ry="1" fill="#CC0000" opacity="0.6"/>
                            <ellipse cx="6" cy="1" rx="1.5" ry="1" fill="#CC0000" opacity="0.6"/>
                          </g>
                        )}
                      </g>
                    </g>
                  </g>
              </g>
            </svg>
          </div>
          {/* ✏️ [แก้ได้] ข้อความ "งาน" ด้านล่างดอกไม้ — เปลี่ยนเป็นคำอื่นได้ */}
          {/* ✏️ [แก้ได้] สีพื้นหลัง badge ด้านล่าง — แก้ที่ COLORS.buttonBg, COLORS.cardBorder */}
          <div className="mt-1 flex items-center gap-1 px-2 py-0.5 rounded-full z-10" style={{ backgroundColor: `${COLORS.buttonBg}99`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
            <span className="text-xs font-black" style={{ color: COLORS.purpleDeep }}>{progress}%</span>
            <div className="w-1 h-1 rounded-full bg-[#FFB3B3]"></div>
            <span className="text-[8px] font-bold text-gray-400 uppercase">{doneToday} / {todayTasksLength} งาน</span>
          </div>
        </div>
      );
    });

    // ==========================================
    // 📊 COMPONENT: CompactStats (สถิติ Next Queue + จำนวนคิว)
    // ==========================================
    // ✏️ [แก้ได้] ในนี้แก้ได้:
    // - ป้ายชื่อ "NEXT QUEUE" และ "จำนวนคิวก่อนหน้า"
    // - หน่วย "คิว" ใต้ตัวเลข
    const CompactStats = React.memo(({ isAdmin, selectedNextDate, nextQueueDate, handleSetManualDate, waitingCount }) => (
      // ✏️ [แก้ได้] สีพื้นหลัง CompactStats card — แก้ที่ COLORS.cardWhite, COLORS.cardBorder
      <div className="backdrop-blur-sm rounded-[28px] p-1 shadow-lg shadow-[#CC0000]/20 h-full flex overflow-hidden relative group transition-all" style={{ backgroundColor: COLORS.cardWhite, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
          <div className={`flex-1 flex flex-col justify-center items-center p-2 relative rounded-l-[24px] transition-colors overflow-hidden ${isAdmin ? 'hover:bg-white/50 cursor-pointer' : ''}`} style={{ backgroundColor: `${COLORS.orange}66` }}>
            {isAdmin && (
              <input type="date" className="absolute inset-0 opacity-0 cursor-pointer w-full h-full z-10" value={selectedNextDate || nextQueueDate} onChange={(e) => handleSetManualDate(e.target.value)} />
            )}
            {/* ✏️ [แก้ได้] ป้าย "NEXT QUEUE" */}
            {/* ✏️ [แก้ได้] สีพื้นหลัง badge — แก้ที่ COLORS.buttonBg */}
            <div className="absolute top-2 left-1/2 -translate-x-1/2 px-2 py-0.5 rounded-md text-[7px] font-black shadow-sm border border-[#FFD700] uppercase tracking-wider whitespace-nowrap" style={{ color: '#CC7700', backgroundColor: '#FFFBE6' }}>NEXT QUEUE</div>
            
            <div className="flex flex-col items-center mt-1 relative z-0 pointer-events-none">
              <span className="text-3xl font-black leading-none tracking-tighter" style={{ color: COLORS.textMain }}>{new Date(nextQueueDate).getDate()}</span>
              <span className="text-[8px] font-black opacity-80 uppercase mt-0.5" style={{ color: COLORS.orangeDeep }}>{new Date(nextQueueDate).toLocaleDateString('en-US', { month: 'short', year: 'numeric' })}</span>
            </div>

            {isAdmin && selectedNextDate && (
              <button 
                onClick={(e) => { e.preventDefault(); e.stopPropagation(); handleSetManualDate(''); }} 
                className="absolute bottom-1.5 left-1/2 -translate-x-1/2 z-20 px-2.5 py-0.5 rounded-md text-[7px] font-black shadow-sm border border-[#FFB3B3] hover:bg-[#FFF5F5] active:scale-90 transition-all"
                style={{ color: COLORS.pinkDeep, backgroundColor: COLORS.buttonBg }}
                title="กลับไปคำนวณวันว่างอัตโนมัติ"
              >
                AUTO
              </button>
            )}
          </div>

          {/* ✏️ [แก้ได้] สีเส้นแบ่ง — แก้ที่ COLORS.dividerColor */}
          <div className="my-4 rounded-full" style={{ width: '1px', backgroundColor: `${COLORS.dividerColor}99` }}></div>
          
          <div className="flex-1 flex flex-col justify-center items-center p-2 relative">
            {/* ✏️ [แก้ได้] ป้าย "จำนวนคิวก่อนหน้า" */}
            {/* ✏️ [แก้ได้] สีพื้นหลัง badge — แก้ที่ COLORS.buttonBg */}
            <div className="absolute top-2 left-1/2 -translate-x-1/2 px-2.5 py-0.5 rounded-md text-[7px] font-black shadow-sm border border-[#93C5FD] uppercase tracking-wider whitespace-nowrap z-10" style={{ color: '#1D4ED8', backgroundColor: '#EFF6FF' }}>จำนวนคิวก่อนหน้า</div>
            
            <div className="relative mt-5 flex flex-col items-center">
               <div className="relative">
                 <div className="absolute inset-0 blur-lg rounded-full opacity-40 scale-125" style={{ backgroundColor: COLORS.blue }}></div>
                 {/* ✏️ [แก้ได้] สีพื้นหลังและขอบวงกลมตัวเลข — แก้ที่ COLORS.cardInner */}
                 <div className="w-11 h-11 rounded-full flex flex-col items-center justify-center shadow-[inset_0_2px_8px_rgba(0,0,0,0.02)] relative z-10" style={{ backgroundColor: '#EFF6FF', borderWidth: '2px', borderColor: '#3B82F6' }}>
                    <span className="text-xl font-black leading-none" style={{ color: '#1D4ED8' }}>{waitingCount}</span>
                 </div>
               </div>
               {/* ✏️ [แก้ได้] หน่วยข้อความใต้ตัวเลข */}
               <span className="text-[8px] font-black opacity-60 uppercase mt-1.5 relative z-10" style={{ color: COLORS.blueDeep }}>คิว</span>
            </div>
          </div>
      </div>
    ));

    // ==========================================
    // 🏷️ WORK STATUS: สถานะการทำงาน + เปอร์เซ็นต์
    // ==========================================
    const WORK_STATUSES = ['รอออกแบบ', 'กำลังออกแบบค่ะ', 'ออกแบบเสร็จแล้วค่ะ', 'กำลังเพ้นท์งานค่ะ', 'แก้ไขงาน', 'เพ้นท์งานเสร็จเรียบร้อยค่ะ'];
    const WORK_STATUS_PERCENT = { 'รอออกแบบ': 0, 'กำลังออกแบบค่ะ': 20, 'ออกแบบเสร็จแล้วค่ะ': 40, 'กำลังเพ้นท์งานค่ะ': 60, 'แก้ไขงาน': 80, 'เพ้นท์งานเสร็จเรียบร้อยค่ะ': 100 };
    const WORK_STATUS_COLOR = {
      'รอออกแบบ':                     { bg: '#F3F4F6', text: '#9CA3AF', border: '#D1D5DB' },
      'กำลังออกแบบค่ะ':               { bg: '#FEF3C7', text: '#D97706', border: '#FCD34D' },
      'ออกแบบเสร็จแล้วค่ะ':           { bg: '#FFE4E6', text: '#E8000D', border: '#FCA5A5' },
      'กำลังเพ้นท์งานค่ะ':            { bg: '#FEE2E2', text: '#B91C1C', border: '#F87171' },
      'แก้ไขงาน':                     { bg: '#FFF3CD', text: '#B45309', border: '#FDE68A' },
      'เพ้นท์งานเสร็จเรียบร้อยค่ะ':  { bg: '#D1FAE5', text: '#059669', border: '#6EE7B7' },
    };

    // 📊 COMPONENT: ProgressBar (หลอดเปอร์เซ็นต์)
    const ProgressBar = React.memo(({ workStatus }) => {
      const uid = React.useId().replace(/:/g, '');
      const pct = WORK_STATUS_PERCENT[workStatus] ?? 0;

      const HeartIcon = ({ idSuffix }) => (
        <svg width="20" height="18" viewBox="0 0 20 18" xmlns="http://www.w3.org/2000/svg">
          <defs>
            <pattern id={`plaid-${uid}-${idSuffix}`} x="0" y="0" width="8" height="8" patternUnits="userSpaceOnUse">
              <rect width="8" height="8" fill="#E8000D"/>
              <line x1="0" y1="0" x2="8" y2="8" stroke="white" strokeWidth="1.6" opacity="0.75"/>
              <line x1="0" y1="8" x2="8" y2="0" stroke="white" strokeWidth="1.6" opacity="0.75"/>
            </pattern>
          </defs>
          <path d="M10,15 C10,15 2,10 2,5.5 C2,3 4,1.5 6.5,1.5 C8,1.5 9.5,2.5 10,4 C10.5,2.5 12,1.5 13.5,1.5 C16,1.5 18,3 18,5.5 C18,10 10,15 10,15Z" fill={`url(#plaid-${uid}-${idSuffix})`} stroke="#cc0000" strokeWidth="1"/>
        </svg>
      );

      return (
        <div className="relative w-full mt-2" style={{ height: '15px' }}>
          {/* track */}
          <div className="absolute inset-0 rounded-full overflow-visible" style={{ border: '1.5px solid #ffffff', backgroundColor: '#FEE2E2', borderRadius: '999px' }}>
            {/* fill — solid red with floating water bubbles */}
            {pct > 0 && (
              <div className="absolute left-0 top-0 bottom-0 rounded-full transition-all duration-700 overflow-hidden"
                style={{ width: `${pct}%`, borderRadius: '999px', backgroundColor: '#E8000D' }}
              >
                <div className="absolute animate-bflow-1" style={{ width: '7px', height: '7px', borderRadius: '50%', backgroundColor: 'rgba(255,255,255,0.55)', top: '1px', left: '6px' }} />
                <div className="absolute animate-bflow-2" style={{ width: '5px', height: '5px', borderRadius: '50%', backgroundColor: 'rgba(255,255,255,0.45)', top: '7px', left: '14px' }} />
                <div className="absolute animate-bflow-3" style={{ width: '6px', height: '6px', borderRadius: '50%', backgroundColor: 'rgba(255,255,255,0.5)', top: '3px', left: '2px' }} />
              </div>
            )}
          </div>
          {/* ❤️ heart with tartan at tip */}
          {pct > 0 && pct < 100 && (
            <div className="absolute animate-tomato" style={{ left: `calc(${pct}% - 10px)`, top: '50%', transform: 'translateY(-50%)', lineHeight: 1, zIndex: 10, filter: 'drop-shadow(0 0 4px rgba(255,255,255,0.95)) drop-shadow(0 0 8px rgba(255,255,255,0.7)) drop-shadow(0 0 2px rgba(255,200,200,0.9))' }}>
              <HeartIcon idSuffix="tip" />
            </div>
          )}
          {pct === 100 && (
            <div className="absolute animate-tomato" style={{ right: '-10px', top: '50%', transform: 'translateY(-50%)', lineHeight: 1, zIndex: 10, filter: 'drop-shadow(0 0 4px rgba(255,255,255,0.95)) drop-shadow(0 0 8px rgba(255,255,255,0.7)) drop-shadow(0 0 2px rgba(255,200,200,0.9))' }}>
              <HeartIcon idSuffix="full" />
            </div>
          )}
        </div>
      );
    });

    // ==========================================
    // 🃏 COMPONENT: TaskCard (การ์ดงานแต่ละชิ้น)
    // ==========================================
    // ✏️ [แก้ได้] ในนี้แก้ได้:
    // - สีแถบซ้าย (channel bar): แก้สี hex ใน backgroundColor ของ div class="absolute left-2 top-3..."
    // - สีและข้อความ badge channel: แก้ใน className ของ <span> ที่ครอบ task.channel
    // - ข้อความ badge ด่วน: แก้ "🔥 ด่วน" เป็นข้อความอื่น
    // - สถานะงาน (workStatus): แก้ label ใน WORK_STATUSES ด้านบน
    const TaskCard = React.memo(({ task, isAdmin, onEdit, onUpdateWorkStatus }) => {
      const workStatus = task.workStatus || 'รอออกแบบ';
      const sc = WORK_STATUS_COLOR[workStatus] || WORK_STATUS_COLOR['รอออกแบบ'];
      const isDone = workStatus === 'เพ้นท์งานเสร็จเรียบร้อยค่ะ';
      return (
        <div onClick={() => isAdmin && onEdit(task)} className={`relative mb-2 rounded-[22px] p-3 transition-all shadow-sm backdrop-blur-sm ${isAdmin ? 'active:scale-[0.97] cursor-pointer' : ''}`}
          style={{ backgroundColor: '#ffffff', borderWidth: '1px', borderStyle: 'solid', borderColor: isDone ? '#D1FAE5' : COLORS.cardBorder, opacity: isDone ? 0.75 : 1 }}
        >
          {/* ✏️ [แก้ได้] แถบสีซ้ายตามช่องทาง */}
          <div className="absolute left-2 top-3 bottom-3 w-1 rounded-full shadow-sm z-10" style={{ backgroundColor: task.channel === 'Line' || task.channel === 'LINE' ? '#22C55E' : task.channel === 'Facebook' || task.channel === 'FB' || task.channel === 'FACEBOOK' ? '#3B82F6' : task.channel === 'Instagram' || task.channel === 'IG' ? '#EC4899' : task.channel === 'Tiktok' || task.channel === 'TIKTOK' ? '#010101' : COLORS.purpleDeep }}></div>
          <div className="pl-3 pr-1 relative z-10">
            {/* แถวที่ 1: ชื่อลูกค้า + badge channel + payment + ด่วน | วันที่ */}
            <div className="flex justify-between items-center mb-0.5">
              <div className="flex items-center gap-1 min-w-0 flex-1 mr-2">
                <span className="font-bold text-base leading-tight truncate" style={{ color: COLORS.textMain }}>{task.client}</span>
                <span className={`text-[7px] px-1.5 py-0.5 rounded-md font-black uppercase border flex-shrink-0 ${
                  task.channel === 'Line' || task.channel === 'LINE' ? 'text-[#1A9E3F] bg-[#AAFFCC]/30 border-[#1A9E3F]/40' :
                  task.channel === 'Facebook' || task.channel === 'FB' || task.channel === 'FACEBOOK' ? 'text-[#1877F2] bg-[#A8DAFF]/30 border-[#1877F2]/40' :
                  task.channel === 'Instagram' || task.channel === 'IG' ? 'text-[#C13584] bg-[#FFB3D9]/30 border-[#C13584]/40' :
                  task.channel === 'Tiktok' || task.channel === 'TIKTOK' ? 'text-[#010101] bg-[#E8E8E8]/60 border-[#010101]/30' :
                  'bg-white/50 text-gray-400 border-gray-100'
                }`}>{task.channel}</span>
                {task.payment && (
                  <span className="text-[7px] font-black px-1.5 py-0.5 rounded-md border flex-shrink-0" style={{ color: '#059669', backgroundColor: '#F0FDF4', borderColor: '#6EE7B7' }}>
                    💳 {task.payment}
                  </span>
                )}
                {task.priority === 'urgent' && <span className="text-[9px] font-bold animate-pulse px-1.5 py-0.5 rounded-md shadow-sm flex-shrink-0" style={{ color: COLORS.pinkDeep, backgroundColor: COLORS.buttonBg }}>🔥 งานเร่ง</span>}
              </div>
              <div className="flex items-center gap-1 text-[9px] font-black px-2 py-0.5 rounded-lg shadow-sm flex-shrink-0" style={{ color: '#E8000D', backgroundColor: '#FFE8F0', border: '1px solid #FF69B4' }}>
                <IconCalendar size={10} style={{ color: COLORS.pinkDeep }} />
                {new Date(task.deadline).toLocaleDateString('th-TH', { day: '2-digit', month: '2-digit', year: '2-digit' })}
              </div>
            </div>

            {/* แถวที่ 2: ประเภทงานเป็น badge + รายละเอียด | สถานะงาน */}
            <div className="flex justify-between items-center mt-2 gap-2">
              <div className="flex items-center gap-1 min-w-0 flex-1">
                <span className="text-[7px] font-black px-1.5 py-0.5 rounded-md border flex-shrink-0 whitespace-nowrap" style={{ color: COLORS.purpleDeep, backgroundColor: '#F5F0FF', borderColor: '#C4B5FD' }}>
                  {task.type}
                </span>
                {task.details && (
                  <span className={`text-[9px] font-bold truncate ${isDone ? 'line-through text-gray-300' : 'text-gray-400'}`}>({task.details})</span>
                )}
              </div>
              {isAdmin ? (
                <select
                  onClick={(e) => e.stopPropagation()}
                  onChange={(e) => { e.stopPropagation(); onUpdateWorkStatus(e, task.id, e.target.value); }}
                  value={workStatus}
                  className="text-[8px] font-black px-1.5 py-0.5 rounded-md border shadow-sm transition-all flex-shrink-0 whitespace-nowrap appearance-none cursor-pointer"
                  style={{ color: sc.text, backgroundColor: sc.bg, borderColor: sc.border, minWidth: 0 }}
                >
                  {WORK_STATUSES.map(s => <option key={s} value={s}>{s}</option>)}
                </select>
              ) : (
                <span className="text-[8px] font-black px-1.5 py-0.5 rounded-md border shadow-sm flex-shrink-0 whitespace-nowrap" style={{ color: sc.text, backgroundColor: sc.bg, borderColor: sc.border }}>
                  {workStatus}
                </span>
              )}
            </div>

            {/* แถวที่ 3: designType ข้อความปกติ */}
            {task.designType && (
              <div className="mt-0.5">
                <span className="text-[9px] font-bold text-gray-400">{task.designType}</span>
              </div>
            )}

            {/* แถบเปอร์เซ็นต์ */}
            <ProgressBar workStatus={workStatus} />
          </div>
        </div>
      );
    });

    // ==========================================
    // 📅 COMPONENT: CalendarView (ปฏิทิน)
    // ==========================================
    // ✏️ [แก้ได้] ชื่อเดือน และชื่อวันใน header ของปฏิทิน
    const CalendarView = React.memo(({ currentMonth, setCurrentMonth, selectedDate, setSelectedDate, today, tasks }) => {
      const year = currentMonth.getFullYear();
      const month = currentMonth.getMonth();
      const daysInMonth = new Date(year, month + 1, 0).getDate();
      const firstDay = new Date(year, month, 1).getDay(); 

      const days = [];
      for (let i = 0; i < firstDay; i++) days.push(null); 
      for (let i = 1; i <= daysInMonth; i++) days.push(i);

      // ✏️ [แก้ได้] ชื่อเดือนภาษาอังกฤษ — เปลี่ยนเป็นภาษาไทยหรืออื่น ๆ ได้
      const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

      return (
        // ✏️ [แก้ได้] สีพื้นหลังปฏิทิน — แก้ที่ COLORS.calendarBg, COLORS.cardBorder
        <div className="backdrop-blur-xl rounded-[32px] p-5 shadow-[0_12px_30px_rgba(204,0,0,0.15)] mb-5 animate-fadeIn" style={{ backgroundColor: `${COLORS.calendarBg}e6`, borderWidth: '4px', borderColor: COLORS.cardBorder }}>
          <div className="flex justify-between items-center mb-4 px-2">
            <button onClick={() => setCurrentMonth(new Date(year, month - 1, 1))} className="p-1.5 hover:bg-[#FFB3D9] rounded-full transition-colors text-[#E8000D]"><IconChevronLeft size={20}/></button>
            <h3 className="font-black text-[16px] tracking-widest" style={{ background: 'linear-gradient(90deg,#E8000D,#FF69B4)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>{monthNames[month]} {year}</h3>
            <button onClick={() => setCurrentMonth(new Date(year, month + 1, 1))} className="p-1.5 hover:bg-[#FFB3D9] rounded-full transition-colors text-[#E8000D]"><IconChevronRight size={20}/></button>
          </div>
          
          {/* ✏️ [แก้ได้] ชื่อวันใน header ปฏิทิน — เปลี่ยนเป็นภาษาไทย เช่น ['อา','จ','อ','พ','พฤ','ศ','ส'] */}
          <div className="grid grid-cols-7 gap-1 text-center mb-3">
            {['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].map(d => (
              <div key={d} className="text-[9px] font-black opacity-80 uppercase" style={{ color: ['#E8000D','#FF9E44','#FFE000','#22C55E','#3B82F6','#7C3AED','#EC4899'][['Sun','Mon','Tue','Wed','Thu','Fri','Sat'].indexOf(d)] }}>{d}</div>
            ))}
          </div>
          
          <div className="grid grid-cols-7 gap-y-3 gap-x-1 text-center">
            {days.map((day, index) => {
              if (!day) return <div key={`empty-${index}`} className="h-10"></div>;
              
              const dateStr = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
              const isSelected = selectedDate === dateStr;
              const isToday = today === dateStr;
              const hasTasks = tasks.some(t => t.deadline === dateStr); 

              return (
                <div key={dateStr} className="flex justify-center items-center h-10">
                  <div 
                    onClick={() => setSelectedDate(dateStr)} 
                    className={`relative w-10 h-10 flex flex-col items-center justify-center cursor-pointer transition-all ${
                      isSelected
                        ? 'bg-[#CC0000] text-white rounded-full font-black shadow-md scale-105'
                        : isToday
                          ? 'text-[#CC0000] font-black bg-[#FFE0E0] rounded-full'
                          : 'text-[#E53535] font-bold hover:bg-[#FFF5F5] hover:shadow-sm rounded-full'
                    }`}
                    style={isToday && !isSelected ? { borderWidth: '2px', borderColor: COLORS.cardBorder } : !isSelected ? { borderWidth: '0px' } : {}}
                  >
                    <span className="text-[13px] z-10 leading-none">{day}</span>
                    {/* จุดแดงบนวันที่มีงาน */}
                    {hasTasks && (
                      <div className="absolute bottom-1 w-1.5 h-1.5 rounded-full" style={{ backgroundColor: isSelected ? COLORS.white : COLORS.pinkDeep }}></div> 
                    )}
                  </div>
                </div>
              );
            })}
          </div>
        </div>
      );
    });

    // ==========================================
    // 🏠 MAIN APP COMPONENT
    // ==========================================
    function App() {
      // ===== STATE: ข้อมูลหลัก =====
      const [tasks, setTasks] = useState([]);

      // ✏️ [แก้ได้] ประเภทงาน default (ถ้า Google Sheets ยังไม่มีข้อมูล)
      const [taskTypes, setTaskTypes] = useState(['Logo', 'Banner', 'Artwork']); 

      // ✏️ [แก้ได้] ช่องทาง default (ถ้า Google Sheets ยังไม่มีข้อมูล)
      const [channels, setChannels] = useState(['LINE', 'FB', 'IG']);
      const [paymentOptions, setPaymentOptions] = useState(['มัดจำ', 'เต็มจำนวน']);
      const [designTypeOptions, setDesignTypeOptions] = useState(['ลูกค้านำแบบมาเอง', 'ทางร้านออกแบบ', 'Omakase ฟรีสไตล์']);
      
      // ===== STATE: UI Loading =====
      const [isLoading, setIsLoading] = useState(true);
      const [isSaving, setIsSaving] = useState(false); 
      
      // ===== STATE: Navigation & View =====
      const [view, setView] = useState('dashboard');
      const [isCalendarView, setIsCalendarView] = useState(false);
      const [currentMonth, setCurrentMonth] = useState(new Date());
      const [selectedDate, setSelectedDate] = useState(() => {
        const d = new Date();
        return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
      });
      
      // ===== STATE: Modal =====
      const [showModal, setShowModal] = useState(false);     
      const [editingTask, setEditingTask] = useState(null);  
      const [taskToDelete, setTaskToDelete] = useState(null);
      const [showAuthModal, setShowAuthModal] = useState(false);   
      const [showImageModal, setShowImageModal] = useState(false); 
      const [showBannerModal, setShowBannerModal] = useState(false); 
      
      // ===== STATE: Search & Filter =====
      const [searchQuery, setSearchQuery] = useState('');
      const [filterType, setFilterType] = useState('all');
      
      // ===== STATE: Admin & Auth =====
      const [isAdmin, setIsAdmin] = useState(false);
      const [password, setPassword] = useState('');
      const [authError, setAuthError] = useState(false);
      const [isVerifyingAuth, setIsVerifyingAuth] = useState(false);
      const [rememberDevice, setRememberDevice] = useState(true); // จดจำอุปกรณ์ (default ติ๊ก)

      // ===== STATE: Images =====
      const [profileImage, setProfileImage] = useState(null);
      const [tempImageUrl, setTempImageUrl] = useState('');   
      const [bannerImage, setBannerImage] = useState(null);   
      const [tempBannerUrl, setTempBannerUrl] = useState(''); 
      const [isBannerVisible, setIsBannerVisible] = useState(true);
      
      // ===== STATE: Misc =====
      const [selectedNextDate, setSelectedNextDate] = useState('');
      const [isBouncing, setIsBouncing] = useState(false);

      // ===== STATE: Notes & Social Links =====
      const [noteText, setNoteText] = useState('คิวงานวันนี้เริ่มช่วงบ่ายน้าา');
      const [fbLink, setFbLink] = useState('');
      const [igLink, setIgLink] = useState('');
      const [tiktokLink, setTiktokLink] = useState('');
      const [showSocialModal, setShowSocialModal] = useState(false);
      const [currentSocialPlatform, setCurrentSocialPlatform] = useState('');
      const [tempSocialLink, setTempSocialLink] = useState('');

      // ===== STATE: Cover Image & Link =====
      const [coverImage, setCoverImage] = useState(null);
      const [coverLink, setCoverLink] = useState('');
      const [showCoverModal, setShowCoverModal] = useState(false);
      const [tempCoverUrl, setTempCoverUrl] = useState('');
      const [tempCoverLink, setTempCoverLink] = useState('');

      // ===== STATE: Click Ripple Effect =====
      const [clickRipples, setClickRipples] = useState([]);

      useEffect(() => {
        const handleGlobalClick = (e) => {
          if (e.target.tagName === 'BUTTON' || e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT' || e.target.closest('a') || e.target.closest('form')) return;
          const id = Date.now() + Math.random();
          setClickRipples(prev => [...prev, { id, x: e.clientX, y: e.clientY }]);
          setTimeout(() => setClickRipples(prev => prev.filter(r => r.id !== id)), 800);
        };
        window.addEventListener('click', handleGlobalClick);
        return () => window.removeEventListener('click', handleGlobalClick);
      }, []);

      // ==========================================
      // 🌐 API: เรียกผ่าน Vercel Proxy (ไม่มี GAS URL ในหน้าบ้านแล้ว)
      // ==========================================
      const TOKEN_KEY = 'bin_admin_token';
      const getToken = () => { try { return localStorage.getItem(TOKEN_KEY) || ''; } catch (e) { return ''; } };
      const setToken = (t) => { try { localStorage.setItem(TOKEN_KEY, t); } catch (e) {} };
      const clearToken = () => { try { localStorage.removeItem(TOKEN_KEY); } catch (e) {} };
      // อ่าน exp จาก JWT payload (แค่กันหมดอายุฝั่ง client — signature ตรวจจริงที่ proxy)
      const tokenValid = (t) => {
        if (!t) return false;
        try {
          const p = JSON.parse(atob(t.split('.')[1].replace(/-/g, '+').replace(/_/g, '/')));
          return !p.exp || (Date.now() / 1000) < p.exp;
        } catch (e) { return false; }
      };

      // ฟังก์ชันเรียก API (POST) ผ่าน proxy — แนบ Bearer token
      const fetchAPI = async (payload) => {
        try {
          const res = await fetch('/api/data', {
            method: 'POST',
            headers: { 'Content-Type': 'text/plain;charset=utf-8', 'Authorization': 'Bearer ' + getToken() },
            body: JSON.stringify(payload)
          });
          if (res.status === 401) {
            // token หมดอายุ/ไม่ถูกต้อง → ล้าง token + logout
            clearToken();
            setIsAdmin(false);
            throw new Error('unauthorized');
          }
          return await res.json();
        } catch (error) {
          console.error("API Error:", error);
          throw error;
        }
      };

      // ==========================================
      // 🔧 useEffect: โหลดข้อมูลครั้งแรก (GET Request)
      // ==========================================
      // ✏️ [แก้ได้] เปลี่ยน document.title เป็นชื่อแท็บที่ต้องการ
      useEffect(() => {
        document.title = "blossom in nails"; // ✏️ ชื่อ tab บน browser

        // restore สถานะแอดมินตอน refresh (ถ้า token ยังไม่หมดอายุ)
        if (tokenValid(getToken())) setIsAdmin(true); else clearToken();

        fetch("/api/data?action=getInitialData")
          .then(res => res.json())
          .then(response => {
            if (response.status === 'success') {
              setTasks(response.data.tasks || []);
              if (response.data.taskTypes && response.data.taskTypes.length > 0) setTaskTypes(response.data.taskTypes);
              if (response.data.channels && response.data.channels.length > 0) setChannels(response.data.channels);
              if (response.data.paymentOptions && response.data.paymentOptions.length > 0) setPaymentOptions(response.data.paymentOptions);
              if (response.data.designTypeOptions && response.data.designTypeOptions.length > 0) setDesignTypeOptions(response.data.designTypeOptions);
              if (response.data.profileImage) setProfileImage(response.data.profileImage);
              if (response.data.bannerImage) setBannerImage(response.data.bannerImage);
              if (response.data.bannerVisible !== undefined) setIsBannerVisible(response.data.bannerVisible);
              if (response.data.lockedNextDate) setSelectedNextDate(response.data.lockedNextDate);
              if (response.data.noteText !== undefined) setNoteText(response.data.noteText);
              if (response.data.fbLink !== undefined) setFbLink(response.data.fbLink);
              if (response.data.igLink !== undefined) setIgLink(response.data.igLink);
              if (response.data.tiktokLink !== undefined) setTiktokLink(response.data.tiktokLink);
              if (response.data.coverImage !== undefined) setCoverImage(response.data.coverImage || null);
              if (response.data.coverLink !== undefined) setCoverLink(response.data.coverLink);
            }
            setIsLoading(false);
          })
          .catch(error => {
            console.error("Error loading data:", error);
            setIsLoading(false);
          });
      }, []);

      // ==========================================
      // 🔐 handleAdminLogin: Login Admin
      // ==========================================
      // ✏️ [แก้ฝั่ง Google Apps Script] รหัสผ่าน Admin อยู่ใน Google Sheets Script ไม่ใช่ที่นี่
      const handleAdminLogin = (e) => {
        e.preventDefault();
        setIsVerifyingAuth(true);
        setAuthError(false);

        fetch('/api/login', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ password, remember: rememberDevice })
        })
          .then(async (res) => {
            setIsVerifyingAuth(false);
            if (res.ok) {
              const data = await res.json();
              setToken(data.token);
              setIsAdmin(true); setShowAuthModal(false); setPassword(''); setAuthError(false);
            } else {
              setAuthError(true);
            }
          })
          .catch(() => { setIsVerifyingAuth(false); setAuthError(true); });
      };

      // ==========================================
      // 📅 handleSetManualDate: ล็อค/ปลดล็อควัน NEXT QUEUE
      // ==========================================
      // ฟังก์ชันนี้ทำงานเมื่อ Admin เลือกวันที่ใน CompactStats
      // ส่ง dateVal = '' เพื่อกลับไปโหมด AUTO
      const handleSetManualDate = useCallback((dateVal) => {
        setSelectedNextDate(dateVal);
        fetchAPI({ action: 'saveLockedNextDate', dateStr: dateVal }); 
      }, []);
      
      // ===== COMPUTED VALUES (useMemo) =====
      const today = useMemo(() => {
        const d = new Date();
        return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
      }, []); 
      
      const todayTasks = useMemo(() => tasks.filter(t => t.deadline === today), [tasks, today]);
      const doneToday = useMemo(() => todayTasks.filter(t => t.status === 'done').length, [todayTasks]);
      const progress = todayTasks.length === 0 ? 0 : Math.round((doneToday / todayTasks.length) * 100);

      // ✏️ [แก้ได้] ฟังก์ชันคำนวณวัน NEXT QUEUE อัตโนมัติ
      // ปัจจุบัน: หาวันที่ยังไม่มีงาน ถ้าต้องการเปลี่ยน logic ให้แก้ตรงนี้
      const nextQueueDate = useMemo(() => {
        if (selectedNextDate) return selectedNextDate;
        let checkDate = new Date();
        for (let i = 0; i < 365; i++) {
          const y = checkDate.getFullYear(); 
          const m = String(checkDate.getMonth() + 1).padStart(2, '0'); 
          const d = String(checkDate.getDate()).padStart(2, '0'); 
          const dateStr = `${y}-${m}-${d}`;
          const tasksOnDate = tasks.filter(t => t.deadline === dateStr);
          if (tasksOnDate.length === 0) return dateStr;
          checkDate.setDate(checkDate.getDate() + 1);
        }
        return today;
      }, [tasks, selectedNextDate]);

      // จำนวนงานที่ยังไม่เสร็จทั้งหมด
      const waitingCount = useMemo(() => tasks.filter(t => t.status !== 'done').length, [tasks]);

      // ==========================================
      // 🔄 toggleStatus: สลับสถานะ done ↔ todo (ปุ่ม ✓)
      // ==========================================
      const toggleStatus = useCallback((e, id) => {
        e.stopPropagation();
        setTasks(prev => {
          return prev.map(t => {
            if (t.id === id) {
              const newStatus = t.status === 'done' ? 'todo' : 'done';
              fetchAPI({ action: 'updateTaskStatus', taskId: id, newStatus: newStatus });
              return { ...t, status: newStatus };
            }
            return t;
          });
        });
      }, []);

      // ==========================================
      // 🔄 toggleDoing: สลับสถานะ doing ↔ todo (ปุ่ม Loader)
      // ==========================================
      const toggleDoing = useCallback((e, id) => {
        e.stopPropagation();
        setTasks(prev => {
          return prev.map(t => {
            if (t.id === id) {
              const newStatus = t.status === 'doing' ? 'todo' : 'doing';
              fetchAPI({ action: 'updateTaskStatus', taskId: id, newStatus: newStatus });
              return { ...t, status: newStatus };
            }
            return t;
          });
        });
      }, []);

      const handleEditTask = useCallback((task) => {
        setEditingTask(task);
        setShowModal(true);
      }, []);

      // ==========================================
      // 💾 handleSaveTask: บันทึก/อัปเดตงาน
      // ==========================================
      // ✏️ [แก้ได้] ถ้าต้องการเพิ่ม field ใหม่ในฟอร์ม ให้เพิ่ม formData.get('fieldName') ที่นี่
      // แล้วเพิ่ม <input name="fieldName"> ในฟอร์มด้านล่างด้วย
      const handleSaveTask = (e) => {
        e.preventDefault();
        setIsSaving(true);
        const formData = new FormData(e.target);
        const taskData = {
          id: editingTask ? editingTask.id : null,
          title: '', 
          client: formData.get('client'),
          type: formData.get('type'), 
          channel: formData.get('channel'),
          priority: formData.get('priority') ? 'urgent' : 'normal',
          deadline: formData.get('deadline'),
          details: formData.get('details'),
          workStatus: formData.get('workStatus') || 'รอออกแบบ',
          designType: formData.get('designType') || '',
          payment: formData.get('payment') || '',
        };

        fetchAPI({ action: 'saveOrUpdateTask', task: taskData })
          .then(res => {
             if (res.status === 'success') {
                setTasks(prev => editingTask ? prev.map(t => t.id === res.task.id ? res.task : t) : [...prev, res.task]);
             }
             setIsSaving(false); setShowModal(false); setEditingTask(null);
          })
          .catch(() => { setIsSaving(false); });
      };

      // ==========================================
      // 🗑️ executeDeleteTask: ลบงานที่เลือก
      // ==========================================
      const executeDeleteTask = () => {
        if (!taskToDelete) return;
        setIsSaving(true);
        fetchAPI({ action: 'deleteTask', taskId: taskToDelete })
          .then(() => {
             setTasks(prev => prev.filter(t => t.id !== taskToDelete));
             setIsSaving(false); setShowModal(false); setEditingTask(null); setTaskToDelete(null);
          })
          .catch(() => { setIsSaving(false); });
      };

      // ==========================================
      // 👁️ toggleBannerVisibility: แสดง/ซ่อนแบนเนอร์
      // ==========================================
      const toggleBannerVisibility = (visible) => {
        setIsBannerVisible(visible);
        fetchAPI({ action: 'saveBannerVisibility', isVisible: visible });
      };

      // ==========================================
      // 🔄 updateWorkStatus: วนสถานะงานไปข้างหน้า
      // ==========================================
      const updateWorkStatus = useCallback((e, id, newWorkStatus) => {
        e.stopPropagation();
        const newStatus = newWorkStatus === 'เพ้นท์งานเสร็จเรียบร้อยค่ะ' ? 'done' : newWorkStatus === 'รอออกแบบ' ? 'todo' : 'doing';
        setTasks(prev => prev.map(t => {
          if (t.id === id) {
            fetchAPI({ action: 'updateTaskStatus', taskId: id, newStatus });
        fetchAPI({ action: 'updateWorkStatus', taskId: id, workStatus: newWorkStatus });
            return { ...t, status: newStatus, workStatus: newWorkStatus };
          }
          return t;
        }));
      }, []);

      const triggerFlowerBounce = useCallback(() => { setIsBouncing(true); setTimeout(() => setIsBouncing(false), 500); }, []);
      const handleImageUpload = useCallback(() => { setShowImageModal(true); }, []);

      // ===== กรองงานสำหรับหน้า "ทั้งหมด" =====
      // ✏️ [แก้ได้] เพิ่ม filter เพิ่มเติมได้ตรงนี้ เช่น filter ตาม channel
      const filteredAllTasks = useMemo(() => tasks.filter(t => {
        const matchSearch = t.type.toLowerCase().includes(searchQuery.toLowerCase()) || t.client.toLowerCase().includes(searchQuery.toLowerCase());
        const matchFilter = filterType === 'all' || (filterType === 'pending' && t.status !== 'done') || (filterType === 'done' && t.status === 'done');
        return matchSearch && matchFilter;
      }), [tasks, searchQuery, filterType]);

      const displayedTasks = isCalendarView 
        ? filteredAllTasks.filter(t => t.deadline === selectedDate) 
        : filteredAllTasks;

      // ==========================================
      // 🔄 Loading Screen
      // ==========================================
      // ✏️ [แก้ได้] ข้อความ "กำลังโหลดข้อมูล" ในหน้า loading
      if (isLoading) {
        return (
          <div className="min-h-screen flex flex-col items-center justify-center relative overflow-hidden" style={{ backgroundColor: COLORS.bg }}>
             <DynamicBackground />
             <div className="flex flex-col items-center z-10 animate-breathe">
               {/* ✏️ [แก้ได้] สีพื้นหลัง loading badge — แก้ที่ COLORS.buttonBg, COLORS.cardBorder */}
               <div className="flex items-center gap-1.5 px-6 py-2.5 backdrop-blur-sm rounded-full shadow-sm" style={{ backgroundColor: `${COLORS.buttonBg}99`, borderWidth: '2px', borderColor: COLORS.cardBorder }}>
                 {/* ✏️ [แก้ได้] ข้อความ loading */}
                 <p className="text-[12px] font-black tracking-widest" style={{ color: COLORS.textMain }}>กำลังโหลดข้อมูล</p>
                 <div className="flex gap-1 pt-1 ml-1">
                   <span className="w-1.5 h-1.5 rounded-full animate-bounce" style={{ backgroundColor: COLORS.pinkDeep, animationDelay: '0s' }}></span>
                   <span className="w-1.5 h-1.5 rounded-full animate-bounce" style={{ backgroundColor: COLORS.blueDeep, animationDelay: '0.15s' }}></span>
                   <span className="w-1.5 h-1.5 rounded-full animate-bounce" style={{ backgroundColor: COLORS.purpleDeep, animationDelay: '0.3s' }}></span>
                 </div>
               </div>
             </div>
          </div>
        );
      }

      // ==========================================
      // 🎨 MAIN RENDER
      // ==========================================
      return (
        <div className="min-h-screen font-sans relative" style={{ backgroundColor: COLORS.bg, color: COLORS.textMain }}>
          <DynamicBackground />
          <div className="max-w-md mx-auto min-h-screen relative pb-28">
            <Header isAdmin={isAdmin} setIsAdmin={(v) => { if (!v) clearToken(); setIsAdmin(v); }} setShowAuthModal={setShowAuthModal} handleImageUpload={handleImageUpload} profileImage={profileImage} />
            
            {/* ===== Banner Section ===== */}
            <div className="px-5 relative z-10 mb-4">
               {bannerImage && isBannerVisible && (
                 // ✏️ [แก้ได้] สีขอบแบนเนอร์ — แก้ที่ COLORS.cardBorder
                 <div className="relative group w-full h-32 rounded-[24px] overflow-hidden shadow-sm backdrop-blur-sm" style={{ borderWidth: '3px', borderColor: COLORS.cardBorder, backgroundColor: COLORS.cardWhite }}>
                    <img src={bannerImage} alt="Shop Banner" className="w-full h-full object-cover" />
                    <div className="absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-300">
                       {isAdmin && (
                         // ✏️ [แก้ได้] สีพื้นหลังปุ่มบนแบนเนอร์ — แก้ที่ COLORS.bannerOverlayBg
                         <button onClick={() => setShowBannerModal(true)} className="p-1.5 backdrop-blur-md rounded-full shadow-sm text-gray-500 hover:text-[#CC0000] transition-colors" style={{ backgroundColor: `${COLORS.bannerOverlayBg}e6` }} title="เปลี่ยนแบนเนอร์">
                            <IconImage size={16} />
                         </button>
                       )}
                       {isAdmin && (
                         // ✏️ [แก้ได้] สีพื้นหลังปุ่มซ่อนแบนเนอร์ — แก้ที่ COLORS.bannerOverlayBg
                         <button onClick={() => toggleBannerVisibility(false)} className="p-1.5 backdrop-blur-md rounded-full shadow-sm text-gray-500 hover:text-[#E53535] transition-colors" style={{ backgroundColor: `${COLORS.bannerOverlayBg}e6` }} title="ซ่อนแบนเนอร์">
                            <IconEyeOff size={16} />
                         </button>
                       )}
                    </div>
                 </div>
               )}

               {bannerImage && !isBannerVisible && isAdmin && (
                 <div className="flex justify-end mb-1">
                    {/* ✏️ [แก้ได้] สีพื้นหลังปุ่มแสดงแบนเนอร์ — แก้ที่ COLORS.buttonBg, COLORS.cardBorder */}
                    <button onClick={() => toggleBannerVisibility(true)} className="text-[10px] font-bold flex items-center gap-1 backdrop-blur-sm px-3 py-1.5 rounded-full shadow-sm hover:opacity-80 transition-colors" style={{ color: COLORS.textSoft, backgroundColor: `${COLORS.buttonBg}99`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                       <IconEye size={12} /> แสดงแบนเนอร์
                    </button>
                 </div>
               )}

               {!bannerImage && isAdmin && (
                 // ✏️ [แก้ได้] สีขอบ placeholder แบนเนอร์ — แก้ที่ COLORS.cardBorder, COLORS.cardWhite
                 <div onClick={() => setShowBannerModal(true)} className="w-full h-16 rounded-[24px] border-[3px] border-dashed backdrop-blur-sm flex items-center justify-center cursor-pointer hover:opacity-80 transition-colors" style={{ borderColor: COLORS.cardBorder, backgroundColor: COLORS.cardWhite }}>
                    {/* ✏️ [แก้ได้] ข้อความปุ่มเพิ่มแบนเนอร์ */}
                    <span className="text-[11px] font-bold flex items-center gap-2" style={{ color: COLORS.textSoft }}><IconPlus size={16}/> เพิ่มรูปแบนเนอร์ร้าน</span>
                 </div>
               )}
            </div>
            
            {/* ===== Main Content ===== */}
            <div className="px-5 relative z-10">
              {/* ===== VIEW: Dashboard ===== */}
              {view === 'dashboard' ? (
                <div className="animate-fadeIn">
                  <div className="flex gap-3 h-28 mb-4">
                    <div className="flex-[1.6]">
                      <CompactStats isAdmin={isAdmin} selectedNextDate={selectedNextDate} nextQueueDate={nextQueueDate} handleSetManualDate={handleSetManualDate} waitingCount={waitingCount} />
                    </div>
                    <div className="flex-1">
                      {/* Cover Image Card */}
                      <div
                        onClick={() => {
                          if (isAdmin) {
                            setTempCoverUrl(coverImage || '');
                            setTempCoverLink(coverLink || '');
                            setShowCoverModal(true);
                          } else if (coverLink) {
                            window.open(coverLink, '_blank');
                          }
                        }}
                        className={`backdrop-blur-sm rounded-[28px] shadow-lg shadow-[#CC0000]/20 h-full relative overflow-hidden transition-all duration-300 ${isAdmin || coverLink ? 'cursor-pointer hover:scale-[1.02] active:scale-95' : ''}`}
                        style={{ backgroundColor: COLORS.cardWhite, borderWidth: '1px', borderColor: COLORS.cardBorder }}
                      >
                        {coverImage ? (
                          <img src={coverImage} alt="Cover" className="w-full h-full object-cover" />
                        ) : (
                          <div className="w-full h-full flex flex-col items-center justify-center gap-1 opacity-40">
                            <IconImage size={22} style={{ color: COLORS.purpleDeep }} />
                            {isAdmin && <span className="text-[8px] font-bold" style={{ color: COLORS.purpleDeep }}>เพิ่มรูป</span>}
                          </div>
                        )}
                        {isAdmin && (
                          <div className="absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center shadow-sm" style={{ backgroundColor: `${COLORS.cardWhite}cc` }}>
                            <span className="text-[8px]">✏️</span>
                          </div>
                        )}
                      </div>
                    </div>
                  </div>
                  {/* ===== Notes & Social Section ===== */}
                  <div className="mb-4">
                    <div className="mb-1 ml-2">
                      <span className="text-[9px] font-black uppercase tracking-widest opacity-60" style={{ color: COLORS.pinkDeep }}>NOTES</span>
                    </div>
                    <div className="flex gap-3 h-[42px]">
                      {/* กล่องข้อความ Note */}
                      <div className="flex-[1.6] bg-white backdrop-blur-sm rounded-[16px] px-4 py-2 shadow-lg shadow-[#fec2db]/20 border border-white flex items-center transition-all">
                        {isAdmin ? (
                          <input
                            type="text"
                            value={noteText}
                            onChange={(e) => setNoteText(e.target.value)}
                            onBlur={(e) => { fetchAPI({ action: 'saveNoteText', noteText: e.target.value }); }}
                            className="w-full bg-transparent outline-none text-[10px] font-bold"
                            style={{ color: COLORS.textMain }}
                            placeholder="เพิ่มข้อความโน้ต..."
                          />
                        ) : (
                          <span className="text-[10px] font-bold truncate" style={{ color: COLORS.textMain }}>{noteText}</span>
                        )}
                      </div>
                      {/* ปุ่ม Social Media: Facebook / Instagram / TikTok */}
                      <div className="flex justify-end gap-2 items-center">
                        <a
                          href={isAdmin ? '#' : (fbLink || '#')}
                          onClick={(e) => { if (isAdmin) { e.preventDefault(); setCurrentSocialPlatform('fb'); setTempSocialLink(fbLink); setShowSocialModal(true); } }}
                          className="w-[42px] h-[42px] shrink-0 rounded-[14px] bg-white border border-white text-[#1877F2] flex items-center justify-center hover:scale-105 transition-all shadow-lg shadow-[#fec2db]/20 cursor-pointer"
                          title="Facebook"
                        >
                          <IconFacebook size={18} />
                        </a>
                        <a
                          href={isAdmin ? '#' : (igLink || '#')}
                          onClick={(e) => { if (isAdmin) { e.preventDefault(); setCurrentSocialPlatform('ig'); setTempSocialLink(igLink); setShowSocialModal(true); } }}
                          className="w-[42px] h-[42px] shrink-0 rounded-[14px] bg-white border border-white text-[#C13584] flex items-center justify-center hover:scale-105 transition-all shadow-lg shadow-[#fec2db]/20 cursor-pointer"
                          title="Instagram"
                        >
                          <IconInstagram size={18} />
                        </a>
                        <a
                          href={isAdmin ? '#' : (tiktokLink || '#')}
                          onClick={(e) => { if (isAdmin) { e.preventDefault(); setCurrentSocialPlatform('tiktok'); setTempSocialLink(tiktokLink); setShowSocialModal(true); } }}
                          className="w-[42px] h-[42px] shrink-0 rounded-[14px] bg-white border border-white text-[#010101] flex items-center justify-center hover:scale-105 transition-all shadow-lg shadow-[#fec2db]/20 cursor-pointer"
                          title="TikTok"
                        >
                          <IconTiktok size={18} />
                        </a>
                      </div>
                    </div>
                  </div>

                  {/* ✏️ [แก้ได้] ข้อความหัวข้อ "Today's Task" */}
                  <div className="flex items-center justify-between mb-2.5 ml-1">
                    <h2 className="text-[10px] font-black text-gray-400 italic uppercase tracking-[0.3em] opacity-60">Today's Task</h2>
                    <div className="h-[2px] flex-1 rounded-full mx-3" style={{ background: 'linear-gradient(90deg,#E8000D,#FF69B4,#C8A8FF,transparent)' }}></div>
                  </div>
                  <div className="space-y-1">
                    {todayTasks.length > 0 ? todayTasks.map(t => <TaskCard key={t.id} task={t} isAdmin={isAdmin} onEdit={handleEditTask} onUpdateWorkStatus={updateWorkStatus} />) : (
                      // ✏️ [แก้ได้] สีขอบ empty state — แก้ที่ COLORS.emptyStateBg
                      <div className="text-center py-10 rounded-[28px] border-2 border-dashed" style={{ backgroundColor: `${COLORS.cardWhite}4d`, borderColor: '#9BCBE880' }}>
                        {/* ✏️ [แก้ได้] ข้อความเมื่อวันนี้ไม่มีงาน */}
                        <p className="text-[9px] font-bold uppercase tracking-widest opacity-40" style={{ color: COLORS.pinkDeep }}>Sky is clear ✨</p>
                      </div>
                    )}
                  </div>
                </div>
              ) : (
                /* ===== VIEW: All Tasks ===== */
                <div className="animate-fadeIn">
                  {/* ✏️ [แก้ได้] placeholder ช่องค้นหา */}
                  {/* ✏️ [แก้ได้] สีพื้นหลังช่องค้นหา — แก้ที่ COLORS.searchInputBg */}
                  <div className="relative mb-4">
                    <div className="absolute left-4 top-1/2 -translate-y-1/2 opacity-50" style={{ color: COLORS.blueDeep }}><IconSearch size={16} /></div>
                    <input type="text" placeholder="ค้นหาคิวงาน..." value={searchQuery} onChange={(e) => setSearchQuery(e.target.value)} className="w-full rounded-[22px] py-3 pl-10 pr-4 outline-none text-xs shadow-lg shadow-[#CC0000]/10 transition-all backdrop-blur-sm" style={{ backgroundColor: `${COLORS.searchInputBg}cc`, borderWidth: '2px', borderColor: COLORS.blue }} />
                  </div>
                  
                  {/* ✏️ [แก้ได้] ข้อความปุ่ม filter: "ทั้งหมด", "ยังไม่ได้เริ่ม", "เสร็จแล้ว" */}
                  {/* ✏️ [แก้ได้] สีพื้นหลังแถบ filter — แก้ที่ COLORS.filterBarBg, COLORS.cardBorder */}
                  <div className="flex gap-2 mb-3 p-1.5 rounded-full backdrop-blur-md shadow-sm" style={{ backgroundColor: 'rgba(255,255,255,0.8)', borderWidth: '2px', borderColor: '#FFD6E8' }}>
                      <button onClick={() => setFilterType('all')} className={`flex-1 text-[9px] font-black py-2 rounded-full transition-all tracking-wider ${filterType === 'all' ? 'shadow-sm' : 'text-gray-400'}`} style={{ color: filterType === 'all' ? '#E8000D' : '', backgroundColor: filterType === 'all' ? '#FFF0F5' : 'transparent', border: filterType === 'all' ? '1px solid #FFB3D9' : 'none' }}>ทั้งหมด</button>
                      <button onClick={() => setFilterType('pending')} className={`flex-1 text-[9px] font-black py-2 rounded-full transition-all tracking-wider ${filterType === 'pending' ? 'shadow-sm' : 'text-gray-400'}`} style={{ color: filterType === 'pending' ? '#CC7700' : '', backgroundColor: filterType === 'pending' ? '#FFFBE6' : 'transparent', border: filterType === 'pending' ? '1px solid #FFD700' : 'none' }}>ยังไม่ได้เริ่ม</button>
                      <button onClick={() => setFilterType('done')} className={`flex-1 text-[9px] font-black py-2 rounded-full transition-all tracking-wider ${filterType === 'done' ? 'shadow-sm' : 'text-gray-400'}`} style={{ color: filterType === 'done' ? '#1A9E3F' : '', backgroundColor: filterType === 'done' ? '#F0FFF4' : 'transparent', border: filterType === 'done' ? '1px solid #22C55E' : 'none' }}>เสร็จแล้ว</button>
                  </div>

                  {/* ✏️ [แก้ได้] ข้อความปุ่มสลับ calendar/list */}
                  {/* ✏️ [แก้ได้] สีพื้นหลังปุ่มสลับ — แก้ที่ COLORS.buttonBg, COLORS.cardBorder */}
                  <div className="flex justify-end mb-4 pr-1">
                    <button onClick={() => { 
                      const newView = !isCalendarView;
                      setIsCalendarView(newView); 
                      if(newView) setFilterType('all'); 
                    }} className="flex items-center gap-1.5 px-3 py-1.5 backdrop-blur-md rounded-full shadow-[0_4px_10px_rgba(204,0,0,0.15)] text-[9px] font-black uppercase tracking-widest hover:text-[#CC0000] transition-all active:scale-95" style={{ color: COLORS.textSoft, backgroundColor: `${COLORS.buttonBg}cc`, borderWidth: '2px', borderColor: COLORS.cardBorder }}>
                      {isCalendarView ? <><IconList size={14} /> รูปแบบรายการ</> : <><IconCalendar size={14} /> รูปแบบปฏิทิน</>}
                    </button>
                  </div>

                  {isCalendarView && <CalendarView currentMonth={currentMonth} setCurrentMonth={setCurrentMonth} selectedDate={selectedDate} setSelectedDate={setSelectedDate} today={today} tasks={tasks} />}

                  <div className="space-y-1">
                    {displayedTasks.length > 0 ? displayedTasks.map(t => <TaskCard key={t.id} task={t} isAdmin={isAdmin} onEdit={handleEditTask} onUpdateWorkStatus={updateWorkStatus} />) : (
                      // ✏️ [แก้ได้] สีขอบ empty state — แก้ที่ COLORS.emptyStateBg, COLORS.cardBorder
                      <div className="text-center py-10 rounded-[28px] border-[4px] border-dashed shadow-sm mt-4" style={{ backgroundColor: `${COLORS.cardWhite}4d`, borderColor: COLORS.cardBorder }}>
                        {/* ✏️ [แก้ได้] ข้อความเมื่อหาไม่เจองาน */}
                        <p className="text-[10px] font-black uppercase tracking-widest opacity-60" style={{ color: COLORS.textSoft }}>
                          {isCalendarView ? "วันนี้คิวว่าง ✨" : "No records found ✨"}
                        </p>
                      </div>
                    )}
                  </div>
                </div>
              )}
            </div>

            {/* ===== Bottom Navigation Bar ===== */}
            {/* ✏️ [แก้ได้] ไอคอน Navigation Bar ล่าง — เปลี่ยน <IconHome> <IconFileText> เป็น icon อื่นได้ */}
            {/* ✏️ [แก้ได้] สีพื้นหลัง Navigation Bar — แก้ที่ COLORS.navBarBg, COLORS.cardBorder */}
            <div className="fixed bottom-6 left-1/2 -translate-x-1/2 w-full max-w-[210px] z-50">
              <div className="backdrop-blur-xl rounded-full h-14 shadow-2xl shadow-[#CC0000]/30 flex items-center justify-between px-6 relative" style={{ backgroundColor: `${COLORS.navBarBg}99`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                  {/* ไอคอน Home */}
                  <button onClick={() => setView('dashboard')} className={`p-1 transition-all ${view === 'dashboard' ? 'scale-110' : 'text-gray-300 opacity-60'}`} style={{ color: view === 'dashboard' ? COLORS.pinkDeep : '' }}>
                    <IconHome size={22} />
                  </button>
                  <div className="w-8"></div>
                  {/* ไอคอน All Tasks */}
                  <button onClick={() => setView('all')} className={`p-1 transition-all ${view === 'all' ? 'scale-110' : 'text-gray-300 opacity-60'}`} style={{ color: view === 'all' ? COLORS.blueDeep : '' }}>
                    <IconFileText size={22} />
                  </button>
                  {/* ปุ่ม + เพิ่มงาน (แสดงเฉพาะ Admin) */}
                  {/* ✏️ [แก้ได้] สีขอบปุ่ม + — แก้ที่ COLORS.cardBorder */}
                  {isAdmin && (
                    <div className="absolute left-1/2 -translate-x-1/2 -top-6">
                      <button onClick={() => { setEditingTask(null); setShowModal(true); }} className="w-14 h-14 rounded-full text-white flex items-center justify-center shadow-xl shadow-[#E8000D]/50 active:scale-90 transition-transform" style={{ background: 'linear-gradient(135deg, #E8000D 0%, #FF69B4 100%)', borderWidth: '4px', borderColor: '#FFE0EC' }}>
                        <IconPlus size={24} />
                      </button>
                    </div>
                  )}
              </div>
            </div>

            {/* ==========================================
                🪟 MODAL: เพิ่ม/แก้ไขงาน
                ========================================== */}
            {showModal && (
              <div className="fixed inset-0 z-[100] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                {/* ✏️ [แก้ได้] สีพื้นหลัง modal — แก้ที่ COLORS.modalBg, COLORS.cardBorder */}
                <form onSubmit={handleSaveTask} className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                   {/* ✏️ [แก้ได้] ชื่อ title modal */}
                   <h3 className="text-sm font-black mb-4 text-center text-gray-800">{editingTask ? 'แก้ไขคิวงาน ✨' : 'เพิ่มคิวใหม่ ✨'}</h3>
                   <div className="space-y-2 relative">
                     {isSaving && (
                        <div className="absolute inset-0 z-50 flex flex-col items-center justify-center rounded-2xl backdrop-blur-sm" style={{ backgroundColor: `${COLORS.modalBg}cc` }}>
                           <IconLoader size={32} className="animate-spin-slow" style={{ color: COLORS.pinkDeep }} />
                           {/* ✏️ [แก้ได้] ข้อความ "กำลังบันทึก..." */}
                           <span className="text-[10px] font-black mt-2 text-gray-500">กำลังบันทึก...</span>
                        </div>
                     )}
                     
                     {/* ✏️ [แก้ได้] label checkbox ด่วน */}
                     {/* ✏️ [แก้ได้] สีพื้นหลัง checkbox — แก้ที่ COLORS.buttonBg */}
                     <div className="flex justify-end mb-1">
                       <label className="flex items-center cursor-pointer gap-2 px-3 py-1.5 rounded-full shadow-sm border border-gray-100" style={{ backgroundColor: COLORS.buttonBg }}>
                         <span className="text-[10px] font-bold text-gray-500">งานเร่ง 🔥</span>
                         <div className="relative">
                           <input type="checkbox" name="priority" value="urgent" defaultChecked={editingTask?.priority === 'urgent'} className="sr-only peer" />
                           <div className={`w-8 h-4 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-3 after:w-3 after:transition-all peer-checked:bg-[${COLORS.pinkDeep}]`}></div>
                         </div>
                       </label>
                     </div>

                     {/* ✏️ [แก้ได้] placeholder ฟอร์ม */}
                     {/* ✏️ [แก้ได้] สีพื้นหลัง input — แก้ที่ COLORS.cardInner */}
                     <input name="client" required defaultValue={editingTask?.client || ''} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all" style={{ backgroundColor: COLORS.cardInner }} placeholder="ชื่อลูกค้า" />
                     
                     <div className="flex flex-col gap-2">
                        {/* datalist ประเภทงาน — option มาจาก taskTypes state */}
                        <input list="taskTypesList" name="type" required defaultValue={editingTask?.type || ''} className="w-full p-3.5 rounded-2xl font-black text-[10px] outline-none border border-gray-100 shadow-sm" style={{ backgroundColor: COLORS.cardInner }} placeholder="ประเภทงาน" />
                        <datalist id="taskTypesList">
                          {taskTypes.map(type => <option key={type} value={type} />)}
                        </datalist>

                        {/* datalist ลูกค้าสั่งงานที่ */}
                        <input list="channelList" name="channel" required defaultValue={editingTask?.channel || ''} className="w-full p-3.5 rounded-2xl font-black text-[10px] outline-none border border-gray-100 shadow-sm" style={{ backgroundColor: COLORS.cardInner }} placeholder="ลูกค้าสั่งงานที่..." />
                        <datalist id="channelList">
                          <option value="Facebook" />
                          <option value="Line" />
                          <option value="Tiktok" />
                          <option value="Instagram" />
                        </datalist>

                        {/* datalist ออกแบบเพิ่มเติมไหม */}
                        <input list="designTypeList" name="designType" defaultValue={editingTask?.designType || ''} className="w-full p-3.5 rounded-2xl font-black text-[10px] outline-none border border-gray-100 shadow-sm" style={{ backgroundColor: COLORS.cardInner }} placeholder="ออกแบบเพิ่มเติมไหม?" />
                        <datalist id="designTypeList">
                          {designTypeOptions.map(o => <option key={o} value={o} />)}
                        </datalist>

                        {/* datalist ชำระ */}
                        <input list="paymentList" name="payment" defaultValue={editingTask?.payment || ''} className="w-full p-3.5 rounded-2xl font-black text-[10px] outline-none border border-gray-100 shadow-sm" style={{ backgroundColor: COLORS.cardInner }} placeholder="ชำระ..." />
                        <datalist id="paymentList">
                          {paymentOptions.map(o => <option key={o} value={o} />)}
                        </datalist>
                     </div>

                     {/* ✏️ [แก้ได้] placeholder textarea รายละเอียด */}
                     <textarea name="details" rows="2" defaultValue={editingTask?.details || ''} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFF5F5] transition-all resize-none" style={{ backgroundColor: COLORS.cardInner }} placeholder="รายละเอียดเพิ่มเติม (ถ้ามี)..."></textarea>

{/* ✏️ [แก้ได้] ช่องสถานะการทำงาน */}
                     <div className="relative">
                       <select name="workStatus" defaultValue={editingTask?.workStatus || 'รอออกแบบ'} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] font-black shadow-sm appearance-none cursor-pointer focus:border-[#FFB3B3] transition-all" style={{ backgroundColor: COLORS.cardInner, color: COLORS.textMain }}>
                         {WORK_STATUSES.map(s => <option key={s} value={s}>{s}</option>)}
                       </select>
                       <div className="absolute right-3.5 top-1/2 -translate-y-1/2 pointer-events-none text-[10px]">🍅</div>
                     </div>

                     <div className="flex items-center justify-between bg-[#FFF5F5]/30 p-1.5 pl-4 rounded-2xl border border-[#FFB3B3]/50 transition-all hover:bg-[#FFF5F5]/80 hover:shadow-sm group mt-1">
                       <div className="flex items-center gap-1.5 text-[10px] uppercase tracking-wider font-black" style={{ color: COLORS.pinkDeep }}>
                         {/* ✏️ [แก้ได้] label "วันที่ต้องใช้งาน" */}
                         <IconCalendar size={12} className="group-hover:animate-bounce-slow transition-transform" /><span>วันที่ต้องใช้งาน</span>
                       </div>
                       {/* ✏️ [แก้ได้] สีพื้นหลัง date input — แก้ที่ COLORS.cardInner */}
                       <input name="deadline" type="date" required defaultValue={editingTask?.deadline || nextQueueDate} className="w-32 p-2.5 rounded-xl border border-[#FFB3B3] outline-none text-[10px] font-black text-[#CC0000] shadow-sm focus:border-[#CC0000] focus:ring-2 focus:ring-[#CC0000]/50 transition-all cursor-pointer active:scale-95 hover:border-[#CC0000]" style={{ backgroundColor: COLORS.cardInner }} />
                     </div>
                     
                     <div className="flex items-center gap-2 mt-3">
                       {/* ✏️ [แก้ได้] ข้อความปุ่ม Save */}
                       <button type="submit" className="flex-1 py-3.5 rounded-2xl font-black text-xs text-white shadow-lg active:scale-95 transition-all disabled:opacity-50" style={{ backgroundColor: COLORS.textMain }}>บันทึกคิวงาน</button>
                       {editingTask && (
                         <button type="button" onClick={() => setTaskToDelete(editingTask.id)} className="w-12 h-[44px] flex items-center justify-center rounded-2xl bg-red-50 text-red-400 border border-red-100 hover:bg-red-100 active:scale-95 transition-all shadow-sm" title="ลบคิวงาน">
                           <IconTrash size={18} />
                         </button>
                       )}
                     </div>
                     {/* ✏️ [แก้ได้] ข้อความปุ่มปิด modal */}
                     <button type="button" onClick={() => { setShowModal(false); setEditingTask(null); }} className="w-full text-[9px] font-bold text-gray-300 mt-2 uppercase tracking-widest">Close</button>
                   </div>
                </form>
              </div>
            )}

            {/* ==========================================
                🔐 MODAL: Login Admin
                ========================================== */}
            {showAuthModal && (
              <div className="fixed inset-0 z-[110] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                {/* ✏️ [แก้ได้] สีพื้นหลัง modal login — แก้ที่ COLORS.modalBg, COLORS.cardBorder */}
                <form onSubmit={handleAdminLogin} className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                   {/* ✏️ [แก้ได้] ชื่อ modal Login */}
                   <h3 className="text-sm font-black mb-4 text-center text-gray-800">เข้าสู่ระบบ Admin</h3>
                   <div className="space-y-2">
                     {/* ✏️ [แก้ได้] สีพื้นหลัง input password — แก้ที่ COLORS.cardInner */}
                     <input type="password" required value={password} onChange={(e) => { setPassword(e.target.value); setAuthError(false); }} className={`w-full p-3.5 rounded-2xl border outline-none text-[11px] shadow-sm transition-all text-center tracking-widest ${authError ? 'border-red-300 focus:border-red-400' : 'border-gray-100 focus:border-[#FFB3B3]'}`} style={{ backgroundColor: COLORS.cardInner }} placeholder="ใส่รหัสผ่าน" disabled={isVerifyingAuth} />
                     {/* ✏️ [แก้ได้] ข้อความ error รหัสผ่านผิด */}
                     {authError && <p className="text-red-400 text-[9px] text-center font-bold">รหัสผ่านไม่ถูกต้อง!</p>}
                     {/* ✅ จดจำอุปกรณ์นี้ (30 วัน) — default ติ๊ก */}
                     <label className="flex items-center justify-center gap-2 cursor-pointer mt-2 select-none">
                       <input type="checkbox" checked={rememberDevice} onChange={(e) => setRememberDevice(e.target.checked)} className="w-3.5 h-3.5 accent-[#E8000D]" disabled={isVerifyingAuth} />
                       <span className="text-[10px] font-bold text-gray-500">จดจำอุปกรณ์นี้ (30 วัน)</span>
                     </label>
                     <button type="submit" disabled={isVerifyingAuth} className="w-full h-11 rounded-2xl font-black text-xs mt-3 text-white shadow-lg flex items-center justify-center active:scale-95 transition-all disabled:opacity-70" style={{ backgroundColor: COLORS.pinkDeep }}>
                        {isVerifyingAuth ? <IconLoader size={16} className="animate-spin-slow" /> : 'Login'}
                     </button>
                     <button type="button" onClick={() => { setShowAuthModal(false); setAuthError(false); setPassword(''); }} className="w-full text-[9px] font-bold text-gray-300 mt-1 uppercase tracking-widest" disabled={isVerifyingAuth}>Close</button>
                   </div>
                </form>
              </div>
            )}

            {/* ==========================================
                🖼️ MODAL: เปลี่ยนรูปโปรไฟล์
                ========================================== */}
            {showImageModal && (
              <div className="fixed inset-0 z-[120] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                {/* ✏️ [แก้ได้] สีพื้นหลัง modal เปลี่ยนรูป — แก้ที่ COLORS.modalBg, COLORS.cardBorder */}
                <form onSubmit={(e) => { 
                    e.preventDefault(); 
                    if (tempImageUrl) { 
                        let finalUrl = tempImageUrl;
                        // แปลง Google Drive share link → direct image URL
                        const match = finalUrl.match(/\/file\/d\/([a-zA-Z0-9_-]+)/) || finalUrl.match(/id=([a-zA-Z0-9_-]+)/) || finalUrl.match(/\/d\/([a-zA-Z0-9_-]+)/);
                        if (match && match[1]) {
                            finalUrl = `https://lh3.googleusercontent.com/d/${match[1]}`;
                        }
                        setProfileImage(finalUrl); 
                        fetchAPI({ action: 'saveProfileImage', imageUrl: finalUrl });
                    } 
                    setShowImageModal(false); 
                    setTempImageUrl(''); 
                }} className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                   {/* ✏️ [แก้ได้] ชื่อ modal เปลี่ยนรูปโปรไฟล์ */}
                   <h3 className="text-sm font-black mb-4 text-center text-gray-800">เปลี่ยนรูปโปรไฟล์ 🐰</h3>
                   <div className="space-y-2">
                     {/* ✏️ [แก้ได้] สีพื้นหลัง input URL — แก้ที่ COLORS.cardInner */}
                     <input type="url" required value={tempImageUrl} onChange={(e) => setTempImageUrl(e.target.value)} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all text-center" style={{ backgroundColor: COLORS.cardInner }} placeholder="วางลิงก์รูปภาพ Google Drive ที่นี่..." />
                     <button type="submit" className="w-full py-3.5 rounded-2xl font-black text-xs mt-3 text-white shadow-lg active:scale-95 transition-all" style={{ backgroundColor: COLORS.pinkDeep }}>Save Image</button>
                     <button type="button" onClick={() => { setShowImageModal(false); setTempImageUrl(''); }} className="w-full text-[9px] font-bold text-gray-300 mt-1 uppercase tracking-widest">Close</button>
                   </div>
                </form>
              </div>
            )}

            {/* ==========================================
                🖼️ MODAL: เปลี่ยนแบนเนอร์ร้าน
                ========================================== */}
            {showBannerModal && (
              <div className="fixed inset-0 z-[120] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                {/* ✏️ [แก้ได้] สีพื้นหลัง modal แบนเนอร์ — แก้ที่ COLORS.modalBg, COLORS.cardBorder */}
                <form onSubmit={(e) => { 
                    e.preventDefault(); 
                    if (tempBannerUrl) { 
                        let finalUrl = tempBannerUrl;
                        // แปลง Google Drive share link → direct image URL
                        const match = finalUrl.match(/\/file\/d\/([a-zA-Z0-9_-]+)/) || finalUrl.match(/id=([a-zA-Z0-9_-]+)/) || finalUrl.match(/\/d\/([a-zA-Z0-9_-]+)/);
                        if (match && match[1]) {
                            finalUrl = `https://lh3.googleusercontent.com/d/${match[1]}`;
                        }
                        setBannerImage(finalUrl); 
                        toggleBannerVisibility(true);
                        fetchAPI({ action: 'saveBannerImage', imageUrl: finalUrl });
                    } 
                    setShowBannerModal(false); 
                    setTempBannerUrl(''); 
                }} className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                   {/* ✏️ [แก้ได้] ชื่อ modal เปลี่ยนแบนเนอร์ */}
                   <h3 className="text-sm font-black mb-4 text-center text-gray-800">เปลี่ยนแบนเนอร์</h3>
                   <div className="space-y-2">
                     {/* ✏️ [แก้ได้] สีพื้นหลัง input URL — แก้ที่ COLORS.cardInner */}
                     <input type="url" required value={tempBannerUrl} onChange={(e) => setTempBannerUrl(e.target.value)} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all text-center" style={{ backgroundColor: COLORS.cardInner }} placeholder="วางลิงก์รูปภาพ Google Drive..." />
                     <button type="submit" className="w-full py-3.5 rounded-2xl font-black text-xs mt-3 text-white shadow-lg active:scale-95 transition-all" style={{ backgroundColor: COLORS.orangeDeep }}>Save Banner</button>
                     <button type="button" onClick={() => { setShowBannerModal(false); setTempBannerUrl(''); }} className="w-full text-[9px] font-bold text-gray-300 mt-1 uppercase tracking-widest">Close</button>
                   </div>
                </form>
              </div>
            )}

            {/* ==========================================
                🖼️ MODAL: รูปปกและลิงก์
                ========================================== */}
            {showCoverModal && (
              <div className="fixed inset-0 z-[120] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                <form onSubmit={(e) => {
                  e.preventDefault();
                  let finalUrl = tempCoverUrl;
                  const match = finalUrl.match(/\/file\/d\/([a-zA-Z0-9_-]+)/) || finalUrl.match(/id=([a-zA-Z0-9_-]+)/) || finalUrl.match(/\/d\/([a-zA-Z0-9_-]+)/);
                  if (match && match[1]) {
                    finalUrl = `https://lh3.googleusercontent.com/d/${match[1]}`;
                  }
                  setCoverImage(finalUrl || null);
                  setCoverLink(tempCoverLink);
                  fetchAPI({ action: 'saveCoverImage', imageUrl: finalUrl, link: tempCoverLink });
                  setShowCoverModal(false);
                  setTempCoverUrl('');
                  setTempCoverLink('');
                }} className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                  <h3 className="text-sm font-black mb-1 text-center text-gray-800">รูปปก ✨</h3>
                  <p className="text-[9px] text-center text-gray-400 font-bold mb-4 tracking-wide">รูปและลิงก์ปลายทางสำหรับการ์ดขวาบน</p>
                  <div className="space-y-2">
                    <input type="text" value={tempCoverUrl} onChange={(e) => setTempCoverUrl(e.target.value)} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all text-center" style={{ backgroundColor: COLORS.cardInner }} placeholder="วางลิงก์รูปภาพ..." />
                    <input type="text" value={tempCoverLink} onChange={(e) => setTempCoverLink(e.target.value)} className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all text-center" style={{ backgroundColor: COLORS.cardInner }} placeholder="ลิงก์ปลายทาง (https://...)" />
                    <button type="submit" className="w-full py-3.5 rounded-2xl font-black text-xs mt-2 text-white shadow-lg active:scale-95 transition-all" style={{ backgroundColor: COLORS.pinkDeep }}>บันทึก</button>
                    {coverImage && (
                      <button type="button" onClick={() => { setCoverImage(null); fetchAPI({ action: 'saveCoverImage', imageUrl: '', link: tempCoverLink }); setShowCoverModal(false); }} className="w-full py-2.5 rounded-2xl font-black text-xs text-gray-400 border border-gray-100 bg-gray-50 active:scale-95 transition-all">ลบรูป</button>
                    )}
                    <button type="button" onClick={() => { setShowCoverModal(false); setTempCoverUrl(''); setTempCoverLink(''); }} className="w-full text-[9px] font-bold text-gray-300 mt-1 uppercase tracking-widest">Close</button>
                  </div>
                </form>
              </div>
            )}

            {/* ==========================================
                🔗 MODAL: แก้ไขลิงก์ Social Media
                ========================================== */}
            {showSocialModal && (
              <div className="fixed inset-0 z-[150] flex items-center justify-center p-6 bg-black/10 backdrop-blur-[2px] animate-fadeIn">
                <div className="backdrop-blur-xl w-full max-w-xs rounded-[35px] p-6 shadow-2xl animate-slideUp" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                  <h3 className="text-sm font-black mb-1 text-center text-gray-800">
                    {currentSocialPlatform === 'fb' ? '🔵 Facebook' : currentSocialPlatform === 'ig' ? '🩷 Instagram' : '⚫ TikTok'}
                  </h3>
                  <p className="text-[9px] text-center text-gray-400 font-bold mb-4 tracking-wide">วางลิงก์ช่องทางติดต่อ</p>
                  <div className="space-y-3">
                    <input
                      type="text"
                      value={tempSocialLink}
                      onChange={(e) => setTempSocialLink(e.target.value)}
                      className="w-full p-3.5 rounded-2xl border border-gray-100 outline-none text-[11px] shadow-sm focus:border-[#FFB3B3] transition-all"
                      style={{ backgroundColor: COLORS.cardInner }}
                      placeholder="https://..."
                    />
                    <button
                      onClick={() => {
                        const saveKey = currentSocialPlatform === 'fb' ? 'fbLink' : currentSocialPlatform === 'line' ? 'lineLink' : 'tiktokLink';
                        if (currentSocialPlatform === 'fb') setFbLink(tempSocialLink);
                        else if (currentSocialPlatform === 'ig') setIgLink(tempSocialLink);
                        else setTiktokLink(tempSocialLink);
                        fetchAPI({ action: 'saveSocialLink', platform: currentSocialPlatform, link: tempSocialLink });
                        setShowSocialModal(false);
                      }}
                      className="w-full py-3.5 rounded-2xl font-black text-xs text-white shadow-lg active:scale-95 transition-all"
                      style={{ backgroundColor: COLORS.textMain }}
                    >บันทึกลิงก์</button>
                    <button type="button" onClick={() => setShowSocialModal(false)} className="w-full text-[9px] font-bold text-gray-300 uppercase tracking-widest">Close</button>
                  </div>
                </div>
              </div>
            )}

            {/* ==========================================
                🗑️ MODAL: ยืนยันการลบงาน
                ========================================== */}
            {taskToDelete && (
              <div className="fixed inset-0 z-[200] flex items-center justify-center p-6 bg-black/20 backdrop-blur-[2px] animate-fadeIn">
                {/* ✏️ [แก้ได้] สีพื้นหลัง modal ลบ — แก้ที่ COLORS.modalBg, COLORS.cardBorder */}
                <div className="backdrop-blur-xl w-full max-w-[260px] rounded-[30px] p-6 shadow-2xl animate-slideUp text-center" style={{ backgroundColor: `${COLORS.modalBg}f2`, borderWidth: '1px', borderColor: COLORS.cardBorder }}>
                  <div className="w-14 h-14 rounded-full bg-red-50 text-red-400 flex items-center justify-center mx-auto mb-3 shadow-sm border border-red-100">
                     <IconTrash size={26} />
                  </div>
                  {/* ✏️ [แก้ได้] ข้อความยืนยันการลบ */}
                  <h3 className="text-[14px] font-black mb-1 text-gray-800">ยืนยันการลบ?</h3>
                  <p className="text-[10px] font-bold text-gray-500 mb-5">คุณต้องการลบคิวงานนี้ใช่หรือไม่<br/>(ไม่สามารถกู้คืนได้)</p>
                  
                  <div className="flex gap-2">
                    {/* ✏️ [แก้ได้] ข้อความปุ่ม "ยกเลิก" และ "ลบข้อมูล" */}
                    <button onClick={() => setTaskToDelete(null)} className="flex-1 py-3 rounded-2xl font-black text-[10px] text-gray-500 bg-gray-100 hover:bg-gray-200 active:scale-95 transition-all shadow-sm">ยกเลิก</button>
                    <button onClick={executeDeleteTask} className="flex-1 py-3 rounded-2xl font-black text-[10px] text-white bg-red-400 hover:bg-red-500 active:scale-95 transition-all shadow-sm">ลบข้อมูล</button>
                  </div>
                </div>
              </div>
            )}

          </div>
          
          {/* ==========================================
              🎬 CSS Animations
              ==========================================
              ✏️ [แก้ได้] ปรับ animation ต่าง ๆ ที่นี่:
              - float / float-reverse: เมฆและ blob เคลื่อนที่
              - breathe: ดอกไม้หายใจ
              - float-particle-1/2/3: จุดลอยรอบดอกไม้
              - spin-slow: หมุนช้า (ไอคอน Loader ตอน doing)
              - slideUp / fadeIn: animation modal
              - text-wave: ชื่อแอปใน header
          */}
          {/* ===== Click Ripple Overlay ===== */}
          {clickRipples.map(ripple => (
            <div key={ripple.id} className="fixed pointer-events-none z-[9999]" style={{ left: ripple.x, top: ripple.y }}>
              {/* 💖 หัวใจเส้นขอบกระจายตัว */}
              <svg className="absolute animate-heart-shape-ripple" style={{ color: COLORS.pinkDeep, left: '-40px', top: '-40px' }} width="80" height="80" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round">
                <path d="M 12 18 C 8 18 2 13 2 8 C 2 4 5 2 8.5 2 C 10.5 2 11.5 3.5 12 4.5 C 12.5 3.5 13.5 2 15.5 2 C 19 2 22 4 22 8 C 22 13 16 18 12 18 Z"></path>
              </svg>
              {/* ✨ ดาววิ้งๆ ดวงที่ 1 */}
              <svg className="absolute animate-sparkle-float" style={{ color: COLORS.pinkDeep, left: '-10px', top: '-10px', '--dx': '-25px', '--dy': '-35px', width: '16px', height: '16px' }} viewBox="0 0 24 24">
                <path fill="currentColor" d="M12 0 C12 8 16 12 24 12 C16 12 12 16 12 24 C12 16 8 12 0 12 C8 12 12 8 12 0 Z" />
              </svg>
              {/* ✨ ดาววิ้งๆ ดวงที่ 2 */}
              <svg className="absolute animate-sparkle-float" style={{ color: '#ffffff', left: '5px', top: '-5px', '--dx': '25px', '--dy': '-25px', animationDelay: '0.1s', width: '12px', height: '12px' }} viewBox="0 0 24 24">
                <path fill="currentColor" d="M12 0 C12 8 16 12 24 12 C16 12 12 16 12 24 C12 16 8 12 0 12 C8 12 12 8 12 0 Z" />
              </svg>
              {/* ✨ ดาววิ้งๆ ดวงที่ 3 */}
              <svg className="absolute animate-sparkle-float" style={{ color: COLORS.pinkDeep, left: '-5px', top: '5px', '--dx': '15px', '--dy': '30px', animationDelay: '0.15s', width: '20px', height: '20px' }} viewBox="0 0 24 24">
                <path fill="currentColor" d="M12 0 C12 8 16 12 24 12 C16 12 12 16 12 24 C12 16 8 12 0 12 C8 12 12 8 12 0 Z" />
              </svg>
            </div>
          ))}

          <style>{`
            @keyframes float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(25px, -15px); } }
            @keyframes float-reverse { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-25px, 15px); } }
            @keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
            @keyframes float-particle-1 { 0% { transform: translateY(0); opacity: 0; } 50% { opacity: 0.8; } 100% { transform: translateY(-20px); opacity: 0; } }
            @keyframes float-particle-2 { 0% { transform: translateY(0); opacity: 0; } 50% { opacity: 0.8; } 100% { transform: translateY(-15px) translateX(5px); opacity: 0; } }
            @keyframes float-particle-3 { 0% { transform: translateY(0); opacity: 0; } 50% { opacity: 0.8; } 100% { transform: translateY(-25px) translateX(-5px); opacity: 0; } }
            @keyframes bounce-slow { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
            @keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
            @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
            @keyframes text-wave { 0%, 20%, 100% { transform: translateY(0px); } 10% { transform: translateY(-5px); } }
            @keyframes spin-slow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
            @keyframes bubble { 0% { transform: translateY(0) scale(1); opacity: 0.7; } 80% { opacity: 0.5; } 100% { transform: translateY(-11px) scale(0.4); opacity: 0; } }
            @keyframes tomato-bounce { 0%, 100% { transform: translateY(-50%); } 50% { transform: translateY(calc(-50% - 3px)); } }
            @keyframes bubble-flow { 0% { transform: translateX(0); opacity: 0; } 15% { opacity: 0.75; } 85% { opacity: 0.45; } 100% { transform: translateX(220px); opacity: 0; } }
            .animate-bubble-1 { animation: bubble 2s ease-out infinite; }
            .animate-bubble-2 { animation: bubble 2.4s ease-out infinite 0.6s; }
            .animate-bubble-3 { animation: bubble 1.8s ease-out infinite 1.2s; }
            .animate-tomato { animation: tomato-bounce 1.4s ease-in-out infinite; }
            .animate-bflow-1 { animation: bubble-flow 2.2s ease-in-out infinite; }
            .animate-bflow-2 { animation: bubble-flow 2.8s ease-in-out infinite 0.5s; }
            .animate-bflow-3 { animation: bubble-flow 1.9s ease-in-out infinite 1.1s; }
            .animate-text-wave { animation: text-wave 4s ease-in-out infinite; }
            .animate-breathe { animation: breathe 4s ease-in-out infinite; transform-origin: center; }
            .animate-float-particle-1 { animation: float-particle-1 3s ease-out infinite; }
            .animate-float-particle-2 { animation: float-particle-2 4s ease-out infinite 1s; }
            .animate-float-particle-3 { animation: float-particle-3 3.5s ease-out infinite 0.5s; }
            .animate-float { animation: float 15s ease-in-out infinite; }
            .animate-float-reverse { animation: float-reverse 18s ease-in-out infinite; }
            .animate-bounce-slow { animation: bounce-slow 4s ease-in-out infinite; }
            .animate-slideUp { animation: slideUp 0.3s ease-out; }
            .animate-fadeIn { animation: fadeIn 0.4s ease-out; }
            .animate-spin-slow { animation: spin-slow 4s linear infinite; }
            @keyframes stripe-move { from { background-position: 0 0; } to { background-position: -40px 0; } }
            .animate-stripe { animation: stripe-move 1.8s linear infinite; background-size: 40px 40px; }
            @keyframes heart-shape-ripple { 0% { transform: scale(0.3); opacity: 0.8; stroke-width: 4px; } 20% { transform: scale(0.6); opacity: 1; stroke-width: 3px; } 100% { transform: scale(2.5); opacity: 0; stroke-width: 1px; } }
            .animate-heart-shape-ripple { animation: heart-shape-ripple 0.8s ease-out forwards; transform-origin: center; }
            @keyframes sparkle-float { 0% { transform: translate(0, 0) scale(0) rotate(0deg); opacity: 0; } 20% { transform: translate(calc(var(--dx) * 0.2), calc(var(--dy) * 0.2)) scale(1) rotate(20deg); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0) rotate(90deg); opacity: 0; } }
            .animate-sparkle-float { animation: sparkle-float 0.8s ease-out forwards; opacity: 0; }
          `}</style>
        </div>
      );
    }

    const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(<App />);
  