/* ============================================
   PT EHR - Main Stylesheet
   Updated with: Patient Autocomplete, Clinical Notes, Unavailability
   ============================================ */

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #0ea5e9;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-active: #3b82f6;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--body-bg);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
}

/* ============================================
   Login Page
   ============================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo {
    width: 64px;
    height: 64px;
    background: var(--primary-color);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.login-header .logo i {
    font-size: 32px;
    color: white;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* Tenant Selection UI */
.tenant-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tenant-option {
    display: block;
    width: 100%;
    padding: 16px 20px;
    background: var(--body-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tenant-option:hover {
    border-color: var(--primary-color);
    background: #f0f7ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.tenant-option .tenant-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 4px;
}

.tenant-option .tenant-subdomain {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================
   Main Layout
   ============================================ */

#mainApp {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header .logo i {
    font-size: 20px;
    color: white;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
}

.sidebar-tenant {
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.sidebar-tenant strong {
    font-size: 14px;
}

.sidebar-tenant span {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s;
}

.sidebar-nav .nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-nav .nav-item.active {
    background: var(--sidebar-active);
    color: white;
}

.sidebar-nav .nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

/* Role-based visibility */
body:not(.super-admin) .requires-super-admin { display: none !important; }
body:not(.admin):not(.super-admin) .requires-admin { display: none !important; }

/* Billing access: visible for super-admin, admin, and biller */
body:not(.super-admin):not(.admin):not(.biller) .requires-billing-access { display: none !important; }

/* Hide clinical actions from Biller and Read-Only */
body.biller .requires-clinical,
body.read-only .requires-clinical { display: none !important; }

/* Read-only users can only view, not modify */
body.read-only .requires-write { display: none !important; }

/* Biller-specific: hide patient editing and appointment creation */
body.biller .hide-from-biller { display: none !important; }

/* Read-only: hide all edit/create buttons */
body.read-only .hide-from-biller { display: none !important; }

/* Therapist/Clinician-specific: hide appointment management and patient editing */
body.clinician .hide-from-therapist { display: none !important; }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-header {
    background: var(--card-bg);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-search {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.header-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.header-search input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.header-search input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Super Admin Clinic Filter */
.clinic-filter-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 8px;
}

.clinic-filter-label {
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
    white-space: nowrap;
}

.clinic-filter-container .form-select {
    min-width: 180px;
    font-size: 13px;
    border-color: #fbbf24;
}

/* Hide clinic filter for non-super-admin by default */
body:not(.super-admin) .requires-super-admin {
    display: none !important;
}

.content-area {
    flex: 1;
    padding: 24px;
}

/* ============================================
   Pages
   ============================================ */

.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}

/* ============================================
   Cards
   ============================================ */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
}

.card-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* Stat Cards */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card.small-stat {
    padding: 16px 20px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============================================
   Tables
   ============================================ */

.table {
    margin: 0;
}

.table th {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
    background: rgba(59, 130, 246, 0.04);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   Status Badges
   ============================================ */

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.status-scheduled { background: #dbeafe; color: #1e40af; }
.status-confirmed { background: #dcfce7; color: #166534; }
.status-checkedin { background: #fef3c7; color: #92400e; }
.status-inprogress { background: #e0e7ff; color: #3730a3; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-noshow { background: #fee2e2; color: #991b1b; }
.status-cancelled { background: #f3f4f6; color: #4b5563; }
.status-active { background: #dcfce7; color: #166534; }
.status-inactive { background: #f3f4f6; color: #6b7280; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-approved { background: #d1fae5; color: #065f46; }
.status-denied { background: #fee2e2; color: #991b1b; }

/* ============================================
   Buttons
   ============================================ */

.btn {
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-action {
    padding: 6px 10px;
    margin-right: 4px;
}

.btn-action:last-child {
    margin-right: 0;
}

/* ============================================
   Calendar
   ============================================ */

#calendar {
    min-height: 600px;
}

.fc .fc-toolbar-title {
    font-size: 18px;
    font-weight: 600;
}

.fc .fc-button {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
}

.fc .fc-button-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.fc .fc-button-primary:not(:disabled):hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* Calendar Events - Block Display */
.fc-event,
.fc-daygrid-event,
.fc-daygrid-block-event {
    border-radius: 4px !important;
    padding: 4px 6px !important;
    font-size: 11px !important;
    cursor: pointer;
    border-width: 2px !important;
    border-style: solid !important;
    border-color: #000 !important;
    margin-bottom: 3px !important;
}

/* Event content styling */
.fc-daygrid-block-event .fc-event-main {
    padding: 2px 4px;
}

/* Hide default time display since we show it in title */
.fc-event-time {
    display: none !important;
}

/* Event title - multi-line with first line bold */
.fc-event-title {
    white-space: pre-line !important;
    line-height: 1.4 !important;
    color: #fff !important;
}

.fc-event-title::first-line {
    font-weight: 700;
}

/* Calendar Legend */
#calendarLegend {
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.legend-item {
    margin-right: 16px;
}

/* ============================================
   Patient Autocomplete - KEY STYLING
   ============================================ */

.patient-autocomplete-container {
    position: relative;
}

.patient-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    max-height: 350px;
    overflow-y: auto;
    z-index: 1050;
    margin-top: 4px;
}

.patient-search-result {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.patient-search-result:last-child {
    border-bottom: none;
}

.patient-search-result:hover {
    background: rgba(59, 130, 246, 0.08);
}

.patient-result-main {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.patient-result-main strong {
    font-size: 14px;
    color: var(--text-primary);
}

.patient-result-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.selected-patient-card {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 12px 16px;
}

.selected-patient-card strong {
    color: #0369a1;
}

/* ============================================
   Clinical Notes
   ============================================ */

.note-content {
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    min-height: 300px;
    font-size: 14px;
    line-height: 1.7;
}

.note-content h1, .note-content h2, .note-content h3, 
.note-content h4, .note-content h5, .note-content h6 {
    margin-top: 24px;
    margin-bottom: 12px;
}

.note-content h1:first-child, .note-content h2:first-child {
    margin-top: 0;
}

.note-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.note-content th, .note-content td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.note-content th {
    background: #f5f5f5;
    font-weight: 600;
}

/* Trumbowyg Editor Customization */
.trumbowyg-box {
    border-radius: 8px;
    border-color: var(--border-color);
}

.trumbowyg-editor {
    min-height: 400px;
    font-size: 14px;
    line-height: 1.6;
    padding: 16px;
}

.trumbowyg-button-pane {
    background: #f8fafc;
}

/* ============================================
   Providers Grid
   ============================================ */

.provider-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.provider-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.provider-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
    font-weight: 700;
    color: white;
}

.provider-card h5 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
}

.provider-card .specialty {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 4px;
}

.provider-card .credentials {
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 12px;
}

/* ============================================
   Patient Detail Modal
   ============================================ */

.patient-header {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.patient-avatar-lg {
    width: 80px;
    height: 80px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    color: white;
}

.patient-info h3 {
    margin: 0 0 4px;
    font-size: 24px;
}

.patient-info .mrn {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

.patient-meta {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-muted);
}

.patient-meta i {
    margin-right: 4px;
}

/* ============================================
   Alerts
   ============================================ */

.alert-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-item i {
    font-size: 18px;
}

.alert-item span {
    flex: 1;
    color: var(--text-secondary);
}

.alert-item strong {
    font-size: 18px;
}

/* A/R Aging */
.aging-bucket {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.aging-bucket:last-child {
    border-bottom: none;
}

/* ============================================
   Form Styles
   ============================================ */

.form-label {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border-color);
    padding: 10px 12px;
    font-size: 14px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-control-plaintext {
    padding: 10px 0;
    font-weight: 500;
}

/* ============================================
   Modal Styles
   ============================================ */

.modal-content {
    border-radius: 12px;
    border: none;
}

.modal-header {
    border-bottom-color: var(--border-color);
    padding: 16px 24px;
}

.modal-title {
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    border-top-color: var(--border-color);
    padding: 16px 24px;
}

.modal-xl {
    max-width: 1140px;
}

/* ============================================
   Toast
   ============================================ */

.toast {
    border-radius: 8px;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 767.98px) {
    .content-area {
        padding: 16px;
    }
    
    .page-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }
    
    .stat-card {
        flex-direction: column;
        text-align: center;
    }
    
    .patient-header {
        flex-direction: column;
        text-align: center;
    }
    
    .patient-meta {
        flex-direction: column;
        gap: 8px;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .sidebar,
    .main-header,
    .modal-header .btn-close,
    .modal-footer {
        display: none !important;
    }

    .main-content {
        margin-left: 0;
    }

    .modal {
        position: static;
        display: block;
    }

    .modal-dialog {
        margin: 0;
        max-width: 100%;
    }

    .modal-content {
        border: none;
        box-shadow: none;
    }

    .note-content {
        border: none;
        background: white;
    }
}

/* ============================================
   Global Loading Overlay
   ============================================ */

.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.global-loader.d-none {
    display: none !important;
}

.loader-content {
    background: var(--card-bg);
    padding: 40px 60px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.loader-content .spinner-border {
    width: 3rem;
    height: 3rem;
}

.loader-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 0;
}

/* ============================================
   Initial App Loading Screen
   ============================================ */

.app-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.app-loading-screen.d-none {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.app-loading-content {
    text-align: center;
    color: white;
}

.app-loading-logo {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    animation: pulse 2s infinite;
}

.app-loading-logo i {
    font-size: 50px;
    color: white;
}

.app-loading-title {
    font-size: 36px;
    font-weight: 700;
    margin: 0 0 8px;
}

.app-loading-subtitle {
    font-size: 16px;
    opacity: 0.8;
    margin: 0;
}

.app-loading-status {
    font-size: 14px;
    opacity: 0.7;
    margin-bottom: 0;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

/* ============================================
   Admin Dashboard - Redesign
   ============================================ */

/* Clickable summary widgets */
.stat-card.dashboard-widget.clickable {
    cursor: pointer;
    transition: all 0.3s ease;
}

.stat-card.dashboard-widget.clickable:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.stat-card.dashboard-widget.clickable:active {
    transform: translateY(-2px);
}

/* Dashboard section cards */
.dashboard-section {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.dashboard-section .card-header {
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.dashboard-section .card-body {
    padding: 0;
    max-height: 400px;
    overflow-y: auto;
}

.dashboard-section .table {
    margin-bottom: 0;
}

.dashboard-section .table th {
    background-color: #f8fafc;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.dashboard-section .table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

/* Section highlight animation */
.section-highlight {
    animation: sectionHighlight 2s ease-out;
}

@keyframes sectionHighlight {
    0% {
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.5);
    }
    100% {
        box-shadow: none;
    }
}

/* Care episode details row */
.episode-details-row {
    background-color: #f8fafc;
}

.episode-details-row td {
    padding: 0 !important;
}

.care-episode-row {
    cursor: pointer;
}

.care-episode-row:hover {
    background-color: #f1f5f9;
}

/* Badge improvements */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

/* Action buttons in tables */
.btn-action {
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
}

.btn-group-sm > .btn {
    padding: 0.35rem 0.5rem;
}

/* Table row hover effect */
.table-hover tbody tr:hover {
    background-color: #f8fafc;
}

/* Loading spinner in buttons */
.btn .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

/* Dashboard empty state */
.text-center.text-muted.py-3 {
    padding: 2rem !important;
    font-size: 0.95rem;
}

/* Responsive adjustments for dashboard */
@media (max-width: 768px) {
    .dashboard-section .card-body {
        max-height: 300px;
    }

    .stat-card.dashboard-widget.clickable {
        margin-bottom: 0.5rem;
    }

    .btn-group-sm > .btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.8rem;
    }
}

/* Smooth scrolling for section navigation */
html {
    scroll-behavior: smooth;
}

/* ============================================
   Reports Section Styles
   ============================================ */

/* Report Card */
.report-card {
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
}

.report-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.report-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

/* Visit Grid Styles */
.visit-grid-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    max-height: calc(100vh - 400px);
    min-height: 300px;
}

.visit-grid-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
}

.visit-grid-table thead {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
}

.visit-grid-table th {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 8px 6px;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

/* Frozen columns (Patient, Therapist) */
.visit-grid-table th.frozen,
.visit-grid-table td.frozen {
    position: sticky;
    background: #fff;
    z-index: 10;
}

.visit-grid-table th.frozen {
    z-index: 25;
}

.visit-grid-table th.frozen-patient,
.visit-grid-table td.frozen-patient {
    left: 0;
    min-width: 180px;
    max-width: 180px;
}

.visit-grid-table th.frozen-therapist,
.visit-grid-table td.frozen-therapist {
    left: 180px;
    min-width: 100px;
    max-width: 100px;
}

.visit-grid-table td {
    border: 1px solid #e2e8f0;
    padding: 6px;
    text-align: center;
    vertical-align: middle;
    background: #fff;
}

/* Clickable cells */
.visit-grid-table td.clickable {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.visit-grid-table td.clickable:hover {
    background-color: #f0f9ff;
}

/* Day column cells */
.visit-grid-table td.day-cell {
    min-width: 28px;
    max-width: 28px;
    padding: 4px 2px;
    font-weight: 600;
}

/* Visit code colors */
.visit-code {
    display: inline-block;
    width: 22px;
    height: 22px;
    line-height: 22px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
    text-align: center;
}

.visit-code-V {
    background-color: #dcfce7;
    color: #166534;
}

.visit-code-E {
    background-color: #dbeafe;
    color: #1e40af;
}

.visit-code-I {
    background-color: #f3e8ff;
    color: #6b21a8;
}

.visit-code-D {
    background-color: #f3f4f6;
    color: #374151;
}

.visit-code-A {
    background-color: #fef9c3;
    color: #854d0e;
}

.visit-code-C {
    background-color: #fee2e2;
    color: #b91c1c;
}

.visit-code-F {
    background-color: #cffafe;
    color: #0e7490;
}

.visit-code-H {
    background-color: #ccfbf1;
    color: #0f766e;
}

.visit-code-N {
    background-color: #e5e7eb;
    color: #4b5563;
}

.visit-code-R {
    background-color: #ffedd5;
    color: #c2410c;
}

/* Legend codes */
.visit-code-legend {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 11px;
    margin-right: 2px;
}

/* Summary columns */
.visit-grid-table td.summary-cell {
    background-color: #f8fafc;
    font-weight: 600;
}

/* Row hover */
.visit-grid-table tbody tr:hover td {
    background-color: #f0f9ff;
}

.visit-grid-table tbody tr:hover td.frozen {
    background-color: #e0f2fe;
}

/* Alternating rows */
.visit-grid-table tbody tr:nth-child(even) td {
    background-color: #fafafa;
}

.visit-grid-table tbody tr:nth-child(even):hover td {
    background-color: #f0f9ff;
}

/* Patient and therapist name cells */
.patient-name-cell {
    text-align: left !important;
    font-weight: 500;
}

.patient-name-link {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
}

.patient-name-link:hover {
    text-decoration: underline;
}

.therapist-name-link {
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
}

.therapist-name-link:hover {
    color: var(--primary-color);
}

/* Insurance cell */
.insurance-cell {
    font-size: 10px;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Report header info */
.report-header-info {
    font-size: 14px;
}

/* Report footer */
.report-footer {
    font-size: 13px;
}

.report-legend {
    line-height: 2;
}

/* Print styles for reports */
@media print {
    .sidebar,
    .main-header,
    .page-header,
    .btn,
    .card-header .btn-group,
    #reportsListView,
    .report-card {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
    }

    .visit-grid-wrapper {
        max-height: none !important;
        overflow: visible !important;
    }

    .visit-grid-table {
        font-size: 10px;
    }

    .visit-grid-table th,
    .visit-grid-table td {
        padding: 4px 3px;
    }

    .visit-code {
        width: 18px;
        height: 18px;
        line-height: 18px;
        font-size: 9px;
    }

    .report-footer {
        display: block !important;
    }

    @page {
        size: landscape;
        margin: 0.5cm;
    }
}

/* Full width mode for reports (hides sidebar) */
.main-content.report-fullwidth {
    margin-left: 0 !important;
    width: 100% !important;
}

.main-content.report-fullwidth .visit-grid-wrapper {
    max-height: calc(100vh - 320px);
}

/* Responsive adjustments for reports */
@media (max-width: 768px) {
    .visit-grid-wrapper {
        max-height: calc(100vh - 350px);
    }

    .visit-grid-table {
        font-size: 11px;
    }

    .visit-grid-table th.frozen-patient,
    .visit-grid-table td.frozen-patient {
        min-width: 120px;
        max-width: 120px;
    }

    .visit-grid-table th.frozen-therapist,
    .visit-grid-table td.frozen-therapist {
        left: 120px;
        min-width: 80px;
        max-width: 80px;
    }
}

/* ============================================
   Cancelled Appointment Styling
   ============================================ */
.cancelled-appointment {
    opacity: 0.7;
    text-decoration: line-through;
    position: relative;
}

.cancelled-appointment::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 5px,
        rgba(0, 0, 0, 0.05) 5px,
        rgba(0, 0, 0, 0.05) 10px
    );
    pointer-events: none;
}

/* Cancelled appointment indicator banner */
.cancelled-appointment-banner {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 10px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cancelled-appointment-banner i {
    font-size: 1.2em;
}

/* ============================================
   Dashboard Appointment Row Click
   ============================================ */
.dashboard-appointment-row {
    transition: background-color 0.15s ease-in-out;
}

.dashboard-appointment-row:hover {
    background-color: rgba(37, 99, 235, 0.08) !important;
}

.dashboard-appointment-row:active {
    background-color: rgba(37, 99, 235, 0.15) !important;
}

/* ============================================
   System-Wide Font Size Reduction
   For a more professional, compact appearance
   ============================================ */

/* Base font size reduction */
html {
    font-size: 14px;
}

body {
    font-size: 0.875rem; /* 14px */
    line-height: 1.45;
}

/* Headings - reduced proportionally */
h1, .h1 {
    font-size: 1.5rem !important; /* 21px instead of 24px */
}

h2, .h2 {
    font-size: 1.35rem !important; /* 18.9px instead of 20px */
}

h3, .h3 {
    font-size: 1.15rem !important; /* 16.1px instead of 18px */
}

h4, .h4 {
    font-size: 1rem !important; /* 14px instead of 16px */
}

h5, .h5 {
    font-size: 0.95rem !important; /* 13.3px instead of 14px */
}

h6, .h6 {
    font-size: 0.85rem !important; /* 11.9px instead of 12px */
}

/* Form elements */
.form-control, .form-select {
    font-size: 0.875rem;
    padding: 0.375rem 0.65rem;
}

.form-label {
    font-size: 0.8125rem; /* 13px */
    margin-bottom: 0.25rem;
}

.form-check-label {
    font-size: 0.8125rem;
}

.input-group-text {
    font-size: 0.8125rem;
    padding: 0.375rem 0.6rem;
}

/* Buttons */
.btn {
    font-size: 0.8125rem;
    padding: 0.35rem 0.75rem;
}

.btn-sm {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
}

.btn-lg {
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
}

/* Tables */
.table {
    font-size: 0.8125rem;
}

.table th,
.table td {
    padding: 0.5rem 0.65rem;
}

.table-sm th,
.table-sm td {
    padding: 0.3rem 0.5rem;
}

/* Cards */
.card-title {
    font-size: 0.95rem;
}

.card-body {
    padding: 0.85rem;
}

.card-header,
.card-footer {
    padding: 0.6rem 0.85rem;
    font-size: 0.875rem;
}

/* Modal */
.modal-title {
    font-size: 1.05rem;
}

.modal-body {
    font-size: 0.875rem;
}

.modal-header,
.modal-footer {
    padding: 0.75rem 1rem;
}

/* Badges */
.badge {
    font-size: 0.7rem;
    padding: 0.25em 0.5em;
}

/* Alerts */
.alert {
    font-size: 0.8125rem;
    padding: 0.6rem 0.85rem;
}

/* Dropdowns */
.dropdown-item {
    font-size: 0.8125rem;
    padding: 0.35rem 1rem;
}

.dropdown-header {
    font-size: 0.75rem;
}

/* List groups */
.list-group-item {
    font-size: 0.875rem;
    padding: 0.5rem 0.85rem;
}

/* Sidebar navigation */
.sidebar .nav-link {
    font-size: 0.8125rem;
    padding: 0.55rem 0.85rem;
}

.sidebar-header h4 {
    font-size: 1rem !important;
}

/* Calendar events - smaller text */
.fc-event-title {
    font-size: 0.7rem;
    line-height: 1.2;
}

.fc-daygrid-event {
    font-size: 0.7rem;
}

.fc-timegrid-event .fc-event-title {
    font-size: 0.7rem;
}

/* Dashboard widgets */
.dashboard-stat {
    font-size: 0.875rem;
}

.dashboard-stat .stat-value {
    font-size: 1.3rem;
}

.dashboard-stat .stat-label {
    font-size: 0.75rem;
}

/* Tabs */
.nav-tabs .nav-link {
    font-size: 0.8125rem;
    padding: 0.45rem 0.85rem;
}

.nav-pills .nav-link {
    font-size: 0.8125rem;
    padding: 0.4rem 0.75rem;
}

/* Pagination */
.page-link {
    font-size: 0.8125rem;
    padding: 0.35rem 0.65rem;
}

/* Breadcrumbs */
.breadcrumb {
    font-size: 0.8125rem;
}

/* Tooltips and popovers */
.tooltip-inner {
    font-size: 0.75rem;
}

.popover-body {
    font-size: 0.8125rem;
}

/* Toast notifications */
.toast {
    font-size: 0.8125rem;
}

/* Small and text utilities */
small, .small {
    font-size: 0.75rem;
}

.text-muted {
    font-size: inherit;
}

/* FullCalendar specific sizing */
.fc .fc-toolbar-title {
    font-size: 1.1rem;
}

.fc .fc-button {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

.fc .fc-col-header-cell-cushion {
    font-size: 0.75rem;
}

.fc .fc-daygrid-day-number {
    font-size: 0.75rem;
}

/* Accordion */
.accordion-button {
    font-size: 0.875rem;
    padding: 0.65rem 1rem;
}

.accordion-body {
    font-size: 0.875rem;
    padding: 0.85rem;
}

/* Progress bars */
.progress {
    height: 0.5rem;
}

/* Legends and labels */
.legend-item {
    font-size: 0.75rem;
}

/* Selected patient card */
.selected-patient-card {
    font-size: 0.875rem;
}

/* Patient search results */
.patient-search-result {
    font-size: 0.8125rem;
    padding: 0.45rem 0.65rem;
}

/* Trumbowyg editor */
.trumbowyg-box {
    font-size: 0.875rem;
}

/* Care episode cards */
.care-episode-card {
    font-size: 0.875rem;
}

/* Reports */
.report-title {
    font-size: 1.15rem;
}

.report-table {
    font-size: 0.8rem;
}

/* Minimize margins and padding globally */
.mb-3 {
    margin-bottom: 0.75rem !important;
}

.mb-4 {
    margin-bottom: 1rem !important;
}

.p-3 {
    padding: 0.75rem !important;
}

.p-4 {
    padding: 1rem !important;
}

/* Compact row spacing */
.row.g-3 {
    --bs-gutter-y: 0.75rem;
    --bs-gutter-x: 0.75rem;
}

/* More compact fs-5 and fs-6 */
.fs-5 {
    font-size: 1rem !important;
}

.fs-6 {
    font-size: 0.875rem !important;
}




.urgency-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

.urgency-warning {
    background-color: #fd7e14; /* Orange */
    box-shadow: 0 0 4px rgba(253, 126, 20, 0.5);
}

.urgency-critical {
    background-color: #dc3545; /* Red */
    box-shadow: 0 0 4px rgba(220, 53, 69, 0.5);
}