:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
    --accent-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --card-bg: #1e293b;
    --input-bg: #334155;
    --input-text: #ffffff;
    --label-color: #cbd5e1;
    --success: #22c55e;
    --danger: #ef4444;
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --accent-color: #2563eb;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(203, 213, 225, 0.8);
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --input-text: #0f172a;
    --label-color: #475569;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .glass-panel {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Sidebar */
.sidebar {
    background: rgba(15, 23, 42, 0.95);
    border-right: 1px solid var(--glass-border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 50;
    box-sizing: border-box;
}

[data-theme="light"] .sidebar {
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
}

/* Scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

[data-theme="light"] .sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-color);
    margin-bottom: 3rem;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] .nav-link {
    color: #64748b;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: #fff;
    transform: translateX(4px);
}

[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
}

.nav-link i {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    padding: 2.5rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* Adjust Layout to respect Fixed Sidebar */
.layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    margin-left: 260px;
    flex: 1;
    min-height: 100vh;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    letter-spacing: -0.025em;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0.5rem 0;
}

.stat-label {
    color: var(--label-color);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--label-color);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0 1rem;
    height: 45px;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--input-text);
    font-family: inherit;
    transition: all 0.2s;
    box-sizing: border-box;
}

textarea.form-control {
    height: auto;
    padding: 0.75rem 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

[data-theme="light"] .form-control {
    border-color: #cbd5e1;
}

[data-theme="light"] .form-control:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.btn {
    padding: 0 1.5rem;
    height: 45px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(59, 130, 246, 0.5);
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.table th {
    text-align: left;
    padding: 1rem;
    color: var(--label-color);
    font-weight: 600;
    border-bottom: 1px solid var(--glass-border);
}

.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--glass-border);
    vertical-align: middle;
}

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

