/* =========================================================
   PROJECT CSS — รถถูกดี.com
   Structure:
   0) Tokens & Base
   1) Components (shared)
   2) Feature Sections (shared)
   3) Responsive: Mobile / Tablet / Desktop
   ========================================================= */

/* ========== 0) TOKENS & BASE ========== */
:root {
    /* สีหลักธีม */
    --c-blue-600: #0d6efd;
    --c-blue-700: #0b5ed7;
    --c-blue-200: rgba(13, 110, 253, .2);
    --c-blue-150: rgba(13, 110, 253, .15);
    --c-blue-100: rgba(13, 110, 253, .10);
    --c-blue-050: rgba(13, 110, 253, .08);

    --c-bg-grad-top: #ffffff;
    --c-bg-grad-bottom: #f0f8ff;

    /* เงา */
    --shadow-sm: 0 4px 10px var(--c-blue-100);
    --shadow-md: 0 6px 16px var(--c-blue-100);
    --shadow-lg: 0 10px 22px rgba(13, 110, 253, .18);
    --shadow-xl: 0 12px 30px rgba(0, 102, 255, .18);

    /* radius */
    --r-8: 8px;
    --r-10: 10px;
    --r-12: 12px;
    --r-14: 14px;
    --r-16: 16px;
    --r-pill: 999px;
}

/* รีเซ็ตนิดๆ ให้ฟอนต์ & ลิงก์ */
body {
    font-family: 'Prompt', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

a {
    text-decoration: none;
}

/* ยูทิลิตี้พื้นฐาน */
.text-center {
    text-align: center;
}

/* =========================================================
   1) COMPONENTS (shared across devices)
   ========================================================= */

/* History Modal */
.history-modal {
    background-color: #1b1664;
    border-radius: 12px;
    border: none
}

.history-header {
    position: sticky;
    top: 0;
    background: transparent;
    border-bottom: none;
    justify-content: center;
    padding: 1rem 1.5rem
}

.history-close {
    position: absolute;
    top: .75rem;
    left: .75rem;
    filter: invert(1)
}

.history-title {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700
}

.history-tabs {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem
}

.history-tab {
    flex: 1;
    padding: .5rem 1rem;
    border-radius: 50px;
    background: #ed1b24;
    color: #fff;
    font-weight: 500;
    border: none
}

.history-tab.active {
    background: #459407;
    color: #fff
}

.history-body {
    padding: .75rem .75rem 1.5rem
}

.history-empty {
    text-align: center;
    color: #eee;
    margin: 2rem 0;
    font-size: 1rem
}

.history-card {
    display: flex;
    background: #181059;
    border: 1px solid #fff;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem
}

.history-card .card-img {
    flex: 0 0 120px;
    background: rgba(255, 255, 255, .15)
}

.history-card .card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover
}

.history-card .card-info {
    flex: 1;
    padding: 1rem 1.25rem;
    color: #fff
}

/* Form custom */
.input-custom2 {
    background: #fff;
    color: #000;
    border: none
}

.input-custom2:focus {
    background: #fff !important;
    color: #000 !important
}

.input-custom2:focus+label {
    color: #000 !important
}

.form-floating .label {
    color: #000 !important;
    padding-left: .75rem
}

.form-floating .form-control:focus {
    box-shadow: none
}

.modal-dialog-centered {
    max-width: 500px
}

/* Load More Button */
#load-more-btn {
    --primary: var(--c-blue-600);
    --primary-dark: var(--c-blue-700);
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1.5rem;
    border: 2px solid var(--primary);
    border-radius: var(--r-pill);
    background: radial-gradient(120% 120% at 50% 0%, var(--c-blue-050), transparent 60%), #fff;
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: all .2s ease;
}

#load-more-btn:hover {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px)
}

#load-more-btn:active {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(0);
    box-shadow: 0 6px 14px rgba(11, 94, 215, .22)
}

#load-more-btn .chev {
    display: inline-block;
    transform: translateY(1px);
    transition: transform .2s ease
}

#load-more-btn:hover .chev {
    transform: translateY(3px)
}

#load-more-btn.is-loading {
    pointer-events: none;
    opacity: .95;
    background: var(--primary);
    color: #fff
}

#load-more-btn.is-loading .chev {
    display: none
}

#load-more-btn.is-loading::after {
    content: "";
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .6);
    border-top-color: #fff;
    display: inline-block;
    margin-left: .25rem;
    animation: spin .7s linear infinite;
}

#load-more-wrap {
    margin-top: 1.25rem
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

/* Global Fullscreen Loader */
#global-loader {
    position: fixed;
    inset: 0;
    z-index: 2147480000;
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s ease, visibility .15s ease
}

#global-loader.is-visible {
    opacity: 1;
    visibility: visible
}

#global-loader .gl-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 102, 255, .08);
    backdrop-filter: blur(1.5px)
}

#global-loader .gl-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)
}

#global-loader .gl-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 220px;
    padding: 20px 24px;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--c-bg-grad-top) 0%, var(--c-bg-grad-bottom) 100%);
    border: 1px solid var(--c-blue-150);
    box-shadow: var(--shadow-xl);
    animation: gl-pop .22s ease-out
}

