/**
 * ทำนายเบอร์.com — Design System v5.0
 * ✦ Red / Crimson / Clean White
 * ✦ No gradients — solid flat colors
 * ✦ High contrast text
 * Max width: 520px (mobile-first PWA)
 */

/* ============================================
   CSS Variables / Design Tokens
   ============================================ */
:root {
    /* ── Red Palette ── */
    --red-900: #7F1D1D;
    --red-800: #991B1B;
    --red-700: #B91C1C;
    --red-600: #DC2626;
    --red-500: #EF4444;
    --red-400: #F87171;
    --red-300: #FCA5A5;
    --red-200: #FECACA;
    --red-100: #FEE2E2;
    --red-50: #FEF2F2;

    /* ── Semantic Colors ── */
    --color-primary: #DC2626;
    --color-primary-light: #EF4444;
    --color-primary-dark: #B91C1C;
    --color-primary-bg: #FEF2F2;

    --color-bg: #FFFFFF;
    --color-bg-alt: #FAFAFA;
    --color-bg-body: #F5F5F5;
    --color-bg-card: #FFFFFF;
    --color-bg-warm: #FEF2F2;

    --color-text: #111111;
    --color-text-secondary: #555555;
    --color-text-muted: #999999;
    --color-text-white: #FFFFFF;

    --color-border: #E5E5E5;
    --color-border-light: #F0F0F0;

    --color-success: #16A34A;
    --color-success-bg: #ECFDF5;
    --color-warning: #D97706;
    --color-warning-bg: #FFFBEB;
    --color-error: #DC2626;
    --color-error-bg: #FEF2F2;
    --color-info: #2563EB;
    --color-info-bg: #EFF6FF;

    /* ── Grade Colors ── */
    --grade-aplus: #FFD700;
    --grade-a: #F59E0B;
    --grade-bplus: #22C55E;
    --grade-b: #3B82F6;
    --grade-cplus: #8B5CF6;
    --grade-c: #F59E0B;
    --grade-dplus: #78716C;
    --grade-d: #EF4444;
    --grade-f: #6B7280;

    /* ── Typography ── */
    --font-primary: 'Prompt', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-xs: 0.85rem;
    --font-size-sm: 0.95rem;
    --font-size-base: 1.05rem;
    --font-size-md: 1.2rem;
    --font-size-lg: 1.4rem;
    --font-size-xl: 1.7rem;
    --font-size-2xl: 2.1rem;
    --font-size-3xl: 2.6rem;

    /* ── Spacing ── */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 14px;
    --space-lg: 20px;
    --space-xl: 28px;
    --space-2xl: 40px;
    --space-3xl: 56px;

    /* ── Layout ── */
    --max-width: 520px;
    --header-height: 56px;
    --nav-height: 64px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    /* ── Shadows ── */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-bottom-nav: 0 -1px 4px rgba(0, 0, 0, 0.06);

    /* ── Transitions ── */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================
   Reset & Base
   ============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    background: var(--color-bg-body);
}

body {
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.7;
    max-width: var(--max-width);
    margin: 0 auto;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ============================================
   App Header — Clean White / Logo Centered
   ============================================ */
.app-header {
    position: relative;
    z-index: 100;
    background: var(--color-bg);
    padding: var(--space-lg) 0;
    border-bottom: 1px solid var(--color-border-light);
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: var(--space-sm) var(--space-lg);
}

.app-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    color: var(--color-primary);
    font-size: var(--font-size-lg);
    font-weight: 800;
    text-decoration: none;
}

.app-logo i {
    font-size: 1.4em;
    color: var(--color-primary);
}

.app-logo span {
    color: var(--color-text);
    letter-spacing: -0.3px;
}

.app-logo:hover {
    color: var(--color-primary);
}

/* Logo image */
.app-logo-img {
    max-height: 170px;
    width: auto;
    display: block;
}

.app-header-actions {
    position: absolute;
    right: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.header-icon {
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    transition: all var(--transition-fast);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
}

.header-icon:hover {
    color: var(--color-primary);
    background: var(--color-primary-bg);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    min-height: calc(100vh - var(--nav-height));
    padding-bottom: calc(var(--nav-height) + var(--space-xl));
    background: var(--color-bg);
}

/* ============================================
   Bottom Navigation — Deep Red
   ============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    height: var(--nav-height);
    background: var(--red-700);
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    font-size: var(--font-size-xs);
    gap: 2px;
    transition: all var(--transition-fast);
    position: relative;
}

.bottom-nav-item i {
    font-size: 1.25rem;
}

.bottom-nav-item span {
    font-weight: 500;
}

.bottom-nav-item:hover {
    color: rgba(255, 255, 255, 0.9);
}

.bottom-nav-item.active {
    color: #FFFFFF;
    font-weight: 700;
}

.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    background: #FFFFFF;
    border-radius: 0 0 4px 4px;
}

/* ============================================
   Flash Messages
   ============================================ */
.flash-message {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    animation: slideDown 0.3s ease;
}

.flash-success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.flash-error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.flash-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.flash-info {
    background: var(--color-info-bg);
    color: var(--color-info);
}

.flash-close {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    padding: 4px;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   Typography
   ============================================ */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.35;
    color: var(--color-text);
}

h1 {
    font-size: var(--font-size-2xl);
}

h2 {
    font-size: var(--font-size-xl);
}

h3 {
    font-size: var(--font-size-lg);
}

h4 {
    font-size: var(--font-size-md);
}

.section-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xl) var(--space-lg) var(--space-md);
    font-size: var(--font-size-md);
    font-weight: 800;
    color: var(--color-text);
}

