:root {
    --navy: #1a2240;
    --navy-light: #243058;
    --navy-mid: #2e3d6e;
    --gold: #c9a84c;
    --gold-light: #e8c96b;
    --gold-dim: #a07a30;
    --bg: #f0f4fb;
    --surface: #ffffff;
    --surface2: #f5f8ff;
    --border: rgba(30, 48, 110, 0.12);
    --text: #1a2240;
    --text-sec: #4a5578;
    --text-mute: #8896b8;
    --card-shadow: 0 2px 16px rgba(26,34,64,0.08);
}
[data-theme="dark"] {
    --bg: #0d1120;
    --surface: #161d33;
    --surface2: #1d2640;
    --border: rgba(200,210,255,0.1);
    --text: #e8eeff;
    --text-sec: #a0aec8;
    --text-mute: #5a6888;
    --card-shadow: 0 2px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
    font-family: 'Kanit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
    -webkit-user-select: none; user-select: none;
}
input[type="text"], select { -webkit-user-select: auto; user-select: auto; }

/* ─── Header ─── */
.site-header {
    background: var(--navy);
    padding: 0;
    position: sticky; top: 0; z-index: 100;
    border-bottom: 2px solid var(--gold-dim);
}
.header-inner {
    max-width: 1400px; margin: 0 auto;
    padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.header-brand {
    display: flex; align-items: center; gap: 12px;
}
.header-logo {
    width: 42px; height: 42px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(232,201,107,0.32);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    padding: 4px;
    flex-shrink: 0;
}
.header-logo-img { width: 100%; height: 100%; display: block; }
.header-title h1 {
    font-size: clamp(14px, 2.5vw, 18px);
    font-weight: 600; color: #ffffff; line-height: 1.2;
}
.header-title p {
    font-size: 11px; color: var(--gold-light);
    font-weight: 400; opacity: 0.85;
}
.header-right { display: flex; align-items: center; gap: 10px; }

.live-clock {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px; padding: 6px 12px;
}
.live-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; flex-shrink: 0;
    box-shadow: 0 0 0 0 rgba(74,222,128,0.4);
    animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0.4); }
    50% { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
}
.clock-text { font-size: 12px; color: rgba(255,255,255,0.75); font-weight: 400; font-family: monospace; }

.theme-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px; padding: 7px 10px;
    color: rgba(255,255,255,0.8); cursor: pointer;
    font-size: 16px; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.theme-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }

/* ─── Hero Banner ─── */
.hero {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, #1e3a5f 100%);
    padding: 34px 24px 48px;
    text-align: center;
    border-bottom: 1px solid rgba(201,168,76,0.25);
}
.hero-logo {
    width: 100px; height: 100px;
    display: block; margin: 0 auto 14px;
    filter: drop-shadow(0 10px 26px rgba(0,0,0,0.28));
}
.season-badge {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(201,168,76,0.15);
    border: 1px solid rgba(201,168,76,0.35);
    color: var(--gold-light);
    padding: 5px 14px; border-radius: 20px;
    font-size: 12px; font-weight: 500; margin-bottom: 16px;
}
.hero h2 {
    font-size: clamp(22px, 4vw, 36px);
    font-weight: 700; color: #fff;
    line-height: 1.3; margin-bottom: 8px;
}
.hero p { font-size: 14px; color: rgba(255,255,255,0.6); margin-bottom: 28px; }

