@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-page: #f4f5f8;
    --bg-card: rgba(255, 255, 255, 0.7);
    --bg-card-solid: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.45);
    --bg-input: rgba(255, 255, 255, 0.8);
    --bg-segment: rgba(0, 0, 0, 0.04);
    --bg-hover: rgba(0, 0, 0, 0.02);
    --bg-inner: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-light: rgba(255, 255, 255, 0.6);
    --border-card: rgba(255, 255, 255, 0.8);
    --shadow-premium: 0 10px 40px -10px rgba(15, 23, 42, 0.08);
    --shadow-inner: inset 0 2px 4px rgba(255,255,255,0.8);
}
.dark {
    --bg-page: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.6);
    --bg-card-solid: #1e293b;
    --bg-glass: rgba(30, 41, 59, 0.4);
    --bg-input: rgba(15, 23, 42, 0.6);
    --bg-segment: rgba(255, 255, 255, 0.08);
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-inner: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-light: rgba(255, 255, 255, 0.05);
    --border-card: rgba(255, 255, 255, 0.1);
    --shadow-premium: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    --shadow-inner: inset 0 1px 1px rgba(255,255,255,0.05);
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Kanit", sans-serif; 
    background-color: var(--bg-page); 
    color: var(--text-primary); 
    -webkit-font-smoothing: antialiased; 
    min-height: 100vh; 
    transition: background-color 0.4s ease, color 0.4s ease; 
    overflow-x: hidden;
}

/* ==========================================
   ⏳ Preloader (หน้าจอโหลดแอป)
   ========================================== */
#preloader {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-page); z-index: 99999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.6s;
}
.loader-logo {
    width: 88px; height: 88px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    border-radius: 2rem; display: flex; justify-content: center; align-items: center;
    animation: pulse-glow 1.5s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 30px rgba(59,130,246,0.4);
}
@keyframes pulse-glow {
    0% { transform: scale(0.95); box-shadow: 0 10px 25px rgba(59,130,246,0.2); }
    100% { transform: scale(1.05); box-shadow: 0 20px 40px rgba(59,130,246,0.6); }
}
.loader-text {
    margin-top: 28px; font-size: 32px; font-weight: 800; letter-spacing: -0.5px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* Ambient Background */
.ambient-bg { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; overflow: hidden; background-color: var(--bg-page); transition: background-color 0.4s ease; }
.ambient-blob { position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.5; animation: float 20s infinite ease-in-out alternate; mix-blend-mode: multiply; }
.dark .ambient-blob { opacity: 0.2; mix-blend-mode: screen; }
@keyframes float { 
    0% { transform: translate(0, 0) scale(1); } 
    50% { transform: translate(40px, -60px) scale(1.1); } 
    100% { transform: translate(-20px, 40px) scale(0.95); } 
}

/* Premium VisionOS Card Design */
.mac-card { 
    background-color: var(--bg-card); 
    backdrop-filter: blur(40px) saturate(200%); 
    -webkit-backdrop-filter: blur(40px) saturate(200%); 
    border-radius: 32px; 
    border: 1px solid var(--border-card); 
    box-shadow: var(--shadow-premium), var(--shadow-inner); 
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease; 
}
.mac-card:hover { transform: translateY(-2px); box-shadow: 0 30px 60px -15px rgba(59, 130, 246, 0.15), var(--shadow-inner); }

/* Bottom Nav (Mobile) */
.mobile-nav {
    background-color: var(--bg-card);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: 1px solid var(--border-card);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.05), var(--shadow-inner);
}
.nav-item { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.nav-item:active { transform: scale(0.9); }

/* Inputs & Buttons */
.mac-segmented { background-color: var(--bg-segment); padding: 6px; border-radius: 20px; display: flex; gap: 4px; }
.mac-segment-btn { border-radius: 14px; color: var(--text-secondary); font-weight: 600; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.mac-segment-btn.active { background-color: var(--bg-card-solid); color: var(--text-primary); box-shadow: 0 4px 15px rgba(0,0,0,0.08); transform: scale(1.02); }

.mac-input { 
    background-color: var(--bg-input); border: 1px solid var(--border-light); border-radius: 16px; padding: 14px 20px; font-size: 15px; color: var(--text-primary); transition: all 0.3s ease; outline: none; box-shadow: inset 0 2px 5px rgba(0,0,0,0.02); 
}
.mac-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15), inset 0 2px 5px rgba(0,0,0,0.02); background-color: var(--bg-card-solid); }

.mac-btn-primary { 
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%); color: #ffffff; border-radius: 18px; font-weight: 700; font-size: 16px; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 0 10px 25px -8px rgba(59, 130, 246, 0.5); border: 1px solid rgba(255,255,255,0.2); 
}
.mac-btn-primary:hover { box-shadow: 0 15px 30px -8px rgba(59, 130, 246, 0.6); transform: translateY(-2px); }
.mac-btn-primary:active { transform: scale(0.96); }

