/* ---
    Nord-Inspired Color Palette
    - Polar Night (Dark Grays): #2E3440, #3B4252, #434C5E, #4C566A
    - Snow Storm (Whites): #D8DEE9, #E5E9F0, #ECEFF4
    - Frost (Blues/Accents): #8FBCBB, #88C0D0, #81A1C1, #5E81AC
    - Aurora (Greens, Pinks): #A3BE8C, #B48EAD
--- */

:root {
    /* Existing colors and general variables */
    --bg-color: #ECEFF4;
    --sidebar-bg: rgba(46, 52, 64, 0.85);
    --card-bg: rgba(255, 255, 255, 0.7);
    --text-color: #2E3440;
    --text-secondary: #4C566A;
    --primary-color: #5E81AC;
    --primary-hover: #81A1C1;
    --border-color: #D8DEE9;
    --sidebar-width: 280px;
    --border-radius: 12px;
    --transition-speed: 0.3s;

    /* New: Typography Variables */
    --font-family-base: 'Vazirmatn', sans-serif;
    --font-size-base: 1rem;
    --line-height-base: 1.6;

    --h1-font-size: 2.5rem;
    --h2-font-size: 2rem;
    --h3-font-size: 1.75rem;
    --h4-font-size: 1.5rem;
    --h5-font-size: 1.25rem;
    --h6-font-size: 1rem;

    --font-weight-light: 300;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* New: Spacing Scale (e.g., based on 8px grid) */
    --spacing-xxs: 4px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-xxl: 48px;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--bg-color);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--text-color);
    overflow-x: hidden;
}

/* --- Beautiful Background --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #E0F7FA 0%, #F3E5F5 100%); /* A soft light blue to light purple gradient */
    z-index: -1;
    opacity: 1;
}

/* --- Sidebar Layout --- */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    align-items: stretch;
    transition: margin-right var(--transition-speed) ease;
}

#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--snow-storm-white);
    backdrop-filter: blur(10px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    transition: all var(--transition-speed) ease;
}

.wrapper.sidebar-collapsed #sidebar {
    margin-right: -var(--sidebar-width);
}

#sidebar .sidebar-header {
    padding: 25px;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
}

#sidebar .sidebar-header h3 {
    color: #ECEFF4;
    font-weight: 700;
    font-size: 1.5rem;
}

#sidebar ul.components {
    padding: 20px 0;
}

#sidebar ul li a {
    padding: 15px 30px;
    font-size: 1.1rem;
    display: block;
    color: #D8DEE9;
    transition: all var(--transition-speed) ease;
    font-weight: 500;
    border-right: 5px solid transparent;
}

#sidebar ul li a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-right-color: var(--primary-hover);
}

#sidebar ul li.active>a {
    color: #fff;
    background: rgba(94, 129, 172, 0.5);
    border-right-color: var(--primary-color);
}

#sidebar .sidebar-header {
    padding: var(--spacing-xl);
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
}

#sidebar .sidebar-header h3 {
    color: #ECEFF4;
    font-weight: var(--font-weight-bold);
    font-size: var(--h4-font-size);
}

#sidebar ul.components {
    padding: var(--spacing-lg) 0;
}

#sidebar ul li a {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: var(--font-size-base);
    display: block;
    color: #D8DEE9;
    transition: all var(--transition-speed) ease;
    font-weight: var(--font-weight-medium);
    border-right: 5px solid transparent;
}

#sidebar ul li a i {
    margin-left: var(--spacing-md);
    transition: transform var(--transition-speed) ease;
}

#sidebar ul li a:hover i {
    transform: scale(1.1);
}

/* --- Main Content Area --- */
#content {
    width: 100%;
    padding: 2.5rem;
    min-height: 100vh;
    transition: all var(--transition-speed) ease;
}

#sidebar-toggle {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
}
#sidebar-toggle:hover {
    transform: scale(1.1);
}

/* --- Custom Components --- */
/* --- Custom Components --- */
.card {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    transition: all var(--transition-speed) ease-in-out;
    position: relative; /* For pseudo-elements */
    overflow: hidden; /* Ensure gradient doesn't spill */
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
    z-index: -1;
    opacity: 0;
    transition: opacity var(--transition-speed) ease-in-out;
}

.card:hover::before {
    opacity: 1;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.15);
}

.card-header {
    background-color: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid var(--border-color);
    font-weight: var(--font-weight-semibold);
    padding: var(--spacing-md) var(--spacing-lg);
}

.card-body {
    padding: var(--spacing-lg);
}