.stats-row {
    display: flex; align-items: center; justify-content: center; gap: 0;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px; overflow: hidden;
    max-width: 360px; margin: 0 auto 24px;
}
.stat-box { padding: 16px 32px; flex: 1; text-align: center; }
.stat-box + .stat-box { border-left: 1px solid rgba(255,255,255,0.12); }
.stat-label { font-size: 11px; color: rgba(255,255,255,0.55); font-weight: 400; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-num { font-size: 28px; font-weight: 700; color: #fff; line-height: 1; }
.stat-num.gold { color: var(--gold-light); }

/* ─── Next Queue Banner ─── */
.next-banner {
    background: var(--surface);
    border-left: 4px solid var(--gold);
    border-radius: 12px;
    margin: 24px auto;
    max-width: 1400px; padding: 20px 24px;
    display: none;
    align-items: flex-start; gap: 20px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--gold);
    box-shadow: var(--card-shadow);
}
.next-banner.visible { display: flex; }
.next-icon {
    width: 52px; height: 52px; flex-shrink: 0;
    background: linear-gradient(135deg, #1e4799, #2563eb);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 22px;
}
.next-content { flex: 1; min-width: 0; }
.next-label {
    font-size: 11px; font-weight: 600; color: #2563eb;
    text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px;
    display: flex; align-items: center; gap: 6px;
}
[data-theme="dark"] .next-label { color: #93c5fd; }
#nq-monk.pending { color: #dc2626; }
[data-theme="dark"] #nq-monk.pending { color: #f87171; }
.next-title { font-size: clamp(16px, 2.5vw, 22px); font-weight: 600; color: var(--text); margin-bottom: 10px; }
.next-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.meta-chip {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 20px; padding: 5px 12px;
    font-size: 12px; color: var(--text-sec);
}
.zoom-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: #2D8CFF; color: white;
    border-radius: 24px; padding: 9px 20px;
    font-size: 13px; font-weight: 500; text-decoration: none;
    transition: opacity 0.2s;
}
.zoom-btn:hover { opacity: 0.88; }

/* ─── Content Area ─── */
.content-area { max-width: 1400px; margin: 0 auto; padding: 0 24px 40px; }

/* ─── Filter Bar ─── */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 18px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 16px; color: var(--text-mute); }
.search-input {
    width: 100%; padding: 8px 12px 8px 38px;
    border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; font-family: 'Kanit', sans-serif;
    background: var(--bg); color: var(--text);
    outline: none; transition: border 0.2s;
}
.search-input:focus { border-color: #2563eb; }
.filter-select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 13px; font-family: 'Kanit', sans-serif;
    background: var(--bg); color: var(--text);
    outline: none; cursor: pointer; min-width: 160px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238896b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
.result-count { font-size: 13px; color: var(--text-mute); white-space: nowrap; }

/* ─── Section Header (Week group) ─── */
.week-section { margin-bottom: 28px; }
.week-header {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 14px;
}
.week-label {
    font-size: 13px; font-weight: 600; color: var(--text-mute);
    text-transform: uppercase; letter-spacing: 0.07em; white-space: nowrap;
}
.week-line { flex: 1; height: 1px; background: var(--border); }
.week-count {
    font-size: 12px; font-weight: 500;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-mute); padding: 2px 10px; border-radius: 12px; white-space: nowrap;
}

/* ─── Card Grid ─── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
/* Saturday = blue accent, Sunday = gold accent */
.temple-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex; flex-direction: column;
}
.temple-card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(26,34,64,0.13); }
.temple-card.timeline-past { opacity: 0.68; }
.temple-card.timeline-next { border-color: rgba(37,99,235,0.45); box-shadow: 0 0 0 2px rgba(37,99,235,0.12), var(--card-shadow); }
.temple-card.timeline-future { border-color: rgba(34,197,94,0.2); }
.temple-card.timeline-past .temple-name { color: var(--text-mute); }
.temple-card.timeline-past .accent-stripe { background: #94a3b8; }
[data-theme="dark"] .temple-card.timeline-next { box-shadow: 0 0 0 2px rgba(147,197,253,0.2), var(--card-shadow); }
[data-theme="dark"] .temple-card:hover { box-shadow: 0 6px 24px rgba(0,0,0,0.5); }

.card-top {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-no-badge {
    min-width: 32px; height: 32px;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sat .card-no-badge { background: rgba(37,99,235,0.12); color: #2563eb; }
.sun .card-no-badge { background: rgba(201,168,76,0.15); color: var(--gold-dim); }
[data-theme="dark"] .sat .card-no-badge { background: rgba(37,99,235,0.2); color: #93c5fd; }
[data-theme="dark"] .sun .card-no-badge { background: rgba(201,168,76,0.2); color: var(--gold-light); }

.day-badge {
    font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 12px;
    letter-spacing: 0.04em;
    white-space: nowrap; flex-shrink: 0;
}
.sat .day-badge { background: rgba(37,99,235,0.1); color: #2563eb; }
.sun .day-badge { background: rgba(201,168,76,0.15); color: var(--gold-dim); }
[data-theme="dark"] .sat .day-badge { background: rgba(37,99,235,0.2); color: #93c5fd; }
[data-theme="dark"] .sun .day-badge { background: rgba(201,168,76,0.2); color: var(--gold-light); }

.status-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.filled { background: #22c55e; }
.status-dot.empty { background: #ef4444; }
.timeline-badge {
    display: inline-flex; align-items: center; gap: 5px;
    border-radius: 999px; padding: 4px 9px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
    margin-left: auto;
}
.timeline-badge span { font-size: 10px; line-height: 1; }
.timeline-badge.past { background: rgba(148,163,184,0.18); color: #64748b; }
.timeline-badge.next { background: rgba(37,99,235,0.12); color: #1d4ed8; }
.timeline-badge.future { background: rgba(34,197,94,0.12); color: #15803d; }
.timeline-badge.unknown { background: rgba(245,158,11,0.14); color: #b45309; }
[data-theme="dark"] .timeline-badge.past { color: #cbd5e1; }
[data-theme="dark"] .timeline-badge.next { color: #93c5fd; }
[data-theme="dark"] .timeline-badge.future { color: #86efac; }
[data-theme="dark"] .timeline-badge.unknown { color: #fcd34d; }

.card-body { padding: 14px 16px 12px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.temple-name {
    font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.3;
}
.temple-name.available { color: #dc2626; }
[data-theme="dark"] .temple-name.available { color: #f87171; }

.info-row { display: flex; align-items: flex-start; gap: 8px; }
.info-icon { font-size: 14px; color: var(--text-mute); flex-shrink: 0; margin-top: 2px; }
.info-text { font-size: 13px; color: var(--text-sec); line-height: 1.4; }
.info-text.pending { color: #dc2626; font-style: italic; }
.timeline-row {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; padding: 7px 9px; margin-top: 2px;
}
.timeline-text { font-weight: 500; }
.timeline-past .timeline-row { background: rgba(148,163,184,0.1); }
.timeline-next .timeline-row { background: rgba(37,99,235,0.08); border-color: rgba(37,99,235,0.18); }
.timeline-future .timeline-row { background: rgba(34,197,94,0.08); border-color: rgba(34,197,94,0.16); }
[data-theme="dark"] .info-text.pending { color: #f87171; }

.card-footer {
    padding: 10px 16px;
    background: var(--surface2);
    border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.round-label { font-size: 12px; color: var(--text-mute); }
.round-num { font-size: 13px; font-weight: 600; color: var(--text-sec); }

/* ─── Accent stripe ─── */
.sat .accent-stripe { height: 3px; background: #2563eb; }
.sun .accent-stripe { height: 3px; background: var(--gold); }

/* ─── Empty State ─── */
.empty-state {
    text-align: center; padding: 60px 24px; color: var(--text-mute);
    font-size: 15px;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

/* ─── Loading ─── */
.loading-state { text-align: center; padding: 60px 24px; color: var(--text-mute); }
.spinner {
    width: 32px; height: 32px; border: 3px solid var(--border);
    border-top-color: #2563eb; border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Weekend Pair ─── */
.weekend-pair {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
    margin-bottom: 14px;
}
@media (max-width: 640px) { .weekend-pair { grid-template-columns: 1fr; } }

/* ─── Footer ─── */
.site-footer {
    background: var(--navy); color: rgba(255,255,255,0.5);
    text-align: center; padding: 20px; font-size: 13px;
}
.site-footer span { color: var(--gold-light); }

/* ─── Scroll to top ─── */
#scrollBtn {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--navy); color: var(--gold);
    border: 2px solid var(--gold-dim); border-radius: 50%;
    width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
    font-size: 18px; cursor: pointer; z-index: 200;
    opacity: 0; transform: translateY(20px); pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
#scrollBtn.visible { opacity: 1; transform: translateY(0); pointer-events: all; }

/* ─── Flag ─── */
.flag-wrap {
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
    border-radius: 7px; padding: 5px 8px; font-size: 17px; line-height: 1;
}

@media (max-width: 600px) {
    .hero { padding: 26px 16px 36px; }
    .hero-logo { width: 64px; height: 64px; }
    .card-top {
        display: grid;
        grid-template-columns: 54px minmax(96px, max-content) 1fr;
        align-items: center;
        justify-content: stretch;
        gap: 10px 12px;
        padding: 16px 18px 14px;
    }
    .card-no-badge {
        width: 44px; height: 44px; min-width: 44px;
        border-radius: 12px; font-size: 15px;
    }
    .day-badge {
        min-width: 88px; height: 44px;
        padding: 0 14px;
        border-radius: 18px;
        display: inline-flex; align-items: center; justify-content: center;
        font-size: 15px; line-height: 1;
    }
    .status-dot {
        grid-column: 3;
        grid-row: 1;
        justify-self: start;
    }
    .timeline-badge {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%; min-height: 40px;
        justify-content: center; order: initial; margin-left: 0;
        font-size: 14px; padding: 9px 14px;
    }
    .timeline-badge span { font-size: 12px; }
    .content-area { padding: 0 14px 40px; }
    .filter-bar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 14px;
        border-radius: 14px;
        overflow: hidden;
    }
    .filter-bar > * { min-width: 0; }
    .search-wrap {
        width: 100%;
        min-width: 0;
    }
    .search-icon {
        left: 14px;
        font-size: 18px;
    }
    .search-input {
        height: 52px;
        padding: 0 14px 0 46px;
        border-radius: 12px;
        font-size: 16px;
        line-height: 1.2;
        -webkit-text-size-adjust: 100%;
    }
    .search-input::placeholder {
        font-size: 16px;
        opacity: 0.72;
    }
    .filter-select {
        width: 100%;
        min-width: 0;
        height: 52px;
        padding: 0 42px 0 14px;
        border-radius: 12px;
        font-size: 16px;
        line-height: 1.2;
        background-position: right 14px center;
        -webkit-text-size-adjust: 100%;
    }
    .result-count {
        width: 100%;
        font-size: 15px;
        padding: 2px 2px 0;
        white-space: normal;
    }
    .next-banner { flex-direction: column; }
    .header-inner { padding: 10px 16px; }
}

.next-area { padding-top: 20px; padding-bottom: 0; }
.main-area { padding-top: 20px; }
.user-flag { font-size: 16px; }
.next-live-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; display: inline-block;
    animation: pulse-green 2s infinite;
}
.nq-no-container { opacity: 0.6; }
