/* public/assets/css/style.css */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --sidebar-bg: #1e1e2d;
    --sidebar-hover: #27273f;
    --sidebar-active: #32324e;
    --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
    --mobile-touch-target: 44px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8fafc;
    color: #334155;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden; /* App shell architecture: independent internal scroll */
}

/* Prevent document scroll when mobile drawer is open */
body.sidebar-open {
    overflow: hidden !important;
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
}

/* Base App Shell Layout - No 100vw Scrollbar Traps */
.app-layout {
    display: flex;
    width: 100%;
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* Sidebar Shell */
#sidebar {
    width: 260px;
    min-width: 260px;
    max-width: 260px;
    height: 100%;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--sidebar-bg);
    color: #fff;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    z-index: 1040;
    flex-shrink: 0;
}

#sidebar .sidebar-header {
    flex-shrink: 0;
    padding: 18px 20px;
    background: #181824;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

#sidebar .sidebar-header h4 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
    color: #ffffff;
}

#sidebar .sidebar-header small {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

#sidebar .sidebar-menu {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Clean Sidebar Scrollbar */
#sidebar .sidebar-menu::-webkit-scrollbar {
    width: 5px;
}
#sidebar .sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}
#sidebar .sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
#sidebar .sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

#sidebar ul.components {
    padding: 16px 12px;
}

#sidebar ul li {
    margin-bottom: 4px;
}

#sidebar ul li a {
    padding: 10px 16px;
    font-size: 0.925rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    min-height: 42px;
}

#sidebar ul li a:hover {
    color: #ffffff;
    background: var(--sidebar-hover);
}

#sidebar ul li.active > a {
    color: #ffffff;
    background: var(--sidebar-active);
    font-weight: 600;
}

#sidebar ul li a i {
    width: 24px;
}

/* Sidebar Backdrop Overlay - Mobile Only (<768px) */
#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1030;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

/* Main Content Container & Independent Scroll Area */
.main-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: #f8fafc;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

.main-content-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 24px;
    box-sizing: border-box;
    overscroll-behavior: auto;
}

/* Page Container Guard for 4K / Ultra-wide Displays */
.container-fluid {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

/* Navbar */
.navbar {
    padding: 12px 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px !important;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
}

/* Cards */
.card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
}

/* KPI Cards */
.kpi-card {
    border-radius: 12px;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* Chart Container Wrapper */
.chart-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-height: 260px;
    height: 320px;
}

/* Controlled Responsive Table Containers */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
}

.table th {
    font-size: 0.825rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    font-weight: 600;
    padding: 14px 16px;
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    color: #334155;
    vertical-align: middle;
}

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

/* Responsive Dropdown Menus */
.dropdown-menu {
    max-width: calc(100vw - 24px);
    word-wrap: break-word;
    border-radius: 10px;
}

.dropdown-menu-end {
    right: 0;
    left: auto;
}

/* Responsive Modal Behavior */
.modal-dialog {
    margin: 1.5rem auto;
    max-width: 95%;
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px;
    }
    .modal-dialog.modal-lg {
        max-width: 800px;
    }
    .modal-dialog.modal-xl {
        max-width: 1140px;
    }
}

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.75rem auto;
        max-width: calc(100% - 1.25rem);
    }
    .modal-content {
        max-height: calc(100dvh - 1.5rem);
        display: flex;
        flex-direction: column;
    }
    .modal-header {
        padding: 12px 16px;
        flex-shrink: 0;
    }
    .modal-body {
        padding: 14px 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-footer {
        padding: 10px 16px;
        flex-shrink: 0;
        flex-wrap: wrap;
        gap: 8px;
    }
    .modal-footer > * {
        margin: 0 !important;
        flex: 1 1 auto;
    }
}

/* Form Controls Base Responsiveness */
.form-control, .form-select {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
}

/* =======================================================
   RESPONSIVE MEDIA QUERIES & BREAKPOINTS
   ======================================================= */

