/* Essential Styles & Mobile Optimizations */

:root {
    --primary-gradient: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.18);
}

[data-bs-theme="dark"] {
    --glass-bg: rgba(33, 37, 41, 0.95);
    --glass-border: rgba(255, 255, 255, 0.1);
}

body {
    background-color: var(--bs-body-bg);
    min-height: 100vh;
}

/* Navbar Enhancements */
.navbar {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
}

.navbar-brand img {
    transition: transform 0.3s ease;
}

.navbar-brand:hover img {
    transform: scale(1.05);
}

/* Mobile Menu Adjustments */
@media (max-width: 991.98px) {
    .navbar-collapse {
        background: var(--glass-bg);
        margin-top: 1rem;
        padding: 1rem;
        border-radius: 16px;
        box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
        border: 1px solid var(--glass-border);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }

    .navbar-nav {
        gap: 0.5rem !important;
    }

    .nav-link {
        padding: 0.75rem 1.25rem !important;
        color: var(--bs-body-color) !important;
        border-radius: 10px;
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .nav-link:hover {
        background-color: rgba(13, 110, 253, 0.1) !important;
        color: #0d6efd !important;
        padding-left: 1.5rem !important;
    }

    .nav-link.active {
        background-color: rgba(13, 110, 253, 0.15) !important;
        color: #0d6efd !important;
    }

    /* Logout specific on mobile */
    .nav-link[href*="logout"] {
        margin-top: 0.5rem;
        border-top: 1px solid var(--glass-border);
        padding-top: 1.25rem !important;
        color: #dc3545 !important;
    }
}

/* Dashboard Header Responsiveness */
@media (max-width: 767.98px) {
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1.5rem;
    }

    .quick-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-left: 0 !important;
    }

    .quick-actions .btn {
        width: 100%;
        margin-left: 0 !important;
        text-align: left;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .quick-actions .btn::after {
        content: '\F285';
        /* Bootstrap icon chevron-right */
        font-family: Bootstrap-icons;
        font-size: 0.8rem;
    }

    .h2 {
        font-size: 1.5rem;
    }
}

/* Table Responsiveness */
.table-responsive {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
}

@media (max-width: 575.98px) {
    .dataTables_wrapper .dt-buttons {
        flex-direction: column;
        width: 100%;
    }

    .dataTables_wrapper .btn {
        width: 100%;
    }

    .card-body {
        padding: 1rem !important;
    }
}

/* Card Improvements */
.card {
    border-radius: 12px !important;
    border: 1px solid var(--bs-border-color) !important;
    overflow: hidden;
}

.metric-card {
    border: none !important;
}

/* Custom Scrollbar for better UX */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Stacked Tables for Mobile (Screen only) */
@media screen and (max-width: 767.98px) {
    .table-mobile-responsive {
        border: 0;
    }

    .table-mobile-responsive thead {
        display: none;
    }

    .table-mobile-responsive tr {
        display: block;
        margin-bottom: 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        background: var(--bs-card-bg);
        border: 1px solid var(--bs-border-color);
        overflow: hidden;
    }

    .table-mobile-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid var(--bs-border-color-translucent);
    }

    .table-mobile-responsive td:last-child {
        border-bottom: 0;
        background: rgba(var(--bs-light-rgb), 0.5);
        justify-content: center;
        gap: 0.5rem;
    }

    .table-mobile-responsive td::before {
        content: attr(data-label);
        font-weight: 700;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: var(--bs-secondary-color);
        float: left;
        text-align: left;
    }
}

/* DataTables Button Styling */
.dt-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.btn-excel {
    background-color: #1d6f42 !important;
    border-color: #1d6f42 !important;
    color: white !important;
}

.btn-csv {
    background-color: #007bff !important;
    border-color: #007bff !important;
    color: white !important;
}

.btn-pdf {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: white !important;
}

.btn-excel:hover,
.btn-csv:hover,
.btn-pdf:hover {
    opacity: 0.85;
}

.dt-paging,
.dataTables_paginate,
.dt-info {
    display: flex !important;
    justify-content: center !important;
    margin-top: 1rem !important;
}

.dt-paging {
    margin-bottom: 2rem !important;
}

html {
    scrollbar-gutter: stable;
}

/* Navbar Style Fixes */
.navbar-brand img {
    max-height: 42px !important;
    width: auto;
    filter: invert(1);
    mix-blend-mode: screen;
}

.nav-link {
    font-weight: 600;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    padding: 0.6rem 1rem !important;
    border-radius: 8px;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-1px);
}

.navbar-nav {
    gap: 1rem !important;
}

#theme-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

/* Border Visibility Enhancements */
.card,
.border,
.border-bottom,
.border-top {
    border-color: #ced4da !important;
    /* Solid grey for clear definition in light mode */
}

/* Dark Mode Refinements */
[data-bs-theme="dark"] {
    --bs-body-color: #dee2e6;
    --bs-secondary-color: #adb5bd;
    --bs-border-color: #495057;
    /* Solid, visible border color */
    --bs-card-border-color: #495057;
}

