* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0891b2;
    --primary-hover: #0e7490;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --sidebar-width: 260px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: var(--primary-color);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Sidebar Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

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

.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand-icon svg {
    width: 22px;
    height: 22px;
    fill: white;
}

.sidebar-brand-text {
    color: #ffffff;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.sidebar-brand-sub {
    color: var(--sidebar-text);
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
}

.sidebar-nav {
    padding: 16px 0;
    flex: 1;
}

.sidebar-section-label {
    padding: 8px 20px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.3);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-item:hover {
    background: rgba(255,255,255,0.06);
    color: #ffffff;
}

.sidebar-item.active {
    background: rgba(8, 145, 178, 0.15);
    color: #ffffff;
    border-left-color: var(--primary-color);
}

.sidebar-item .icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
    opacity: 0.8;
}

.sidebar-item.active .icon {
    opacity: 1;
}

.sidebar-item .badge {
    margin-left: auto;
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-text);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar-item.active .badge {
    background: var(--primary-color);
    color: white;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 8px 20px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-user-name {
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.sidebar-user-role {
    color: var(--sidebar-text);
    font-size: 11px;
    opacity: 0.7;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background: rgba(255,255,255,0.06);
    color: var(--sidebar-text);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}

/* Mobile Top Bar */
.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    padding: 0 16px;
    height: 56px;
    z-index: 90;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
}

.mobile-topbar-brand .sidebar-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.mobile-topbar-brand .sidebar-brand-icon svg {
    width: 18px;
    height: 18px;
}

.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.hamburger:active {
    background: rgba(255,255,255,0.1);
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #ffffff;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Header */
.header {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 32px;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.header-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* Tabs - hidden, replaced by sidebar */
.tabs {
    display: none;
}

/* Tab Content */
.tab-content {
    display: none;
    background: var(--bg-primary);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.tab-content.active {
    display: block;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    align-items: center;
    flex-wrap: wrap;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-input-wrapper .search-input {
    width: 100%;
    padding-right: 42px;
}

.search-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.search-btn:hover {
    background: var(--primary-hover);
}

.search-input, .select-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.search-input:focus, .select-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.12);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-primary {
    background: #0891b2;
    color: white;
    box-shadow: 0 4px 12px rgba(8, 145, 178, 0.25);
}

.btn-primary:hover {
    background: #0e7490;
    box-shadow: 0 6px 16px rgba(8, 145, 178, 0.35);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    padding: 6px 12px;
    font-size: 13px;
}

.btn-danger:hover {
    background: #dc2626;
    box-shadow: var(--shadow-sm);
}

.btn-info {
    background: var(--info-color);
    color: white;
    padding: 5px 10px;
    font-size: 12px;
}

.btn-info:hover {
    background: #2563eb;
    box-shadow: var(--shadow-sm);
}

/* Table */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.data-table thead {
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
}

.data-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.data-table th.sortable {
    user-select: none;
    position: relative;
}

.data-table th.sortable:hover {
    background: var(--bg-tertiary);
}

.sort-indicator {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.7;
}

.date-filters {
    display: flex;
    gap: 8px;
    align-items: center;
}

.date-filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.date-filter-btn.active:hover {
    background: var(--primary-hover);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 14px;
}

.data-table tbody tr {
    transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
    background: var(--bg-secondary);
}

.data-table tbody tr.patient-row:hover {
    background: var(--bg-tertiary);
    box-shadow: inset 3px 0 0 var(--primary-color);
}

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

.data-table .loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.search-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-active {
    background: #d1fae5;
    color: #065f46;
}

.status-inactive {
    background: #fee2e2;
    color: #991b1b;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-top: 24px;
    padding: 16px 0;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-width: 40px;
}

.pagination button:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination .page-info {
    padding: 8px 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    overflow-y: auto;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
}

.modal-content {
    background: var(--bg-primary);
    padding: 32px;
    border-radius: var(--radius-lg);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease;
    margin-top: 40px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.close:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.modal-content h2 {
    margin-bottom: 24px;
    color: var(--text-primary);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

/* Form */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.12);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

/* Action Dropdown */
.action-dropdown {
    position: relative;
    display: inline-block;
}

.action-dropdown-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.action-dropdown-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-color);
}

.action-dropdown-btn .caret {
    font-size: 10px;
    opacity: 0.6;
}

.action-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    z-index: 50;
    overflow: hidden;
    animation: dropdownFadeIn 0.15s ease;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.action-dropdown.open .action-dropdown-menu {
    display: block;
}

.action-dropdown-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s ease;
    white-space: nowrap;
}

.action-dropdown-item:hover {
    background: var(--bg-secondary);
    color: var(--primary-color);
}

.action-dropdown-item + .action-dropdown-item {
    border-top: 1px solid var(--border-color);
}

.action-dropdown-item.action-delete {
    color: #dc3545;
}

.action-dropdown-item.action-delete:hover {
    background: #fdf0f0;
    color: #b02a37;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

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

/* ===== Responsive ===== */

@media (max-width: 1024px) {
    .container {
        padding: 16px;
    }

    .header {
        padding: 24px 20px;
    }

    .header h1 {
        font-size: 24px;
    }

    .header-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .tab-content {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    body {
        font-size: 13px;
    }

    /* Sidebar hidden on mobile, slides in */
    .sidebar {
        transform: translateX(-100%);
        z-index: 200;
        width: min(82vw, 300px);
    }

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

    .mobile-topbar {
        display: flex;
    }

    .main-content {
        margin-left: 0;
    }

    .container {
        padding: 14px 12px 32px;
    }

    .header {
        padding: 18px 16px;
        margin-bottom: 14px;
        border-radius: var(--radius-md);
    }

    .header h1 {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .header > div[style*="justify-content: space-between"] {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-label {
        font-size: 10px;
    }

    .tab-content {
        padding: 12px;
        border-radius: var(--radius-md);
    }

    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 14px;
    }

    /* Force any inline-style grid-template-columns to stack on mobile */
    .modal-content div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 0;
        margin-bottom: 16px;
    }

    .toolbar > .btn {
        width: 100%;
    }

    .search-input-wrapper {
        width: 100%;
        min-width: 0;
    }

    .search-input, .select-input {
        width: 100%;
        min-width: 0;
    }

    /* Date filter rows → horizontal scroll */
    .date-filters {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-wrap: nowrap !important;
        padding-bottom: 4px;
        margin: 0 -4px;
        scrollbar-width: none;
    }
    .date-filters::-webkit-scrollbar { display: none; }
    .date-filter-btn {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 12px;
        padding: 7px 12px;
    }

    /* Modal → near-fullscreen sheet */
    .modal.active {
        padding: 0;
        align-items: stretch;
    }
    .modal-content {
        padding: 20px 16px;
        margin: 0;
        max-width: 100%;
        width: 100%;
        min-height: 100vh;
        max-height: none;
        border-radius: 0;
        border: none;
        animation: slideUp 0.25s ease;
    }
    .modal-content h2 {
        font-size: 18px;
        margin-bottom: 16px;
        padding-right: 36px;
    }
    .close {
        right: 12px;
        top: 12px;
        width: 36px;
        height: 36px;
        font-size: 26px;
        background: var(--bg-secondary);
        border-radius: 50%;
    }

    /* Form actions → full-width stacked buttons */
    .form-actions {
        flex-direction: column-reverse;
        gap: 10px;
        margin-top: 20px;
        padding-top: 18px;
    }
    .form-actions .btn {
        width: 100%;
    }

    /* Data tables → keep horizontal scroll but smooth */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-md);
        position: relative;
        /* scroll shadow hint on right edge */
        background:
            linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
            linear-gradient(to right, rgba(0,0,0,0.08), rgba(0,0,0,0) 30%) 100% 0,
            var(--bg-primary);
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%, 100% 100%;
        background-attachment: local, scroll, local;
    }

    .data-table {
        font-size: 12px;
        min-width: 100%;
    }
    .data-table th,
    .data-table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    .data-table th {
        font-size: 10px;
        letter-spacing: 0.3px;
    }

    /* Action buttons inside table rows → compact */
    .action-buttons {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 4px;
    }
    .action-buttons .btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .btn {
        font-size: 13px;
        padding: 10px 16px;
    }

    /* Pagination → tight */
    .pagination {
        gap: 4px;
        margin-top: 18px;
        padding: 12px 0;
        flex-wrap: wrap;
    }
    .pagination button,
    .pagination .page-info {
        font-size: 12px;
        padding: 7px 10px;
        min-width: 36px;
    }

    /* Action dropdown inside table */
    .action-dropdown-menu {
        right: auto;
        left: 0;
        min-width: 160px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px 10px 28px;
    }

    .header {
        padding: 14px 14px;
    }

    .header h1 {
        font-size: 18px;
    }

    .header-stats {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 20px;
    }

    .tab-content {
        padding: 10px;
    }

    .modal-content {
        padding: 16px 12px;
    }

    .modal-content h2 {
        font-size: 17px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }

    .date-filter-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .pagination button,
    .pagination .page-info {
        font-size: 11px;
        padding: 6px 9px;
        min-width: 32px;
    }

    .btn {
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* ===== Billing Styles ===== */

/* Top bar */
.billing-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}
.billing-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.billing-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin: 4px 0 0;
}
.billing-actions {
    display: flex;
    gap: 8px;
}

/* Summary Cards */
.billing-summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.billing-summary-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 22px 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.billing-summary-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.billing-card-icon {
    font-size: 28px;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
}
.billing-card-revenue .billing-card-icon { background: #eff6ff; }
.billing-card-outstanding .billing-card-icon { background: #fef3c7; }
.billing-card-collected .billing-card-icon { background: #ecfdf5; }

.billing-summary-card .card-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    margin-bottom: 4px;
}
.billing-summary-card .card-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}
.billing-card-revenue .card-value { color: #2563eb; }
.billing-card-outstanding .card-value { color: #d97706; }
.billing-card-collected .card-value { color: #059669; }

/* Section card wrapper */
.billing-section-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

/* Date filter pills */
.billing-date-filters {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
.date-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.date-pill {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.date-pill:hover {
    border-color: #2563eb;
    color: #2563eb;
    background: #eff6ff;
}
.date-pill.active {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}
.custom-date-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.custom-date-row label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.custom-date-row input[type="date"] {
    padding: 7px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-primary);
}
.btn-sm {
    padding: 7px 16px !important;
    font-size: 13px !important;
}

/* Status filter toolbar */
.billing-table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
}
.status-filter-group {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    padding: 3px;
    border-radius: 8px;
}
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
}
.status-pill:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}
.status-pill.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-weight: 600;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* Service multi-select filter */
.service-filter-wrap {
    margin-left: auto;
    position: relative;
}
.service-multi-select {
    position: relative;
}
.service-multi-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-primary);
    cursor: pointer;
    min-width: 180px;
    justify-content: space-between;
    transition: border-color 0.15s;
}
.service-multi-btn:hover {
    border-color: #2563eb;
}
.service-multi-btn .caret {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
}
.service-multi-select.open .service-multi-btn {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.service-multi-select.open .service-multi-btn .caret {
    transform: rotate(180deg);
}
.service-multi-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 240px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 100;
}
.service-multi-select.open .service-multi-menu {
    display: block;
}
.service-check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s;
}
.service-check-item:hover {
    background: var(--bg-secondary);
}
.service-check-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
    cursor: pointer;
    flex-shrink: 0;
}
.dot-unpaid { background: #dc2626; }
.dot-partial { background: #d97706; }
.dot-paid { background: #059669; }

/* Status badges */
.status-unpaid {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: #fef2f2;
    color: #dc2626;
    letter-spacing: 0.3px;
}
.status-partial {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: #fffbeb;
    color: #d97706;
    letter-spacing: 0.3px;
}
.status-paid {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: #ecfdf5;
    color: #059669;
    letter-spacing: 0.3px;
}
.status-cancelled {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

.invoice-items-list {
    margin: 16px 0;
}

.invoice-item-row {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
    align-items: center;
}

.invoice-item-row .item-service { flex: 2; }
.invoice-item-row .item-desc { flex: 2; }
.invoice-item-row .item-price { width: 100px; flex-shrink: 0; }
.invoice-item-row .item-qty { width: 80px; flex-shrink: 0; }
.invoice-item-row .item-subtotal { width: 100px; flex-shrink: 0; }

.invoice-item-row input, .invoice-item-row select {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.item-service-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.item-service-search:focus {
    outline: none;
    border-color: #0891b2;
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
}
.service-dropdown::-webkit-scrollbar { width: 6px; }
.service-dropdown::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.invoice-totals {
    border-top: 2px solid var(--border-color);
    padding-top: 16px;
    margin-top: 16px;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}

.invoice-total-row.grand-total {
    font-weight: 700;
    font-size: 16px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
    margin-top: 6px;
}

@media (max-width: 768px) {
    .billing-topbar { flex-direction: column; align-items: stretch; gap: 12px; }
    .billing-title { font-size: 20px; }
    .billing-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
    .billing-actions .btn { flex: 1 1 calc(50% - 4px); font-size: 12px; padding: 10px 8px; }
    .billing-summary-cards { grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
    .billing-summary-card { padding: 14px 16px; }
    .billing-summary-card .card-value { font-size: 20px; }
    .billing-card-icon { font-size: 22px; width: 44px; height: 44px; }
    .billing-section-card { border-radius: var(--radius-md); }
    .billing-date-filters { padding: 12px 14px; }
    .date-filter-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        margin: 0 -4px;
        scrollbar-width: none;
    }
    .date-filter-row::-webkit-scrollbar { display: none; }
    .date-pill { flex-shrink: 0; }
    .custom-date-row { flex-wrap: wrap; gap: 8px; }
    .custom-date-row input[type="date"] { flex: 1; min-width: 120px; }

    .billing-table-toolbar {
        padding: 12px 14px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .status-filter-group { width: 100%; }
    .status-pill { flex: 1; justify-content: center; padding: 8px 4px; font-size: 12px; }
    .service-filter-wrap { margin-left: 0; width: 100%; }
    .service-multi-btn { width: 100%; min-width: 0; }
    .service-multi-menu {
        left: 0;
        right: 0;
        min-width: 0;
        width: 100%;
    }

    /* Invoice items */
    .invoice-item-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--bg-secondary);
        margin-bottom: 10px;
    }
    .invoice-item-row .item-service,
    .invoice-item-row .item-desc,
    .invoice-item-row .item-price,
    .invoice-item-row .item-qty,
    .invoice-item-row .item-subtotal {
        width: 100%;
    }
    .invoice-item-row > .btn-danger {
        align-self: flex-end;
        width: auto;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .tab-btn,
    button {
        min-height: 44px;
    }

    input,
    select {
        font-size: 16px !important;
    }

    .sidebar-item {
        padding: 14px 20px;
    }
}
