:root {
    --sidebar-width: 250px;
    --sidebar-bg: #1a1d21;
    --sidebar-hover: #2c3136;
    --sidebar-active: #0d6efd;
    --sidebar-text: #adb5bd;
    --sidebar-text-active: #ffffff;
    --primary: #0d6efd;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #0dcaf0;
    --body-bg: #f4f6f9;
    --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --card-shadow-hover: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}

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

body {
    background-color: var(--body-bg);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: clamp(0.8rem, 0.75rem + 0.4vw, 0.95rem);
    color: #333;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

img, video, svg {
    max-width: 100%;
    height: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand {
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: 0.5px;
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-brand i {
    color: var(--primary);
}

.sidebar-close {
    color: var(--sidebar-text);
    font-size: 1.2rem;
    padding: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-nav .nav-item {
    margin: 2px 0.75rem;
}

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: 0.6rem 1rem;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

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

.sidebar-nav .nav-link.active {
    color: var(--sidebar-text-active);
    background-color: var(--sidebar-active);
    font-weight: 500;
}

.sidebar-nav .nav-icon {
    width: 20px;
    text-align: center;
    margin-right: 0.75rem;
    font-size: 0.9rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user-name {
    color: #fff;
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.sidebar-user-role {
    color: var(--sidebar-text);
    font-size: 0.75rem;
}

.avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.main-content {
    margin-left: var(--sidebar-width);
    padding: 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content.no-sidebar {
    margin-left: 0;
    padding: 0;
}

.sidebar-toggle {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 1050;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1035;
    display: none;
}

.sidebar-overlay.show {
    display: block;
}

.app-footer {
    margin-top: auto;
    border-top: 1px solid #dee2e6;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1,
.page-header h2 {
    margin-bottom: 0;
    font-weight: 600;
    font-size: clamp(1.1rem, 1rem + 1vw, 1.5rem);
    word-break: break-word;
}

.card {
    border: none;
    border-radius: 0.5rem;
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.dashboard-card {
    border-top: 3px solid var(--primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.dashboard-card.card-primary { border-top-color: var(--primary); }
.dashboard-card.card-success { border-top-color: var(--success); }
.dashboard-card.card-warning { border-top-color: var(--warning); }
.dashboard-card.card-danger { border-top-color: var(--danger); }
.dashboard-card.card-info { border-top-color: var(--info); }

.dashboard-card .card-icon {
    font-size: 2rem;
    opacity: 0.7;
}

.dashboard-card .card-value {
    font-size: clamp(1.25rem, 1rem + 1.5vw, 1.75rem);
    font-weight: 700;
    line-height: 1.2;
    word-break: break-word;
}

.dashboard-card .card-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
}

.table {
    font-size: 0.875rem;
}

.table thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    color: #495057;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.04);
}

.table .actions {
    white-space: nowrap;
}

.table .actions .btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
}

.table-sortable th {
    cursor: pointer;
    user-select: none;
}

.table-sortable th:hover {
    background-color: #e9ecef;
}

.table-sortable th .sort-icon {
    margin-left: 0.25rem;
    opacity: 0.3;
}

.table-sortable th.sort-asc .sort-icon,
.table-sortable th.sort-desc .sort-icon {
    opacity: 1;
}

.badge-status {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-active, .badge-status-active { background-color: var(--success) !important; color: #fff; }
.badge-past-due, .badge-status-past_due { background-color: #fd7e14 !important; color: #fff; }
.badge-suspended, .badge-status-suspended { background-color: var(--danger) !important; color: #fff; }
.badge-cancelled, .badge-status-cancelled { background-color: #6c757d !important; color: #fff; }
.badge-pending, .badge-status-pending { background-color: var(--warning) !important; color: #212529; }
.badge-completed, .badge-status-completed { background-color: var(--success) !important; color: #fff; }
.badge-in-progress, .badge-status-in_progress { background-color: var(--info) !important; color: #212529; }
.badge-draft, .badge-status-draft { background-color: #adb5bd !important; color: #212529; }
.badge-paid, .badge-status-paid { background-color: var(--success) !important; color: #fff; }
.badge-unpaid, .badge-status-unpaid { background-color: var(--danger) !important; color: #fff; }

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.35rem;
}

.form-control, .form-select {
    font-size: 0.875rem;
    border-radius: 0.375rem;
    min-height: 44px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.input-group-text {
    font-size: 0.875rem;
    background-color: #f8f9fa;
}

.btn {
    font-size: 0.875rem;
    border-radius: 0.375rem;
    font-weight: 500;
    min-height: 44px;
    padding: 0.5rem 1rem;
    touch-action: manipulation;
}

.btn-sm {
    min-height: 36px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.table .actions .btn {
    min-height: 32px;
}

.flash-messages {
    margin-bottom: 1rem;
}

.alert {
    font-size: 0.875rem;
    border-radius: 0.375rem;
}

.currency-pkr::before {
    content: 'PKR ';
    font-weight: 500;
}

.text-pkr {
    font-family: 'Segoe UI', system-ui, monospace;
    font-weight: 600;
}

.upload-widget {
    position: relative;
}

.upload-drop-zone {
    border: 2px dashed #dee2e6;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    position: relative;
    background-color: #fafbfc;
}

.upload-drop-zone:hover,
.upload-drop-zone.drag-over {
    border-color: var(--primary);
    background-color: rgba(13, 110, 253, 0.04);
}

.upload-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.upload-preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 0.375rem;
    overflow: hidden;
    border: 1px solid #dee2e6;
}

.upload-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upload-preview-item .remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.auth-page {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
}

.auth-logo {
    width: 70px;
    height: 70px;
    border-radius: 1rem;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.3);
}

.search-box {
    max-width: 300px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: var(--card-shadow);
}

.stat-card {
    text-align: center;
    padding: 1.25rem;
}

.stat-card .stat-value {
    font-size: clamp(1.4rem, 1.2rem + 1.5vw, 2rem);
    font-weight: 700;
    color: var(--primary);
    word-break: break-word;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.breadcrumb {
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

body.dark-mode {
    background-color: #1a1a2e;
    color: #e0e0e0;
}
body.dark-mode .card { background-color: #16213e; border-color: #0f3460; }
body.dark-mode .sidebar { background-color: #0f3460; }
body.dark-mode .table { color: #e0e0e0; }
body.dark-mode .table thead th { background-color: #0f3460; color: #e0e0e0; border-color: #1a1a2e; }
body.dark-mode .table-striped tbody tr:nth-of-type(odd) { background-color: rgba(255,255,255,0.05); }
body.dark-mode .table-hover tbody tr:hover { background-color: rgba(255,255,255,0.08); }
body.dark-mode .form-control, body.dark-mode .form-select { background-color: #16213e; color: #e0e0e0; border-color: #0f3460; }
body.dark-mode .form-control:focus, body.dark-mode .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25); }
body.dark-mode .modal-content { background-color: #16213e; color: #e0e0e0; }
body.dark-mode .btn-light { background-color: #16213e; color: #e0e0e0; border-color: #0f3460; }
body.dark-mode .dropdown-menu { background-color: #16213e; border-color: #0f3460; }
body.dark-mode .dropdown-item { color: #e0e0e0; }
body.dark-mode .dropdown-item:hover { background-color: #0f3460; }
body.dark-mode .text-muted { color: #aaa !important; }
body.dark-mode .bg-white { background-color: #16213e !important; }
body.dark-mode .bg-light { background-color: #1a1a2e !important; }
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4, body.dark-mode h5 { color: #e0e0e0; }
body.dark-mode .page-link { background-color: #16213e; color: #e0e0e0; border-color: #0f3460; }
body.dark-mode .input-group-text { background-color: #0f3460; color: #e0e0e0; border-color: #0f3460; }
body.dark-mode .filter-bar { background: #16213e; }
body.dark-mode .dashboard-card .card-label { color: #aaa; }
body.dark-mode .app-footer { border-top-color: #0f3460; }
body.dark-mode .breadcrumb { color: #aaa; }
body.dark-mode .breadcrumb-item a { color: var(--primary); }
body.dark-mode .alert { border-color: #0f3460; }
body.dark-mode .nav-tabs .nav-link { color: #aaa; }
body.dark-mode .nav-tabs .nav-link.active { background-color: #16213e; color: #e0e0e0; border-color: #0f3460 #0f3460 #16213e; }
body.dark-mode .list-group-item { background-color: #16213e; color: #e0e0e0; border-color: #0f3460; }
body.dark-mode .border { border-color: #0f3460 !important; }
body.dark-mode .sidebar-toggle { background-color: #0f3460; border-color: #0f3460; color: #e0e0e0; }

.dark-mode-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: #adb5bd;
    padding: 0.4rem 0.6rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}
.dark-mode-toggle:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.4);
}

.lang-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: #adb5bd;
    padding: 0.4rem 0.6rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
    font-weight: 500;
}
.lang-toggle:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.4);
}

.sidebar-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3.5rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header .btn,
    .page-header .btn-group {
        width: 100%;
    }

    .page-header .btn-group .btn {
        flex: 1;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-control,
    .filter-bar .form-select,
    .filter-bar .btn {
        width: 100%;
    }

    .search-box {
        max-width: 100%;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 767.98px) {
    .stat-card {
        margin-bottom: 10px;
        padding: 0.75rem;
    }

    .stat-card .stat-value {
        font-size: 1.3rem;
    }

    .kanban-board { flex-direction: column; }
    .kanban-column { min-width: 100%; }
    .btn-group-mobile { display: flex; flex-direction: column; gap: 5px; }

    .dashboard-card .card-icon {
        font-size: 1.5rem;
    }

    .dashboard-card .card-body {
        padding: 0.75rem;
    }

    .table {
        font-size: 0.8rem;
    }

    .table thead th {
        font-size: 0.7rem;
        padding: 0.5rem 0.4rem;
    }

    .table td {
        padding: 0.5rem 0.4rem;
    }

    .table .actions {
        display: flex;
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .table .actions .btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.7rem;
        min-height: 30px;
    }

    .table .actions .btn .d-none-mobile-text {
        display: none;
    }

    .badge-status {
        font-size: 0.65rem;
        padding: 0.25em 0.5em;
    }

    .breadcrumb {
        font-size: 0.75rem;
    }

    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-state i {
        font-size: 2.5rem;
    }

    .upload-drop-zone {
        padding: 1.25rem;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination .page-link {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    .input-group {
        flex-wrap: nowrap;
    }

    .col-md-6, .col-md-4, .col-md-3 {
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 575.98px) {
    .main-content {
        padding: 0.5rem;
        padding-top: 3.5rem;
    }

    .page-header {
        margin-bottom: 1rem;
        gap: 0.5rem;
    }

    .card {
        border-radius: 0.375rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .card-header {
        padding: 0.6rem 0.75rem;
    }

    .filter-bar {
        padding: 0.5rem;
        gap: 0.4rem;
        border-radius: 0.375rem;
    }

    .table-responsive {
        font-size: 0.75rem;
        margin: 0 -0.5rem;
        width: calc(100% + 1rem);
        border-radius: 0;
    }

    .table td, .table th {
        padding: 0.4rem 0.35rem;
    }

    .form-label {
        font-size: 0.8rem;
    }

    .alert {
        font-size: 0.8rem;
        padding: 0.6rem 0.75rem;
    }

    .sidebar-footer {
        padding: 0.75rem 1rem;
    }

    .sidebar-user-name {
        max-width: 120px;
        font-size: 0.8rem;
    }

    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }

    .modal-header {
        padding: 0.75rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-footer {
        padding: 0.5rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 0;
    }

    .auth-logo {
        width: 56px;
        height: 56px;
        font-size: 1.5rem;
    }

    .auth-page h2 {
        font-size: 1.3rem;
    }

    .auth-page .card-body {
        padding: 1.25rem;
    }

    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.15rem; }
    h3 { font-size: 1.05rem; }
    h4 { font-size: 0.95rem; }
    h5 { font-size: 0.875rem; }

    .btn {
        font-size: 0.8rem;
        padding: 0.45rem 0.75rem;
    }

    .form-control, .form-select {
        font-size: 0.8rem;
    }

    .input-group-text {
        font-size: 0.8rem;
        padding: 0.375rem 0.5rem;
    }

    .sidebar-nav .nav-link {
        padding: 0.7rem 1rem;
        font-size: 0.85rem;
    }

    .sidebar-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .pak-flag-wrapper {
        width: 160px;
        height: 107px;
    }

    .pak-flag-text {
        font-size: 0.9rem;
    }
}

@media (max-width: 359.98px) {
    .main-content {
        padding: 0.35rem;
        padding-top: 3.5rem;
    }

    .card-body {
        padding: 0.5rem;
    }

    .table td, .table th {
        padding: 0.3rem 0.25rem;
        font-size: 0.7rem;
    }

    .btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }

    .form-control, .form-select {
        font-size: 0.75rem;
        min-height: 40px;
    }

    .auth-page .card-body {
        padding: 1rem;
    }

    .sidebar-brand {
        font-size: 1.2rem;
    }

    .page-header h1, .page-header h2 {
        font-size: 1rem;
    }
}

@media (min-width: 1200px) {
    .container, .container-lg, .container-xl {
        max-width: 1140px;
    }

    .main-content {
        padding: 1.5rem 2rem;
    }
}

@media (min-width: 1400px) {
    .main-content {
        padding: 2rem 2.5rem;
    }
}

@media print {
    .sidebar,
    .sidebar-toggle,
    .sidebar-overlay,
    .app-footer,
    .btn,
    .flash-messages,
    .pagination,
    .filter-bar {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 12pt;
    }

    .table thead th {
        background-color: #eee !important;
    }

    a[href]::after {
        content: none !important;
    }
}