.table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-card {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

/* Button styles override or new specific class */
.btn-view {
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    /* Very subtle background */
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    transition: all 0.2s ease;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-view:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn-back {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: translateX(-2px);
}

.btn-dashed {
    width: 100%;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    color: #94a3b8;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-dashed:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

/* Form Grid Utilities */
.form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.split-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 2rem;
    align-items: start;
}

/* Mobile Responsive */
.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 99;
    backdrop-filter: blur(12px);
}

.brand-mobile {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-toggle,
.close-sidebar {
    background: transparent !important;
    border: none !important;
    outline: none !important;
    color: #fff !important;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.menu-toggle:hover,
.close-sidebar:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}

.close-sidebar {
    display: none;
    /* Only show on mobile sidebar */
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 1024px) {
    .split-layout {
        grid-template-columns: 1fr;
    }

    .form-grid-3,
    .form-grid-2 {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 768px) {
    .layout {
        display: block;
        /* Stack layout */
    }

    .main-content {
        margin-left: 0;
        /* Reset margin for mobile */
    }

    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 80%;
        max-width: 280px;
        transform: translateX(-110%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        box-shadow: 10px 0 25px rgba(0, 0, 0, 0.5);
        border-right: none;
        overflow-y: auto;
        /* Ensure scroll on mobile */
        height: 100dvh;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar .brand {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 2rem;
        padding-right: 0;
        width: 100%;
    }

    .close-sidebar {
        display: flex;
    }

    .main-content {
        padding: 1.5rem;
    }

    /* Force grids to 1 column on mobile */
    .form-grid-3,
    .form-grid-2,
    .card-grid,
    .split-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    h1 {
        font-size: 1.75rem;
        margin-bottom: 1.5rem;
    }

    /* Adjust tables */
    .table th,
    .table td {
        white-space: nowrap;
        /* Prevent wrapping in cells */
    }

    /* Make stat cards smaller padding */
    .stat-card {
        padding: 1.25rem;
    }

    /* Stack form groups with radios */
    .form-group>div {
        flex-direction: column;
        gap: 0.75rem !important;
    }

    /* Modal full width on mobile */
    .modal-card {
        width: 95%;
        padding: 1.5rem;
    }
}

/* -------------------------------------------------------------------------- */
/* PRINT LAYOUT (PDF)                                                         */
/* -------------------------------------------------------------------------- */
@media print {

    /* Hide UI Elements */
    .sidebar,
    .navbar,
    .btn,
    .no-print,
    .mobile-header,
    .menu-toggle,
    .modal-overlay,
    a[href]::after,
    .site-footer {
        display: none !important;
    }

    /* Reset Body */
    body {
        background: #fff !important;
        color: #000 !important;
        font-family: 'Times New Roman', serif;
        /* Classic document font */
        margin: 0 !important;
        padding: 0 !important;
        font-size: 12pt;
    }

    /* Reset Layout */
    .layout {
        display: block !important;
        grid-template-columns: 1fr !important;
    }

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

    /* Reset Panels/Cards */
    .glass-panel,
    .card {
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        color: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        backdrop-filter: none !important;
    }

    /* Tables */
    .table {
        width: 100% !important;
        border-collapse: collapse !important;
        border: 1px solid #000 !important;
        margin-top: 1rem;
    }

    .table th {
        background: #f3f3f3 !important;
        color: #000 !important;
        font-weight: bold;
        border: 1px solid #000 !important;
        text-align: left;
        padding: 8px !important;
    }

    .table td {
        border: 1px solid #000 !important;
        color: #000 !important;
        padding: 8px !important;
        border-bottom: 1px solid #000 !important;
    }

    /* Typography Overrides */
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        color: #000 !important;
        margin-top: 0;
    }

    h1 {
        font-size: 24pt;
        margin-bottom: 20px;
    }

    h4 {
        font-size: 14pt;
        margin-bottom: 10px;
    }

    /* Text Colors */
    .text-muted,
    span[style*="gray"],
    div[style*="gray"],
    .stat-label {
        color: #000 !important;
        opacity: 1 !important;
    }

    /* Specific Invoice Styling */
    .invoice-header {
        display: flex !important;
        justify-content: space-between !important;
        margin-bottom: 30px !important;
        border-bottom: 2px solid #000 !important;
        padding-bottom: 20px !important;
    }

    .invoice-to {
        margin-top: 20px;
    }

    /* Ensure backgrounds don't print unless simplified */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        text-shadow: none !important;
    }

    /* Page Break */
    .page-break {
        page-break-before: always;
    }

    .print-only {
        display: block !important;
    }
}

/* -------------------------------------------------------------------------- */
/* TOM SELECT CUSTOMIZATION (Dark Mode)                                       */
/* -------------------------------------------------------------------------- */
.ts-wrapper.single .ts-control,
.ts-control {
    background-color: rgba(51, 65, 85, 0.5) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    border-radius: 8px !important;
    padding: 0.75rem 1rem !important;
    min-height: 44px;
    box-shadow: none !important;
    background-image: none !important;
    display: flex;
    align-items: center;
}

/* Focus State - Blue Border */
.ts-wrapper.focus .ts-control {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 1px #3b82f6 !important;
}

.ts-wrapper {
    width: 100%;
    min-width: 150px;
}

.ts-control>input {
    color: #fff !important;
    background: transparent !important;
    box-shadow: none !important;
    font-weight: 500 !important;
}

.ts-dropdown {
    background-color: #1e293b !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #cbd5e1 !important;
    z-index: 99999 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5) !important;
    border-radius: 0 0 8px 8px !important;
    margin-top: 4px !important;
    padding: 0 !important;
}

.ts-dropdown .option {
    padding: 0.75rem 1rem !important;
}

/* Selected/Active Option Blue Background */
.ts-dropdown .active,
.ts-dropdown .option:hover {
    background-color: #2563eb !important;
    /* Brighter blue matching image */
    color: #fff !important;
}

/* Remove Button */
.ts-wrapper .item .remove {
    border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #94a3b8 !important;
    margin-left: 0.5rem;
    padding-left: 0.5rem;
}

.ts-wrapper .item .remove:hover {
    background: transparent !important;
    color: #ef4444 !important;
}

/* Arrow Icon */
.ts-wrapper.single .ts-control:after {
    border: none !important;
    content: '\f107' !important;
    /* FontAwsome Chevron Down */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: #fff !important;
    right: 1rem !important;
    font-size: 0.8rem;
}

/* Fix Double Box Issue */
.ts-wrapper.form-control,
.ts-wrapper.form-select {
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}