/* =========================================
   DEEPSEARCH - HIGH PERFORMANCE STYLESHEET
   Engineered with GPU Acceleration & Spring Physics
========================================= */

/* --- 1. Base & Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans Thai', sans-serif;
    -webkit-tap-highlight-color: transparent; /* ลดแสงกระพริบเวลากดปุ่มบนมือถือ */
}

body {
    background-color: #e5e7eb;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 420px;
    background-color: #ffffff;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden; 
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* --- 2. ระบบเปลี่ยนหน้า (GPU-Accelerated SPA Views) --- */
.page-view {
    display: none;
    width: 100%;
    min-height: 100vh;
    background-color: #ffffff;
    padding-bottom: 80px; 
    /* ย้ายการคำนวณพิกัดไปที่ GPU เพื่อเฟรมเรต 60fps คงที่ */
    will-change: transform, opacity; 
}

.page-view.active {
    display: block;
}

/* เอฟเฟกต์แอนิเมชันตอนเปลี่ยนหน้า (ใช้สมการ Spring Physics: cubic-bezier) */
.slide-in-right { animation: slideInRight 0.4s forwards cubic-bezier(0.175, 0.885, 0.32, 1.05); }
.slide-in-left { animation: slideInLeft 0.4s forwards cubic-bezier(0.175, 0.885, 0.32, 1.05); }

@keyframes slideInRight {
    from { transform: translate3d(100%, 0, 0); opacity: 0.5; } /* ใช้ translate3d บังคับใช้ GPU */
    to { transform: translate3d(0, 0, 0); opacity: 1; }
}

@keyframes slideInLeft {
    from { transform: translate3d(-100%, 0, 0); opacity: 0.5; }
    to { transform: translate3d(0, 0, 0); opacity: 1; }
}

/* เพิ่มการจัดการหน่วยความจำให้รูปภาพ */
img {
    content-visibility: auto; /* ให้เบราว์เซอร์ไม่เรนเดอร์รูปที่อยู่นอกจอ */
    object-fit: cover;
}

/* --- 3. Top Bar & Navigation --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background-color: #ffffff;
    z-index: 10;
}
.sticky-top {
    position: sticky;
    top: 0;
    border-bottom: 1px solid #f3f4f6;
}
.user-greeting {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}
.profile-pic {
    width: 36px;
    height: 36px;
    background-color: #f3f4f6;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #4b5563;
}
.top-bar-right {
    display: flex;
    gap: 12px;
}
.page-title {
    font-weight: 600;
    font-size: 16px;
    color: #111827;
    flex-grow: 1;
    text-align: center;
    margin-right: 36px; /* Balance the back button */
}
.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: #4b5563;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 12px; /* แก้ไขจาก 50% เป็นสี่เหลี่ยมขอบมน */
    transition: background-color 0.2s, border-radius 0.2s;
}
.icon-btn:hover { background-color: #f3f4f6; }

/* --- 4. Home View (Hero, Search, Categories) --- */
.hero-section {
    padding: 24px 16px;
    text-align: center; /* จัดให้ข้อความและส่วนประกอบต่างๆ ตรงกลาง */
}
.hero-title {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 4px;
}
.hero-subtitle {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 24px;
}
.main-search-bar {
    display: flex;
    align-items: center;
    background-color: #f3f4f6;
    padding: 12px 16px;
    border-radius: 24px;
    gap: 12px;
    cursor: text;
    transition: box-shadow 0.2s;
    text-align: left; /* ให้ข้อความใน input ชิดซ้ายตามปกติ */
}
.main-search-bar:focus-within {
    box-shadow: 0 0 0 2px #3b82f6;
    background-color: #ffffff;
}
.main-search-bar input {
    flex-grow: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    outline: none;
    color: #1f2937;
}
.main-search-bar i {
    color: #9ca3af;
    font-size: 18px;
}

/* เพิ่มสไตล์ให้ส่วนค้นหาล่าสุด (Recent Searches) */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 24px 16px;
}
.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: #f9fafb;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.recent-item:hover { background-color: #f3f4f6; }
.recent-icon { 
    color: #9ca3af; 
    margin-right: 12px; 
}
.recent-text { 
    flex-grow: 1; 
    font-size: 14px; 
    color: #374151; 
}
.recent-remove { 
    background: none; 
    border: none; 
    color: #d1d5db; 
    cursor: pointer; 
    padding: 4px; 
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}
.recent-remove:hover { 
    background-color: #fee2e2;
    color: #ef4444; 
}