#global-loader .gl-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid rgba(13, 110, 253, .25);
    border-top-color: var(--c-blue-600);
    animation: gl-spin .8s linear infinite
}

#global-loader .gl-text {
    color: var(--c-blue-600);
    font-weight: 600;
    font-size: 14px
}

@keyframes gl-spin {
    to {
        transform: rotate(360deg)
    }
}

@keyframes gl-pop {
    from {
        transform: scale(.96);
        opacity: .6
    }

    to {
        transform: scale(1);
        opacity: 1
    }
}

body.loading-overlay {
    overflow: hidden
}

/* ปิด loader เก่าในคอนเทนเนอร์ */
#loading-spinner,
#loading-spinner .spinner-overlay,
#loading-spinner .spinner-text {
    display: none !important
}

/* Magnific Popup theming (optional) */
.mfp-bg {
    background: rgba(10, 45, 87, 0.85);
}

/* พื้นหลังเข้มฟ้า */
.mfp-image-holder .mfp-close {
    color: #fff;
    text-shadow: none;
}

.mfp-arrow {
    opacity: .9;
}

.car-card-list {
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.car-card-list:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* =========================================================
   2) FEATURE SECTIONS (shared styles before responsive)
   ========================================================= */

/* Empty State: no-car */
.no-car-result {
    background: linear-gradient(180deg, var(--c-bg-grad-top) 0%, var(--c-bg-grad-bottom) 100%);
    border: 1px solid var(--c-blue-150);
    border-radius: var(--r-16);
    box-shadow: 0 6px 18px var(--c-blue-100);
    color: var(--c-blue-600);
    transition: transform .2s ease;
}

.no-car-result:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(13, 110, 253, .18)
}

.no-car-icon i {
    font-size: 48px;
    color: var(--c-blue-600);
    opacity: .8
}

.no-car-title {
    font-weight: 700;
    font-size: 1.25rem
}

.no-car-sub {
    font-size: .95rem;
    color: #0056b3
}

/* Type search (คง 4 คอลัมน์เดิม) */
.type-header {
    color: #24267a;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1rem
}

.type-box {
    background: linear-gradient(180deg, var(--c-bg-grad-top) 0%, var(--c-bg-grad-bottom) 100%);
    border: 1px solid var(--c-blue-200);
    border-radius: var(--r-10);
    padding: 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all .2s ease-in-out;
}

.type-box:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(13, 110, 253, .4)
}

.type-img {
    width: 100%;
    max-width: 120px;
    height: auto;
    transition: transform .2s ease
}

.type-box:hover .type-img {
    transform: scale(1.05)
}

/* Car info cells (ค่า default กลางๆ) */
.car-card-list .info-cell {
    min-height: auto;
    height: auto
}

.car-card-list .car-info-grid .info-cell .value,
.car-card-list .car-info-grid .info-cell .label {
    line-height: 1.25
}

/* =========================================================
   3) RESPONSIVE ZONES (Mobile-first)
   ========================================================= */

/* ---------- Mobile ≤ 768px ---------- */
@media (max-width: 768px) {

    /* Keep 4 columns on mobile as requested */
    .custom-gutter .col-3 {
        flex: 0 0 25%;
        max-width: 25%
    }

    .type-img {
        max-width: 90px
    }

    .type-box {
        padding: 2px
    }

    .mb-3 {
        margin-bottom: 2px !important
    }

    /* Clamp 2 lines on mobile (brand/model/year/gear) */
    .car-card-list .car-info-grid .info-cell .value,
    .car-card-list .car-info-grid .info-cell .label {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
    }

    /* Footer spacing ถ้าใช้ bottom bar แบบ sticky/fixed ให้ปรับใน JS ตามความสูงจริง */
    /* body { padding-bottom: 0 !important; }  // ใช้เมื่อต้องการตัดช่องว่างใต้ footer */
}

/* ---------- Tablet 768–991px ---------- */
@media (min-width: 769px) and (max-width: 991.98px) {

    /* ระยะและสเกลภาพให้สมดุลขึ้นบนแท็บเล็ต */
    .type-img {
        max-width: 110px
    }

    .type-box {
        padding: 10px;
        border-radius: 12px
    }

    /* แสดงข้อมูลได้มากกว่ามือถือ: คลาย clamp เหลือ 3 บรรทัด */
    .car-card-list .car-info-grid .info-cell .value,
    .car-card-list .car-info-grid .info-cell .label {
        -webkit-line-clamp: 3;
    }
}

/* ---------- Desktop ≥ 992px ---------- */
@media (min-width: 992px) {

    /* สัดส่วนไอคอนประเภท */
    .type-img {
        max-width: 140px
    }

    .type-box {
        padding: 12px;
        border-radius: 14px
    }

    /* Desktop แสดงเต็ม ไม่ต้อง clamp */
    .car-card-list .car-info-grid .info-cell .value,
    .car-card-list .car-info-grid .info-cell .label {
        display: block;
        /* ยกเลิก line-clamp */
        -webkit-line-clamp: unset;
        -webkit-box-orient: unset;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
    }

    /* โมดอล/การ์ดในหน้าประวัติ ให้สบายตาขึ้น */
    .history-card .card-img {
        flex: 0 0 140px
    }
}