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

:root {
    /* Colors */
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #818cf8;
    
    /* Backgrounds */
    --bg-body: #f1f5f9;
    --bg-sidebar: #0f172a;
    --card-bg: #ffffff;
    
    /* Status Colors */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --rose: #ec4899;
    --gold: #eab308;
    --gem: #a855f7;
    
    /* Text */
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    /* Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed: 80px;
    
    /* Effects */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius-md: 12px;
    --radius-lg: 20px;
}

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

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden !important; 
}

body {
    font-family: 'Kanit', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    word-wrap: break-word; 
    overflow-wrap: break-word;
    -webkit-font-smoothing: antialiased;
}

/* ===============================
   2. LAYOUT STRUCTURE
   =============================== */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden !important;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-collapsed);
    background-color: var(--bg-sidebar);
    color: white;
    position: fixed;
    height: 100%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    box-shadow: 4px 0 15px rgba(0,0,0,0.05);
    
    /* ปิด Scrollbar เพื่อป้องกันการเบียดปุ่มเมนูให้เบี้ยว */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* ซ่อน Scrollbar ของ Chrome/Safari/Edge */
.sidebar::-webkit-scrollbar {
    width: 0;
    display: none;
}

.app-container.sidebar-pushed .sidebar {
    width: var(--sidebar-width);
}

.main-content {
    flex: none; 
    width: calc(100% - var(--sidebar-collapsed));
    max-width: calc(100% - var(--sidebar-collapsed));
    margin-left: var(--sidebar-collapsed);
    padding: 30px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 0; 
    box-sizing: border-box;
    overflow-x: hidden !important;
}

.app-container.sidebar-pushed .main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
}

/* ปุ่ม Hamburger */
.hamburger-btn {
    background: #1e293b; 
    border: none;
    color: white;
    width: 52px;
    height: 52px;
    border-radius: 16px; 
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 19px;
    left: 14px; /* ตรงกลางพอดีของเมนูตอนพับ (80px) */
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); 
    padding: 0;
}

.hamburger-btn:hover { 
    background: #334155; 
    transform: translateY(-2px); 
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); 
}

.hamburger-btn:active { transform: translateY(1px) scale(0.95); }

.hamburger-btn .material-icons {
    font-size: 24px; 
    transition: transform 0.2s ease;
}

nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 25px; 
    margin-top: 80px; /* เว้นที่ให้ Hamburger */
}

nav ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px; 
    height: 100%;
    margin: 0;
    padding: 0;
}

/* เมนูต่างๆ (ชิดซ้ายให้ตรงกับ Hamburger เสมอ ไม่ว่ากางหรือหุบ) */
.nav-link {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* บังคับให้ไอคอนชิดซ้ายเสมอ */
    color: #64748b;
    text-decoration: none;
    border-radius: 16px; 
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 52px; 
    height: 52px;
    min-width: 52px; 
    margin: 0 14px; 
    padding-left: 14px; /* ล็อกระยะห่างด้านซ้ายของไอคอนให้อยู่นิ่ง */
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

/* เมื่อกางเมนูออก */
.app-container.sidebar-pushed .nav-link {
    width: calc(100% - 28px); 
    /* ไม่ต้องแก้ padding/justify แล้ว เพราะล็อกพิกัดไว้จากตัวแม่ */
}

.nav-link:hover { 
    color: #cbd5e1; 
    background-color: rgba(255,255,255,0.05); 
}

.nav-link.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.nav-link.active .material-icons { 
    transform: scale(1.1); 
}

.nav-link .material-icons { 
    font-size: 24px; 
    min-width: 24px; 
    margin: 0; 
    transition: transform 0.3s ease;
}

/* ข้อความเมนู */
.nav-text { 
    display: none; 
    margin-left: 16px; 
    font-weight: 500;
    font-size: 1.05rem;
    white-space: nowrap;
    opacity: 0;
    animation: fadeInText 0.3s forwards 0.1s;
}

.app-container.sidebar-pushed .nav-text { 
    display: block; 
}

@keyframes fadeInText { to { opacity: 1; } }

/* ===============================
   3. PAGE CONTENT & ANIMATION
   =============================== */
.page-content {
    display: none;
    animation: fadeUp 0.4s ease-out;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}
.page-content.active-page { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--bg-sidebar);
    font-weight: 600;
    word-break: break-word;
}

