/* ========================================
   Invoice Generator - Custom Styles
   ======================================== */

/* Body */
body {
    background-color: #f8f9fa;
    overflow-x: hidden;
}

/* Prevent horizontal scroll globally */
html {
    overflow-x: hidden;
    max-width: 100vw;
}

* {
    box-sizing: border-box;
}

/* Sidebar */
#sidebar {
    width: 250px;
    height: 100vh;
    background: white;
    position: fixed;
    left: 0;
    top: 0;
    overflow-y: auto;
    transition: margin-left 0.3s ease;
    z-index: 1000;
}

#sidebar nav {
    padding-top: 0;
}

#sidebar .nav-link {    
    color: #000000;
    white-space: nowrap;
}

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

/* Logo styles */
#sidebar .logo-container {
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid #dee2e6;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
}

#sidebar .logo-container img {
    max-width: 100%;
    max-height: 80px;
    height: auto;
    width: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

/* Header */
#header {
    position: fixed;
    top: 0;
    left: 250px;
    /* matches sidebar width */
    right: 0;
    height: 60px;
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1050;
    transition: left 0.3s ease;
}

/* Mobile Header Logo */
#header .mobile-logo {
    display: none;
}

#header .mobile-logo img {
    max-height: 45px;
    width: auto;
    object-fit: contain;
}

/* Main content */
#content {
    margin-left: 250px;
    /* matches sidebar width */
    transition: margin-left 0.3s ease;
    padding: 80px 20px 20px 20px;
    overflow-x: hidden;
}

/* Toggle states */
#sidebar.toggled {
    margin-left: -250px;
}

#header.toggled {
    left: 0;
}

#content.toggled {
    margin-left: 0;
}

/* Form validation */
.is-invalid {
    border-color: #dc3545 !important;
    background-color: #fff6f6;
}

/* Table headers */
table thead th,
table th,
.table thead th,
.table th,
.table-dark thead th,
.table-dark th {
    background-color: var(--table-header-color, rgb(0, 0, 0)) !important;
    color: var(--table-header-text-color, white) !important;
}

/* Table footer headers */
table tfoot th,
.table tfoot th,
.table-bordered tfoot th,
.table-responsive table tfoot th,
tfoot th {
    background-color: var(--table-header-color, rgb(0, 0, 0)) !important;
    color: var(--table-header-text-color, white) !important;
}

/* Buttons */
.btn-primary,
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-primary.active,
.btn-primary:not(:disabled):not(.disabled):active,
.btn-primary:not(:disabled):not(.disabled).active {
    background-color: #D9FF5C !important;
    border-color: #D9FF5C !important;
    color: black !important;
}

.btn-primary:hover {
    background-color: #D9FF5C !important;
    border-color: #D9FF5C !important;
    color: black !important;
}

/* Responsive behavior */
@media (max-width: 768px) {
    #sidebar {
        margin-left: -250px;
        width: 250px;
    }

    #sidebar.toggled {
        margin-left: 0;
        top: 60px !important; /* Start below header */
        height: calc(100vh - 60px) !important; /* Adjust height */
        z-index: 1060 !important; /* Higher than header z-index (1050) */
    }

    #sidebar .logo-container {
        padding: 12px 10px;
        min-height: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #sidebar .logo-container img {
        max-width: 100%;
        max-height: 70px;
        width: auto;
        height: auto;
    }

    #header {
        left: 0;
    }

    /* Show mobile logo in header by default on mobile */
    #header .mobile-logo {
        display: block;
        margin-left: 10px;
        flex: 1;
        max-width: calc(100% - 120px);
    }
    
    /* Hide header logo when sidebar is open */
    body.sidebar-open #header .mobile-logo {
        display: none !important;
    }
    
    /* Completely hide sidebar logo on mobile - always use header logo */
    #sidebar .logo-container {
        display: none !important;
    }

    /* Add padding-top to sidebar nav on mobile */
    #sidebar nav {
        padding-top: 15px !important;
        margin-top: 0 !important;
    }

    /* Ensure sidebar starts from top when not toggled */
    #sidebar {
        top: 0;
    }

    #content {
        margin-left: 0;
        width: 100%;
        padding: 70px 10px 20px 10px;
    }

    #content.toggled {
        margin-left: 250px;
    }

    

    .card {
        border-radius: 0;
    }

    /* Remove all horizontal padding and margins on mobile */
    #content {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Prevent horizontal scroll */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        position: relative;
    }

    /* Fix table containers */
    .table-responsive,
    .table-wrapper,
    .invoices-table-container {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .recent-invoices {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Prevent DataTables from causing horizontal scroll */
    .dataTables_wrapper {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .dataTables_scroll,
    .dataTables_scrollHead,
    .dataTables_scrollBody {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Ensure table doesn't exceed viewport */
    table.dataTable,
    table.invoices-table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }



    /* Fix any elements that might cause overflow */
    .d-flex {
        flex-wrap: wrap;
    }

    /* Ensure buttons and form elements don't overflow */
    .btn,
    .form-select,
    .form-control {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Fix recent invoices header */
    .recent-invoices-header {
        flex-wrap: wrap;
        gap: 10px;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .recent-invoices-controls {
        width: 100%;
        flex-wrap: wrap;
    }
}

/* ========================================
   Recent Invoices Table Styles (Transaction Style)
   ======================================== */

.recent-invoices {
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Header Section */
.recent-invoices-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.recent-invoices-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0;
}

.recent-invoices-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}


.invoices-table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}

.invoices-table thead {
    border-bottom: 1px solid #f0f0f0;
}

.invoices-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 600;
    color: #6b7280;
    letter-spacing: 0.5px;
    background: transparent;
    border: none;
}

.invoices-table tbody tr {
    border-bottom: 1px solid #f5f5f5;
    transition: background-color 0.2s ease;
}

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

.invoices-table tbody tr:last-child {
    border-bottom: none;
}

.invoices-table tbody td {
    padding: 16px;
    vertical-align: middle;
}

/* Invoice Name Cell with Icon */
.invoice-name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.invoice-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.875rem;
    color: #ffffff;
    text-transform: uppercase;
}

