/* --- Fonts Import (เปลี่ยนเป็น IBM Plex Sans Thai) --- */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&display=swap');

/* --- Global Variables & Reset (คงเดิม) --- */
:root {
    --primary: #003781;
    --primary-dark: #002a61;
    --primary-light: #e6f0ff;
    --accent: #C5001C;
    --success: #10B981; 
    --success-dark: #059669;
    --success-bg: #d1fae5;
    --bg-body: #f8f9fa;
    --bg-white: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    /* เปลี่ยนฟอนต์หลัก */
    --font-main: 'IBM Plex Sans Thai', sans-serif;
}

body { font-family: var(--font-main); background-color: var(--bg-body); margin: 0; color: var(--text-main); -webkit-font-smoothing: antialiased; padding-bottom: 40px; }
button, input, textarea, select { font-family: var(--font-main); }
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Navbar */
.navbar { background: var(--bg-white); box-shadow: 0 2px 10px rgba(0,0,0,0.05); position: sticky; top: 0; z-index: 100; height: 64px; display: flex; align-items: center; }
.nav-content { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--primary); font-size: 1.2rem; }
.logo-img { height: 40px; width: auto; object-fit: contain; } /* เพิ่มความสูงโลโก้ */
.user-profile { display: flex; align-items: center; gap: 12px; font-size: 0.95rem; font-weight: 500; }
.btn-logout { background: #fee2e2; color: var(--accent); border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.btn-logout:hover { background: var(--accent); color: white; }

/* Hero Swiper */
.hero-section { margin-bottom: 20px; background: white; padding-bottom: 20px; }
.swiper { width: 100%; height: 350px; } 
@media (min-width: 768px) { .swiper { height: 450px; } }
.swiper-slide { background-position: center; background-size: cover; position: relative; cursor: default; }
.hero-content { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px); width: 90%; max-width: 600px; background: rgba(255, 255, 255, 0.45); backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, 0.6); padding: 24px; border-radius: 20px; box-shadow: 0 8px 32px rgba(0,0,0,0.15); opacity: 0; transition: 0.6s cubic-bezier(0.22, 1, 0.36, 1); text-align: center; }
.swiper-slide-active .hero-content { transform: translateX(-50%) translateY(0); opacity: 1; }
.hero-tag { background: var(--primary); color: white; padding: 4px 14px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; margin-bottom: 12px; display: inline-block; }
.hero-title { margin: 0 0 10px; font-size: 1.8rem; color: var(--primary-dark); line-height: 1.3; font-weight: 700; }
.hero-desc { margin: 0; color: #111; font-size: 1.05rem; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.greeting-box { position: absolute; top: 20px; left: 20px; z-index: 10; background: rgba(255,255,255,0.9); color: var(--primary); padding: 8px 16px; border-radius: 30px; font-size: 0.95rem; font-weight: 600; box-shadow: 0 4px 10px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 8px; }
.swiper-pagination-bullet-active { background: var(--primary); width: 35px; border-radius: 4px; transition: width 0.3s; }

/* Mini Banners */
.mini-banner-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; padding: 10px 0; margin-bottom: 20px; }
.mini-banner-item { height: 80px; border-radius: 12px; background-color: var(--primary); color: white; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 600; font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow); position: relative; overflow: hidden; padding: 10px; transition: 0.2s; }
.mini-banner-item:hover { transform: scale(1.02); box-shadow: var(--shadow-hover); }

/* --- Search & Filter Bar (Improved Mobile UI) --- */
.sticky-bar { 
    background: var(--bg-white); 
    padding: 15px 0; 
    position: sticky; 
    top: 64px; 
    z-index: 90; 
    border-bottom: 1px solid #eee; 
    margin-bottom: 30px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
}

.agent-search-container { 
    position: relative; 
    margin-bottom: 15px; 
    width: 100%;
}