.card-title {
    font-size: var(--h2-font-size);
    font-weight: var(--font-weight-bold);
    color: var(--primary-color);
    margin-bottom: var(--spacing-xs);
}

.card-subtitle {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
}

.kpi-icon {
    font-size: var(--h1-font-size);
    color: var(--primary-color);
    opacity: 0.7;
    margin-bottom: var(--spacing-md);
}

/* Tab Navigation Styling */
.nav-tabs {
    border-bottom: 1px solid var(--border-color);
}

.nav-tabs .nav-link {
    border: 1px solid transparent;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
    color: var(--text-secondary);
    transition: all var(--transition-speed) ease;
    padding: 0.75rem 1.25rem;
    margin-bottom: -1px; /* Overlap border */
}

.nav-tabs .nav-link:hover {
    border-color: transparent;
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--primary-color);
}

.nav-tabs .nav-link.active {
    color: var(--primary-color);
    background-color: var(--card-bg);
    border-color: var(--border-color) var(--border-color) transparent var(--border-color);
    font-weight: var(--font-weight-semibold);
    position: relative;
}

.nav-tabs .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 2px 2px 0 0;
}

/* Chart Container Styling */
[id$="_chart"] {
    min-height: 300px; /* Ensure charts have a minimum height */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Search Bar Refinement */
.search-input-container {
    position: relative;
    margin-bottom: var(--spacing-lg);
}

#metricSearch {
    padding-right: var(--spacing-xxl);
    padding-left: var(--spacing-md);
    border-radius: var(--border-radius);
    background-color: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) ease;
}

#metricSearch:focus {
    box-shadow: 0 0 0 0.25rem rgba(94, 129, 172, 0.25);
    border-color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.9);
}

.search-icon {
    position: absolute;
    left: var(--spacing-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: var(--h5-font-size);
}

/* Fixed Height Card for Services and Customers Tab */
.fixed-height-card {
    max-height: 500px; /* Adjust as needed */
    display: flex;
    flex-direction: column;
}

.fixed-height-card .card-body {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.fixed-height-card .card-body canvas {
    max-height: 150px; /* Set a max height for the chart */
    flex-shrink: 0; /* Prevent chart from shrinking */
    margin-bottom: var(--spacing-md);
}

.fixed-height-card .card-body .scrollable-list {
    flex-grow: 1; /* Allow list to take remaining space and scroll */
    overflow-y: auto;
    max-height: 150px; /* Set a max height for the list within the card */
}

/* List Group Item Styling */
.list-group-item {
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-xs);
    padding: var(--spacing-md) var(--spacing-lg);
    transition: all var(--transition-speed) ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    align-items: center; /* Vertically align items in the list */
}

.list-group-item:hover {
    background-color: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.list-group-item strong {
    color: var(--text-color);
    margin-left: var(--spacing-xs);
}

.list-group-item small.text-muted {
    font-size: var(--font-size-base);
    color: var(--text-secondary) !important;
    margin-top: 0;
    margin-bottom: 0;
    margin-right: var(--spacing-xs);
}

.list-group-item .badge {
    margin-top: 0;
    margin-bottom: 0;
    min-width: 60px;
    text-align: center;
}

.scrollable-list {
    max-height: 300px; /* Adjust as needed */
    overflow-y: auto;
    padding-right: 10px; /* Space for scrollbar */
}

.scrollable-list::-webkit-scrollbar {
    width: 8px;
}

.scrollable-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.scrollable-list::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
}

.scrollable-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* Ensure card-body pushes show-more-btn to bottom */
.card-body {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%; /* Ensure card-body takes full height */
}

/* Table Styling for Recent Patients */
.table-responsive.scrollable-list {
    max-height: 400px; /* Adjust height for the table */
}

.table thead th {
    background-color: rgba(255, 255, 255, 0.7); /* Lighter header background */
    position: sticky; /* Make header sticky */
    top: 0;
    z-index: 1;
}

.table tbody tr {
    background-color: rgba(255, 255, 255, 0.4);
}

.table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.3); /* Zebra striping */
}

.table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.6);
}

.table td, .table th {
    border-color: rgba(255, 255, 255, 0.2);
}

.table td strong {
    color: var(--primary-color); /* Highlight patient name */
}

.table td small.text-muted {
    margin-top: 0.2rem; /* Space below national code */
}

.btn.show-more-btn {
    align-self: flex-end; /* Push button to the right within flex container */
    margin-top: auto; /* Push button to the bottom */
}

.list-group-item strong {
    color: var(--text-color);
}

.list-group-item small.text-muted {
    font-size: 0.8rem;
    color: var(--text-secondary) !important;
    margin-top: 0.2rem;
}