.invoice-name-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.invoice-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.4;
}

.invoice-business {
    font-size: 0.8125rem;
    color: #9ca3af;
    line-height: 1.4;
}

/* Invoice Type */
.invoice-type {
    font-size: 0.875rem;
    color: #6b7280;
    font-weight: 500;
}

/* Invoice Amount */
.invoice-amount {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #1a1a1a;
}

/* Invoice Date */
.invoice-date {
    font-size: 0.875rem;
    color: #6b7280;
}

/* Invoice Actions - Desktop only (md and above) */
@media screen and (min-width: 768px) {
.invoice-actions {
    display: flex;
        gap: 6px;
    justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        max-width: 100%;
    }
}

.invoice-action-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6b7280 !important;
    background: transparent;
    border: 1px solid #e5e7eb;
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    gap: 4px;
}

.invoice-action-btn:hover {
    background-color: #f3f4f6;
    border-color: #d1d5db;
    color: #374151 !important;
}

.invoice-action-btn i {
    font-size: 0.875rem;
    color: inherit;
}

.invoice-action-btn span {
    font-size: 0.875rem;
    color: inherit;
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 768px) {
    .recent-invoices {
        padding: 16px;
    }

    .recent-invoices-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .recent-invoices-title {
        font-size: 1.25rem;
    }

    .invoices-table thead {
        display: none;
    }

    .invoices-table tbody tr {
        display: block;
        margin-bottom: 16px;
        padding: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        background: #ffffff;
    }

    .invoices-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
    }

    .invoices-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 0.875rem;
    }

    .invoice-name-cell {
        width: 100%;
    }
}

/* ========================================
   Generic Table Styles for All Tables
   ======================================== */

/* Apply transaction style to all DataTables and standard tables */
table.dataTable,
.table.dataTable,
#quotationTable,
#customerTable,
#reportTable,
table.table {
    width: 100% !important;
    table-layout: auto;
}

/* Ensure table containers handle overflow properly */
.table-responsive,
.table-wrapper,
.invoices-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table-responsive table,
.table-wrapper table,
.invoices-table-container table {
    min-width: 100%;
    max-width: 100%;
}

table.dataTable thead th,
.table.dataTable thead th,
#quotationTable thead th,
#customerTable thead th,
#reportTable thead th,
table.table thead th {
    background: transparent !important;
    color: #6b7280 !important;
    border: none !important;
    border-bottom: 1px solid #f0f0f0 !important;
    padding: 12px 16px !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.5px;
}

table.dataTable tbody tr,
.table.dataTable tbody tr,
#quotationTable tbody tr,
#customerTable tbody tr,
#reportTable tbody tr,
table.table tbody tr {
    border-bottom: 1px solid #f5f5f5 !important;
    transition: background-color 0.2s ease;
}

table.dataTable tbody tr:hover,
.table.dataTable tbody tr:hover,
#quotationTable tbody tr:hover,
#customerTable tbody tr:hover,
#reportTable tbody tr:hover,
table.table tbody tr:hover {
    background-color: #fafafa !important;
}

table.dataTable tbody td,
.table.dataTable tbody td,
#quotationTable tbody td,
#customerTable tbody td,
#reportTable tbody td,
table.table tbody td {
    padding: 16px !important;
    vertical-align: middle;
    border: none !important;
    color: #1a1a1a;
}

