/* ============================================
   Common Styles - Optimized for Performance
   ลด backdrop-filter และ animation ที่ไม่จำเป็น
   ============================================ */

:root {
    --primary: #38bdf8;
    --primary-dark: #0ea5e9;
    --secondary: #818cf8;
    --bg-gradient: linear-gradient(135deg, #e0f2fe 0%, #f3e8ff 50%, #f8fafc 100%);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: #1e293b;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ============================================
   Toast (สำคัญ - ต้องมี)
   ============================================ */
#toastContainer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: white;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-width: 300px;
    word-wrap: break-word;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-info { background: linear-gradient(135deg, #38bdf8, #818cf8); }
.toast-success { background: linear-gradient(135deg, #34d399, #059669); }
.toast-error { background: linear-gradient(135deg, #f87171, #ef4444); }

/* ============================================
   Glass Panels (ลด blur เพื่อประสิทธิภาพ)
   ============================================ */
.glass-panel-white {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    /* ลบ backdrop-filter ออกเพื่อประสิทธิภาพบนมือถือ */
}

/* ============================================
   Navbar (ปรับให้เล็กลง)
   ============================================ */
.navbar {
    position: sticky;
    top: 12px;
    z-index: 50;
    max-width: 900px;
    margin: 0 auto 1.5rem;
    width: calc(100% - 1.5rem);
}

.navbar-brand {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
}

/* Hamburger */
.hamburger-btn {
    width: 40px;
    height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
    background: rgba(56, 189, 248, 0.1);
}

.hamburger-bar {
    width: 22px;
    height: 2.5px;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    border-radius: 3px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hamburger-btn.active .hamburger-bar:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
.hamburger-btn.active .hamburger-bar:nth-child(2) { opacity: 0; width: 0; }
.hamburger-btn.active .hamburger-bar:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

/* ============================================
   Buttons
   ============================================ */
.btn-liquid {
    background: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
    color: white;
    border-radius: 100px;
    border: none;
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3);
    transition: all 0.2s ease;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-liquid:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.4);
}

.btn-liquid:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================
   Avatar & Balance
   ============================================ */
.avatar-glass {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(56, 189, 248, 0.25);
    flex-shrink: 0;
}

.balance-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 20px;
    font-size: 13px;
    color: #0284c7;
    font-weight: 600;
    white-space: nowrap;
}

/* ============================================
   Profile Dropdown (สำคัญ - ต้องมีครบ 5 เมนู)
   ============================================ */
.profile-dropdown-container {
    position: relative;
}

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 4px 12px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.2s;
}

.profile-trigger:hover,
.profile-trigger.active {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.15);
}

.glass-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 280px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 100;
    transform-origin: top right;
    transform: scale(0.95);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.2s ease;
}

.glass-dropdown.active {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    margin: 2px 8px;
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 8px;
    border-bottom: none;
}

.dropdown-item:hover {
    background: rgba(56, 189, 248, 0.08);
    color: #0ea5e9;
}

.dropdown-item:hover .dropdown-icon {
    color: #0ea5e9;
}

.dropdown-icon {
    width: 20px;
    height: 20px;
    color: #94a3b8;
    transition: color 0.15s;
    flex-shrink: 0;
}

.dropdown-item.admin-item {
    color: #7c3aed;
}

.dropdown-item.admin-item .dropdown-icon {
    color: #7c3aed;
}

.dropdown-item.admin-item:hover {
    background: rgba(124, 58, 237, 0.08);
    color: #6d28d9;
}

.dropdown-item.logout-item {
    color: #dc2626;
    margin-top: 4px;
    border-top: 1px solid rgba(226, 232, 240, 0.6);
    border-radius: 0;
    margin: 4px 0 0 0;
    padding: 12px 16px;
}

.dropdown-item.logout-item:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

.dropdown-item.logout-item .dropdown-icon {
    color: #ef4444;
}

/* ============================================
   Sidebar (สำคัญ - ครบทุกฟังก์ชัน)
   ============================================ */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 55;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
}

.sidebar-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    max-width: 85vw;
    height: 100dvh;
    background: rgba(255, 255, 255, 0.98);
    border-right: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
    z-index: 60;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transform: translateX(-110%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-overflow-scrolling: touch;
}

.sidebar-drawer.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.sidebar-logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: rgba(241, 245, 249, 0.8);
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sidebar-close-btn:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* User Strip */
.sidebar-user-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 16px;
    padding: 12px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(129, 140, 248, 0.08));
    border: 1px solid rgba(56, 189, 248, 0.15);
    border-radius: 12px;
}

.sidebar-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3);
}

.sidebar-user-info {
    min-width: 0;
    flex: 1;
}

.sidebar-username {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-balance {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #0284c7;
    font-weight: 600;
    margin-top: 2px;
}

/* Navigation */
.sidebar-nav {
    padding: 8px 12px;
    flex: 1;
}

.sidebar-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    padding: 8px 12px 4px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    margin: 2px 0;
    border-radius: 10px;
    color: #475569;
    font-weight: 500;
    font-size: 0.92rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
    min-height: 44px; /* Touch target */
}

.sidebar-item:hover {
    background: rgba(56, 189, 248, 0.07);
    color: #0ea5e9;
}

.sidebar-item:hover .sidebar-item-icon {
    color: #0ea5e9;
}

.sidebar-item.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(129, 140, 248, 0.10));
    color: #0284c7;
    font-weight: 600;
}

.sidebar-item.active .sidebar-item-icon {
    color: #0284c7;
    background: rgba(56, 189, 248, 0.1);
}

.sidebar-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(241, 245, 249, 0.8);
    color: #94a3b8;
    flex-shrink: 0;
    transition: all 0.2s;
}

.sidebar-item-icon svg {
    width: 18px;
    height: 18px;
}

.sidebar-badge {
    margin-left: auto;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 50px;
    background: #f59e0b;
    color: white;
}

.sidebar-logout {
    color: #ef4444;
    margin-top: 4px;
}

.sidebar-logout .sidebar-item-icon {
    background: rgba(254, 226, 226, 0.6);
    color: #ef4444;
}

.sidebar-logout:hover {
    background: rgba(254, 226, 226, 0.5);
    color: #dc2626;
}

.sidebar-divider {
    height: 1px;
    background: rgba(226, 232, 240, 0.6);
    margin: 8px 16px;
}

/* Auth Sections */
.sidebar-auth-section {
    padding: 4px 12px 8px;
}

.sidebar-auth-btn {
    width: 100%;
    padding: 11px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    margin: 4px 0;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    transition: all 0.2s;
}

.sidebar-login-btn {
    background: rgba(241, 245, 249, 0.9);
    color: #475569;
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.sidebar-login-btn:hover {
    background: rgba(224, 242, 254, 0.9);
    color: #0284c7;
    border-color: rgba(56, 189, 248, 0.3);
}

.sidebar-register-btn {
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    color: white;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

.sidebar-register-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(56, 189, 248, 0.4);
}

.sidebar-version {
    text-align: center;
    font-size: 0.75rem;
    color: #cbd5e1;
    padding: 16px;
    margin-top: auto;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 640px) {
    .glass-dropdown {
        position: fixed;
        top: 70px;
        right: 12px;
        left: 12px;
        width: auto;
    }
    
    .navbar-brand {
        font-size: 1.25rem;
    }
}
