/*
 * "Clinical & Calm" Style Guide
 */

:root {
    --primary-color: #5B7C99; /* Slate Blue */
    --accent-color: #F5A623;  /* Muted Gold/Orange */
    --background-color: #F8F9FA;
    --text-color: #343A40;
    --border-color: #DEE2E6;

    --status-urgent: #D9534F;
    --status-active: #5B7C99;
    --status-resolved: #5CB85C;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Design Tokens for Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --space-xl: 1.25rem;
    --space-xxl: 1.5rem;
    --space-xxxl: 2rem;

    /* Breakpoint tokens */
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 992px;
    --breakpoint-xl: 1200px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    font-size: 16px;
    margin: 0;
    padding: 0;
    line-height: 1.6;
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

/* Ensure content doesn't get hidden behind sticky navbar */
.container-fluid {
    padding-top: 10px; /* Account for sticky navbar height */
    min-height: calc(100vh - 60px); /* Ensure full height minus navbar */
}

h1, h2, h3 {
    color: var(--primary-color);
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

h1 { font-size: 1.625rem; } /* 26px */
h2 { font-size: 1.25rem; }  /* 20px */
h3 { font-size: 1.125rem; } /* 18px */

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Modern Grid System */
.grid {
    display: grid;
    gap: 1rem;
}

/* Flexbox Utilities */
.flex {
    display: flex;
}

.flex-row {
    flex-direction: row;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

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

.justify-end {
    justify-content: flex-end;
}

.flex-wrap {
    flex-wrap: wrap;
}

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

.gap-1 { gap: var(--space-xs); }
.gap-2 { gap: var(--space-sm); }
.gap-3 { gap: var(--space-md); }
.gap-4 { gap: var(--space-lg); }

/* Margin utilities for search forms */
.ml-2 { margin-left: var(--space-sm); }

.text-start { text-align: left; }
.text-center { text-align: center; }
.text-end { text-align: right; }

/* Custom Container */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
}

/* Spacing Classes */
.m-0 { margin: 0; }
.m-1 { margin: var(--space-xs); }
.m-2 { margin: var(--space-sm); }
.m-3 { margin: var(--space-md); }
.m-4 { margin: var(--space-lg); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-xs); }
.mt-2 { margin-top: var(--space-sm); }
.mt-3 { margin-top: var(--space-md); }
.mt-4 { margin-top: var(--space-lg); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-xs); }
.mb-2 { margin-bottom: var(--space-sm); }
.mb-3 { margin-bottom: var(--space-md); }
.mb-4 { margin-bottom: var(--space-lg); }

.p-0 { padding: 0; }
.p-1 { padding: var(--space-xs); }
.p-2 { padding: var(--space-sm); }
.p-3 { padding: var(--space-md); }
.p-4 { padding: var(--space-lg); }

.px-1 { padding-left: var(--space-xs); padding-right: var(--space-xs); }
.px-2 { padding-left: var(--space-sm); padding-right: var(--space-sm); }
.px-3 { padding-left: var(--space-md); padding-right: var(--space-md); }
.px-4 { padding-left: var(--space-lg); padding-right: var(--space-lg); }

.py-1 { padding-top: var(--space-xs); padding-bottom: var(--space-xs); }
.py-2 { padding-top: var(--space-sm); padding-bottom: var(--space-sm); }
.py-3 { padding-top: var(--space-md); padding-bottom: var(--space-md); }
.py-4 { padding-top: var(--space-lg); padding-bottom: var(--space-lg); }

/* Compact Buttons */
.btn {
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid transparent;
    font-size: 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: var(--font-family);
    transition: all 0.2s ease;
    min-height: 36px; /* Reduced from 44px for more compact design */
    vertical-align: middle;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.btn-primary:hover {
    background-color: #e6991f;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    border-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #545b62;
}

.btn-success {
    background-color: var(--status-resolved);
    color: white;
    border-color: var(--status-resolved);
}

.btn-success:hover {
    background-color: #4cae4c;
}

.btn-danger {
    background-color: var(--status-urgent);
    color: white;
    border-color: var(--status-urgent);
}

.btn-info {
    background-color: #17a2b8;
    color: white;
    border-color: #17a2b8;
}

.btn-info:hover {
    background-color: #138496;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 12px 18px;
    font-size: 1.125rem;
}

.btn-remove {
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.5;
    min-height: auto;
}

.btn-group {
    display: flex;
}

.btn-group .btn:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* Custom Card System */
.card {
    background-color: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

.card .card {
    margin-bottom: 0;
}

.card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    background-color: #f8f9fa;
    font-weight: 600;
}

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

.card-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
    background-color: #f8f9fa;
}

