/* ============================================================
   Symbiotech Clinics - App Theme CSS
   Bootstrap 5.3 companion styles
   ============================================================ */

/* ----- CSS Custom Properties ----- */
:root {
    --primary: #1e3a5f;
    --primary-light: #2a4f7f;
    --primary-dark: #152a45;
    --accent: #0ea5e9;
    --accent-light: #38bdf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 260px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

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

html { font-size: 14px; }

body {
    font-family: var(--font-family);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent); }

/* ----- Layout: Sidebar ----- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.sidebar-brand {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 2;
}

.sidebar-brand img { display: block; }

/* ----- Sidebar Nav ----- */
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    margin: 1px 0;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
    background: #f0f7ff;
    color: var(--primary);
}

.sidebar-nav .nav-link.active {
    background: #eef4ff;
    color: var(--primary);
    border-left-color: var(--accent);
    font-weight: 600;
}

.sidebar-nav .nav-link .nav-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-link .submenu-arrow {
    font-size: 18px;
    transition: transform 0.3s;
}

.sidebar-nav .nav-link[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}

.sidebar-nav .has-submenu { cursor: pointer; }

/* Sub-menus */
.sidebar-nav .submenu {
    padding: 2px 0 2px 20px;
}

.sidebar-nav .submenu .nav-link {
    font-size: 0.8125rem;
    padding: 6px 14px;
    font-weight: 400;
    border-left: 2px solid transparent;
}

.sidebar-nav .submenu .nav-link:hover {
    background: #f0f7ff;
    color: var(--primary);
}

.sidebar-nav .submenu .nav-link.active {
    background: #eef4ff;
    color: var(--primary);
    border-left-color: var(--accent);
    font-weight: 600;
}

/* ----- Layout: Main Content ----- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-body);
    display: flex;
    flex-direction: column;
}

/* ----- Top Navbar ----- */
.top-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* ----- Sidebar Backdrop (mobile) ----- */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1039;
    display: none;
    backdrop-filter: blur(2px);
}

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

/* ----- Responsive: Mobile Sidebar ----- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
}

/* ----- Container on XL screens ----- */
@media (min-width: 1200px) {
    .content-container { max-width: 95%; }
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ----- Cards ----- */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: var(--bg-card);
    transition: box-shadow 0.2s;
}

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

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-body { padding: 1.25rem; }

.card-footer {
    background: transparent;
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
}

/* ----- Buttons ----- */
.btn {
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border: none;
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    border: none;
    color: #fff;
}

.btn-accent:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-success { background: var(--success); border-color: var(--success); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }

/* ----- Tables ----- */
.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table > thead > tr > th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table > tbody > tr > td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary);
}

.table > tbody > tr:hover > td {
    background: #f8fafc;
}

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

