/* ============================================
   CORTEX PM UNIVERSAL DARK MODE STYLES
   For use across all modules
   ============================================ */

/* CSS Custom Properties for Enhanced Theming */
:root {    /* CortexPM Brand Colors */
    --cortex-primary: #667eea;
    --cortex-secondary: #764ba2;
    --cortex-accent: #4a2c96;    --cortex-gradient: linear-gradient(135deg, #a86edc 0%, #7041c4 40%, #4a2c96 70%, #2e1c6a 100%);
    --cortex-gradient-dark: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);    --cortex-gradient-subtle: linear-gradient(135deg, rgba(168, 110, 220, 0.05) 0%, rgba(112, 65, 196, 0.05) 40%, rgba(74, 44, 150, 0.05) 70%, rgba(46, 28, 106, 0.05) 100%);
    --cortex-gradient-subtle-dark: rgba(74, 85, 104, 0.3);
    
    /* Status colors */
    --cortex-success: #198754;
    --cortex-warning: #ffc107;
    --cortex-danger: #dc3545;
    --cortex-info: #0dcaf0;
}

[data-bs-theme="dark"] {
    /* Bootstrap Dark Mode Overrides */
    --bs-body-bg: #1a1a1a;
    --bs-body-color: #e2e8f0;
    --bs-border-color: #4a5568;
    --bs-tertiary-bg: #2d3748;
    --bs-secondary-bg: #374151;
    --bs-emphasis-color: #f7fafc;

    /* CortexPM Dark Theme Colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d3748;
    --bg-tertiary: #374151;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --border-color: #4a5568;
    --card-bg: #2d3748;
    --card-border: #4a5568;
    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3);
    --shadow-md: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.4);

    /* Ensure consistent info color in dark mode */
    --bs-info: #0dcaf0;
    --bs-info-rgb: 13, 202, 240;
}

/* ============================================
   GLOBAL CONTAINERS
   ============================================ */

.content-wrapper {
    background-color: var(--bg-secondary); /* Updated to use variable */
    min-height: 100vh;
}

/* [data-bs-theme="dark"] .content-wrapper is implicitly handled by --bg-secondary variable update */

/* ============================================
   CARDS & CONTAINERS
   ============================================ */

.card {
    background: var(--card-bg); /* Updated to use variable */
    border: none; /* Consider if border should use var(--card-border) or if "none" is intentional */
    border-radius: 0.375rem;
    box-shadow: var(--shadow-sm); /* Updated to use variable */
    margin-bottom: 1.5rem;
    color: var(--text-primary); /* Added for consistency */
}

/* [data-bs-theme="dark"] .card is implicitly handled by variables */

/* Styles for .content-card, .info-container, .selector-container are now in custom.css and use these variables. */

/* ============================================
   FORMS & INPUTS
   ============================================ */

.form-control,
.form-select {
    font-size: 0.9rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color); /* Updated to use variable */
    border-radius: 0.375rem;
    background-color: var(--bg-primary); /* Updated to use variable */
    color: var(--text-primary); /* Updated to use variable */
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background: var(--bs-secondary-bg); /* Using a slightly different dark form background */
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background: var(--bs-secondary-bg);
    border-color: #81c1f7; /* Standard Bootstrap focus color */
    box-shadow: 0 0 0 0.2rem rgba(129, 193, 247, 0.25);
}

/* ============================================
   TABLES & BOOTSTRAP OVERRIDES
   ============================================ */

/* Standard table styling */
.table {
    color: var(--text-primary);
}

/* [data-bs-theme="dark"] .table is implicitly handled by --text-primary variable */

.table th,
.table td {
    padding: 0.75rem;
    vertical-align: middle;
    border-top: 1px solid var(--border-color);
}

/* [data-bs-theme="dark"] .table th, [data-bs-theme="dark"] .table td are implicitly handled by --border-color */

