/* ============================================
   4D Betting System - Main Stylesheet
   Mobile-first responsive design
   ============================================ */

/* ============================================
   Theme Variables
   ============================================ */
:root {
    --bg-body: #f1f5f9;
    --bg-card: #fff;
    --bg-card-header: #fff;
    --bg-card-footer: #f8fafc;
    --bg-topbar: #fff;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --bg-table-hover: #f8fafc;
    --bg-table-header: #f8fafc;
    --bg-input: #fff;
    --bg-badge: #f1f5f9;
    --bg-totals-row: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-heading: #0f172a;
    --border-color: #e2e8f0;
    --border-input: #d1d5db;
    --link-color: #2563eb;
    --shadow-card: none;
    --btn-secondary-bg: #e2e8f0;
    --btn-secondary-text: #475569;
    --btn-secondary-border: #cbd5e1;
    --keypad-bg: #fff;
    --keypad-text: #0f172a;
    --receipt-bg: #fff;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-card-header: #1e293b;
    --bg-card-footer: #162032;
    --bg-topbar: #1e293b;
    --bg-sidebar: #020617;
    --bg-sidebar-hover: #0f172a;
    --bg-table-hover: #162032;
    --bg-table-header: #162032;
    --bg-input: #0f172a;
    --bg-badge: #0f172a;
    --bg-totals-row: #162032;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-heading: #f1f5f9;
    --border-color: #334155;
    --border-input: #475569;
    --link-color: #60a5fa;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.3);
    --btn-secondary-bg: #334155;
    --btn-secondary-text: #cbd5e1;
    --btn-secondary-border: #475569;
    --keypad-bg: #1e293b;
    --keypad-text: #e2e8f0;
    --receipt-bg: #1e293b;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-body);
}
a { color: var(--link-color); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

/* Typography */
h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; }

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--bg-sidebar);
    color: #e2e8f0;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s ease;
}
.sidebar-brand {
    padding: 1.25rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-brand small {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 400;
}
.sidebar-nav { padding: 0.5rem 0; }
.sidebar-section {
    padding: 0.75rem 1rem 0.25rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #475569;
    font-weight: 600;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    color: #94a3b8;
    font-size: 0.875rem;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-link:hover {
    color: #e2e8f0;
    background: #1e293b;
    text-decoration: none;
}
.sidebar-link.active {
    color: #38bdf8;
    background: #1e293b;
    border-left-color: #38bdf8;
}

/* Main content area */
.main-content {
    flex: 1;
    margin-left: 250px;
    min-height: 100vh;
}
.topbar {
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar-user-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Agent balance bar */
.agent-balance-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, #064e3b, #065f46);
    color: #fff;
    font-size: 0.85rem;
}
.agent-balance-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.agent-balance-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
}
.agent-balance-amount {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.agent-role-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.2rem 0.6rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 100px;
    opacity: 0.9;
}
.page-content { padding: 1.5rem; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #475569;
    cursor: pointer;
    padding: 0.25rem;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-card);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 1.25rem; }
.card-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card-footer);
    border-radius: 0 0 8px 8px;
}

/* Stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
}
.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-heading);
}
.stat-value.positive { color: #059669; }
.stat-value.negative { color: #dc2626; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}
.form-control {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-control::placeholder { color: #9ca3af; }
select.form-control { appearance: auto; }
.form-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row .form-group {
    flex: 1;
    min-width: 120px;
}
.form-inline {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: #2563eb;
    color: #fff;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-success {
    background: #059669;
    color: #fff;
}
.btn-success:hover { background: #047857; }
.btn-danger {
    background: #dc2626;
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }
.btn-warning {
    background: #d97706;
    color: #fff;
}
.btn-warning:hover { background: #b45309; }
.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border-color: var(--btn-secondary-border);
}
.btn-secondary:hover { opacity: 0.85; }
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}
.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 0.5rem; }

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}
.table th {
    background: var(--bg-table-header);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.table tbody tr:hover { background: var(--bg-table-hover); }
.table .text-right { text-align: right; }
.table .text-center { text-align: center; }
.table .number-cell {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.1em;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: var(--bg-badge); color: var(--text-secondary); }

/* Theme toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.theme-toggle:hover { background: var(--bg-table-hover); }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* Pagination */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    margin-top: 1.5rem;
}
.pagination a, .pagination span {
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.875rem;
    color: #475569;
}
.pagination a:hover { background: #f1f5f9; text-decoration: none; }
.pagination .active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}
.empty-state p { margin-top: 0.5rem; font-size: 0.9rem; }