/* Table Styling (Recent Patients) */
.table thead th {
    font-weight: 700; /* Bolder headers */
    background-color: rgba(255, 255, 255, 0.3); /* Slightly distinct header background */
}

.table tbody tr td {
    padding: 0.85rem 1rem; /* Consistent row height */
}

.table tbody tr td small.text-muted {
    font-size: 0.8rem;
    color: var(--text-secondary) !important;
}

/* General Spacing & Typography */
h1 {
    font-weight: 700;
    color: var(--text-color);
}

h5.card-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-color);
}

p.card-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.mb-4 {
    margin-bottom: 1.5rem !important;
}

.mt-3 {
    margin-top: 1rem !important;
}

.mt-2 {
    margin-top: 0.75rem !important;
}

.me-sm-2 {
    margin-right: 0.5rem !important;
}

.d-block {
    display: block !important;
}

.d-sm-inline-block {
    display: inline-block !important;
}

.align-items-start {
    align-items: flex-start !important;
}

.align-items-sm-center {
    align-items: center !important;
}

.flex-column {
    flex-direction: column !important;
}

.flex-sm-row {
    flex-direction: row !important;
}

.justify-content-between {
    justify-content: space-between !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        z-index: 999;
        height: 100%;
    }
    .wrapper.sidebar-collapsed #sidebar {
        margin-right: -var(--sidebar-width);
    }
    #content {
        padding: 1.5rem;
    }
    #sidebar-toggle {
        top: 1rem;
        left: 1rem;
    }
    .card-title {
        font-size: 1.8rem; /* Adjust for smaller screens */
    }
    .kpi-icon {
        font-size: 2rem;
    }
}

/* --- Loading Spinner Overlay --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5); /* Semi-transparent dark background */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* Ensure it's on top of everything */
    visibility: hidden; /* Hidden by default */
    opacity: 0;
    transition: visibility 0s, opacity 0.3s linear;
}

#loading-overlay.show {
    visibility: visible;
    opacity: 1;
}

.spinner-border-custom {
    width: 3rem;
    height: 3rem;
    border-width: 0.3em;
    color: #fff; /* White spinner */
}

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    top: 1rem; /* Adjust as needed */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050; /* Above Bootstrap modals (1040) */
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none; /* Allow clicks to pass through container */
}

.toast {
    width: auto; /* Adjust width based on content */
    max-width: 350px; /* Max width for toasts */
    background-color: rgba(255, 255, 255, 0.9); /* Slightly transparent white */
    backdrop-filter: blur(8px); /* Glassmorphism effect */
    border: 1px solid rgba(0, 0, 0, 0.1); /* Subtle border */
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); /* Soft shadow */
    color: var(--text-color);
    margin-bottom: 0.75rem;
    pointer-events: auto; /* Re-enable pointer events for individual toasts */
}

.toast-header {
    background-color: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    color: var(--text-color);
    font-weight: var(--font-weight-semibold);
}

.toast-body {
    color: var(--text-secondary);
}

/* Specific toast colors */
.toast.bg-success .toast-header {
    color: #198754; /* Bootstrap success green */
}
.toast.bg-danger .toast-header {
    color: #dc3545; /* Bootstrap danger red */
}
.toast.bg-info .toast-header {
    color: #0dcaf0; /* Bootstrap info blue */
}
.toast.bg-warning .toast-header {
    color: #ffc107; /* Bootstrap warning yellow */
}

/* DataTables.js specific styling adjustments */
.dataTables_wrapper .dataTables_filter input {
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: var(--spacing-xs) var(--spacing-md);
    background-color: rgba(255, 255, 255, 0.7);
    color: var(--text-color);
}

.dataTables_wrapper .dataTables_length select {
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: var(--spacing-xs) var(--spacing-md);
    background-color: rgba(255, 255, 255, 0.7);
    color: var(--text-color);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: var(--border-radius);
    margin: 0 var(--spacing-xxs);
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-color) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current, 
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    color: #fff !important;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-secondary);
}

.dataTables_wrapper .table {
    background-color: rgba(255, 255, 255, 0.5);
}

.dataTables_wrapper .table thead th {
    background-color: rgba(255, 255, 255, 0.7);
}

.dataTables_wrapper .table tbody tr {
    background-color: rgba(255, 255, 255, 0.4);
}

.dataTables_wrapper .table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.3);
}

.dataTables_wrapper .table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.6);
}

.dataTables_wrapper .table td, .dataTables_wrapper .table th {
    border-color: rgba(255, 255, 255, 0.2);
}