.empty-state {
    text-align: center;
    color: #94a3b8;
    padding: 60px 20px;
    background: white;
    border-radius: var(--radius-lg);
    border: 1px dashed #cbd5e1;
    margin-top: 20px;
}
.empty-state .material-icons {
    font-size: 64px;
    color: #cbd5e1;
    margin-bottom: 15px;
    display: block;
}
.empty-state p {
    font-size: 1.1rem;
    margin: 0;
}

/* ===============================
   4. DASHBOARD STATS (Cards)
   =============================== */
.stats-grid {
    display: grid;
    gap: 20px;
    margin-bottom: 30px;
    width: 100%;
}
.stats-grid-row1 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.stats-grid-row2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); }

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #e2e8f0;
    min-width: 0;
    max-width: 100%;
}
.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.stat-card > .material-icons {
    font-size: 36px;
    padding: 15px;
    border-radius: 16px;
    margin-right: 20px;
}

.api-today-card > .material-icons { color: var(--warning); background: #fffbeb; }
.item-card > .material-icons { color: var(--info); background: #f0f9ff; }
.api-status-card > .material-icons { color: var(--primary-color); background: #eef2ff; }

.refresh-btn {
    background: #e0e7ff;
    padding: 4px;
    border-radius: 50%;
    margin-left: 8px;
    font-size: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-main); margin-top: 5px; word-break: break-all; }
.stat-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }

.full-usage-card { flex-direction: column; align-items: stretch; }
.usage-header { display: flex; align-items: center; border-bottom: 1px solid #f1f5f9; padding-bottom: 15px; }
.usage-header h3 { font-size: 1.1rem; margin: 0; margin-left: 8px; color: var(--bg-sidebar); }

/* ===============================
   5. SEARCH UI & BUTTONS
   =============================== */
.search-container {
    background: white;
    padding: 10px 15px;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    width: 100%;
    box-sizing: border-box;
}
.search-container > .material-icons {
    color: var(--text-muted);
    font-size: 24px;
    margin-left: 5px;
}
#username-input, #clan-name-input {
    flex: 1;
    border: none;
    padding: 10px 0;
    font-size: 1rem;
    outline: none;
    background: transparent;
    font-family: inherit;
    min-width: 0; 
}
button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
    white-space: nowrap;
}
button:hover { filter: brightness(95%); }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }

/* --- PROFILE HEADER --- */
.profile-header-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 30px;
    display: flex;
    align-items: center;
    gap: 30px;
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
    border-left: 5px solid var(--primary-color);
    max-width: 100%;
}
.profile-avatar-wrapper { position: relative; flex-shrink: 0; }
.profile-avatar-lg {
    width: 120px;
    height: 120px;
    border-radius: 20px;
    object-fit: cover;
    border: 4px solid #f1f5f9;
    box-shadow: var(--shadow-md);
}
.level-badge {
    position: absolute;
    bottom: -10px;
    right: -10px;
    background: var(--warning);
    color: white;
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: bold;
    border: 2px solid white;
}
.profile-main-info { flex: 1; min-width: 0; max-width: 100%; }
.player-name { font-size: 1.8rem; font-weight: 700; margin-bottom: 5px; word-break: break-word; line-height: 1.2; }
.clan-tag {
    background: #e2e8f0;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    vertical-align: middle;
    display: inline-block;
    margin-top: 5px;
}
.player-bio {
    font-style: italic;
    color: var(--text-muted);
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    max-width: 100%;
    word-break: break-word;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 10px;
    margin-right: 5px;
}
.status-badge.play { background: #dbeafe; color: #1e40af; }
.status-badge.online { background: #dcfce7; color: #166534; }
.status-badge.dnd { background: #fee2e2; color: #ef4444; }
.status-badge.offline { background: #f1f5f9; color: #64748b; }

.rose-stat {
    display: inline-flex;
    align-items: center;
    color: var(--rose);
    font-weight: 600;
    margin-right: 15px;
    font-size: 0.9rem;
}
.rose-stat .material-icons { font-size: 16px; margin-right: 4px; }

/* --- STATS GRID --- */
.stats-section-title {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.stats-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 20px;
    margin-bottom: 40px;
}
.stat-box {
    background: white;
    padding: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9;
}
.box-title {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--primary-color);
}
.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 0.95rem;
}
.value-green { color: var(--success); font-weight: bold; }
.value-red { color: var(--danger); font-weight: bold; }

.progress-container { margin-top: 10px; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 5px; }
.progress-track { background: #e2e8f0; height: 8px; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; }
.fill-win { background: var(--success); }
.fill-wolf { background: #8b5cf6; }
.fill-solo { background: var(--warning); }

/* --- ROLE CARDS --- */
.role-cards-wrapper {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
    gap: 15px;
}
.game-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid #e2e8f0;
    transition: transform 0.2s;
}
.game-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
.card-top {
    height: 50px;
    background: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
}
.rarity-COMMON { background: #94a3b8; }
.rarity-RARE { background: #0ea5e9; }
.rarity-EPIC { background: #a855f7; }
.rarity-LEGENDARY { background: #eab308; }
.rarity-MYTHICAL { background: #ea0840; }
.card-body { padding: 15px; text-align: center; }
.card-title { font-weight: bold; font-size: 0.95rem; margin-bottom: 5px; word-break: break-word; }
.card-subtitle { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 10px; }
.ability-list { list-style: none; padding: 0; }
.ability-item {
    font-size: 0.75rem;
    background: #f8fafc;
    padding: 3px;
    margin-bottom: 3px;
    border-radius: 4px;
    color: #475569;
}

/* --- ACHIEVEMENTS --- */
.achievements-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}
.achievement-tag {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 500;
}
.achievement-tag strong { color: var(--primary-color); margin-right: 5px; }
.achievement-lvl { 
    background: var(--warning); 
    color: white; 
    border-radius: 4px; 
    padding: 1px 6px; 
    font-size: 0.75rem; 
    margin-left: 8px; 
}

/* --- CLAN MANAGER STYLES --- */
.clan-bio {
    white-space: pre-wrap; 
    font-size: 0.9rem;
    line-height: 1.6;
    word-break: break-word; 
    max-width: 100%;
}
.clan-bio a { color: var(--primary-color); text-decoration: none; font-weight: 500; }
.clan-bio a:hover { text-decoration: underline; }

.clan-wallet {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 15px;
}
.currency-badge {
    background: #f8fafc;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    font-size: 0.9rem;
}
.currency-badge.gold { color: var(--gold); border: 1px solid #fef08a; background: #fefce8; }
.currency-badge.gems { color: var(--gem); border: 1px solid #f3e8ff; background: #faf5ff; }

.member-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 15px;
}
.member-card {
    background: white;
    padding: 15px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 0;
    max-width: 100%;
}
.member-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}
.member-card.leader { border-left: 4px solid var(--warning); }
.member-card.coleader { border-left: 4px solid var(--info); }

.member-avatar {
    width: 45px; height: 45px;
    border-radius: 10px;
    margin-right: 12px;
    border: 2px solid #e2e8f0;
    background: #f1f5f9;
    flex-shrink: 0;
}
.member-details { flex: 1; min-width: 0; }
.member-details h5 { margin: 0; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-meta { font-size: 0.75rem; color: #64748b; margin-top: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.member-flair { background: #f1f5f9; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; color: var(--primary-color); word-break: break-all;}
.quest-status { margin-left: auto; color: var(--success); font-size: 1rem; }
.quest-status.off { color: #cbd5e1; }

.role-badge {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 5px;
    vertical-align: middle;
}
.role-badge.leader { background: var(--warning); color: white; }
.role-badge.coleader { background: var(--info); color: white; }

.clan-scroll-area {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden; 
    padding-right: 5px;
    word-break: break-word; 
    max-width: 100%;
}
.ledger-list, .history-list {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 5px;
    word-break: break-word; 
    max-width: 100%;
}
.ledger-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.85rem;
    flex-wrap: wrap;
}
.ledger-item:last-child { border-bottom: none; }
.ledger-meta { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.ledger-meta strong { word-break: break-word; }
.ledger-time { font-size: 0.7rem; color: var(--text-muted); }
.ledger-amount { font-weight: 600; display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ledger-amount.income { color: var(--success); }
.ledger-amount.expense { color: var(--danger); }

.history-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    display: block; 
    max-width: 100%;
}

/* ===============================
   6. API CONSOLE & DEBUG
   =============================== */
.api-console {
    margin-top: 40px;
    border-top: 2px dashed #e2e8f0;
    padding-top: 20px;
    max-width: 100%;
}

.api-console details summary {
    cursor: pointer;
    background-color: #f1f5f9;
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    transition: all 0.2s;
    list-style: none;
    border: 1px solid transparent;
}
.api-console details summary:hover { background-color: #e2e8f0; border-color: #cbd5e1; }
.api-console details summary::-webkit-details-marker { display: none; }

.json-output {
    background-color: #1e1e1e;
    color: #ce9178;
    padding: 20px;
    border-radius: 12px;
    margin-top: 15px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
    max-height: 500px;
    white-space: pre-wrap; 
    word-break: break-all;
}

/* ===============================
   7. SETTINGS PAGE
   =============================== */
.settings-group {
    background: white;
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    margin: 40px auto;
    text-align: center;
    width: 100%;
}
.settings-group h3 { color: var(--primary-color); margin-bottom: 15px; }
#api-key-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    margin: 15px 0;
    font-size: 1rem;
    text-align: center;
    background: #f8fafc;
    min-width: 0;
}
#api-key-input:focus { border-color: var(--primary-color); outline: none; }
#save-api-key-btn {
    background: var(--success);
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
}
#save-api-key-btn:hover { background: #059669; }

/* ===============================
   8. ANIMATIONS & DETAILS
   =============================== */
@keyframes expandFade {
    0% { opacity: 0; transform: translateY(-10px); max-height: 0; }
    100% { opacity: 1; transform: translateY(0); max-height: 500px; }
}

details[open] .clan-scroll-area {
    animation: expandFade 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    transform-origin: top;
}

details summary {
    transition: all 0.3s ease;
    user-select: none;
    outline: none;
}
details summary:hover { background-color: #e2e8f0 !important; }
details summary:active { transform: scale(0.99); }

/* ===============================
   9. MODAL & MEMBER DETAILS
   =============================== */

@keyframes dropDownBounce {
    0% {
        opacity: 0;
        transform: translateY(-80px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex; justify-content: center; align-items: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: white;
    width: 95%; max-width: 600px; max-height: 90vh;
    overflow-y: auto;
    border-radius: 24px;
    padding: 25px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    position: relative;
    animation: dropDownBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-close-btn {
    position: absolute;
    top: 15px; right: 15px;
    background: #f1f5f9;
    border: none;
    width: 40px; height: 40px;
    border-radius: 50% !important; 
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #64748b;
    transition: 0.2s;
    padding: 0;
    line-height: 0;
}
.modal-close-btn:hover { background: #ef4444; color: white; transform: rotate(90deg); }

.clickable-name {
    cursor: pointer;
    transition: color 0.2s;
    display: inline-block;
    border-bottom: 2px solid transparent;
}
.clickable-name:hover {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* ===============================
   10. APP SPECIFIC STYLES (QUEST CARDS)
   =============================== */

.loading-container { 
    text-align: center; 
    padding: 40px; 
    max-width: 400px; 
    margin: 0 auto; 
    width: 100%; 
    box-sizing: border-box; 
}
.loading-bar-track { width: 100%; height: 10px; background: #e2e8f0; border-radius: 5px; margin: 15px 0; overflow: hidden; position: relative; }
.loading-bar-fill { height: 100%; background: linear-gradient(90deg, #3b82f6, #06b6d4); width: 0%; transition: width 0.3s ease-out; border-radius: 5px; }
.loading-text { color: #64748b; font-size: 0.9rem; font-weight: 500; }

.custom-modal-buttons { margin-top: 25px; display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; }
.btn-modal { padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 0.95rem; transition: transform 0.1s; }
.btn-modal:active { transform: scale(0.95); }
.btn-confirm { background: #0ea5e9; color: white; }
.btn-cancel { background: #e2e8f0; color: #475569; }
.btn-danger { background: #ef4444; color: white; }

/* --- QUEST CARDS (ORIGINAL STYLE) --- */
.quest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 15px; margin-top: 15px; width: 100%; }
.quest-card-large { position: relative; border-radius: 12px; overflow: hidden; background: #f8fafc; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); transition: transform 0.2s; border: 1px solid #e2e8f0; cursor: pointer; max-width: 100%; }
.quest-card-large:hover { transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.15); }
.quest-card-large-img { width: 100%; height: 180px; object-fit: cover; display: block; }
.quest-card-overlay { position: absolute; bottom: 0; left: 0; width: 100%; background: linear-gradient(to top, rgba(0,0,0,0.9), transparent); padding: 30px 15px 15px; color: white; display: flex; justify-content: space-between; align-items: flex-end; }
.quest-price-tag { background: rgba(0,0,0,0.6); padding: 4px 8px; border-radius: 6px; font-weight: bold; display: flex; align-items: center; gap: 5px; font-size: 0.95rem; backdrop-filter: blur(4px); }
.quest-votes-badge { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.7); color: white; padding: 4px 8px; border-radius: 6px; font-size: 0.8rem; display: flex; align-items: center; gap: 4px; backdrop-filter: blur(4px); }

.active-quest-container { background: white; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.08); margin-bottom: 25px; position: relative; border: 1px solid #e2e8f0; width: 100%; max-width: 100%; min-width: 0; }
.active-quest-banner { width: 100%; height: 220px; object-fit: cover; display: block; position: relative; }
.active-quest-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 220px; background: linear-gradient(to bottom, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.6) 60%, rgba(0,0,0,0.9) 100%); display: flex; flex-direction: column; justify-content: flex-end; padding: 20px; color: white; pointer-events: none; }
.active-quest-title-lg { font-size: 1.8rem; font-weight: 800; margin: 0; text-shadow: 0 2px 4px rgba(0,0,0,0.5); line-height: 1.2; word-break: break-word; }
.active-quest-meta-lg { display: flex; align-items: center; gap: 10px; margin-top: 5px; font-size: 0.9rem; color: #e2e8f0; flex-wrap: wrap; }
.active-quest-body { padding: 20px; width: 100%; box-sizing: border-box; min-width: 0; }

.active-quest-body > div[style*="display:flex"] {
    flex-wrap: wrap !important;
}

.battle-pass-hub { 
    position: relative; 
    padding: 30px 0 40px 0; 
    margin-top: 10px; 
    overflow-x: auto; 
    max-width: 100%; 
    width: 100%; 
    box-sizing: border-box; 
    min-width: 0; 
    -webkit-overflow-scrolling: touch; 
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.battle-pass-hub::-webkit-scrollbar { height: 6px; }
.battle-pass-hub::-webkit-scrollbar-track { background: transparent; }
.battle-pass-hub::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 4px; }

.xp-progress-wrapper { position: absolute; top: 50%; left: 40px; right: 40px; height: 14px; background: #e2e8f0; border-radius: 10px; overflow: hidden; transform: translateY(-50%); box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); border: 2px solid #cbd5e1; z-index: 1; }
.xp-progress-fill { height: 100%; background: linear-gradient(90deg, #f59e0b, #fbbf24); width: 0%; transition: width 1s ease-out; border-radius: 10px; position: relative; }
.xp-progress-fill::after { content: ""; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-image: linear-gradient(-45deg,rgba(255,255,255,.2) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.2) 50%,rgba(255,255,255,.2) 75%,transparent 75%,transparent); z-index: 1; background-size: 30px 30px; animation: move 2s linear infinite; }
@keyframes move { from { background-position: 0 0; } to { background-position: 30px 0; } }

.battle-pass-track { display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 2; min-width: max-content; }
.reward-step { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.reward-icon-box { width: 58px; height: 58px; background: #fff; border: 3px solid #cbd5e1; border-radius: 14px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 8px rgba(0,0,0,0.15); margin-bottom: 0; position: relative; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.reward-icon-box img { width: 42px; height: 42px; object-fit: contain; }
.reward-step.completed-tier .reward-icon-box { background: #dcfce7; border-color: #22c55e; }
.reward-step.completed-tier .reward-icon-box::after { content: '✓'; position: absolute; bottom: -8px; background: #22c55e; color: white; width: 18px; height: 18px; border-radius: 50%; font-size: 11px; display: flex; align-items: center; justify-content: center; border: 2px solid white; }
.reward-step.active-tier .reward-icon-box { border-color: #f59e0b; background: #fffbeb; transform: scale(1.15); box-shadow: 0 0 15px rgba(245, 158, 11, 0.4); }
.xp-label-floating { position: absolute; top: -25px; left: 50%; transform: translateX(-50%); background: #334155; color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: bold; white-space: nowrap; }
.tier-label { margin-top: 15px; font-size: 0.7rem; color: #64748b; font-weight: 700; text-transform: uppercase; }
.reward-badge { position: absolute; top: -8px; right: -8px; background: #ef4444; color: white; font-size: 0.65rem; font-weight: bold; padding: 1px 5px; border-radius: 8px; border: 2px solid white; }

.quest-inline-icon { font-size: 20px !important; margin-left: 8px; vertical-align: middle; cursor: default; transition: transform 0.2s, opacity 0.2s; }
.quest-inline-icon.clickable { cursor: pointer; }
.quest-inline-icon.clickable:hover { transform: scale(1.2); }
.quest-inline-icon.on { color: #22c55e; }
.quest-inline-icon.off { color: #ef4444; opacity: 0.4; }
.quest-inline-icon.loading { animation: spin 1s linear infinite; color: #64748b; }
.action-icon { font-size: 18px !important; margin-left: 5px; vertical-align: middle; cursor: pointer; opacity: 0.7; transition: all 0.2s; }
.action-icon:hover { opacity: 1; transform: scale(1.1); }
.kick-icon { color: #ef4444; }
.block-icon { color: #64748b; }
.flair-editable { cursor: pointer; border: 1px dashed transparent; padding: 0 4px; border-radius: 4px; transition: all 0.2s; }
.flair-editable:hover { background: #f1f5f9; border-color: #cbd5e1; }
.btn-unblock { background: none; border: none; color: #22c55e; cursor: pointer; font-weight: bold; font-size: 0.8rem; }
.chat-emoji-img { width: 64px; height: 64px; vertical-align: middle; object-fit: contain; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.blocklist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
    gap: 15px;
    margin-top: 15px;
    max-width: 100%;
}

.blocked-member-card {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
    min-width: 0;
    max-width: 100%;
}

.blocked-member-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-color: #ef4444;
}

.blocked-member-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.blocked-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    object-fit: cover;
    flex-shrink: 0;
}

.blocked-name {
    font-weight: 600;
    color: #991b1b;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.blocked-name:hover {
    text-decoration: underline;
}

.btn-unblock-icon {
    background: #ffffff;
    border: 1px solid #fca5a5;
    color: #ef4444;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-unblock-icon:hover {
    background: #ef4444;
    color: white;
}

.loading-spinner {
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

/* ===============================
   11. FLOATING FEEDBACK BUTTON & MODAL
   =============================== */
.fab-feedback {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: var(--primary-color);
    color: white;
    border-radius: 50% !important; 
    border: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    padding: 0; 
}
.fab-feedback:hover {
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}
.fab-feedback .material-icons {
    font-size: 28px;
    margin: 0; 
}

/* 🌟🌟🌟 MOBILE RESPONSIVE FIXES 🌟🌟🌟 */
@media (max-width: 768px) {
    /* บนมือถือให้ซ่อน Sidebar โดยการดันออกไปข้างนอก (-100%) */
    .sidebar { 
        width: var(--sidebar-width); 
        transform: translateX(-100%); 
        z-index: 1500; 
    }
    
    /* เมื่อมีคลาส sidebar-pushed ค่อยเลื่อน Sidebar กลับเข้ามา */
    .app-container.sidebar-pushed .sidebar { 
        transform: translateX(0); 
        box-shadow: 10px 0 25px rgba(0,0,0,0.5);
    }
    
    /* ขยายหน้าหลักให้กว้างเต็มจอ */
    .main-content { 
        margin-left: 0; 
        padding: 90px 15px 20px 15px !important; 
        width: 100vw !important; 
        max-width: 100vw !important; 
        overflow-x: hidden !important; 
        box-sizing: border-box;
    }
    .app-container.sidebar-pushed .main-content {
        margin-left: 0;
        width: 100vw !important;
        max-width: 100vw !important;
    }
    
    /* แสดงปุ่ม Hamburger ตลอดเวลาบนมือถือ */
    .hamburger-btn {
        display: flex !important;
        position: fixed;
    }

    /* บังคับให้เมนูเต็มความกว้างตอนกางบนมือถือ */
    .nav-link {
        width: calc(100% - 28px); 
        justify-content: flex-start; 
        padding-left: 14px; 
    }
    
    .nav-text {
        display: block;
        opacity: 1;
        animation: none;
    }
    
    .stats-grid-row1, .stats-grid-row2 { 
        grid-template-columns: minmax(0, 1fr) !important; 
    }
    .active-quest-container, .active-quest-body, .battle-pass-hub {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .profile-header-card { flex-direction: column; text-align: center; border-left: none; border-top: 5px solid var(--primary-color); }
    
    .search-container { flex-wrap: wrap; }
    .search-container > .material-icons { display: none; }
    .search-container input { width: 100%; text-align: center; border-bottom: 1px solid #cbd5e1; padding-bottom: 10px; margin-bottom: 10px; }
    .search-container button { width: 100%; margin-left: 0 !important; margin-top: 5px; }

    .fab-feedback {
        bottom: 20px;
        right: 20px;
        width: 56px !important; 
        height: 56px !important; 
        min-width: 56px !important; 
        min-height: 56px !important;
        border-radius: 50% !important; 
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        aspect-ratio: 1 / 1 !important;
    }
    .fab-feedback .material-icons { font-size: 26px !important; margin: 0 !important; }
}

.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: flex; justify-content: center; align-items: center;
    animation: fadeIn 0.2s ease-out;
}
.custom-modal-box {
    background: white;
    padding: 25px;
    border-radius: 20px;
    width: 95%; 
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    position: relative;
    animation: dropDownBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 90vh; 
    overflow-y: auto;
}
.form-input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
    max-width: 100%;
}
.form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.submit-btn {
    width: 100%;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: 0.2s;
}
.submit-btn:hover { filter: brightness(90%); }
.submit-btn:disabled { opacity: 0.7; cursor: not-allowed; }
