/*
 * เฮงเฮง ปังจัง Lucky Draw — Global CSS
 * Design: พื้นขาว + แดง #FD1803 + เหลือง
 * Font: Kanit (ตัวสูงใหญ่)
 * Responsive: ทุกขนาดจอ
 */

/* ═══════════════════════════════════════════
   GOOGLE FONT
   ═══════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@400;600;800&display=swap');

/* ═══════════════════════════════════════════
   CSS VARIABLES
   ═══════════════════════════════════════════ */
:root {
    /* แดง (Brand) */
    --red:          #FD1803;
    --red-dark:     #D91403;
    --red-deep:     #B01002;
    --red-light:    rgba(253, 24, 3, 0.06);

    /* เหลือง */
    --yellow:       #FFD600;
    --yellow-light: #FFF3B0;

    /* ทอง */
    --gold:         #F7D37A;
    --gold-dark:    #C9963A;

    /* เขียว (Merchant) */
    --green:        #2ECC71;
    --green-dark:   #1A8F4B;
    --green-light:  rgba(46, 204, 113, 0.06);

    /* Neutral */
    --bg:           #F5F5F5;
    --white:        #FFFFFF;
    --text:         #1A1A1A;
    --text-secondary: #888888;
    --text-light:   #BBBBBB;
    --border:       #EEEEEE;
    --danger:       #FF3B30;

    /* Layout */
    --header-height: 64px;
    --nav-height:    72px;
    --max-width:     480px;
    --radius:        14px;
    --radius-lg:     20px;
    --shadow-sm:     0 1px 4px rgba(0,0,0,0.04);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg:     0 8px 30px rgba(0,0,0,0.08);
}

/* ═══════════════════════════════════════════
   RESET
   ═══════════════════════════════════════════ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Kanit', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { color: var(--red); text-decoration: none; }
a:hover { opacity: 0.85; }
img { max-width: 100%; height: auto; display: block; }
input, button, textarea, select {
    font-family: inherit;
    font-size: inherit;
}

/* ═══════════════════════════════════════════
   LAYOUT — App Shell (max 480px centered)
   ═══════════════════════════════════════════ */
.app-shell {
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--white);
    position: relative;
    box-shadow: 0 0 40px rgba(0,0,0,0.05);
}

.page-content {
    padding-bottom: calc(var(--nav-height) + 20px);
}

/* ═══════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--white);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    border-bottom: 1px solid var(--border);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 20px;
    font-weight: 800;
    flex-shrink: 0;
}

.logo-text {
    font-size: 17px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.logo-text small {
    display: block;
    font-size: 10px;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.header-btn {
    background: var(--yellow);
    color: var(--text);
    padding: 8px 18px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

.header-btn:hover {
    background: #E6C100;
}

.header-back {
    font-size: 20px;
    color: var(--text);
    cursor: pointer;
    padding: 4px;
}

.header-action {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: 0.2s;
}

.header-action:hover {
    background: var(--border);
}

/* ═══════════════════════════════════════════
   BOTTOM NAV
   ═══════════════════════════════════════════ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    background: var(--white);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
    padding: 6px 0 env(safe-area-inset-bottom, 12px);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    color: var(--text-light);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
    color: var(--red);
}

.nav-item i {
    font-size: 22px;
}

.nav-scan {
    margin-top: -24px;
}

.scan-fab {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--red);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 20px rgba(253, 24, 3, 0.3);
    border: 4px solid var(--bg);
    transition: 0.2s;
}

.scan-fab:active {
    transform: scale(0.95);
}

/* ═══════════════════════════════════════════
   HERO CARD (Red card with big text)
   ═══════════════════════════════════════════ */
.hero-card {
    margin: 12px 20px;
    border-radius: var(--radius-lg);
    background: var(--red);
    padding: 32px 24px;
    position: relative;
    overflow: hidden;
}

.hero-card::after {
    content: '🐻';
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 160px;
    opacity: 0.1;
    pointer-events: none;
}

.hero-card .hero-title {
    font-size: 32px;
    font-weight: 800;
    color: var(--white);
    line-height: 1.2;
    position: relative;
    z-index: 1;
}

.hero-card .hero-title .highlight {
    color: var(--yellow);
}

.hero-card .hero-sub {
    font-size: 14px;
    color: rgba(255,255,255,0.85);
    font-weight: 400;
    margin-top: 8px;
    position: relative;
    z-index: 1;
}

.hero-card .hero-btn {
    display: inline-block;
    margin-top: 18px;
    background: var(--white);
    color: var(--text);
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 800;
    position: relative;
    z-index: 1;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

.hero-card .hero-btn:hover {
    background: var(--bg);
}

/* ═══════════════════════════════════════════
   STATS BAR
   ═══════════════════════════════════════════ */
.stats-bar {
    display: flex;
    gap: 10px;
    margin: 16px 20px;
}

.stat-item {
    flex: 1;
    background: var(--white);
    border-radius: var(--radius);
    padding: 14px 8px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-item .stat-num {
    font-size: 24px;
    font-weight: 800;
    color: var(--red);
}

.stat-item .stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ═══════════════════════════════════════════
   SECTION
   ═══════════════════════════════════════════ */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 10px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
}

.section-header a,
.section-header .see-all {
    color: var(--red);
    font-size: 14px;
    font-weight: 600;
}

/* ═══════════════════════════════════════════
   CARD (Generic white card)
   ═══════════════════════════════════════════ */
.card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    margin: 0 20px 10px;
    transition: 0.2s;
}