/* 1. Mobile Phones (320px to 767.98px) */
@media (max-width: 767.98px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        max-width: 85vw;
        height: 100%;
        height: 100dvh;
        transform: translateX(-100%);
        z-index: 1060;
    }
    
    #sidebar.active {
        transform: translateX(0);
    }

    #sidebar-overlay.active {
        display: block !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        visibility: visible !important;
    }

    .main-content-scroll {
        padding: 14px 12px;
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    .navbar {
        padding: 10px 12px;
        margin-bottom: 16px;
        border-radius: 10px !important;
    }

    /* Touch-friendly touch targets */
    .btn, .form-control, .form-select {
        min-height: var(--mobile-touch-target);
        font-size: 0.95rem;
    }

    .btn-sm, .form-control-sm, .form-select-sm {
        min-height: 38px;
        font-size: 0.875rem;
    }

    /* Stack buttons gracefully */
    .mobile-stack-btn {
        width: 100%;
        margin-bottom: 8px;
    }

    /* Mobile Quotation / Invoice Line Item Cards */
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px dashed #f1f5f9;
    }

    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.8rem;
        color: #64748b;
        text-transform: uppercase;
        margin-right: 10px;
        flex-shrink: 0;
    }

    /* Cells with wide content stack vertically to avoid squashing */
    .table-mobile-cards tbody td[data-label="Item / Description"],
    .table-mobile-cards tbody td[data-label="Item"],
    .table-mobile-cards tbody td[data-label="Description"],
    .table-mobile-cards tbody td.stack-mobile-cell {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .table-mobile-cards tbody td[data-label="Item / Description"]::before,
    .table-mobile-cards tbody td[data-label="Item"]::before,
    .table-mobile-cards tbody td[data-label="Description"]::before,
    .table-mobile-cards tbody td.stack-mobile-cell::before {
        margin-bottom: 2px;
    }

    .table-mobile-cards tbody td .form-control,
    .table-mobile-cards tbody td .form-select {
        max-width: 65%;
    }

    .table-mobile-cards tbody td[data-label="Item / Description"] .form-control,
    .table-mobile-cards tbody td[data-label="Item / Description"] .form-select,
    .table-mobile-cards tbody td.stack-mobile-cell .form-control,
    .table-mobile-cards tbody td.stack-mobile-cell .form-select {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Fixed Mobile Bottom Navigation Bar */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: #ffffff;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 1050;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        color: #64748b;
        text-decoration: none;
        font-size: 0.725rem;
        font-weight: 500;
        transition: all 0.2s ease;
        padding: 4px 0;
        background: transparent;
        border: none;
        min-height: 44px;
    }

    .mobile-bottom-nav-item i {
        font-size: 1.15rem;
        margin-bottom: 2px;
        transition: transform 0.2s ease, color 0.2s ease;
    }

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

    .mobile-bottom-nav-item.active {
        color: var(--primary-color);
        font-weight: 700;
    }

    .mobile-bottom-nav-item.active i {
        color: var(--primary-color);
        transform: translateY(-2px);
    }

    /* Offcanvas More Bottom Sheet Styling */
    .mobile-more-offcanvas {
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        max-height: 80vh;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
    }

    .mobile-more-offcanvas .offcanvas-header {
        border-bottom: 1px solid #f1f5f9;
        padding: 16px 20px;
    }

    .mobile-more-offcanvas .more-menu-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 16px;
    }

    .mobile-more-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 12px 6px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        color: #334155;
        text-decoration: none;
        font-size: 0.775rem;
        font-weight: 600;
        text-align: center;
        transition: all 0.2s ease;
        min-height: 44px;
    }

    .mobile-more-item:hover,
    .mobile-more-item:active {
        background: #ffffff;
        border-color: var(--primary-color);
        color: var(--primary-color);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.12);
    }

    .mobile-more-item i {
        font-size: 1.35rem;
        margin-bottom: 4px;
    }
}

/* 2. Tablets and Desktops (768px and above) - Persistent Sidebar, Never Show Overlay */
@media (min-width: 768px) {
    #sidebar-overlay,
    #sidebar-overlay.active {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
        visibility: hidden !important;
    }
}

/* 2. Tablets (768px to 991.98px) */
@media (min-width: 768px) and (max-width: 991.98px) {
    #sidebar {
        min-width: 220px;
        max-width: 220px;
    }
    
    .main-content-scroll {
        padding: 20px;
    }
}

/* 3. Laptops & Desktops (992px and above) */
@media (min-width: 992px) {
    #sidebarCollapse {
        display: none !important;
    }
}

/* 4. Ultra-wide Desktop Monitors (1920px+) */
@media (min-width: 1920px) {
    .container-fluid {
        max-width: 1750px;
    }
}

/* =======================================================
   Universal Modal Viewport Containment & Scroll Protection
   ======================================================= */
.modal {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

.modal-dialog {
    max-height: calc(100vh - 2rem);
    margin: 1rem auto;
}

@media (min-width: 576px) {
    .modal-dialog {
        max-height: calc(100vh - 3.5rem);
        margin: 1.75rem auto;
    }
}

.modal-dialog-scrollable {
    height: calc(100% - 3.5rem);
    max-height: calc(100vh - 3.5rem);
}

.modal-dialog-scrollable .modal-content {
    max-height: 100%;
    overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: #ffffff;
    z-index: 10;
}