.section-title i {
    color: var(--color-primary);
    font-size: 1.1em;
}

.section-title .view-all {
    margin-left: auto;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-primary);
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
    border: 1px solid var(--color-border-light);
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.card-body {
    padding: var(--space-lg);
}

.card-title {
    font-size: var(--font-size-base);
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.card-text {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    line-height: 1.6;
}

/* ============================================
   Buttons — Solid Colors, Pill Shape
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: var(--font-size-sm);
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-text-white);
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.2);
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
    color: var(--color-text-white);
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-sm);
}

.btn-lg {
    padding: var(--space-lg) var(--space-2xl);
    font-size: var(--font-size-md);
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: var(--space-xl);
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 700;
    margin-bottom: var(--space-sm);
    color: var(--color-text);
}

.form-input {
    width: 100%;
    padding: 12px var(--space-lg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

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

.form-input-lg {
    padding: var(--space-lg) var(--space-xl);
    font-size: var(--font-size-lg);
    text-align: center;
    letter-spacing: 3px;
    font-weight: 700;
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-error);
    margin-top: var(--space-xs);
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 12px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 700;
    white-space: nowrap;
}

.badge-default {
    background: var(--color-bg-alt);
    color: var(--color-text-secondary);
}

.badge-primary {
    background: var(--color-primary-bg);
    color: var(--color-primary);
}

.badge-success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.badge-error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

/* Grade Badges */
.grade-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    font-weight: 900;
    font-size: var(--font-size-sm);
    color: white;
}

.grade-aplus {
    background: #FFD700;
    color: #111;
}

.grade-a {
    background: #F59E0B;
    color: #111;
}

.grade-bplus {
    background: #22C55E;
}

.grade-b {
    background: #3B82F6;
}

.grade-cplus {
    background: #8B5CF6;
}

.grade-c {
    background: #F59E0B;
    color: #111;
}

.grade-dplus {
    background: #78716C;
}

.grade-d {
    background: #EF4444;
}

.grade-f {
    background: #6B7280;
}

/* ============================================
   Utility Classes
   ============================================ */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--color-text-muted);
}

.text-primary {
    color: var(--color-primary);
}

.text-success {
    color: var(--color-success);
}

.text-error {
    color: var(--color-error);
}

.text-sm {
    font-size: var(--font-size-sm);
}

.text-xs {
    font-size: var(--font-size-xs);
}

.text-lg {
    font-size: var(--font-size-lg);
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.mt-0 {
    margin-top: 0;
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mt-xl {
    margin-top: var(--space-xl);
}

.mb-0 {
    margin-bottom: 0;
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.mb-xl {
    margin-bottom: var(--space-xl);
}

.p-md {
    padding: var(--space-md);
}

.p-lg {
    padding: var(--space-lg);
}

.p-xl {
    padding: var(--space-xl);
}

.px-lg {
    padding-left: var(--space-lg);
    padding-right: var(--space-lg);
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

.hidden {
    display: none;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--space-md);
}

.grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: var(--space-sm);
}

/* ============================================
   Spinner
   ============================================ */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
    color: var(--color-text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: var(--space-lg);
    opacity: 0.3;
    color: var(--color-primary);
}

.empty-state p {
    font-size: var(--font-size-base);
}

/* Empty State Card — Enhanced */
.empty-state-card {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
    margin: var(--space-lg);
    background: var(--color-bg);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-lg);
}

.empty-state-card .empty-state-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FEE2E2, #FECACA);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-lg);
}

.empty-state-card .empty-state-icon i {
    font-size: 28px;
    color: var(--color-primary);
}

.empty-state-card h3 {
    font-size: var(--font-size-md);
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.empty-state-card p {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    line-height: 1.7;
    margin-bottom: var(--space-xl);
}

.empty-state-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 28px;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-primary);
    background: white;
    border: 2px solid var(--color-primary);
    text-decoration: none;
    transition: all 0.25s ease;
}

.empty-state-btn:hover {
    background: var(--color-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(220, 38, 38, 0.25);
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-xl) var(--space-lg);
}

.pagination a,
.pagination span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.pagination a:hover {
    background: var(--color-primary-bg);
    color: var(--color-primary);
}

.pagination .active {
    background: var(--color-primary);
    color: var(--color-text-white);
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

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

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease forwards;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease forwards;
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

/* ============================================
   Misc
   ============================================ */
.section-divider {
    height: 8px;
    background: var(--color-bg-alt);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border-light);
    overflow-x: auto;
    white-space: nowrap;
}

.breadcrumb a {
    color: var(--color-text-muted);
}

.breadcrumb a:hover {
    color: var(--color-primary);
}

.breadcrumb .fa-chevron-right {
    font-size: 0.6rem;
    opacity: 0.4;
}

.breadcrumb-current {
    color: var(--color-text);
    font-weight: 600;
}