.categories-container {
    padding: 16px;
}
.section-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 12px;
    padding: 0 16px; /* ขยับให้ตรงกับขอบ */
    display: flex;
    align-items: center;
    gap: 8px;
}
.categories-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 0 16px;
}
.category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.category-icon {
    width: 56px;
    height: 56px;
    background-color: #f3f4f6;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: #3b82f6;
    transition: transform 0.2s, background-color 0.2s;
}
.category-item:hover .category-icon {
    transform: scale(1.05);
    background-color: #e0e7ff;
}
.category-name {
    font-size: 12px;
    color: #4b5563;
    font-weight: 500;
    text-align: center;
}

/* --- 5. List View (Category Items) --- */
.list-container {
    padding: 8px 16px;
}
.list-item {
    display: flex;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    gap: 16px;
}
.list-item:last-child { border-bottom: none; }
.list-img {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    object-fit: cover;
    background-color: #f3f4f6;
}
.list-info {
    flex-grow: 1;
    overflow: hidden;
}
.list-title {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-subtitle {
    font-size: 13px;
    color: #6b7280;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.chevron-icon {
    color: #d1d5db;
    font-size: 14px;
}
.status-message {
    text-align: center;
    padding: 40px 16px;
    color: #6b7280;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- 6. Search Detail View --- */
#app-content {
    padding-bottom: 24px;
}
.main-title {
    font-size: 24px;
    font-weight: 700;
    padding: 0 16px;
    margin-bottom: 16px;
    color: #111827;
}
.gallery {
    display: flex;
    overflow-x: auto;
    gap: 12px;
    padding: 0 16px 16px 16px;
    scrollbar-width: none; /* Firefox */
}
.gallery::-webkit-scrollbar { display: none; } /* Chrome, Safari */
.gallery img {
    width: 140px;
    height: 200px; /* เพิ่มความสูงของรูปตามที่ร้องขอ */
    border-radius: 12px;
    flex-shrink: 0;
}
.feedback-box {
    margin: 0 16px 24px 16px;
    padding: 16px;
    background-color: #f9fafb;
    border-radius: 12px;
    text-align: center;
}
.feedback-box p {
    font-size: 14px;
    color: #4b5563;
    margin-bottom: 12px;
}
.feedback-btns {
    display: flex;
    justify-content: center;
    gap: 12px;
}
.feedback-btn {
    padding: 8px 24px;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
    border-radius: 12px; /* ปรับเป็นสี่เหลี่ยมขอบมน */
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
}
.feedback-btn:hover { background-color: #f3f4f6; }

.sources-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 16px 24px 16px;
}
.source-card {
    background-color: #f9fafb;
    border: 1px solid #f3f4f6;
    padding: 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s;
}
.source-card:hover { background-color: #f3f4f6; }
.source-card.more {
    grid-column: span 2;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}
.source-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}
.source-subtitle {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pro-badge {
    background-color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    color: #3b82f6;
}
.answer-text {
    padding: 0 16px;
    font-size: 15px;
    line-height: 1.6;
    color: #374151;
    margin-bottom: 16px;
}
.action-btns {
    display: flex;
    gap: 8px;
    padding: 0 16px;
}
.related-list {
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.related-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: #f9fafb;
    border-radius: 12px;
    font-size: 14px;
    color: #1f2937;
    cursor: pointer;
}

/* --- 7. Bottom Bar (Search Input) --- */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 50%; /* ตรึงให้อยู่กึ่งกลางเสมอ */
    transform: translateX(-50%); /* ตรึงให้อยู่กึ่งกลางเสมอ */
    width: 100%;
    max-width: 420px;
    background-color: #ffffff;
    padding: 12px 16px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 20;
}
.search-input {
    flex-grow: 1;
    display: flex;
    align-items: center;
    background-color: #f3f4f6;
    padding: 10px 16px;
    border-radius: 20px;
    gap: 10px;
}
.search-input input {
    border: none;
    background: transparent;
    font-size: 14px;
    outline: none;
    width: 100%;
    color: #1f2937;
}
.search-input i { color: #9ca3af; }
.send-btn {
    background-color: #3b82f6;
    color: white;
    border: none;
    width: 48px; /* ปรับความกว้างให้เป็นทรงสี่เหลี่ยมมากขึ้น */
    height: 40px;
    border-radius: 12px; /* ปรับเป็นสี่เหลี่ยมขอบมน */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.2);
    transition: background-color 0.2s, transform 0.1s;
}
.send-btn:active {
    transform: scale(0.95);
}