.card-title {
    margin-bottom: var(--space-sm);
}

/* Form Controls */
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem; /* Reduced padding to match button height */
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font-family);
    background-color: white;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 36px; /* Reduced to match buttons */
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(91, 124, 153, 0.25);
}

.form-control-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem; /* Reduced padding to match button height */
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font-family);
    background-color: white;
    background-image: url("data:image/svg+xml;charset=UTF-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23666'><path d='M4 5h8l-4 4z'></path></svg>");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    appearance: none;
    background-clip: padding-box;
    padding-right: 2.5rem;
    min-height: 36px; /* Reduced to match buttons */
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(91, 124, 153, 0.25);
}

.form-select-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background-position: right 0.5rem center;
    padding-right: 2rem;
}

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

.form-check {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
}

.form-check-input {
    margin-right: 0.75rem;
    margin-top: 0;
}

.form-check-label {
    margin-bottom: 0;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

/* Utility Classes */
.d-none {
    display: none !important;
}

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

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

.w-100 {
    width: 100%;
}

.text-muted {
    color: #6c757d;
}

.border {
    border: 1px solid var(--border-color);
}

.rounded {
    border-radius: 4px;
}

.bg-primary {
    background-color: var(--primary-color);
    color: white;
}

.bg-dark {
    background-color: #343a40;
    color: white;
}

.bg-info {
    background-color: #17a2b8;
    color: white;
}

.text-white {
    color: white;
}

.text-primary {
    color: var(--primary-color);
}

.text-success {
    color: var(--status-resolved);
}

.fw-semibold {
    font-weight: 600;
}

/* Alerts */
.alert {
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    border-radius: 4px;
    border-left: 4px solid;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: var(--status-urgent);
    color: #721c24;
}

.alert-success {
    background-color: #d4edda;
    border-color: var(--status-resolved);
    color: #155724;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1050;
    /* Hidden by default */
    display: none;
}

.modal.show {
    display: flex;
}

.modal-dialog {
    max-width: 500px;
    width: 90%;
    margin: 0;
}

.modal-dialog-lg {
    max-width: 800px;
}

.modal-content {
    background-color: white;
    border-radius: 8px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    flex-grow: 1;
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

/* Modal close button styling */
.btn-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: none;
    color: var(--text-color);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: var(--space-md);
    transition: all 0.2s ease;
    line-height: 1;
    cursor: pointer;
}

.btn-close:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: var(--primary-color);
}

.btn-close:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(91, 124, 153, 0.25);
}

/* Sticky Elements */
#sticky-buttons {
    background-color: rgba(248, 249, 250, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: var(--space-lg);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: var(--space-lg);
    z-index: 100;
}

/* Navbar Styles */
.navbar {
    background-color: var(--primary-color);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 56px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1030;
    width: 100%;
}

.navbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 1rem;
}

.navbar-brand {
    display: flex;
    align-items: center;
    font-weight: 600;
    color: white !important;
    text-decoration: none;
    font-size: 1.1rem;
    padding: 0.25rem 0.5rem;
}

.navbar-brand img {
    margin-right: 0.5rem;
}

.navbar-nav-main,
.navbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}


.nav-link {
    display: flex;
    align-items: center;
}

/* Button Link Styles */
.btn-link {
    display: inline-flex;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
}

.btn-link:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.btn-link i {
    margin-right: 0.375rem;
    font-size: 0.9em;
}

.btn-link.dropdown-toggle::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 0.375rem;
    vertical-align: 0.05em;
    border-top: 0.3em solid currentColor;
    border-right: 0.3em solid transparent;
    border-bottom: 0;
    border-left: 0.3em solid transparent;
}

/* Welcome Text */
.welcome-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    margin-right: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Dropdown Support */
.dropdown {
    position: relative;
}

.dropdown-toggle {
    cursor: pointer;
}

/* Dropdown Menu Improvements */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    min-width: 160px;
    padding: 0.5rem 0;
    margin: 0.125rem 0 0;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: none;
    list-style: none; /* Remove default list bullets */
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu .dropdown-item {
    display: block;
    padding: 0.375rem 1rem;
    clear: both;
    font-weight: 400;
    color: var(--text-color);
    text-decoration: none;
    border: 0;
    background: transparent;
    white-space: nowrap;
}

.dropdown-menu .dropdown-item:hover {
    background-color: #f8f9fa;
    color: var(--primary-color);
}