[data-bs-theme="dark"] .card {
    border: 1px solid var(--bs-border-color) !important;
}

/* Fix invisible dark-outline buttons in dark mode */
[data-bs-theme="dark"] .btn-outline-dark {
    border-color: #dee2e6;
    color: #dee2e6;
}

[data-bs-theme="dark"] .btn-outline-dark:hover {
    background-color: #dee2e6;
    color: #121212;
}

/* Fix bg-light padding/contrast in dark mode */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-white {
    background-color: var(--bs-body-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
}

/* Ensure borders are visible on specifically marked elements in dark mode */
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-top {
    border-color: var(--bs-border-color) !important;
}

/* Pivot Table & Services Styles */
.pivot-table {
    font-size: 0.85rem;
    border: 2px solid #333;
    border-collapse: separate;
    /* Required for sticky */
    border-spacing: 0;
}

/* Sticky First Column for Mobile Pivot */
@media screen and (max-width: 767.98px) {

    .pivot-table th:first-child,
    .pivot-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 10;
        background-color: #fff !important;
        border-right: 2px solid #dee2e6 !important;
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    }

    [data-bs-theme="dark"] .pivot-table th:first-child,
    [data-bs-theme="dark"] .pivot-table td:first-child {
        background-color: #212529 !important;
        border-right: 2px solid #444 !important;
    }

    .pivot-table thead th {
        position: sticky;
        top: 0;
        z-index: 11;
    }

    .pivot-table thead th:first-child {
        z-index: 12;
    }

    .pivot-table {
        font-size: 0.75rem;
        /* More compact on mobile */
        min-width: 800px;
        /* Force overflow so scrolling activates */
    }

    .pivot-container {
        max-width: 100vw;
        overflow-x: hidden;
        /* Constrain the container to the screen */
    }

    .pivot-container .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    .pivot-table th,
    .pivot-table td {
        padding: 4px 6px !important;
    }
}

.pivot-table th,
.pivot-table td {
    border: 1px solid #ccc;
    padding: 4px 8px;
    white-space: nowrap;
}

.title-col {
    min-width: 200px;
    background-color: #f8f9fa;
    color: #000;
}

.th-title {
    background-color: #eee !important;
    color: #121212 !important;
}

.th-month {
    background-color: #e6f2ff !important;
    color: #121212 !important;
}

.th-total {
    background-color: #e6ffe6 !important;
    color: #121212 !important;
}

.th-title a,
[data-url-services] {
    color: #121212 !important;
}

.link-overlay {
    cursor: pointer;
    text-decoration: underline;
}

.link-overlay:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* DataTables header styling */
table.data-table thead th,
table.data-table thead td {
    background-color: #eee !important;
    color: #121212 !important;
}

table.data-table .sorting::before,
table.data-table .sorting::after {
    color: #121212 !important;
}

.row-group-header {
    background-color: #e9ecef;
}

.row-group-footer {
    background-color: #f0f0f0;
    border-top: 2px solid #000;
}

.spacer-row {
    height: 10px;
    background-color: #fff;
}

.text-danger {
    color: #d9534f !important;
}

@media print {
    @page {
        size: landscape;
        margin: 5mm;
    }

    .navbar,
    .no-print,
    .breadcrumb,
    body>h1,
    body>h2,
    body>h3 {
        display: none !important;
    }

    /* Ensure DataTables-generated print view headers are visible */
    .dt-print-view h1 {
        display: block !important;
        text-align: center !important;
        margin-bottom: 10px !important;
        font-size: 16pt !important;
    }

    .container {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        background: white !important;
        padding-top: 0 !important;
        zoom: 0.95;
    }

    .print-only {
        display: block !important;
        margin-bottom: 2mm;
    }

    .pivot-container {
        margin-top: 0 !important;
        page-break-inside: avoid;
    }

    .pivot-table {
        width: 100% !important;
        font-size: 7pt !important;
        border: 2px solid black !important;
        table-layout: auto !important;
        margin-bottom: 0 !important;
    }

    .pivot-table th,
    .pivot-table td {
        padding: 1px 3px !important;
        border: 1px solid black !important;
        line-height: 1.4 !important;
    }

    .pivot-table th {
        background: #333 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .title-col {
        min-width: 110px !important;
    }

    .spacer-row td {
        height: 3px !important;
        padding: 0 !important;
    }
}

/* detail-table Styles (from services/details) */
.detail-table {
    font-size: 0.95rem;
}

.detail-table th,
.detail-table td {
    padding: 8px 12px;
}

@media print {
    .detail-table {
        font-size: 10pt !important;
        border-collapse: collapse !important;
        width: 100% !important;
    }

    .detail-table th {
        background-color: #eee !important;
        color: black !important;
        border: 1px solid black !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .detail-table td {
        border: 1px solid #ddd !important;
    }
}

/* dashboard metric Styles (from home) */
.metric-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.1) !important;
}

.metric-icon {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 5px;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Logs / DataTable generic styles */
.data-table td {
    vertical-align: middle;
    padding: 12px 15px;
}