/* SweetAlert Premium Customization */
.hide-scroll::-webkit-scrollbar { display: none; }
.swal2-popup { border-radius: 32px !important; font-family: inherit !important; backdrop-filter: blur(40px) saturate(200%); background-color: var(--bg-card) !important; color: var(--text-primary) !important; border: 1px solid var(--border-card); box-shadow: 0 30px 60px -15px rgba(0,0,0,0.3), var(--shadow-inner) !important; }
.swal2-title { font-size: 24px !important; font-weight: 800 !important; color: var(--text-primary) !important; }
.swal2-html-container { color: var(--text-secondary) !important; }
.swal2-confirm { border-radius: 16px !important; background: linear-gradient(135deg, #3b82f6, #6366f1) !important; font-weight: 700 !important; border: 0 !important; box-shadow: 0 8px 20px rgba(59,130,246,0.3) !important; padding: 12px 28px !important; }
.swal2-cancel { border-radius: 16px !important; background-color: var(--bg-segment) !important; color: var(--text-primary) !important; font-weight: 700 !important; border: 0 !important; padding: 12px 28px !important; }
.swal2-input { background-color: var(--bg-input) !important; color: var(--text-primary) !important; border: 1px solid var(--border-light) !important; border-radius: 16px !important; padding: 14px 20px !important; }
.swal2-input:focus { border-color: #3b82f6 !important; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15) !important; }

/* ⌚️ Premium Rings */
.ring-bg { fill: none; stroke: var(--bg-segment); stroke-width: 9; stroke-linecap: round; }
.ring-progress { fill: none; stroke-width: 9; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1); filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15)); }

/* Gradient Texts */
.text-gradient { background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.text-gradient-blue { background-image: linear-gradient(135deg, #3b82f6, #8b5cf6); }
.text-gradient-green { background-image: linear-gradient(135deg, #10b981, #06b6d4); }
.text-gradient-orange { background-image: linear-gradient(135deg, #f59e0b, #ef4444); }

/* Custom Animations */
.scanner-container { position: relative; width: 100%; max-width: 280px; margin: 0 auto; border-radius: 24px; overflow: hidden; border: 3px solid rgba(59, 130, 246, 0.5); box-shadow: 0 15px 35px rgba(59, 130, 246, 0.25); }
.scanner-image { width: 100%; display: block; border-radius: 20px; filter: contrast(1.05) brightness(0.95); }
.scanner-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: radial-gradient(rgba(59, 130, 246, 0.35) 1px, transparent 1px); background-size: 12px 12px; z-index: 1; pointer-events: none; }
.scan-line { position: absolute; top: 0; left: 0; width: 100%; height: 5px; background: #3b82f6; box-shadow: 0 0 20px #3b82f6, 0 0 40px #3b82f6; z-index: 2; animation: scan-anim 2s infinite cubic-bezier(0.4, 0, 0.2, 1) alternate; border-radius: 5px; }
@keyframes scan-anim { 0% { top: 0%; opacity: 0.2; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { top: calc(100% - 5px); opacity: 0.2; } }

.mic-pulse { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); animation: pulse-mic 2s infinite cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes pulse-mic { 0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); } 70% { transform: scale(1.05); box-shadow: 0 0 0 25px rgba(239, 68, 68, 0); } 100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }

/* ==========================================
   🤖 Premium AI Coach Features 
   ========================================== */
.ai-coach-fab {
    animation: float-fab 4s ease-in-out infinite;
}
@keyframes float-fab {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.02); box-shadow: 0 25px 40px rgba(59, 130, 246, 0.4); }
    100% { transform: translateY(0) scale(1); }
}

#chatPanel { 
    transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease-in-out; 
    background-color: var(--bg-glass);
    backdrop-filter: blur(50px) saturate(200%);
    -webkit-backdrop-filter: blur(50px) saturate(200%);
    border: 1px solid var(--border-light);
    box-shadow: 0 30px 60px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.4);
}
#chatPanel.chat-expanded {
    bottom: 0 !important; left: 0 !important; width: 100vw !important; height: 100dvh !important;
    border-radius: 0 !important; z-index: 99999 !important; transform: translateY(0) !important;
}

.chat-bubble-user { 
    background: linear-gradient(135deg, #3b82f6, #6366f1); color: #ffffff; 
    border-radius: 24px 24px 6px 24px; box-shadow: 0 8px 20px -5px rgba(59, 130, 246, 0.4); 
    animation: chatSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform-origin: bottom right; padding: 12px 16px; font-size: 14px;
}
.chat-bubble-ai { 
    background-color: var(--bg-card-solid); color: var(--text-primary); 
    border-radius: 24px 24px 24px 6px; border: 1px solid var(--border-light);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    animation: chatSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform-origin: bottom left; padding: 12px 16px; font-size: 14px; line-height: 1.5;
}

@keyframes chatSlideUp { 0% { opacity: 0; transform: translateY(20px) scale(0.9); } 100% { opacity: 1; transform: translateY(0) scale(1); } }