/* ----- Forms ----- */
.form-control,
.form-select {
    border-radius: var(--radius);
    border: 1px solid #d1d5db;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

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

.form-control[disabled],
.form-control[readonly] {
    background: #f8fafc;
    color: var(--text-primary);
    opacity: 0.8;
}

.form-label {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

textarea.form-control { height: auto !important; min-height: 80px; }

.input-group-text {
    border-radius: var(--radius);
    background: #f8fafc;
    border: 1px solid #d1d5db;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ----- Select2 Bootstrap 5 Overrides ----- */
.select2-container--bootstrap-5 .select2-selection {
    border-radius: var(--radius) !important;
    border-color: #d1d5db !important;
    min-height: 38px !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15) !important;
}

.select2-container--default .select2-search--inline .select2-search__field { width: 100% !important; }
.select2-container--default .select2-selection--multiple .select2-selection__rendered li.select2-search--inline { width: 100% !important; }

.select2-dropdown {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-lg) !important;
    border-color: var(--border-color) !important;
}

.select2-results__option--highlighted[aria-selected] {
    background: var(--accent) !important;
}

/* ----- Modals ----- */
.modal-content {
    border: none;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.modal-title {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.modal-body { padding: 1.25rem; }

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    background: #f8fafc;
}

.btn-close { opacity: 0.5; }
.btn-close:hover { opacity: 1; }

@media (min-width: 992px) {
    .modal-lg { max-width: 900px !important; }
}

/* ----- Badges ----- */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    border-radius: 50px;
    letter-spacing: 0.02em;
}

.badge-success { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.badge-danger  { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.badge-info    { background: rgba(14, 165, 233, 0.12); color: var(--accent); }
.badge-primary { background: rgba(30, 58, 95, 0.12); color: var(--primary); }

/* ----- Dropdown ----- */
.dropdown-menu {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.dropdown-item {
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    transition: background 0.15s;
}

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

.dropdown-divider { border-color: var(--border-color); }

/* ----- Breadcrumbs ----- */
.breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 0.8125rem;
}

.breadcrumb-item a { color: var(--text-secondary); }
.breadcrumb-item a:hover { color: var(--accent); }
.breadcrumb-item.active { color: var(--text-primary); font-weight: 500; }

/* ----- Alerts ----- */
.alert {
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.alert-success { background: rgba(16, 185, 129, 0.1); color: #065f46; }
.alert-danger  { background: rgba(239, 68, 68, 0.1); color: #991b1b; }
.alert-warning { background: rgba(245, 158, 11, 0.1); color: #92400e; }
.alert-info    { background: rgba(14, 165, 233, 0.1); color: #0c4a6e; }

/* ----- Pagination ----- */
.page-link {
    border-radius: var(--radius) !important;
    margin: 0 2px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 0.4rem 0.75rem;
}

.page-link:hover {
    background: #f0f7ff;
    color: var(--primary);
    border-color: var(--accent);
}

.page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ----- Nav Tabs ----- */
.nav-tabs {
    border-bottom: 2px solid var(--border-color);
}

.nav-tabs .nav-link {
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 0.75rem 1.25rem;
    position: relative;
    font-size: 0.875rem;
}

.nav-tabs .nav-link:hover { color: var(--primary); }

.nav-tabs .nav-link.active {
    color: var(--primary);
    background: transparent;
    border: none;
}

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

/* ----- Progress Bars ----- */
.progress {
    border-radius: 50px;
    height: 8px;
    background: #e5e7eb;
}

.progress-bar {
    border-radius: 50px;
    background: linear-gradient(135deg, var(--accent), var(--primary));
}

/* ----- Tooltips ----- */
.tooltip-inner {
    border-radius: var(--radius);
    font-size: 0.8125rem;
    padding: 0.4rem 0.75rem;
}

/* ----- Material Icons Size Utils ----- */
.material-icons { font-size: 20px; }
.material-icons.fs-14 { font-size: 14px !important; }
.material-icons.fs-16 { font-size: 16px !important; }
.material-icons.fs-18 { font-size: 18px !important; }
.material-icons.fs-24 { font-size: 24px !important; }

/* ============================================================
   UTILITIES
   ============================================================ */

/* Text colors */
.text-primary-custom { color: var(--primary) !important; }
.text-accent { color: var(--accent) !important; }

/* Background */
.bg-body-custom { background: var(--bg-body) !important; }

/* Borders */
.border-dashed { border: 1px dashed #d1d5db !important; min-height: 100px; border-radius: var(--radius); }

/* Shadows */
.shadow-custom { box-shadow: var(--shadow) !important; }
.shadow-md-custom { box-shadow: var(--shadow-md) !important; }

/* Sticky for desktop */
@media (min-width: 992px) {
    .position-lg-sticky {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 80px;
    }
}

/* Number valid styling */
.numbervalid { font-variant-numeric: tabular-nums; }

/* Loading overlay */
.loader-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: var(--radius-lg);
}

.loader-overlay .spinner-border { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

/* ----- Footer ----- */
footer {
    margin-top: auto;
}

footer a { color: var(--text-secondary); }
footer a:hover { color: var(--accent); }

/* ----- Chat Styles (legacy support) ----- */
.chat-view .chat-bubble { max-width: 100%; }
.chat-view .chat-info { font-size: 10px; padding: 0 10px; }
.chat-view .chat-info.from-me,
.chat-view .chat-info.from-me small { float: right; width: 100%; text-align: right; }
.chat-view .chat-info.from-them,
.chat-view .chat-info.from-them small { float: left; width: 100%; text-align: left; }
.chat-view .chat-input { height: 45px !important; }

/* ----- Page Title / Header ----- */
.page-header {
    padding: 1.25rem 0;
}

.page-header h4,
.page-header h3 {
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* ----- Stat Cards ----- */
.stat-card {
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ----- Scrollbar for main content ----- */
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ----- DataTables BS5 Overrides ----- */
.dataTables_wrapper .dataTables_info { font-size: 0.8125rem; color: var(--text-secondary); }
.dataTables_wrapper .dataTables_paginate .paginate_button { border-radius: var(--radius) !important; margin: 0 2px; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--primary) !important; border-color: var(--primary) !important; color: #fff !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { background: #f0f7ff !important; border-color: var(--accent) !important; color: var(--primary) !important; }
.dataTables_wrapper .dataTables_filter input { border-radius: var(--radius); border: 1px solid #d1d5db; padding: 0.4rem 0.75rem; font-size: 0.875rem; }
.dataTables_wrapper .dataTables_filter input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,0.15); outline: none; }
.dataTables_wrapper .dataTables_length select { border-radius: var(--radius); border: 1px solid #d1d5db; padding: 0.3rem 0.5rem; font-size: 0.875rem; }
table.dataTable thead th { font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); border-bottom: 2px solid var(--border-color) !important; }
table.dataTable tbody td { vertical-align: middle; font-size: 0.875rem; border-bottom: 1px solid #f1f5f9 !important; }
table.dataTable tbody tr:hover td { background: #f8fafc !important; }
table.dataTable.no-footer { border-bottom: none !important; }

/* Form switches (status toggles) */
.form-switch .form-check-input { width: 2.5em; height: 1.25em; cursor: pointer; border-radius: 50px; }
.form-switch .form-check-input:checked { background-color: var(--success); border-color: var(--success); }
.form-check-input.status_checkbox { width: 2.5em; height: 1.25em; cursor: pointer; }
.form-check-input.status_checkbox:checked { background-color: var(--success); border-color: var(--success); }
.status_checkbox { cursor: pointer; }

/* ----- Form Labels ----- */
.form-label { font-weight: 500; font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
label.form-label { display: block; }

/* ----- Modal Enhancements ----- */
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h5, .modal-header .modal-title { font-weight: 600; font-size: 1.05rem; margin: 0; }
.modal-body .mb-3 label { font-weight: 500; font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: 0.35rem; display: block; }
.modal-body .form-control { border-radius: var(--radius); }
.modal-body .form-select { border-radius: var(--radius); }
.modal-footer .btn { min-width: 100px; }

/* ----- Action Buttons in Tables ----- */
.table .btn-outline-secondary { border-color: #d1d5db; color: var(--text-secondary); padding: 0.25rem 0.5rem; }
.table .btn-outline-secondary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.table .btn-outline-secondary .material-icons { font-size: 16px; }
.table .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.table .btn-sm + .btn-sm { margin-left: 0.25rem; }

/* ----- Page Header / Breadcrumb Bar ----- */
.page-breadcrumb { background: #fff; border-radius: var(--radius-lg); padding: 0.75rem 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow-sm); }
.page-breadcrumb .breadcrumb { margin: 0; }

/* ----- Card Title ----- */
.card-title { font-weight: 600; font-size: 1rem; color: var(--text-primary); margin: 0; }

/* ----- Search Input in Card Header ----- */
.card-header .form-control { max-width: 250px; border-radius: var(--radius); font-size: 0.8125rem; }

/* ----- Tab Navigation ----- */
.nav-tabs-simple { border-bottom: 2px solid var(--border-color); }
.nav-tabs-simple .nav-link { border: none; color: var(--text-secondary); font-weight: 500; padding: 0.75rem 1.25rem; position: relative; }
.nav-tabs-simple .nav-link:hover { color: var(--primary); }
.nav-tabs-simple .nav-link.active { color: var(--primary); }
.nav-tabs-simple .nav-link.active::after { content: ''; position: absolute; bottom: -2px; left: 0; right: 0; height: 2px; background: var(--primary); border-radius: 2px; }

/* ----- Empty State ----- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .material-icons { font-size: 48px; opacity: 0.3; margin-bottom: 0.5rem; }

/* ----- Loading Overlay (for modals and cards) ----- */
.loading-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.9); z-index: 10; border-radius: inherit; display: flex; align-items: center; justify-content: center; }

/* ----- Select2 in Modals ----- */
.modal .select2-container { width: 100% !important; }

/* ----- Multiselect ----- */
.select2-container--bootstrap-5 .select2-selection--multiple { min-height: 38px; border-radius: var(--radius); }

/* ----- Print ----- */
@media print {
    .sidebar,
    .top-navbar,
    .sidebar-backdrop,
    footer { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}
