@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --sidebar-bg: #111827;
    --sidebar-text: #F9FAFB;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.08);
    --sidebar-active-bg: var(--brand-primary, #2563eb);
    --sidebar-active-text: var(--button-text, #ffffff);
    --topbar-bg: var(--header-bg, #ffffff);
    --body-bg: var(--page-bg, #f8fafc);
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --primary: var(--brand-primary, #2563eb);
    --primary-hover: var(--brand-primary, #1d4ed8);
    --secondary: var(--brand-secondary, #0F172A);
    --accent: var(--brand-accent, #F59E0B);
    --text-main: var(--text-color, #1e293b);
    --text-muted: #64748b;
    --button-text: #ffffff;
    --app-border-radius: 8px;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--page-bg, var(--body-bg));
    color: var(--text-color, var(--text-main));
    overflow-x: hidden;
}

/* Layout Architecture */
.wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* Main Top Header Navigation */
.main-header {
    background-color: var(--sidebar-bg, #111827);
    color: var(--sidebar-text, #ffffff);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: 0;
    z-index: 1040;
}

.top-nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    min-height: 64px;
    gap: 1rem;
}

.brand-section {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.brand-logo {
    max-height: 40px;
    max-width: 190px;
    object-fit: contain;
}

.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--sidebar-text, #ffffff);
    letter-spacing: 0.5px;
}

.brand-icon {
    color: var(--brand-primary, #60a5fa);
}

/* Desktop Navigation Menu */
.desktop-nav {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-left: 1rem;
}

.top-nav-menu {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.top-nav-item {
    position: relative;
}

.top-nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    color: var(--sidebar-text, rgba(255, 255, 255, 0.85));
    text-decoration: none;
    border-radius: var(--app-border-radius, 8px);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.top-nav-link:hover,
.top-nav-link:focus {
    color: #ffffff;
    background-color: var(--sidebar-hover-bg, rgba(255, 255, 255, 0.12));
}

.top-nav-link.active {
    background-color: var(--brand-primary, var(--sidebar-active-bg, #2563eb));
    color: var(--button-text, var(--sidebar-active-text, #ffffff)) !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Primary Worker Actions Highlight */
.top-nav-link.primary-action-link {
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

.top-nav-link.primary-action-link:hover {
    background-color: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.top-nav-link.primary-action-link.active {
    background-color: var(--brand-primary, #2563eb);
    border-color: var(--brand-primary, #2563eb);
    color: var(--button-text, #ffffff) !important;
}

/* Header Controls & Search */
.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.btn-nav-search {
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--sidebar-text, #ffffff);
    padding: 0.4rem 0.85rem;
    border-radius: var(--app-border-radius, 8px);
    transition: all 0.2s ease;
}

.btn-nav-search:hover,
.btn-nav-search:focus {
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.nav-search-dropdown {
    width: 320px;
    border-radius: var(--app-border-radius, 12px);
    top: 100% !important;
    margin-top: 0.5rem !important;
}

.nav-search-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    color: var(--text-color, #1e293b);
    text-decoration: none;
    border-radius: var(--app-border-radius, 6px);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background-color 0.15s ease;
}

.nav-search-item:hover,
.nav-search-item:focus {
    background-color: #f1f5f9;
    color: var(--brand-primary, #2563eb);
}

/* Dropdown Menu Z-Index & Styling */
.main-header .dropdown-menu,
.top-nav-item .dropdown-menu,
.user-profile .dropdown-menu,
.nav-search-dropdown {
    border-radius: var(--app-border-radius, 10px);
    margin-top: 0.35rem;
    padding: 0.5rem;
    z-index: 1045 !important;
}

.top-nav-item .dropdown-item {
    border-radius: calc(var(--app-border-radius, 8px) - 2px);
    padding: 0.5rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.top-nav-item .dropdown-item.active,
.top-nav-item .dropdown-item:active {
    background-color: var(--brand-primary, #2563eb);
    color: var(--button-text, #ffffff);
}

.user-profile-btn {
    padding: 0.25rem 0.5rem;
    border-radius: var(--app-border-radius, 8px);
    transition: background-color 0.2s;
}

.user-profile-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-toggle-btn {
    color: var(--sidebar-text, #ffffff);
    padding: 0.25rem 0.5rem;
}

.mobile-toggle-btn:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Mobile Offcanvas Drawer */
.mobile-nav-drawer {
    width: 300px;
    z-index: 1050;
}

.fs-xs {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

/* Main Content Area full width */
#content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
}

.page-title-header {
    min-height: 48px;
}

.user-profile {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.user-profile .dropdown-menu {
    min-width: 230px;
    border-radius: var(--app-border-radius, 10px);
    margin-top: 0.5rem !important;
    padding: 0.5rem;
    z-index: 1045 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.18), 0 8px 10px -6px rgba(0, 0, 0, 0.12) !important;
}

.user-profile .dropdown-item {
    border-radius: calc(var(--app-border-radius, 8px) - 2px);
    padding: 0.5rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.user-profile .dropdown-item:hover,
.user-profile .dropdown-item:focus {
    background-color: #f1f5f9;
    color: var(--brand-primary, #2563eb);
}

.avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--brand-primary, #2563eb);
    color: var(--button-text, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.95rem;
}

/* Cards & Components */
.main-body {
    padding: 2rem;
    flex-grow: 1;
}

.card-custom {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--app-border-radius, 12px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card-header-custom {
    padding: 1.25rem 1.5rem;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title-custom {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-color, var(--text-main));
}

/* Tables */
.table-custom {
    margin: 0;
    width: 100%;
}

.table-custom th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.table-custom td {
    padding: 1rem 1.25rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

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

/* Badges */
.badge-active {
    background-color: #dcfce7;
    color: #15803d;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-inactive {
    background-color: #fee2e2;
    color: #b91c1c;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-type {
    background-color: #e0f2fe;
    color: #0369a1;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Buttons */
.btn-primary-custom {
    background-color: var(--brand-primary, var(--primary));
    color: var(--button-text, #ffffff);
    border: none;
    border-radius: var(--app-border-radius, 8px);
    padding: 0.55rem 1.25rem;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-primary-custom:hover {
    filter: brightness(0.92);
    color: var(--button-text, #ffffff);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-primary, #2563eb);
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.25);
}

/* Icon Picker Grid */
.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
    gap: 12px;
    max-height: 280px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--app-border-radius, 12px);
    background-color: #f8fafc;
}

.icon-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 6px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background-color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    user-select: none;
}

.icon-option:hover {
    border-color: var(--brand-primary, #93c5fd);
    background-color: #f0f9ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.icon-option.selected {
    border-color: var(--brand-primary, #2563eb);
    background-color: #eff6ff;
    color: var(--brand-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.icon-option i {
    font-size: 1.6rem;
    margin-bottom: 6px;
}

.icon-option span {
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    color: #334155;
    line-height: 1.1;
}

.icon-option.selected span {
    color: var(--brand-primary, #1d4ed8);
}

/* Stats Widget */
.stat-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--app-border-radius, 12px);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.blue { background-color: #eff6ff; color: var(--brand-primary, #2563eb); }
.stat-icon.green { background-color: #ecfdf5; color: #10b981; }
.stat-icon.purple { background-color: #f5f3ff; color: #8b5cf6; }
.stat-icon.orange { background-color: #fff7ed; color: #f97316; }
.stat-icon.teal { background-color: #f0fdf4; color: #14b8a6; }
.stat-icon.indigo { background-color: #eef2ff; color: #6366f1; }

.stat-details h3 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-color, var(--text-main));
}

.stat-details p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Helper Classes */
.min-h-120 { min-height: 120px; }
.max-h-80 { max-height: 80px; }
.cursor-pointer { cursor: pointer; }

/* ==========================================================================
   Service Bill Module Tablet & Responsive Optimizations (Scoped)
   Preserves 100% of visual branding, calculations, and functionality.
   ========================================================================== */

/* Dynamic sticky offset CSS variable with safe default fallback */
:root {
    --header-sticky-offset: 80px;
}

/* Page Spacing & Container Compaction (Scoped to Service Bill) */
@media (max-width: 991.98px) {
    /* Tablet Portrait & Mobile (<992px): Compact main canvas padding */
    .main-body:has(.service-bill-page) {
        padding: 1rem 0.75rem !important;
    }
    .service-bill-page .row.g-4 {
        --bs-gutter-x: 0.875rem;
        --bs-gutter-y: 0.875rem;
    }
    .service-bill-page .mb-4 {
        margin-bottom: 0.875rem !important;
    }
    .service-bill-page .card-header.py-3 {
        padding-top: 0.65rem !important;
        padding-bottom: 0.65rem !important;
    }
    .service-bill-page .card-body.p-4 {
        padding: 1rem !important;
    }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
    /* Tablet Landscape (992px - 1199px): Moderate padding reduction */
    .main-body:has(.service-bill-page) {
        padding: 1.25rem 1rem !important;
    }
    .service-bill-page .row.g-4 {
        --bs-gutter-x: 1.25rem;
        --bs-gutter-y: 1.25rem;
    }
    .service-bill-page .mb-4 {
        margin-bottom: 1rem !important;
    }
    .service-bill-page .card-header.py-3 {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
    .service-bill-page .card-body.p-4 {
        padding: 1.25rem !important;
    }
}

/* Billing Summary Sticky Positioning (Scoped to Service Bill) */
.service-bill-page .service-bill-summary-sticky {
    position: sticky;
    top: var(--header-sticky-offset, 80px);
    width: 100%;
    z-index: 1020;
    transition: top 0.15s ease-out;
}

/* On mobile & tablet portrait (<992px), summary is stacked below, so it must scroll naturally */
@media (max-width: 991.98px) {
    .service-bill-page .service-bill-summary-sticky {
        position: static !important;
        top: auto !important;
    }
}

/* On short viewports (height <= 720px), sticky cards hide action buttons; allow natural scrolling */
@media (max-height: 720px) {
    .service-bill-page .service-bill-summary-sticky {
        position: static !important;
        top: auto !important;
    }
}

/* Line Items Table Responsive Widths & Touch Ergonomics (Scoped) */
.service-bill-page #tblLineItems th,
.service-bill-page #tblLineItems td {
    vertical-align: middle;
}

@media (max-width: 1199.98px) {
    .service-bill-page #tblLineItems th,
    .service-bill-page #tblLineItems td {
        padding: 0.45rem 0.35rem;
    }
    .service-bill-page #tblLineItems .col-stage { width: 105px !important; }
    .service-bill-page #tblLineItems .col-price { width: 95px !important; }
    .service-bill-page #tblLineItems .col-qty { width: 62px !important; }
    .service-bill-page #tblLineItems .col-disc { width: 85px !important; }
    .service-bill-page #tblLineItems .col-tax { width: 85px !important; }
    .service-bill-page #tblLineItems .col-total { width: 100px !important; }
    .service-bill-page #tblLineItems .col-action { width: 48px !important; }
    
    .service-bill-page #tblLineItems .form-control-sm {
        padding: 0.25rem 0.35rem;
        font-size: 0.8125rem;
    }
}

/* Touch Target for Remove Service Action (44x44px ergonomic touch guideline) */
.service-bill-page .btn-remove-line {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: -4px 0;
    padding: 0;
    border-radius: 8px;
    color: #dc3545;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.service-bill-page .btn-remove-line:hover,
.service-bill-page .btn-remove-line:focus {
    background-color: rgba(220, 53, 69, 0.12);
    color: #b02a37;
}

.service-bill-page .btn-remove-line:active {
    transform: scale(0.94);
}

/* Dialog & Modal Optimizations on Tablet Viewports (Scoped) */
#quickVehicleModal .modal-body {
    max-height: calc(100vh - 170px);
    overflow-y: auto;
}

@media (max-width: 768px) {
    #quickVehicleModal .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 130px);
    }
}

#pdfPreviewModal .modal-dialog {
    max-width: 960px;
}

#pdfPreviewModal .pdf-preview-modal-body {
    height: 72vh;
    min-height: 380px;
    max-height: 680px;
}

#pdfPreviewModal .pdf-preview-iframe {
    width: 100%;
    height: 100%;
}

@media (max-height: 720px) {
    #pdfPreviewModal .pdf-preview-modal-body {
        height: 62vh;
        min-height: 300px;
    }
}

/* ==========================================================================
   Responsive Navigation System (Breakpoint: 1400px / xxl)
   Measured available header space vs unwrapped menu width (~1,760px total).
   Ensures compact single-row header on tablet portrait, landscape, and mobile,
   while showing expanded single-row menu on large desktop displays.
   ========================================================================== */

/* Compact Mode Defaults (< 1400px) */
@media (max-width: 1399.98px) {
    .main-header {
        height: 64px;
    }
    .top-nav-container {
        min-height: 64px;
        height: 64px;
        padding: 0 1rem;
        flex-wrap: nowrap;
    }
    .mobile-toggle-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        color: var(--sidebar-text, #ffffff);
        padding: 0;
        border-radius: var(--app-border-radius, 8px);
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.15);
        transition: background-color 0.15s ease;
    }
    .mobile-toggle-btn:hover,
    .mobile-toggle-btn:focus {
        background-color: var(--sidebar-hover-bg, rgba(255, 255, 255, 0.12));
        color: #ffffff;
    }
    .desktop-nav {
        display: none !important;
    }
    .header-controls {
        flex-shrink: 0;
    }
}

/* Expanded Desktop Mode (>= 1400px) */
@media (min-width: 1400px) {
    .mobile-toggle-btn {
        display: none !important;
    }
    .desktop-nav {
        display: flex !important;
        flex-grow: 1;
        align-items: center;
        justify-content: flex-start;
        margin-left: 0.75rem;
        min-width: 0;
    }
    .top-nav-container {
        flex-wrap: nowrap;
    }
    .top-nav-menu {
        flex-wrap: nowrap;
        gap: 0.25rem;
    }
    .top-nav-link {
        padding: 0.4rem 0.55rem;
        font-size: 0.8125rem;
        gap: 0.35rem;
    }
}

@media (min-width: 1600px) {
    .top-nav-menu {
        gap: 0.35rem;
    }
    .top-nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        gap: 0.5rem;
    }
}

/* Offcanvas Mobile/Tablet Navigation Drawer Styling */
.mobile-nav-drawer {
    width: 340px;
    max-width: 85vw;
}

.mobile-nav-drawer .offcanvas-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-nav-drawer .list-group-item {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 0.85rem 1.25rem;
    font-size: 0.9375rem;
    border-color: rgba(0, 0, 0, 0.05);
}

.mobile-nav-drawer .accordion-button {
    min-height: 48px;
    padding: 0.85rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.mobile-nav-drawer .accordion-body .list-group-item {
    min-height: 44px;
    padding: 0.75rem 1.25rem 0.75rem 2.25rem;
    font-size: 0.875rem;
}