/* Remove bullet points from dropdown items */
.dropdown-menu li {
    list-style: none;
}

.dropdown-menu li::marker {
    display: none;
}


/* Mobile Menu Styles */
.mobile-menu-overlay {
    position: fixed;
    top: 56px; /* navbar height */
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100vh - 56px);
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1025;
    display: none;
    backdrop-filter: blur(2px);
}

.mobile-menu-overlay.show {
    display: block;
}

.mobile-menu {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    max-width: 85vw; /* Prevent cutoff on very small screens */
    background-color: var(--primary-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}


.mobile-menu-overlay.show .mobile-menu {
    transform: translateX(0);
}

.mobile-menu-header {
    display: flex;
    justify-content: flex-end;
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-menu-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
}

.mobile-menu-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-menu-content {
    padding: 0;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allows user section to be pushed to bottom */
}


.mobile-nav-link {
    margin-bottom: 0.25rem;
    padding: 0;
}

.mobile-nav-link .btn-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: white;
    text-decoration: none;
    transition: background-color 0.2s ease;
    width: 100%;
    border-radius: 0;
}

.mobile-nav-link .btn-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.mobile-nav-link.sub-menu .btn-link {
    padding: 0.5rem 2rem;
    font-size: 0.9rem;
}

.mobile-directory-section {
    margin: 1rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.mobile-section-title {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 1rem 0.5rem 1rem;
    font-weight: 600;
}

.mobile-user-section {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.mobile-welcome-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.5rem;
}

.mobile-welcome-text small {
    color: rgba(255, 255, 255, 0.7);
    font-weight: 400;
}

/* Extra small button size */
.btn-xs {
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.2;
}

/* Enhanced dashboard card styling */
.case-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
}