.card:active {
    background: var(--bg);
}

.card-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--red-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--red);
    font-size: 22px;
    flex-shrink: 0;
}

.card-info {
    flex: 1;
    min-width: 0;
}

.card-info .card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-info .card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.card-arrow {
    color: var(--text-light);
    font-size: 14px;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 800;
    text-align: center;
    border: none;
    cursor: pointer;
    transition: 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.98);
}

.btn-red {
    background: var(--red);
    color: var(--white);
}

.btn-red:hover { background: var(--red-dark); }

.btn-green {
    background: var(--green);
    color: var(--white);
}

.btn-green:hover { background: var(--green-dark); }

.btn-outline {
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover { background: var(--bg); }

.btn-yellow {
    background: var(--yellow);
    color: var(--text);
}

.btn-line {
    background: #06C755;
    color: var(--white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* ═══════════════════════════════════════════
   BADGE / CHIP
   ═══════════════════════════════════════════ */
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-red {
    background: var(--red-light);
    color: var(--red);
    border: 1px solid rgba(253, 24, 3, 0.15);
}

.badge-green {
    background: var(--green-light);
    color: var(--green-dark);
    border: 1px solid rgba(46, 204, 113, 0.2);
}

.badge-gold {
    background: rgba(247, 211, 122, 0.15);
    color: var(--gold-dark);
    border: 1px solid var(--gold);
}

.badge-gray {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════
   FORM INPUTS
   ═══════════════════════════════════════════ */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    color: var(--text);
    outline: none;
    transition: 0.2s;
}

.form-input:focus {
    border-color: var(--red);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(253, 24, 3, 0.08);
}

.form-input::placeholder {
    color: var(--text-light);
}

/* ═══════════════════════════════════════════
   FEED ITEM
   ═══════════════════════════════════════════ */
.feed-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.feed-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--red);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    flex-shrink: 0;
}

.feed-content {
    flex: 1;
    min-width: 0;
}

.feed-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.feed-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════
   TOAST / ALERT
   ═══════════════════════════════════════════ */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-120%);
    background: var(--text);
    color: var(--white);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    transition: transform 0.3s ease;
    max-width: calc(100% - 40px);
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--green-dark); }
.toast.error { background: var(--danger); }

/* ═══════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════ */
.text-red { color: var(--red) !important; }
.text-green { color: var(--green-dark) !important; }
.text-gold { color: var(--gold-dark) !important; }
.text-muted { color: var(--text-secondary) !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.fw-300 { font-weight: 400; }
.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 600; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 800; }
.fw-800 { font-weight: 800; }
.fw-900 { font-weight: 800; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.px-20 { padding-left: 20px; padding-right: 20px; }
.py-20 { padding-top: 20px; padding-bottom: 20px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.hidden { display: none !important; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════════════════════════════════════
   LOADING SPINNER
   ═══════════════════════════════════════════ */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 40px auto;
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ═══════════════════════════════════════════
   RESPONSIVE — Mobile First
   ═══════════════════════════════════════════ */

/* เล็กมาก (iPhone SE) */
@media (max-width: 374px) {
    :root {
        --max-width: 100%;
    }
    .hero-card .hero-title {
        font-size: 26px;
    }
    .stat-item .stat-num {
        font-size: 20px;
    }
    .hero-card {
        margin: 10px 14px;
        padding: 24px 18px;
    }
    .card {
        margin: 0 14px 8px;
    }
    .section-header {
        padding: 16px 14px 8px;
    }
    .stats-bar {
        margin: 12px 14px;
    }
}

/* มือถือปกติ (375px - 480px) */
@media (min-width: 375px) and (max-width: 480px) {
    :root {
        --max-width: 100%;
    }
}

/* มือถือใหญ่ + Tablet เล็ก (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --max-width: 480px;
    }
    body {
        background: var(--bg);
    }
}

/* Tablet + Desktop (769px+) */
@media (min-width: 769px) {
    :root {
        --max-width: 480px;
    }
    body {
        background: #E8E8E8;
    }
    .app-shell {
        border-radius: 20px;
        margin-top: 20px;
        margin-bottom: 20px;
        overflow: hidden;
        box-shadow: 0 8px 40px rgba(0,0,0,0.08);
    }
    .bottom-nav {
        border-radius: 0 0 20px 20px;
    }
}

/* ═══════════════════════════════════════════
   SAFE AREA (iPhone notch)
   ═══════════════════════════════════════════ */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }
}

/* ═══════════════════════════════════════════
   PRINT (ซ่อน nav เวลา print)
   ═══════════════════════════════════════════ */
@media print {
    .bottom-nav,
    .app-header {
        display: none !important;
    }
    .page-content {
        padding-bottom: 0;
    }
}
