/* =============================================
   App Shell Layout
   ============================================= */

:root {
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--body-bg);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* =============================================
   App Shell
   ============================================= */

.app-shell {
    display: flex;
    min-height: 100vh;
    /* Respect the safe area on notched iPhones when installed as a PWA */
    padding-bottom: env(safe-area-inset-bottom);
}

/* =============================================
   Sidebar
   ============================================= */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1030; /* above overlay (1025) */
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px;
    border-bottom: 1px solid #334155;
}

.sidebar-logo {
    font-size: 1.5rem;
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: #f1f5f9;
    flex: 1;
}

.sidebar-close {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    display: none;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid #334155;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 8px 12px;
    border-radius: 6px;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
}

    .logout-btn:hover {
        background: var(--sidebar-hover);
        color: #f1f5f9;
    }

/* =============================================
   Nav Links
   ============================================= */

.nav-links {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
}

    .nav-links li {
        margin-bottom: 2px;
    }

    .nav-links a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        border-radius: 8px;
        color: var(--sidebar-text);
        text-decoration: none;
        font-size: 0.875rem;
        transition: background 0.2s, color 0.2s;
    }

        .nav-links a:hover {
            background: var(--sidebar-hover);
            color: #f1f5f9;
        }

        .nav-links a.active {
            background: var(--sidebar-active);
            color: #ffffff;
        }

.nav-icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
}

.nav-label {
    font-weight: 500;
    flex: 1;
}

.nav-chevron {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-left: auto;
}

.nav-sub {
    list-style: none;
    padding: 0;
    margin: 0;
}

    .nav-sub li a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 7px 12px 7px 36px;
        border-radius: 8px;
        color: var(--sidebar-text);
        text-decoration: none;
        font-size: 0.8rem;
        transition: background 0.2s, color 0.2s;
    }

        .nav-sub li a:hover {
            background: var(--sidebar-hover);
            color: #f1f5f9;
        }

        .nav-sub li a.active {
            background: var(--sidebar-active);
            color: #ffffff;
        }

/* =============================================
   Main Content
   ============================================= */

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-body {
    padding: 24px;
    flex: 1;
    max-width: 1400px;
    width: 100%;
}

/* =============================================
   Top Bar (Mobile only)
   ============================================= */

.topbar {
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    background: var(--sidebar-bg);
    color: #f1f5f9;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: env(safe-area-inset-top) 16px 0;
    position: sticky;
    top: 0;
    z-index: 900;
}

.hamburger {
    background: none;
    border: none;
    color: #f1f5f9;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
}

/* =============================================
   Sidebar Overlay (Mobile)
   ============================================= */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1025; /* above Bootstrap sticky (1020) and dropdowns (1000) */
    -webkit-tap-highlight-color: transparent;
}

    .sidebar-overlay.show {
        display: block;
    }

/* =============================================
   Blazor Error UI
   ============================================= */

#blazor-error-ui {
    background: var(--danger);
    color: white;
    padding: 12px 20px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: none;
    font-size: 0.875rem;
}

    #blazor-error-ui .reload {
        color: white;
        font-weight: 600;
        margin-left: 8px;
    }

    #blazor-error-ui .dismiss {
        float: right;
        cursor: pointer;
    }

/* =============================================
   Mobile Responsive
   ============================================= */

@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .sidebar-close {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .page-body {
        padding: 12px;
    }

    /* Touch targets: minimum 44px for interactive elements */
    .btn,
    .form-select,
    .form-control,
    .hamburger,
    .logout-btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    .btn-xs {
        min-height: 36px;
    }

    .form-check-input[type="checkbox"] {
        width: 20px;
        height: 20px;
        margin-top: 0;
    }

    /* Tables: horizontal scroll within cards */
    .card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent nested overflow issues */
    .card-body .card-body {
        overflow-x: visible;
    }

    /* Bulk action bar: stack vertically on mobile */
    .bulk-bar .card-body {
        flex-wrap: wrap;
        gap: 8px !important;
        overflow-x: visible;
    }

    .bulk-bar .card-body > div[style*="min-width"] {
        min-width: 100% !important;
    }

    /* Page header responsive */
    .page-header {
        margin-bottom: 16px;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

    /* Card padding reduction on mobile */
    .card {
        padding: 14px;
    }

    /* Flex wrap for filter bars */
    .d-flex.gap-3.mb-4 {
        gap: 8px !important;
    }

    /* Full-width selects in filter bars */
    .d-flex.flex-wrap select.form-select {
        width: 100% !important;
    }

    /* Recent transactions max-width relaxed */
    .table td[style*="max-width"] {
        max-width: 100px !important;
    }

    /* Nav sub-menu items larger tap targets */
    .nav-links a,
    .nav-sub li a {
        padding-top: 12px;
        padding-bottom: 12px;
    }
}

@media (min-width: 768px) {
    .topbar {
        display: none !important;
    }
}

/* =============================================
   PWA Install Banner
   ============================================= */

.pwa-install-banner {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 1100;
    max-width: 420px;
    width: calc(100vw - 32px);
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(20px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

.pwa-install-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.pwa-install-text {
    flex: 1;
    min-width: 0;
}

.pwa-install-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #f1f5f9;
}

.pwa-install-sub {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 2px;
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* =============================================
   Utility Classes
   ============================================= */

.d-md-none {
    display: block;
}

@media (min-width: 768px) {
    .d-md-none {
        display: none !important;
    }
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.page-header {
    margin-bottom: 24px;
}

    .page-header h1 {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--text-primary);
    }

    .page-header p {
        color: var(--text-muted);
        margin-top: 4px;
        font-size: 0.875rem;
    }
