:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --radius: 8px;
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #e2e8f0;
    --border: #cbd5e1;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

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

.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 { font-size: 16px; margin-bottom: 4px; }

.staff-badge {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-hover);
    padding: 2px 8px;
    border-radius: 10px;
}

.nav-links { flex: 1; padding: 10px 0; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
}

.nav-link:hover, .nav-link.active {
    background: var(--surface-hover);
    color: var(--text);
}

.nav-link.active { border-left: 3px solid var(--primary); }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 10px 0;
}

.logout-link { color: var(--text-muted); }
.logout-link:hover { color: var(--danger); }

.main { flex: 1; padding: 30px; max-width: 1200px; }

.page-title {
    font-size: 24px;
    margin-bottom: 24px;
    font-weight: 600;
}

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card h3 { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.card .value { font-size: 32px; font-weight: 700; }
.card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.value.printed { color: var(--warning); }
.value.collected { color: var(--success); }
.value.voided { color: var(--danger); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    color-scheme: dark;
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
    color-scheme: light;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    color: #fff;
}

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #000; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* Table */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 16px; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 10px 16px; font-size: 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-hover); }

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-printed { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-collected { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-void { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Typeahead */
.typeahead-wrap { position: relative; }

.typeahead-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.typeahead-results.show { display: block; }

.typeahead-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover { background: var(--surface-hover); }
.typeahead-item .name { font-weight: 500; }
.typeahead-item .id { color: var(--text-muted); font-size: 12px; margin-left: 8px; }

/* Payment method buttons */
.payment-options { display: flex; gap: 8px; flex-wrap: wrap; }

.payment-option {
    padding: 8px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.payment-option:disabled { opacity: 0.4; cursor: not-allowed; }
.payment-option:hover:not(:disabled) { border-color: var(--primary); }
.payment-option.selected { border-color: var(--primary); background: rgba(59, 130, 246, 0.15); }
.payment-option-shitbag { border-color: var(--danger, #dc3545); color: var(--danger, #dc3545); font-style: italic; }
.payment-option-shitbag:hover { border-color: var(--danger, #dc3545); background: rgba(220, 53, 69, 0.1); }
.payment-option-shitbag.selected { border-color: var(--danger, #dc3545); background: rgba(220, 53, 69, 0.2); }

/* Toggle switch */
.toggle-label {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--text-muted); cursor: pointer; margin-top: 6px; user-select: none;
}
.toggle-switch {
    position: relative; display: inline-block; width: 34px; height: 18px; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute; inset: 0; background: var(--border); border-radius: 9px; transition: background 0.2s;
}
.toggle-slider::before {
    content: ''; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px;
    background: var(--text-muted); border-radius: 50%; transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); background: #fff; }

/* Toast notification (fixed position, no layout shift) */
.toast {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 9999;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    max-width: calc(100% - 32px);
    width: auto;
    min-width: 280px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.toast-success { background: rgba(34, 197, 94, 0.95); color: #fff; }
.toast-error { background: rgba(239, 68, 68, 0.95); color: #fff; }

/* Legacy .alert kept for any other pages using it */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}
.alert.show { display: block; }
.alert-success { background: rgba(34, 197, 94, 0.15); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.3); }
.alert-error { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: end;
    flex-wrap: wrap;
}

.filter-bar .form-group { margin-bottom: 0; }
.filter-bar input, .filter-bar select { min-width: 150px; }

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    font-size: 24px;
    margin-bottom: 4px;
}

.login-sub {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}

/* QR Scanner */
.serial-input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.serial-input-group input { flex: 1; }

.btn-scan {
    padding: 10px 14px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-scan:hover { border-color: var(--primary); color: var(--primary); }
.btn-scan.scanning { border-color: var(--danger); color: var(--danger); }

#qr-reader {
    margin-bottom: 12px;
    border-radius: var(--radius);
    overflow: hidden;
    display: none;
}

#qr-reader.show { display: block; }

#qr-reader video { width: 100%; border-radius: var(--radius); }

/* Theme toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
}

.theme-toggle-label {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.theme-switch input { opacity: 0; width: 0; height: 0; }

.theme-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.theme-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: transform 0.2s;
}

.theme-switch input:checked + .theme-slider { background: var(--primary); }
.theme-switch input:checked + .theme-slider::before { transform: translateX(20px); }

/* ---- Responsive / Mobile ---- */
@media (max-width: 768px) {
    .app { flex-direction: column; padding-bottom: 64px; }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
        z-index: 1000;
    }

    .sidebar-header { display: none; }
    .sidebar-footer { display: none; }

    .nav-links {
        display: flex;
        padding: 0;
        width: 100%;
    }

    .nav-link {
        flex: 1;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 8px 4px;
        font-size: 10px;
        border-left: none !important;
    }

    .nav-link.active {
        border-left: none;
        border-top: 2px solid var(--primary);
        color: var(--primary);
    }

    .nav-link svg { width: 20px; height: 20px; }

    .main { padding: 16px; }
    .page-title { font-size: 20px; margin-bottom: 16px; }
    .form-row { flex-direction: column; }
    .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .card { padding: 14px; }
    .card .value { font-size: 24px; }
    .filter-bar { flex-direction: column; }
    .filter-bar input, .filter-bar select { min-width: auto; }

    /* Payment buttons wrap nicely on mobile */
    .payment-options { gap: 6px; }
    .payment-option { flex: 1; min-width: calc(50% - 4px); text-align: center; padding: 12px 8px; }
}

/* ---- Native App Shell (Capacitor WebView) ---- */
.native-app .sidebar {
    /* Account for device safe areas (notch, home indicator) */
    padding-bottom: env(safe-area-inset-bottom);
}

.native-app .app {
    /* Extra padding for bottom safe area */
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.native-app .sidebar-header {
    /* Account for status bar / notch at top */
    padding-top: calc(20px + env(safe-area-inset-top));
}

@media (max-width: 768px) {
    .native-app .app {
        padding-top: env(safe-area-inset-top);
    }
}
