/* ================================
   ฟอนต์ + ตัวแปรสี
================================== */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;600;800&display=swap');

/* Light mode */
:root {
    --primary: #558b2f;
    --secondary: #c5e1a5;
    --accent: #ffca28;
    --bg: #f0f4c3;
    --text: #333333;
    --white: #ffffff;
    --navbar-bg: #ffffff;
    --font-main: 'Prompt', sans-serif;
}

/* Dark mode ตัวแปร */
[data-theme="dark"] {
    --primary: #81c784;
    --secondary: #2e7d32;
    --accent: #ffd54f;
    --bg: #121212;
    --text: #e0e0e0;
    --white: #1e1e1e;
    --navbar-bg: #1e1e1e;
}

/* ================================
   Global reset เล็ก ๆ
================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* บังคับให้ฟอนต์ในปุ่ม / ฟอร์มใช้ Prompt แน่นอน */
button,
input,
select,
textarea {
    font-family: var(--font-main) !important;
}

/* ================================
   Layout พื้นฐาน
================================== */
body {
    font-family: var(--font-main);
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 60px 20px 20px; /* top รวมเผื่อ navbar */
}

/* ================================
   NAVBAR (Desktop base)
================================== */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    background-color: var(--navbar-bg);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    z-index: 1000;
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* โลโก้ */
.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.nav-brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
}

.nav-brand-text {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary);
}

/* เมนูด้านขวา */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* กลุ่ม auth (guest / user) */
.auth-group {
    display: flex;
    align-items: center;
}

/* ================================
   ปุ่มหลัก ๆ
================================== */

.btn {
    padding: 8px 20px;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 600;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

[data-theme="dark"] .btn-primary {
    color: #000;
    font-weight: 700;
}

.btn-outline {
    border: 2px solid var(--primary);
    color: var(--primary);
    background: transparent;
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

.btn-danger {
    background: #ef5350;
    color: #fff;
}

/* ปุ่มเล็ก (ใช้ใน header) */
.btn.small {
    padding: 6px 14px;
    font-size: 0.9rem;
}

/* ================================
   ปุ่มเปลี่ยนธีม
================================== */
.theme-btn {
    background: var(--white);
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.theme-btn:hover {
    transform: rotate(15deg) scale(1.1);
}

[data-theme="dark"] .theme-btn {
    background: #333;
    border-color: #555;
    color: #ffd700;
}

/* ================================
   ปุ่มเปลี่ยนภาษา (lang switch)
================================== */
.lang-switch {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    border: 2px solid #d3e6b2;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    cursor: pointer;
    transition: 0.2s ease;
}

.lang-switch:hover {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

#lang-flag-img {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    object-fit: cover;
}

[data-theme="dark"] .lang-switch {
    background: #333;
    border-color: #555;
}

[data-theme="dark"] .lang-switch:hover {
    background: #444;
    box-shadow: 0 4px 10px rgba(0,0,0,0.45);
}

/* ================================
   FOOTER
================================== */
.site-footer {
    background-color: #37474f;
    color: #cfd8dc;
    text-align: center;
    padding: 30px 0;
    margin-top: auto;
}

.site-footer a {
    color: var(--secondary);
    text-decoration: none;
    margin: 0 10px;
}

/* ================================
   DARK MODE พื้นฐาน
================================== */
[data-theme="dark"] body {
    background-color: var(--bg);
    color: var(--text);
}

[data-theme="dark"] .navbar {
    background: #1a1a1a;
    border-bottom: 1px solid #333;
}

[data-theme="dark"] .nav-brand-text {
    color: #ffffff;
}

/* ให้หัวข้อเด่นขึ้นในโหมดมืด */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3 {
    color: #ffffff;
}

/* ================================
   Responsive: Tablet
================================== */
@media (max-width: 900px) {
    .navbar-container {
        padding: 10px 16px;
    }

    .nav-brand-text {
        font-size: 1rem;
    }
}

/* ================================
   Responsive: Mobile Navbar
================================== */
@media (max-width: 600px) {

    .navbar-container {
        padding: 10px 12px;
    }

    /* ซ่อนชื่อเว็บ เหลือแค่ icon */
    .nav-brand-text {
        display: none;
    }

    .nav-brand-logo {
        width: 36px;
        height: 36px;
    }

    /* เมนูขวาอยู่บรรทัดเดียวกับโลโก้ */
    .nav-menu {
        margin-left: auto;
        gap: 6px;
    }

    .theme-btn,
    .lang-switch {
        width: 32px;
        height: 32px;
    }

    /* ปุ่มเข้าสู่ระบบ / สมัครสมาชิก อยู่บรรทัดเดียวกัน */
    .auth-group .btn.small {
        padding: 6px 12px;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* กันชื่อ user ยาวไปในกรณีล็อกอินแล้ว */
    #user-name {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8rem;
    }
}

/* ================================
   USER DROPDOWN (ใหม่)
================================== */

.nav-user,
.auth-group {
    position: relative;
}

/* ปุ่มที่กดแล้วเปิดเมนู */
.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    font-family: var(--font-main);
    border-radius: 999px;
    transition: background 0.18s ease, transform 0.12s ease;
}

.user-dropdown-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

[data-theme="dark"] .user-dropdown-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.dropdown-arrow {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* กล่องเมนู */
.user-dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--white);
    border-radius: 14px;
    box-shadow:
        0 18px 45px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: 6px 6px 8px;
    width: 210px;
    z-index: 1000;
}

/* ลูกศรเล็กด้านบนเมนู */
.user-dropdown-menu::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 26px;
    width: 10px;
    height: 10px;
    background: inherit;
    transform: rotate(45deg);
    border-radius: 2px;
    box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.04);
}

.user-dropdown-menu.hidden {
    display: none;
}

/* รายการเมนูแต่ละอัน */
.dropdown-item {
    display: block;
    padding: 8px 10px;
    margin: 2px 4px;
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

.dropdown-item:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

/* รายการระหว่างกลางมีระยะห่างนิดหน่อย */
.dropdown-item + .dropdown-item {
    margin-top: 4px;
}

/* ปุ่ม Logout ให้ดูเป็น danger แต่ไม่แดงทั้งแท่ง */
.dropdown-item.logout {
    margin-top: 6px;
    border-top: 1px solid rgba(0,0,0,0.06);
    font-weight: 600;
    color: #c62828;
}

/* hover logout */
.dropdown-item.logout:hover {
    background: #ffebee;
    color: #b71c1c;
}

/* ----- DARK MODE STYLE ----- */
[data-theme="dark"] .user-dropdown-menu {
    background: #262626;
    box-shadow:
        0 16px 40px rgba(0, 0, 0, 0.85),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .user-dropdown-menu::before {
    box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .dropdown-item {
    color: #f5f5f5;
}

[data-theme="dark"] .dropdown-item:hover {
    background: #333;
}

[data-theme="dark"] .dropdown-item.logout {
    border-top-color: rgba(255,255,255,0.08);
    color: #ff8a80;
}

[data-theme="dark"] .dropdown-item.logout:hover {
    background: #4a1d1d;
    color: #ffb3b0;
}

/* ================================
   ชื่อผู้ใช้บน Header
================================== */

#user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);   /* โหมดปกติ = ใช้สีตัวหนังสือหลัก */
}

/* ใน Dark mode ให้เด่นขึ้นหน่อย */
[data-theme="dark"] #user-name {
    color: var(--accent);  /* ถ้าอยากให้ขาวล้วน ใช้ #ffffff ก็ได้ */
}