.agent-search-container input { 
    width: 100%; 
    padding: 14px 16px 14px 50px; /* เพิ่ม Padding ซ้าย */
    border: 1px solid #e5e7eb; 
    border-radius: 50px; /* ทำให้กลมมน */
    background: #f9fafb; 
    font-size: 1rem; 
    box-sizing: border-box; /* สำคัญ: ป้องกันล้นจอ */
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.agent-search-container input:focus {
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
    outline: none;
}

.agent-search-container .search-icon { 
    position: absolute; 
    left: 20px; 
    top: 50%; 
    transform: translateY(-50%); 
    color: var(--text-muted); 
    font-size: 1.2rem; 
    pointer-events: none;
}

/* Category Filters (Wrappable) */
.filter-scroll { 
    display: flex; 
    flex-wrap: wrap; /* เปลี่ยนเป็น Wrap เพื่อให้ขึ้นบรรทัดใหม่ */
    gap: 10px; 
    padding-bottom: 5px; 
    justify-content: center; /* จัดกึ่งกลาง */
}

.filter-chip { 
    background: #fff; 
    border: 1px solid #e5e7eb; 
    padding: 8px 18px; 
    border-radius: 20px; 
    color: var(--text-muted); 
    cursor: pointer; 
    font-size: 0.95rem; 
    font-weight: 500; 
    transition: all 0.2s ease;
    white-space: nowrap; /* ข้อความไม่ตัดคำในปุ่ม */
    flex-grow: 0; /* ไม่ขยายเต็มพื้นที่ */
}

.filter-chip:hover {
    background: #f3f4f6;
    transform: translateY(-1px);
}

.filter-chip.active { 
    background: var(--primary); 
    color: white; 
    border-color: var(--primary); 
    font-weight: 600; 
    box-shadow: 0 4px 6px rgba(0, 55, 129, 0.2);
}

/* Mobile Specific Tweaks */
@media (max-width: 768px) {
    .container { padding: 0 15px; } /* ลด padding ด้านข้างเล็กน้อย */
    .sticky-bar { top: 60px; padding: 12px 0; }
    .filter-scroll { 
        justify-content: flex-start; /* บนมือถือจัดชิดซ้ายให้อ่านง่าย */
        gap: 8px;
    }
    .filter-chip {
        font-size: 0.85rem; /* ลดขนาดตัวอักษรนิดหน่อย */
        padding: 6px 14px;
    }
}

/* Layout & Cards */
.section-container { margin-bottom: 40px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-title { font-size: 1.6rem; font-weight: 600; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ''; display: block; width: 6px; height: 28px; background: var(--accent); border-radius: 4px; }
.horizontal-scroll { display: flex; gap: 20px; overflow-x: auto; padding-bottom: 20px; scrollbar-width: none; }
.horizontal-scroll .card { min-width: 280px; max-width: 280px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }

.card { background: white; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: all 0.3s; display: flex; flex-direction: column; cursor: pointer; position: relative; border: 1px solid rgba(0,0,0,0.02); }
.card:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); }
.card.downloaded { border: 2px solid var(--success); }
.download-badge { position: absolute; top: 10px; left: 10px; background: var(--success); color: white; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; z-index: 5; box-shadow: 0 2px 5px rgba(0,0,0,0.2); font-size: 1rem; }
.multiple-badge { position: absolute; top: 10px; right: 80px; background: rgba(0,0,0,0.7); color: white; padding: 4px 10px; border-radius: 6px; font-size: 0.8rem; z-index: 2; display: flex; align-items: center; gap: 5px; font-weight: 500; }
.card-media-wrapper { position: relative; padding-top: 100%; background: #eee; overflow: hidden; }
.card-media { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transition: 0.5s; }
.card-type-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; backdrop-filter: blur(4px); z-index: 2; font-weight: 500; }
.card-category-badge { position: absolute; bottom: 10px; right: 10px; background: var(--primary); color: white; padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; z-index: 2; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.card-body { padding: 20px; flex-grow: 1; display: flex; flex-direction: column; }
.card-tags { margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.card-tag { font-size: 0.8rem; color: var(--primary); background: #e0e7ff; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.card-title { font-size: 1.2rem; font-weight: 600; margin: 0 0 8px; color: var(--text-main); line-height: 1.4; }
.caption-preview { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 20px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.6; flex-grow: 1; }
.btn-group { margin-top: auto; }
.btn-view-content { width: 100%; padding: 12px; border: 1px solid var(--primary); background: white; color: var(--primary); border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 1rem; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-view-content:hover { background: var(--primary); color: white; }
.card.downloaded .btn-view-content { background-color: var(--success-bg) !important; color: var(--success-dark) !important; border-color: var(--success-bg) !important; }

/* Modal */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); backdrop-filter: blur(5px); align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s ease; }
.modal.show { display: flex; opacity: 1; }
.modal-content { background-color: #fff; width: 90%; max-width: 1000px; height: 85vh; border-radius: 20px; overflow: hidden; position: relative; display: flex; flex-direction: column; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); transform: scale(0.95); transition: transform 0.3s ease; }
.modal.show .modal-content { transform: scale(1); }
.close-modal { position: absolute; top: 20px; right: 20px; z-index: 10; background: rgba(255,255,255,0.8); border: none; border-radius: 50%; width: 40px; height: 40px; cursor: pointer; font-size: 24px; display: flex; align-items: center; justify-content: center; transition: 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.close-modal:hover { background: #fff; transform: rotate(90deg); color: var(--accent); }
.modal-body-layout { display: flex; height: 100%; }
.modal-media-section { flex: 1.5; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.modal-info-section { flex: 1; padding: 40px; overflow-y: auto; background: #fff; display: flex; flex-direction: column; }
.modal-gallery-swiper { width: 100%; height: 100%; }
.modal-slide { display: flex; align-items: center; justify-content: center; background: #000; }
.modal-media-wrapper { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.modal-media-wrapper img, .modal-media-wrapper video { max-width: 100%; max-height: 100%; object-fit: contain; }
.modal-gallery-swiper .swiper-button-next, .modal-gallery-swiper .swiper-button-prev { color: white; opacity: 0.7; }
.modal-gallery-swiper .swiper-pagination-bullet-active { background: var(--primary); opacity: 1; }
.modal-meta-header { display: flex; gap: 10px; margin-bottom: 15px; align-items: center; flex-wrap: wrap; }
.category-pill { background: var(--primary); color: white; padding: 6px 14px; border-radius: 20px; font-size: 0.9rem; font-weight: 600; display: inline-flex; align-items: center; }
.download-status-pill { background: var(--success-bg); color: var(--success-dark); padding: 6px 14px; border-radius: 20px; font-size: 0.9rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--success-bg); }
.modal-title { font-size: 2rem; color: var(--primary); margin: 5px 0 20px 0; line-height: 1.3; font-weight: 700; }
.modal-caption-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 12px; padding: 20px; position: relative; margin-bottom: 25px; flex-grow: 1; display: flex; flex-direction: column; }
.modal-caption-box textarea { width: 100%; flex-grow: 1; border: none; background: transparent; font-size: 1.05rem; color: var(--text-main); resize: none; outline: none; min-height: 150px; line-height: 1.6; }
.btn-copy-floating { background: #fff; border: 1px solid #ddd; padding: 6px 14px; border-radius: 20px; font-size: 0.85rem; cursor: pointer; transition: 0.2s; color: var(--text-muted); position: absolute; bottom: 15px; right: 15px; font-weight: 600; }
.btn-copy-floating:hover { background: var(--primary); color: white; border-color: var(--primary); }
.modal-actions { display: flex; margin-top: auto; }
.btn-download-list { margin-top: 8px; width: 100%; text-align: left; justify-content: flex-start; padding: 14px 20px; }
button.btn-action.primary.downloaded { background: var(--success) !important; box-shadow: 0 4px 6px rgba(16, 185, 129, 0.3) !important; }
button.btn-action.primary.downloaded:hover { background: var(--success-dark) !important; transform: translateY(-2px); }
.btn-action { flex: 1; padding: 14px; border: none; border-radius: 12px; font-size: 1rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: 0.2s; }
.btn-action.primary { background: var(--primary); color: white; box-shadow: 0 4px 6px rgba(0, 55, 129, 0.2); }
.btn-action.primary:hover { background: var(--primary-dark); transform: translateY(-2px); }
.reaction-container { margin-bottom: 20px; border-top: 1px solid #eee; padding-top: 20px; }
.btn-reaction { border: 1px solid #e5e7eb; background: white; padding: 8px 18px; border-radius: 30px; cursor: pointer; font-size: 0.95rem; transition: all 0.2s; display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-weight: 500; }
.btn-reaction:hover { background: #f3f4f6; border-color: #d1d5db; }
.btn-reaction.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); font-weight: 700; box-shadow: 0 2px 4px rgba(0, 55, 129, 0.1); }
#btn-dislike.active { border-color: var(--accent); color: var(--accent); background: #fee2e2; }
@media (max-width: 900px) { .modal-body-layout { flex-direction: column; } .modal-media-section { height: 40vh; flex: none; } .modal-info-section { flex: 1; padding: 25px; } }
.skeleton { background: #f0f0f0; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 0.3; } 100% { opacity: 0.6; } }
.skeleton-slide { width: 100%; height: 100%; background: #e0e0e0; animation: pulse 1.5s infinite; }
.toast { visibility: hidden; min-width: 280px; background-color: #333; color: #fff; text-align: center; border-radius: 50px; padding: 16px 24px; position: fixed; z-index: 3000; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: all 0.3s; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.toast.show { visibility: visible; transform: translateX(-50%) translateY(0); opacity: 1; }
footer { text-align: center; color: #9ca3af; font-size: 0.85rem; padding-top: 40px; }
#ackModal { z-index: 2500; }

/* LINE Browser Modal */
#lineModal { display: none; position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.6); backdrop-filter: blur(5px); }
#lineModalContent { background: #fff; color: var(--text-main); margin: 15% auto; padding: 30px; border-radius: 20px; width: 90%; max-width: 420px; text-align: center; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); font-family: var(--font-main); border: 1px solid #e5e7eb; }
#lineModalContent strong { color: var(--primary); font-size: 1.3rem; display: block; margin-bottom: 12px; }
#currentUrl { color: var(--primary); word-break: break-all; background: #e6f0ff; padding: 10px; border-radius: 8px; display: block; margin: 15px 0; font-size: 0.9rem; font-weight: 500; border: 1px solid #dbeafe; }
.line-modal-btn { margin-top: 10px; background-color: var(--primary); border: none; color: white; padding: 12px 24px; border-radius: 12px; cursor: pointer; font-size: 1rem; font-family: var(--font-main); transition: 0.2s; width: 100%; font-weight: 600; box-shadow: 0 4px 6px rgba(0, 55, 129, 0.2); }
.line-modal-btn:hover { background-color: var(--primary-dark); transform: translateY(-2px); }
.line-modal-btn.secondary { background-color: transparent; color: var(--text-muted); border: 1px solid #e5e7eb; margin-top: 10px; box-shadow: none; }
.line-modal-btn.secondary:hover { background-color: #f3f4f6; transform: none; }

/* -------------------------------------------------------- */
/* MOBILE OPTIMIZATIONS (เพิ่มส่วนนี้ท้ายไฟล์เพื่อแก้ปัญหา) */
/* -------------------------------------------------------- */

/* Default Hidden Controls */
.mobile-filter-controls { display: none; }

@media (max-width: 768px) {
    /* 1. Header Compact: ซ่อนชื่อยาวๆ */
    .navbar { height: 56px; padding: 0 10px; }
    .brand span { display: none; } /* ซ่อนชื่อเว็บเต็ม */
    .brand::after { content: "SMA Space"; display: block; font-size: 1.1rem; } /* แสดงชื่อย่อ */
    .user-profile span { display: none; } /* ซ่อนชื่อ User */
    .logo-img { height: 32px; }

    /* 2. Filter Bar: เปลี่ยนเป็น Dropdown */
    .sticky-bar { top: 56px; padding: 10px 0; }
    
    .filter-scroll { 
        display: none; /* ซ่อน List ยาวๆ */
        position: absolute; top: 100%; left: 0; right: 0;
        background: white; padding: 15px;
        flex-direction: column; 
        box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        border-top: 1px solid #eee;
        z-index: 95;
    }
    .filter-scroll.show { display: flex; } /* แสดงเมื่อกดปุ่ม */
    .filter-chip { width: 100%; text-align: left; margin-bottom: 5px; }

    .mobile-filter-controls { 
        display: flex; gap: 10px; justify-content: space-between; align-items: center; width: 100%;
    }
    .current-category-display {
        font-size: 0.9rem; font-weight: 600; color: var(--primary);
        background: #e6f0ff; padding: 8px 15px; border-radius: 20px;
        flex-grow: 1; display: flex; align-items: center; gap: 6px;
    }
    .btn-toggle-filter {
        background: white; border: 1px solid #ddd; padding: 8px 15px;
        border-radius: 20px; font-size: 0.9rem; color: #555;
        cursor: pointer; display: flex; align-items: center; gap: 5px;
    }

    /* 3. Grid: 2 Columns Fix */
    .grid { 
        grid-template-columns: repeat(2, 1fr) !important; /* บังคับ 2 คอลัมน์ */
        gap: 12px;
    }
    .card { border-radius: 10px; }
    .card-body { padding: 10px; }
    .card-title { font-size: 0.95rem; height: 2.6em; overflow: hidden; margin-bottom: 4px; }
    .caption-preview { font-size: 0.8rem; -webkit-line-clamp: 2; margin-bottom: 8px; }
    .card-tags { display: none; } /* ซ่อน Tags บนมือถือ */
    .btn-view-content { padding: 6px; font-size: 0.8rem; height: 32px; }
    
    /* Horizontal Scroll Cards */
    .horizontal-scroll .card {
        min-width: 160px;
        max-width: 160px;
    }
    
    /* Modal Mobile */
    .modal-content { height: 90vh; }
    .modal-media-section { height: 40%; }
    .modal-info-section { height: 60%; padding: 20px; }
}
