:root {
    --primary: #0f766e;
    --primary-hover: #115e59;
    --emerald: #10b981;
    --emerald-dark: #059669;
    --emerald-light: #d1fae5;
    --emerald-subtle: #ecfdf5;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --surface-bg: #f8fafc;
    --card-border: #e2e8f0;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(226, 232, 240, 0.8);
}

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background-color: var(--surface-bg);
    overflow-x: hidden;
    min-height: 100vh;
}

code, pre, .font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Typography Helpers */
.fs-xs { font-size: 0.75rem; }
.fs-sm { font-size: 0.875rem; }
.tracking-tight { letter-spacing: -0.025em; }
.tracking-wider { letter-spacing: 0.05em; }

/* Custom Colors */
.bg-surface { background-color: var(--surface-bg); }
.bg-sidebar { background-color: var(--sidebar-bg); }
.text-emerald { color: var(--emerald-dark) !important; }
.bg-emerald { background-color: var(--emerald-dark) !important; }
.bg-emerald-subtle { background-color: var(--emerald-light) !important; }
.border-white-10 { border-color: rgba(255, 255, 255, 0.1) !important; }
.bg-dark-tint { background-color: rgba(255, 255, 255, 0.06); }

/* Main App Wrapper Layout */
#wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

#page-content-wrapper {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0; /* Prevents flexbox item blowout on wide tables */
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Desktop Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1045;
}

/* Mobile Sidebar Drawer (< 992px) */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        max-width: 85vw;
        width: 280px;
        transform: translateX(-100%);
        box-shadow: 0 0 35px rgba(0, 0, 0, 0.45);
        z-index: 1055;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open {
        overflow: hidden; /* Prevent scrolling body behind drawer */
    }

    /* Mobile Backdrop */
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(15, 23, 42, 0.65);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1050;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        visibility: visible;
    }
}

/* Brand Styling */
.brand-logo-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25) 0%, rgba(15, 118, 110, 0.45) 100%);
    border: 1px solid rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: all 0.25s ease;
}

.brand-logo-icon:hover {
    transform: scale(1.06);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.45);
    border-color: rgba(16, 185, 129, 0.65);
}

.brand-badge-di {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.35);
    text-transform: uppercase;
    display: inline-block;
}

/* Pulsing Live Gateway Indicator */
.pulse-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.sidebar .nav-link {
    color: #94a3b8;
    padding: 0.65rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.sidebar .nav-link:hover {
    color: #ffffff;
    background-color: var(--sidebar-hover);
}

.sidebar .nav-link.active {
    color: #ffffff;
    background-color: var(--primary);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.35);
}

.user-avatar {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
}

/* Topbar Sticky Styling */
.topbar {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: rgba(255, 255, 255, 0.95);
    z-index: 1030;
    transition: padding 0.2s ease;
}

/* Mobile Bottom Navigation Dock (< 768px) */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
        z-index: 1035;
        padding: 0 0.5rem;
        align-items: center;
        justify-content: space-around;
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #64748b;
        font-size: 0.68rem;
        font-weight: 600;
        padding: 0.3rem 0.5rem;
        border-radius: 8px;
        transition: all 0.2s ease;
        position: relative;
        min-width: 54px;
    }

    .mobile-nav-item i {
        font-size: 1.25rem;
        line-height: 1;
        margin-bottom: 2px;
    }

    .mobile-nav-item:hover,
    .mobile-nav-item.active {
        color: var(--primary);
    }

    .mobile-nav-item.active::after {
        content: '';
        position: absolute;
        top: 0;
        width: 22px;
        height: 3px;
        background-color: var(--emerald);
        border-radius: 2px;
    }

    /* Central Floating Action Button (New Invoice) */
    .mobile-nav-fab {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: #ffffff !important;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45);
        margin-top: -24px;
        border: 3px solid #ffffff;
        transition: transform 0.15s ease, box-shadow 0.15s ease;
        text-decoration: none;
    }

    .mobile-nav-fab i {
        font-size: 1.35rem;
        margin: 0;
    }

    .mobile-nav-fab:active {
        transform: scale(0.92);
    }

    /* Ensure main body doesn't get covered by mobile bottom bar */
    main.container-fluid {
        padding-bottom: 80px !important;
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
        padding-top: 1rem !important;
    }

    .topbar {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
    }
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.98);
}

.btn-emerald {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-color: #059669;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
}

.btn-emerald:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    border-color: #047857;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

/* Cards & Surface */
.card {
    border-color: var(--card-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background-color: #ffffff;
}

.card-header {
    background-color: #ffffff;
    border-bottom-color: var(--card-border);
    padding: 1rem 1.25rem;
    border-top-left-radius: 12px !important;
    border-top-right-radius: 12px !important;
}

/* Stat Cards */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

/* Badges */
.badge-status {
    padding: 0.4em 0.8em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-fbr-submitted {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge-draft {
    background-color: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
}

.badge-failed {
    background-color: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Responsive Tables & Touch Optimization */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    position: relative;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

.table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    background-color: #f8fafc;
    border-bottom: 2px solid var(--card-border);
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--card-border);
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

/* Mobile Swipe Helper Pill */
.table-swipe-hint {
    display: none;
}

@media (max-width: 767.98px) {
    .table-swipe-hint {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        font-size: 0.72rem;
        color: #64748b;
        background-color: #f1f5f9;
        padding: 0.25rem 0.65rem;
        border-radius: 6px;
        margin-bottom: 0.5rem;
    }
}

/* Form Controls & Mobile Touch (Prevent iOS Auto-Zoom) */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #cbd5e1;
    font-size: 0.875rem;
    padding: 0.55rem 0.85rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--emerald);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.input-group-text {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    font-size: 0.875rem;
}

/* Mobile specific touch targets and font sizes */
@media (max-width: 767.98px) {
    .form-control, .form-select, .input-group-text {
        font-size: 16px !important; /* Critical: Stops iOS Safari from zooming in when focusing */
        min-height: 44px;
    }

    .form-control-sm, .form-select-sm {
        min-height: 38px;
        font-size: 15px !important;
    }

    .btn {
        min-height: 40px;
    }

    .btn-sm {
        min-height: 34px;
    }
}

/* Item Picker Table row safety for smaller screens */
.item-row td {
    vertical-align: middle;
}

/* Print Invoice Styling */
@media print {
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
    }

    #sidebar-wrapper, .topbar, footer, .mobile-bottom-nav, .no-print, .btn, .alerts-container, .sidebar-backdrop {
        display: none !important;
    }

    #page-content-wrapper {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    main.container-fluid {
        padding: 0 !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
    }

    .printable-invoice {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .printable-invoice table th {
        background-color: #e2e8f0 !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