.status-badges {
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.status-badges .status-active,
.status-badges .status-urgent,
.status-badges .status-resolved,
.status-badges .text-muted.fw-medium {
    display: inline-block;
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.case-updated {
    color: #6c757d !important;
    font-size: 0.75rem !important;
    margin-top: 0.25rem !important;
}

.case-contacts {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.record-list__card-detail {
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.record-list__card-detail:last-child {
    margin-bottom: 0;
}

.record-list__card-label {
    color: #495057;
    margin-bottom: 0.25rem;
    font-weight: 600 !important;
}

.record-list__card-detail > div:last-child {
    margin-top: 0.25rem;
}

.case-actions {
    background-color: rgba(248, 249, 250, 0.5);
    padding-top: 0.75rem !important;
    margin-top: 0.75rem !important;
    border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
}

/* Enhanced empty state styling */
.record-list__item--empty .bi-folder-open {
    font-size: 3rem;
    opacity: 0.3;
    margin-bottom: 1rem;
}

/* Status-based styling for cases */
.status-active, .text-success.fw-medium {
    background-color: rgba(25, 135, 84, 0.1);
    color: #198754;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

.status-urgent, .text-danger {
    background-color: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

.status-resolved, .text-secondary.fw-medium {
    background-color: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

.text-muted.fw-medium {
    background-color: rgba(255, 255, 255, 0.1);
    color: #6c757d;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.875rem;
}

/* Record List */
.record-list {
    background-color: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

.record-list__item {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.record-list__item:last-child {
    border-bottom: none;
}

.record-list__item--action {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.record-list__item--action:hover {
    background-color: #f8f9fa;
}

/* --- Case Details Page --- */
.case-details-header {
    background-color: #f8f9fa;
    padding: 1rem;
    margin: -1rem -1rem 1.5rem -1rem;
    border-bottom: 1px solid #dee2e6;
}

.case-details-header__title {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.5rem;
}

.case-section {
    margin-top: 2rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #ffffff;
}

.case-section--patient {
    background-color: #e3f2fd;
    border-color: #bde0fe;
}

.case-section--medical {
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

.case-section__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 0;
    margin-bottom: 1rem;
}

.case-section__title--accent {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.case-section__title--medical {
    color: #856404;
    border-bottom-color: #ffeaa7;
}

.case-actions-bar {
    border-top: 2px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 2rem;
}

/* --- Login Page --- */
.login-container {
    max-width: 400px;
    margin: 50px auto;
    padding: 30px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* --- Sticky Buttons --- */
.sticky-container {
    position: sticky;
    top: 70px; /* Adjust to match navbar height */
    z-index: 1020;
}

#sticky-buttons {
    background-color: rgba(248, 249, 250, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#validation-feedback {
    margin-bottom: 10px !important;
}
#sticky-buttons.has-errors {
    border: 2px solid #dc3545;
}

.is-invalid {
    border-color: #dc3545;
}

.form-control.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}


/* --- Media Queries --- */

/* Small screens and up */
@media (min-width: 576px) {
    .container {
        max-width: 540px;
    }
    .navbar-brand {
        font-size: 1rem;
        padding: 0.25rem 0.375rem;
    }
    .navbar-brand img {
        width: 28px;
        height: 28px;
    }
}

/* Medium screens and up */
@media (min-width: 768px) {
    .grid-cols-md-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-md-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-cols-md-4 { grid-template-columns: repeat(4, 1fr); }
    .justify-content-md-end { justify-content: flex-end; }
    .container {
        max-width: 720px;
    }
    .d-md-none {
        display: none !important;
    }
    .d-md-flex {
        display: flex !important;
    }
    .navbar-inner {
        padding: 0 2rem;
    }
    .navbar-nav-main {
        flex: 1 1 auto;
        justify-content: center;
        margin-right: 2rem;
    }
    .navbar-user {
        flex: 0 0 auto;
    }
    .mobile-menu-overlay, .mobile-menu {
        display: none !important;
    }
}

/* Large screens and up */
@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }
    .d-lg-none {
        display: none !important;
    }
    .d-lg-block {
        display: block !important;
    }
    .d-lg-grid {
        display: grid !important;
    }
    .d-lg-flex {
        display: flex !important;
    }
    .d-lg-inline {
        display: inline !important;
    }
    .navbar-inner {
        padding: 0 2.5rem;
    }
    .navbar-nav-main {
        margin-right: 3rem;
    }
    .navbar-toggler {
        display: none !important;
    }
    .desktop-nav {
        display: flex !important;
    }
    .record-list {
        max-width: 1400px;
        margin: 0 auto;
        font-size: 1rem;
    }
    .record-list__item {
        padding: 1.25rem 2rem;
        align-items: center;
        display: flex;
    }
}

/* Extra-large screens and up */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
    .welcome-text {
        max-width: 250px;
    }
}

/* XXL screens and up */
@media (min-width: 1400px) {
    .container {
        max-width: 1300px;
    }
}

/* XXXL screens and up */
@media (min-width: 1600px) {
    .container {
        max-width: 1400px;
    }
}

@media (min-width: 1900px) {
    .container {
        max-width: min(1500px, calc(100vw - 6rem)); /* Cap at 1500px with side margins */
    }
}

/* --- Mobile and Tablet Specific --- */

@media (max-width: 991px) {
    .desktop-nav {
        display: none !important;
    }
    .navbar-toggler {
        display: block !important;
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 4px;
        padding: 0.375rem 0.75rem;
        color: white;
        cursor: pointer;
        font-size: 1.25rem;
        line-height: 1;
    }
    .navbar-toggler-icon {
        display: inline-block;
        width: 1.5em;
        height: 1.5em;
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3e%3cpath stroke='rgba%28255, 255, 255, 0.8%29' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
        background-repeat: no-repeat;
        background-position: center;
        background-size: 100%;
    }
    .record-list__item {
        position: relative !important;
        padding-right: 5rem !important; /* Adjusted space for buttons */
        min-height: auto;
    }
    .btn-group-tablet {
        position: absolute !important;
        right: 0.25rem !important; /* Closer to edge */
        top: 50% !important;
        transform: translateY(-50%) !important;
        gap: 0.5rem !important;
        flex-direction: column !important;
        align-items: flex-end !important;
    }
    .case-actions {
        padding-right: 0 !important; /* Reset */
    }
    .navbar {
        flex-wrap: wrap;
        padding: 0.5rem 1rem;
    }
    .nav-text, .welcome-text {
        display: none;
    }
    .record-list__header, .record-list__item--header {
        display: none !important;
    }
    .record-list__item--card-grid {
        display: grid;
        grid-template-columns: 1fr 1fr auto;
        gap: 1rem;
        align-items: start;
    }
    .record-list__card-column {
        display: flex;
        flex-direction: column;
    }
    .record-list__card-column:last-child {
        align-items: flex-end;
    }
}

@media (max-width: 767px) {
    #sticky-buttons {
        position: sticky;
        top: 10px;
        z-index: 1000;
    }
    .record-list__item {
        flex-wrap: wrap;
        gap: var(--space-sm);
        padding: 1rem;
        margin-bottom: 0.5rem;
        border-radius: 6px;
        border-left: 3px solid var(--primary-color);
        padding-right: 6rem !important; /* Consistent with tablet */
        min-height: auto;
    }
    .case-header {
        text-align: center;
        padding-bottom: 0.5rem;
        border-bottom-style: dotted;
    }
    .case-contacts {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    .record-list__card-detail {
        margin-bottom: 0.5rem;
        display: block;
    }
    .record-list__card-label {
        color: var(--primary-color);
        margin-bottom: 0.125rem;
    }
    .record-list__card-detail > div:last-child {
        margin-top: 0.125rem;
        padding-left: 0.5rem;
    }
    .case-actions {
        padding-top: 0.5rem;
        padding-right: 0 !important; /* Reset */
    }
    .btn-group-tablet {
        right: 0.5rem !important; /* Consistent alignment */
    }
}

/* --- Admin User Table Specifics --- */
@media (min-width: 992px) {
    .record-list--users .record-list__item--header,
    .record-list--users .record-list__item.d-lg-grid {
        display: grid !important; /* Ensure grid layout is applied */
        grid-template-columns: 0.5fr 1.5fr 2fr 1.5fr 1.5fr 2fr 1fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--users .record-list__cell--id { grid-column: 1; }
    .record-list--users .record-list__cell--username { grid-column: 2; }
    .record-list--users .record-list__cell--name { grid-column: 3; }
    .record-list--users .record-list__cell--mobile { grid-column: 4; }
    .record-list--users .record-list__cell--congregation { grid-column: 5; }
    .record-list--users .record-list__cell--groups { grid-column: 6; }
    .record-list--users .record-list__cell--actions { grid-column: 7; }
}

/* --- Cases Overview Table Specifics --- */
@media (min-width: 992px) {
    .record-list--cases-overview .record-list__item--header,
    .record-list--cases-overview .record-list__item.d-lg-grid {
        grid-template-columns: 2fr 1fr 1fr 1.5fr 1.5fr 1.5fr 1.2fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--cases-overview .record-list__cell--patient { grid-column: 1; }
    .record-list--cases-overview .record-list__cell--status { grid-column: 2; }
    .record-list--cases-overview .record-list__cell--updated { grid-column: 3; }
    .record-list--cases-overview .record-list__cell--contact1 { grid-column: 4; }
    .record-list--cases-overview .record-list__cell--contact2 { grid-column: 5; }
    .record-list--cases-overview .record-list__cell--pvg { grid-column: 6; }
    .record-list--cases-overview .record-list__cell--actions { grid-column: 7; }
}
/* --- Doctors Directory Table Specifics --- */
@media (min-width: 992px) {
    .record-list--doctors .record-list__item--header,
    .record-list--doctors .record-list__item.d-lg-grid {
        grid-template-columns: 2fr 2fr 1fr 1.5fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--doctors .record-list__cell--name { grid-column: 1; }
    .record-list--doctors .record-list__cell--specialty { grid-column: 2; }
    .record-list--doctors .record-list__cell--phone { grid-column: 3; }
    .record-list--doctors .record-list__cell--actions { grid-column: 4; }
}
/* --- Hospitals Directory Table Specifics --- */
@media (min-width: 992px) {
    .record-list--hospitals .record-list__item--header,
    .record-list--hospitals .record-list__item.d-lg-grid {
        grid-template-columns: 2.5fr 3fr 1.5fr 0.5fr 1fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--hospitals .record-list__cell--name { grid-column: 1; }
    .record-list--hospitals .record-list__cell--address { grid-column: 2; }
    .record-list--hospitals .record-list__cell--phone { grid-column: 3; }
    .record-list--hospitals .record-list__cell--website { grid-column: 4; }
    .record-list--hospitals .record-list__cell--actions { grid-column: 5; }
}

/* --- Members Directory Table Specifics --- */
@media (min-width: 992px) {
    .record-list--members .record-list__item--header,
    .record-list--members .record-list__item.d-lg-grid {
        grid-template-columns: 2fr 2fr 1.5fr 2.5fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--members .record-list__cell--name { grid-column: 1; }
    .record-list--members .record-list__cell--role { grid-column: 2; }
    .record-list--members .record-list__cell--mobile { grid-column: 3; }
    .record-list--members .record-list__cell--email { grid-column: 4; }
}

/* --- Specialties Directory Table Specifics --- */
@media (min-width: 992px) {
    .record-list--specialties .record-list__item--header,
    .record-list--specialties .record-list__item.d-lg-grid {
        grid-template-columns: 4fr 1fr;
        gap: 1rem;
        align-items: center;
    }

    .record-list--specialties .record-list__cell--name { grid-column: 1; }
    .record-list--specialties .record-list__cell--actions { grid-column: 2; }
}