/* Utilities */
.text-success { color: #059669; }
.text-danger { color: #dc2626; }
.text-warning { color: #d97706; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-mono { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.hidden { display: none; }

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
    /* Sidebar: hidden by default, slide in on toggle */
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open {
        display: block;
    }
    .sidebar-toggle {
        display: block;
    }

    /* Layout */
    .main-content {
        margin-left: 0;
    }
    .page-content {
        padding: 0.75rem;
    }
    .topbar {
        padding: 0.5rem 0.75rem;
    }
    .topbar-right {
        font-size: 0.8rem;
        gap: 0.5rem;
    }
    .topbar-user-info {
        display: none;
    }
    .agent-balance-bar {
        padding: 0.4rem 0.75rem;
    }
    .agent-balance-amount {
        font-size: 1rem;
    }
    .topbar-balance {
        font-size: 0.8rem;
    }

    /* Page headers */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .page-header h1 {
        font-size: 1.25rem;
    }
    .page-header .btn {
        width: 100%;
    }

    /* Stats grid: 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    .stat-card {
        padding: 0.75rem;
    }
    .stat-value {
        font-size: 1.2rem;
    }
    .stat-label {
        font-size: 0.65rem;
    }

    /* Cards */
    .card {
        border-radius: 6px;
    }
    .card-header {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    .card-body {
        padding: 0.75rem;
    }

    /* Forms */
    .form-row {
        flex-direction: column;
    }
    .form-row .form-group {
        min-width: 100%;
    }
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
    .form-inline .form-group {
        width: 100%;
    }
    .form-inline .btn {
        width: 100%;
    }
    .form-control {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Tables: horizontal scroll */
    .table-responsive {
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }
    .table th, .table td {
        padding: 0.5rem 0.375rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }
    .table .number-cell {
        font-size: 0.85rem;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    .btn-lg {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }
    .btn-block {
        width: 100%;
    }
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    .btn-group .btn {
        width: 100%;
    }

    /* Provider chips: fill width evenly */
    .provider-grid {
        gap: 0.375rem;
    }
    .provider-chip {
        flex: 1 1 auto;
        min-width: 60px;
        justify-content: center;
        padding: 0.5rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Cart items */
    .cart-item {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    .cart-number {
        font-size: 1rem;
    }
    .cart-details {
        font-size: 0.7rem;
    }

    /* Receipt */
    .receipt {
        padding: 1rem;
        margin: 0;
        max-width: 100%;
    }

    /* Alerts */
    .alert {
        font-size: 0.8rem;
        padding: 0.625rem 0.75rem;
    }

    /* Badges */
    .badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
    }
    .pagination a, .pagination span {
        padding: 0.375rem 0.5rem;
        font-size: 0.8rem;
    }

    /* Filters: stack vertically */
    .card-body form.form-inline .form-group label {
        font-size: 0.75rem;
    }

    /* Hide/show elements on mobile */
    .hide-mobile {
        display: none !important;
    }
    .show-mobile {
        display: block !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-value {
        font-size: 1.1rem;
    }
    .page-content {
        padding: 0.5rem;
    }
    .topbar {
        padding: 0.375rem 0.5rem;
    }
    h1 {
        font-size: 1.1rem;
    }
    h2, h3 {
        font-size: 1rem;
    }
    .table th, .table td {
        padding: 0.375rem 0.25rem;
        font-size: 0.7rem;
    }
}

/* ============================================
   Bet-specific styles
   ============================================ */

/* Bet page layout */
.bet-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 768px) {
    .bet-layout {
        grid-template-columns: 1fr;
    }
    .bet-layout > div:last-child .card {
        position: static !important;
    }
    .number-display .number {
        font-size: 2.25rem !important;
        letter-spacing: 0.3rem !important;
    }
    .keypad {
        max-width: 100% !important;
    }
    .keypad-btn {
        padding: 0.75rem !important;
        font-size: 1.25rem !important;
    }
    .bet-type-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Number keypad */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    max-width: 300px;
    margin: 0 auto;
}
.keypad-btn {
    padding: 1rem;
    font-size: 1.5rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--keypad-bg);
    color: var(--keypad-text);
    cursor: pointer;
    transition: all 0.1s;
    touch-action: manipulation;
}
.keypad-btn:active {
    background: #2563eb;
    color: #fff;
    transform: scale(0.95);
}
.keypad-btn.delete { color: #dc2626; }
.keypad-btn.clear { color: #d97706; font-size: 0.875rem; }

/* Number display */
.number-display {
    text-align: center;
    padding: 1rem;
    margin-bottom: 1rem;
}
.number-display .number {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    color: var(--text-heading);
    min-height: 4rem;
    line-height: 4rem;
}
.number-display .number.placeholder { color: var(--text-muted); }

/* Bet type toggles */
.bet-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.bet-type-btn {
    padding: 0.75rem 0.5rem;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.15s;
}
.bet-type-btn.selected {
    border-color: #2563eb;
    background: #eff6ff;
    color: #2563eb;
}
.bet-type-btn:hover { border-color: #93c5fd; }

/* Provider checkboxes */
.provider-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.provider-chip {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
}
.provider-chip input { display: none; }
.provider-chip.selected {
    border-color: #059669;
    background: #ecfdf5;
    color: #059669;
}

/* Cart */
.cart-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}
.cart-item:last-child { border-bottom: none; }
.cart-number {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 1.1rem;
    font-weight: 600;
}
.cart-details {
    font-size: 0.8rem;
    color: #64748b;
}
.cart-amount {
    font-weight: 600;
    white-space: nowrap;
}
.cart-remove {
    color: #dc2626;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border: none;
    background: none;
    font-size: 1.1rem;
}
.cart-total {
    display: flex;
    justify-content: space-between;
    padding: 1rem 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    border-top: 2px solid #e2e8f0;
}

/* Receipt */
.receipt {
    max-width: 400px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.5rem;
    font-size: 0.875rem;
}
.receipt-header {
    text-align: center;
    border-bottom: 1px dashed #cbd5e1;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.receipt-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
}
.receipt-divider {
    border-top: 1px dashed #cbd5e1;
    margin: 0.75rem 0;
}
.receipt-total {
    font-weight: 700;
    font-size: 1rem;
}

/* Print styles */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin-left: 0; }
    .receipt { border: none; box-shadow: none; }
}