/* Bootstrap table header class overrides */
[data-bs-theme="dark"] .table-light {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
    color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .table-light th,
[data-bs-theme="dark"] .table-light td {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
    color: var(--bs-body-color) !important;
    border-color: var(--bs-tertiary-bg) !important; /* Adjusted variable */
}

[data-bs-theme="dark"] .table-secondary {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
    color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .table-secondary th,
[data-bs-theme="dark"] .table-secondary td {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
    color: var(--bs-body-color) !important;
    border-color: var(--bs-tertiary-bg) !important; /* Adjusted variable */
}

[data-bs-theme="dark"] .thead-light,
[data-bs-theme="dark"] .thead-secondary {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
}

[data-bs-theme="dark"] .thead-light th,
[data-bs-theme="dark"] .thead-secondary th {
    background-color: var(--bs-secondary-bg) !important; /* Adjusted variable */
    color: var(--bs-body-color) !important;
    border-color: var(--bs-tertiary-bg) !important; /* Adjusted variable */
}

/* ============================================
   DATATABLES STYLING
   ============================================ */

/* Custom DataTable header styling - THIS IS NOW THE AUTHORITATIVE STYLE FOR HEADERS */
table.dataTable thead th {
    background: linear-gradient(135deg, #5a5a5a 0%, #434343 100%); /* Standard dark gradient for light mode */
    color: white; /* Light text for light mode */
    border-bottom: 1px solid #666; /* Border for the header */
    font-size: 0.9rem;
    padding: 0.75rem 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

table.dataTable thead th:hover {
    background: linear-gradient(135deg, #666 0%, #4a4a4a 100%); /* Hover state for light mode */
}

[data-bs-theme="dark"] table.dataTable thead th {
    background: var(--cortex-gradient-dark) !important; /* Dark mode gradient from variable */
    color: var(--bs-body-color) !important; /* Light text for dark mode */
    border-bottom-color: var(--bs-border-color) !important;
    font-size: 0.9rem; /* Consistent font styling */
    padding: 0.75rem 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

[data-bs-theme="dark"] table.dataTable thead th:hover {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%) !important; /* Hover state for dark mode */
}

/* DataTable footer styling */
table.dataTable tfoot th,
table.dataTable tfoot td {
    background: var(--cortex-gradient-subtle);
    border-top: 2px solid var(--cortex-primary);
    font-weight: bold;
    color: var(--text-primary);
}

[data-bs-theme="dark"] table.dataTable tfoot th,
[data-bs-theme="dark"] table.dataTable tfoot td {
    background: var(--cortex-gradient-subtle-dark);
    border-top-color: var(--bs-border-color); /* Adjusted variable */
    color: var(--bs-body-color);
}

/* ============================================
   DATATABLES UNIVERSAL STYLING 
   ============================================ */

/* DataTables wrapper improvements */
.dataTables_wrapper {
    margin-bottom: 1rem;
}

.dataTables_wrapper .row {
    margin: 0;
}

/* DataTables search input */
.dataTables_filter input {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    margin-left: 0.5rem;
    width: auto;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

[data-bs-theme="dark"] .dataTables_filter input {
    background: var(--bs-secondary-bg);
    border-color: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
}

/* DataTables info */
.dataTables_info {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding-top: 0.75rem;
}

/* [data-bs-theme="dark"] .dataTables_info is implicitly handled by --text-secondary */

/* Ensure all DataTable tables are responsive and well-styled */
table.dataTable {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 0 !important;
}

table.dataTable tbody td {
    padding: 0.75rem 0.5rem;
    vertical-align: middle;
    font-size: 0.875rem;
    border-color: var(--border-color); /* Added for consistency */
}

table.dataTable tbody tr:hover {
    background-color: var(--bg-tertiary); /* Light hover */
}

[data-bs-theme="dark"] table.dataTable tbody tr:hover {
    background-color: var(--bs-secondary-bg); /* Dark hover */
}

/* Responsive DataTables */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.child,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.child,
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dataTables_empty {
    cursor: default !important;
}

table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > td:first-child:before,
table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > th:first-child:before {
    background-color: var(--cortex-primary);
    border: 2px solid var(--bg-primary); /* Use variable for border */
    border-radius: 50%;
    box-shadow: 0 0 3px var(--cortex-primary);
}

[data-bs-theme="dark"] table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > td:first-child:before,
[data-bs-theme="dark"] table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > th:first-child:before {
    border-color: var(--card-bg); /* Use variable for dark border */
}

/* Financial summary cards with Cortex colors */
.bg-primary.bg-opacity-10 {
    background-color: rgba(102, 126, 234, 0.1) !important;
}

.bg-success.bg-opacity-10 {
    background-color: rgba(25, 135, 84, 0.1) !important;
}

.bg-warning.bg-opacity-10 {
    background-color: rgba(255, 193, 7, 0.1) !important;
}

.bg-info.bg-opacity-10 {
    background-color: rgba(13, 202, 240, 0.1) !important;
}

[data-bs-theme="dark"] .bg-primary.bg-opacity-10 {
    background-color: rgba(102, 126, 234, 0.15) !important;
}

[data-bs-theme="dark"] .bg-success.bg-opacity-10 {
    background-color: rgba(25, 135, 84, 0.15) !important;
}

[data-bs-theme="dark"] .bg-warning.bg-opacity-10 {
    background-color: rgba(255, 193, 7, 0.15) !important;
}

[data-bs-theme="dark"] .bg-info.bg-opacity-10 {
    background-color: rgba(13, 202, 240, 0.15) !important;
}

/* Enhanced table styling for purchase order items */
.table-hover tbody tr:hover {
    background-color: var(--cortex-gradient-subtle);
}

[data-bs-theme="dark"] .table-hover tbody tr:hover {
    background-color: var(--cortex-gradient-subtle-dark);
}

/* Purchase Order item rows styling for create/update forms */
.po-item-row {
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

[data-bs-theme="dark"] .po-item-row {
    background-color: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

/* Override Bootstrap's bg-light class for PO items in dark mode */
[data-bs-theme="dark"] .po-item-row.bg-light {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
}

/* Form elements within PO item rows */
[data-bs-theme="dark"] .po-item-row .form-control,
[data-bs-theme="dark"] .po-item-row .form-select {
    background-color: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .po-item-row .form-control:focus,
[data-bs-theme="dark"] .po-item-row .form-select:focus {
    background-color: var(--bs-secondary-bg);
    border-color: #81c1f7;
    box-shadow: 0 0 0 0.2rem rgba(129, 193, 247, 0.25);
    color: var(--bs-body-color);
}

/* Labels within PO item rows */
[data-bs-theme="dark"] .po-item-row .form-label {
    color: var(--bs-body-color);
}

/* Checkboxes within PO item rows */
[data-bs-theme="dark"] .po-item-row .form-check-label {
    color: var(--bs-body-color);
}

/* Status badges with Cortex accent */
.badge.bg-light {
    background-color: rgba(102, 126, 234, 0.1) !important;
    color: var(--cortex-primary) !important;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

[data-bs-theme="dark"] .badge.bg-light {
    background-color: rgba(102, 126, 234, 0.2) !important;
    color: var(--cortex-primary) !important;
}

/* Compact row spacing for overview cards */
.row.g-2 > * {
    margin-bottom: 0.5rem;
}

.row.g-2 small.text-muted {
    font-size: 0.75rem;
    margin-bottom: 0.125rem;
}

/* Button group improvements */
.btn-group-sm .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* ============================================
   ACTIVITY LOG & DOCUMENTS STYLING
   ============================================ */

/* Compact activity log */
.table-sm th, .table-sm td {
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
}

/* Document type badges */
.badge.bg-light.text-dark {
    background-color: var(--cortex-gradient-subtle) !important;
    color: var(--cortex-primary) !important;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

[data-bs-theme="dark"] .badge.bg-light.text-dark {
    background-color: var(--cortex-gradient-subtle-dark) !important;
    color: var(--cortex-primary) !important;
}

/* ============================================
   LEGACY PURCHASE ORDER ITEMS TABLE - DEPRECATED
   Use DataTables styling above instead
   ============================================ */

.purchase-order-items-table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
}

.purchase-order-items-table th,
.purchase-order-items-table td {
    vertical-align: middle;
    padding: 0.75rem 0.5rem;
    word-wrap: break-word;
}

.purchase-order-items-table .table-bordered th,
.purchase-order-items-table .table-bordered td {
    border: 1px solid var(--bs-border-color);
}

/* Better spacing for billed/remaining info */
.purchase-order-items-table .text-success,
.purchase-order-items-table .text-danger {
    font-weight: 500;
}

.purchase-order-items-table small {
    font-size: 0.75rem;
    line-height: 1.2;
}

/* ============================================
   PURCHASE ORDER SPECIFIC TABLE IMPROVEMENTS
   ============================================ */

/* Better column width distribution for purchase order items table */
.purchase-order-items-table th:nth-child(1) { width: 30px; }    /* # (further reduced) */
.purchase-order-items-table th:nth-child(2) { width: 180px; }   /* Description (further reduced) */
.purchase-order-items-table th:nth-child(3) { width: 50px; }    /* Cost Code (further reduced) */
.purchase-order-items-table th:nth-child(4) { width: 60px; }    /* Quantity (further reduced) */
.purchase-order-items-table th:nth-child(5) { width: 45px; }    /* Unit (further reduced) */
.purchase-order-items-table th:nth-child(6) { width: 80px; }    /* Unit Price (further reduced) */
.purchase-order-items-table th:nth-child(7) { width: 80px; }    /* Total (further reduced) */
.purchase-order-items-table th:nth-child(8) { width: 100px; }   /* Billed (further reduced) */
.purchase-order-items-table th:nth-child(9) { width: 100px; }   /* Remaining (further reduced) */

/* Styling for related tables */
#related-invoices-table,
#related-documents-table,
#activity-log-table {
    width: 100%;
}

#related-invoices-table th,
#related-documents-table th,
#activity-log-table th,
#related-invoices-table td,
#related-documents-table td,
#activity-log-table td {
    vertical-align: middle;
    padding: 0.75rem 0.5rem;
}

/* Ensure badges and status indicators look good in tables */
table.dataTable .badge {
    font-size: 0.75rem;
    padding: 0.375rem 0.5rem;
}

table.dataTable .btn-group-sm .btn {
    padding: 0.25rem 0.375rem;
    font-size: 0.75rem;
    line-height: 1.25;
}

/* Remove default table margins when in DataTables */
.table-responsive table.dataTable {
    margin-bottom: 0 !important;
}

/* Force table constraint to prevent horizontal scroll */
.table-responsive {
    max-width: 100%;
    overflow: visible; /* This might be problematic, usually auto or scroll */
}

/* Better responsive behavior for smaller text in tables */
@media (max-width: 1200px) {
    .purchase-order-items-table th,
    .purchase-order-items-table td {
        font-size: 0.8rem;
        padding: 0.5rem 0.25rem;
    }
    
    .purchase-order-items-table small {
        font-size: 0.7rem;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    [data-bs-theme="dark"] {
        background: white !important;
        color: black !important;
    }
    
    [data-bs-theme="dark"] .card,
    [data-bs-theme="dark"] .content-card {
        background: white !important;
        color: black !important;
        border: 1px solid #ccc !important;
    }
    
    [data-bs-theme="dark"] table.dataTable thead th {
        background: #f8f9fa !important;
        color: black !important;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus indicators */
[data-bs-theme="dark"] .btn:focus,
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    box-shadow: 0 0 0 0.2rem rgba(129, 193, 247, 0.25);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    [data-bs-theme="dark"] {
        --bs-body-bg: #000000;
        --bs-body-color: #ffffff;
        --bs-border-color: #ffffff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .card,
    /* .project-card, */ /* Assuming .project-card is defined elsewhere or can be added if needed */
    /* .widget-card, */ /* Assuming .widget-card is defined elsewhere or can be added if needed */
    .theme-toggle {
        transition: none;
    }
}

/* ============================================
   TIMELINE COMPONENTS
   ============================================ */

/* Timeline for client interactions and activity logs */
.timeline {
    position: relative;
    padding: 1rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 0;
    left: 1.5rem;
    width: 2px;
    height: 100%;
    background-color: var(--border-color);
}

/* [data-bs-theme="dark"] .timeline::before is implicitly handled by --border-color */

.timeline-item {
    position: relative;
    margin-bottom: 1.5rem;
    padding-left: 3.5rem;
}

.timeline-marker {
    position: absolute;
    left: 0.75rem;
    top: 0.5rem;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background-color: var(--cortex-primary);
    border: 3px solid var(--bg-primary);
    z-index: 2;
}

/* [data-bs-theme="dark"] .timeline-marker is implicitly handled by variables */

.timeline-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--cortex-primary);
    border-radius: 0.375rem;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

/* [data-bs-theme="dark"] .timeline-content is implicitly handled by variables */

.timeline-header {
    display: flex;
    justify-content: space-between; /* Corrected from 'between' */
    align-items: center;
    margin-bottom: 0.5rem;
}

.timeline-time {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* [data-bs-theme="dark"] .timeline-time is implicitly handled by --text-secondary */

/* ============================================
   DROPDOWN MENU DARK MODE OVERRIDES
   ============================================ */

/* Enhanced dropdown styling for dark mode legibility */
[data-bs-theme="dark"] .dropdown-menu {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.6);
}

/* Dropdown items in dark mode with better contrast */
[data-bs-theme="dark"] .dropdown-item {
    color: var(--text-primary);
    background: transparent;
}

/* Hover state using CortexPM gradient for dark mode */
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    background: var(--cortex-gradient) !important;
    color: white !important;
    border-color: transparent;
}

/* Active dropdown items in dark mode */
[data-bs-theme="dark"] .dropdown-item.active,
[data-bs-theme="dark"] .dropdown-item:active {
    background: var(--cortex-gradient) !important;
    color: white !important;
}

/* Disabled dropdown items */
[data-bs-theme="dark"] .dropdown-item:disabled,
[data-bs-theme="dark"] .dropdown-item.disabled {
    color: var(--text-secondary);
    background: transparent;
}

/* Dropdown headers in dark mode */
[data-bs-theme="dark"] .dropdown-header {
    color: var(--cortex-primary);
    font-weight: 600;
}

/* Dropdown text items in dark mode */
[data-bs-theme="dark"] .dropdown-item-text {
    color: var(--text-secondary);
}

/* Bootstrap override for dropdown menu positioning */
[data-bs-theme="dark"] .dropdown-menu[data-bs-popper] {
    border-color: var(--border-color);
}

/* ============================================
   END DROPDOWN DARK MODE OVERRIDES
   ============================================ */