/* Status badge styles - Must override DataTables and table styles */
.status-badge {
    display: inline-block !important;
    padding: 6px 16px !important;
    border-radius: 8px !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    text-align: center !important;
    border: none !important;
    cursor: default !important;
    min-width: 80px !important;
}

table.dataTable tbody td .status-badge-pending,
.table.dataTable tbody td .status-badge-pending,
#invoiceTable tbody td .status-badge-pending,
.invoices-table tbody td .status-badge-pending,
.status-badge-pending {
    background-color: #fee2e2 !important;
    background: #fee2e2 !important;
    color: #dc2626 !important;
}

table.dataTable tbody td .status-badge-partial,
.table.dataTable tbody td .status-badge-partial,
#invoiceTable tbody td .status-badge-partial,
.invoices-table tbody td .status-badge-partial,
.status-badge-partial {
    background-color: #dbeafe !important;
    background: #dbeafe !important;
    color: #2563eb !important;
}

table.dataTable tbody td .status-badge-paid,
.table.dataTable tbody td .status-badge-paid,
#invoiceTable tbody td .status-badge-paid,
.invoices-table tbody td .status-badge-paid,
.status-badge-paid {
    background-color: #d1fae5 !important;
    background: #d1fae5 !important;
    color: #059669 !important;
}

/* Generic name cell styles */
.name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.name-cell .table-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.875rem;
    color: #ffffff;
    text-transform: uppercase;
}

.name-cell .name-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.name-cell .table-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.4;
}

.name-cell .table-subtitle {
    font-size: 0.8125rem;
    color: #9ca3af;
    line-height: 1.4;
}

/* Generic action buttons */
.table-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.table-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    background: transparent;
    border: 1px solid #e5e7eb;
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.table-action-btn:hover {
    background-color: #f3f4f6;
    border-color: #d1d5db;
    color: #374151;
}

/* Override Bootstrap table-dark for all tables */
table thead.table-dark th,
.table-dark thead th {
    background: transparent !important;
    color: #6b7280 !important;
    border-bottom: 1px solid #f0f0f0 !important;
}

/* Responsive for all tables */
@media (max-width: 768px) {
    table.dataTable thead,
    .table.dataTable thead,
    #quotationTable thead,
    #customerTable thead,
    #reportTable thead {
        display: none;
    }

    table.dataTable tbody tr,
    .table.dataTable tbody tr,
    #quotationTable tbody tr,
    #customerTable tbody tr,
    #reportTable tbody tr {
        display: block;
        margin-bottom: 16px;
        padding: 16px;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px;
        background: #ffffff;
    }

    table.dataTable tbody td,
    .table.dataTable tbody td,
    #quotationTable tbody td,
    #customerTable tbody td,
    #reportTable tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0 !important;
        border: none !important;
    }

    table.dataTable tbody td[data-label]::before,
    .table.dataTable tbody td[data-label]::before,
    #quotationTable tbody td[data-label]::before,
    #customerTable tbody td[data-label]::before,
    #reportTable tbody td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 0.875rem;
        margin-right: 12px;
    }

    /* Fix Action column overflow on mobile */
    table.dataTable tbody td[data-label="Action"],
    .table.dataTable tbody td[data-label="Action"],
    #quotationTable tbody td[data-label="Action"],
    #customerTable tbody td[data-label="Action"],
    #reportTable tbody td[data-label="Action"],
    .invoices-table tbody td[data-label="Action"] {
        min-width: 0;
        flex-wrap: wrap;
        overflow: visible;
    }

    table.dataTable tbody td[data-label="Action"]::before,
    .table.dataTable tbody td[data-label="Action"]::before,
    #quotationTable tbody td[data-label="Action"]::before,
    #customerTable tbody td[data-label="Action"]::before,
    #reportTable tbody td[data-label="Action"]::before,
    .invoices-table tbody td[data-label="Action"]::before {
        flex-shrink: 0;
        min-width: 60px;
    }
}

/* Prevent Action column from breaking table layout on desktop */
table.dataTable tbody td[data-label="Action"],
.table.dataTable tbody td[data-label="Action"],
#quotationTable tbody td[data-label="Action"],
#customerTable tbody td[data-label="Action"],
#reportTable tbody td[data-label="Action"],
.invoices-table tbody td[data-label="Action"],
table tbody td[data-label="Action"] {
    white-space: nowrap;
    width: auto;
    min-width: 120px;
    max-width: 200px;
    overflow: visible;
}

/* Ensure Action column header doesn't break */
table.dataTable thead th:last-child,
.table.dataTable thead th:last-child,
#quotationTable thead th:last-child,
#customerTable thead th:last-child,
#reportTable thead th:last-child,
.invoices-table thead th:last-child,
table thead th:last-child {
    white-space: nowrap;
    width: auto;
    min-width: 120px;
}