/* ============================================
   ເກມລ໋ອດໂຕ໊ - Mobile-First App Style CSS
   ============================================ */

/* Google Noto Sans Lao Font */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Lao:wght@400;500;600;700;800;900&display=swap');

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img, svg, video, canvas, table, input, select, textarea { max-width: 100%; height: auto; }

:root {
    --primary: #e63946;
    --primary-dark: #c1121f;
    --success: #2a9d8f;
    --warning: #f4a261;
    --danger: #e76f51;
    --bg: #f8f9fa;
    --card-bg: #ffffff;
    --text: #1d3557;
    --text-light: #6c757d;
    --border: #dee2e6;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --font: 'Noto Sans Lao', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; }
body, input, select, button, textarea, table, th, td, .form-input, .btn, .amount-btn, .game-tab, .num-cell, .digit-box, .whatsapp-input {
    font-family: var(--font);
}
body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 70px;
    overflow-x: hidden;
    word-break: break-word;
}

/* --- Typography --- */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }

/* --- Header --- */
.app-header {
    background: var(--primary);
    color: #fff;
    padding: 12px 16px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.app-header h1 { font-size: 1.1rem; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .subtitle { font-size: 0.7rem; opacity: 0.85; }

/* --- Cards --- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px;
    margin: 8px 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; min-height: 36px; }
.btn-lg { padding: 16px 32px; font-size: 1.15rem; min-height: 56px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: var(--text);
}
.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font);
    background: var(--card-bg);
    transition: border-color 0.2s;
    -webkit-appearance: none;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
}
.form-input.error { border-color: var(--danger); }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 4px; }
select.form-input { cursor: pointer; }

/* --- Game Type Tabs --- */
.game-tabs {
    display: flex;
    gap: 8px;
    margin: 12px;
}
.game-tab {
    flex: 1;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    background: var(--card-bg);
    transition: all 0.2s;
    font-family: var(--font);
}
.game-tab.active {
    border-color: var(--primary);
    background: #fef0f0;
    color: var(--primary);
}
.game-tab .ratio { font-size: 0.75rem; color: var(--text-light); font-weight: 400; }

/* --- Number Grid (2D) --- */
.number-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 12px;
}
.num-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text);
    min-width: 44px;
    min-height: 44px;
}
.num-cell:active { transform: scale(0.93); }
.num-cell.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.num-cell.locked { background: #f1f3f5; color: #adb5bd; border-color: #e9ecef; pointer-events: none; text-decoration: line-through; }

/* 3D number input */
.number-input-3d {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 20px 12px;
}
.digit-box {
    width: 72px;
    height: 88px;
    border: 3px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    font-family: var(--font);
    text-align: center;
    background: var(--card-bg);
    transition: border-color 0.2s;
}
.digit-box:focus { border-color: var(--primary); outline: none; }

/* --- Amount Selector --- */
.amount-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 12px;
}
.amount-btn {
    flex: 1;
    min-width: 60px;
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    font-family: var(--font);
}
.amount-btn.active { border-color: var(--primary); background: #fef0f0; color: var(--primary); }

.amount-input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    font-family: var(--font);
}
.amount-input:focus { outline: none; border-color: var(--primary); }

/* --- Bet Summary --- */
.bet-summary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px;
    text-align: center;
}
.bet-summary .number-display { font-size: 2.5rem; font-weight: 800; letter-spacing: 4px; }
.bet-summary .payout-info { font-size: 0.9rem; opacity: 0.9; margin-top: 4px; }
.bet-summary .btn { margin-top: 12px; background: #fff; color: var(--primary); }

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    z-index: 100;
    padding: 2px 0;
    padding-bottom: env(safe-area-inset-bottom);
    overflow: hidden;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 2px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.6rem;
    font-weight: 500;
    transition: color 0.2s;
    gap: 2px;
    white-space: nowrap;
}
.nav-item.active { color: var(--primary); }
.nav-item .nav-icon { font-size: 1.2rem; }

/* --- Alert / Toast --- */
/* Inline message (inside forms/pages) */
.msg-inline {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 12px;
    word-break: break-word;
}
.msg-inline.success { background: var(--success); }
.msg-inline.error { background: var(--danger); }
.msg-inline.warning { background: var(--warning); }

/* Popup toast (JS injected, screen center) */
.toast {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    pointer-events: none;
}
.toast > span {
    padding: 14px 22px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    max-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: fadeIn 0.25s ease;
    word-break: break-word;
}
.toast.success > span { background: var(--success); }
.toast.error > span { background: var(--danger); }
.toast.warning > span { background: var(--warning); }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-primary { background: #fef0f0; color: var(--primary); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-light); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; background: var(--bg); white-space: nowrap; }
tr:active { background: #f8f9fa; }

/* --- Stats Cards --- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 12px; }
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px 8px;
    box-shadow: var(--shadow);
    text-align: center;
    overflow: hidden;
}
.stat-card .stat-value { font-size: 1.2rem; font-weight: 800; color: var(--primary); white-space: nowrap; }
.stat-card .stat-label { font-size: 0.65rem; color: var(--text-light); margin-top: 2px; }

/* --- Balance Display --- */
.balance-bar {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin: 8px 12px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}
.balance-amount { font-size: 1.2rem; font-weight: 800; color: var(--success); white-space: nowrap; }
.balance-label { font-size: 0.7rem; color: var(--text-light); }

/* --- WhatsApp Entry --- */
.whatsapp-entry {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    gap: 20px;
}
.whatsapp-entry .icon { font-size: 4rem; }
.whatsapp-entry h2 { font-size: 1.3rem; }
.whatsapp-input {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.1rem;
    text-align: center;
    font-family: var(--font);
    letter-spacing: 1px;
    max-width: 100%;
    box-sizing: border-box;
}
.whatsapp-input:focus { outline: none; border-color: var(--success); }

/* --- Draw Results --- */
.winning-number-display {
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    color: #fff;
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 6px;
    padding: 30px;
    border-radius: var(--radius);
    text-align: center;
    margin: 12px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky; top: 0; background: var(--card-bg); z-index: 1;
}
.modal-body { padding: 12px 14px; }
.modal-footer { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.expand-row { cursor: pointer; user-select: none; }
.expand-row:hover { background: #f0f4ff; }
.expand-detail { display: none; background: #fafafa; border-radius: 6px; padding: 8px; margin: 4px 0 8px 0; font-size: 0.8rem; }
.expand-detail.open { display: block; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-light); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.p-2 { padding: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* --- Small screen fixes --- */
@media (max-width: 360px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 4px; margin: 6px 8px; }
    .stat-card { padding: 8px 4px; }
    .stat-card .stat-value { font-size: 1rem; }
    .card { padding: 10px; margin: 6px 8px; }
    .btn { padding: 10px 16px; font-size: 0.9rem; }
    .btn-sm { padding: 6px 10px; font-size: 0.75rem; }
    .form-input { padding: 10px 12px; font-size: 0.9rem; }
    .game-tab { padding: 10px; font-size: 0.95rem; }
    .num-cell { font-size: 0.9rem; }
}

/* --- Loading --- */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Admin specific --- */
.admin-header {
    background: #1d3557;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    overflow: hidden;
    gap: 8px;
}
.admin-header h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
