:root {
    --ehr-bg: #f5f8fc;
    --ehr-primary: #0b396b;
    --ehr-primary-dark: #082a50;
    --ehr-primary-light: #eaf1f8;
    --ehr-accent: #f26513;
    --ehr-accent-light: #fff3eb;
    --ehr-border: #d8e3ef;
    --ehr-text: #162436;
    --ehr-muted: #5c6f84;
    --bs-primary: #0b396b;
    --bs-primary-rgb: 11, 57, 107;
}

.btn-primary {
    --bs-btn-bg: #0b396b;
    --bs-btn-border-color: #0b396b;
    --bs-btn-hover-bg: #082a50;
    --bs-btn-hover-border-color: #082a50;
    --bs-btn-active-bg: #062140;
}

.btn-outline-primary {
    --bs-btn-color: #0b396b;
    --bs-btn-border-color: #0b396b;
    --bs-btn-hover-bg: #0b396b;
    --bs-btn-hover-border-color: #0b396b;
}

.text-primary {
    color: #0b396b !important;
}

.bg-primary {
    background-color: #0b396b !important;
}

.text-accent {
    color: #f26513 !important;
}

/* Brand Preloader */
#ehr-preloader {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

#ehr-preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

.ehr-preloader-logo {
    max-width: 240px;
    width: 72%;
    height: auto;
    margin-bottom: 14px;
}

.ehr-preloader-bar {
    width: 140px;
    height: 4px;
    background: var(--ehr-primary-light);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.ehr-preloader-bar::after {
    content: '';
    position: absolute;
    left: -50%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, var(--ehr-primary), var(--ehr-accent));
    animation: ehrLoadSlide 1s infinite ease-in-out;
}

@keyframes ehrLoadSlide {
    0% { left: -50%; }
    100% { left: 100%; }
}

html, body {
    overflow-x: clip;
}

body {
    background-color: var(--ehr-bg);
    color: var(--ehr-text);
    font-family: 'Noto Sans Devanagari', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 0.86rem;
}

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

main .ehr-card,
main .ehr-stat-card {
    animation: ehrFadeSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

main .row > [class*="col-"]:nth-child(1) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(1) .ehr-card { animation-delay: 0.02s; }
main .row > [class*="col-"]:nth-child(2) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(2) .ehr-card { animation-delay: 0.05s; }
main .row > [class*="col-"]:nth-child(3) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(3) .ehr-card { animation-delay: 0.08s; }
main .row > [class*="col-"]:nth-child(4) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(4) .ehr-card { animation-delay: 0.11s; }
main .row > [class*="col-"]:nth-child(5) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(5) .ehr-card { animation-delay: 0.14s; }
main .row > [class*="col-"]:nth-child(6) .ehr-stat-card,
main .row > [class*="col-"]:nth-child(6) .ehr-card { animation-delay: 0.17s; }

.ehr-sidebar {
    width: 220px;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
    background: #ffffff;
    border-right: 1px solid var(--ehr-border);
    transition: width 0.2s ease;
    flex-shrink: 0;
}

.ehr-sidebar .nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-wrap: nowrap;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.ehr-sidebar .nav::-webkit-scrollbar {
    width: 5px;
}

.ehr-sidebar .nav::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

.ehr-sidebar .nav-link {
    color: var(--ehr-text);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.18rem;
    font-weight: 500;
    font-size: 0.94rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    white-space: nowrap;
    border-left: 3px solid transparent;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.ehr-sidebar .nav-link:hover {
    background-color: var(--ehr-primary-light);
    color: var(--ehr-primary);
    transform: translateX(2px);
}

.ehr-sidebar .nav-link.active {
    background: linear-gradient(90deg, var(--ehr-primary-light) 0%, #ffffff 100%);
    color: var(--ehr-primary);
    font-weight: 600;
    border-left-color: var(--ehr-accent);
}

.ehr-sidebar .nav-link i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

body.sidebar-collapsed .ehr-sidebar {
    width: 64px;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

body.sidebar-collapsed .ehr-sidebar .nav-text,
body.sidebar-collapsed .ehr-sidebar .brand-text {
    display: none !important;
}

body.sidebar-collapsed .ehr-sidebar .collapsed-icon {
    display: inline-block !important;
}

body.sidebar-collapsed .ehr-sidebar .nav-link {
    justify-content: center;
    padding: 0.55rem;
}

.ehr-sidebar .nav-link:hover,
.ehr-sidebar .nav-link.active {
    background-color: var(--ehr-primary-light);
    color: var(--ehr-primary);
}

.ehr-topbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 3px solid var(--ehr-accent);
    border-bottom: 1px solid var(--ehr-border);
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 2px 10px rgba(11, 57, 107, 0.06);
}

.ehr-card {
    background: #ffffff;
    border: 1px solid var(--ehr-border);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(11, 57, 107, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.ehr-card:hover {
    box-shadow: 0 8px 22px rgba(11, 57, 107, 0.08);
}

.ehr-stat-card {
    background: linear-gradient(135deg, #ffffff 0%, #f7faff 100%);
    border: 1px solid var(--ehr-border);
    border-left: 4px solid var(--ehr-primary);
    border-radius: 12px;
    padding: 0.65rem 0.85rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ehr-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(11, 57, 107, 0.09);
}

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

.btn {
    min-height: 34px;
    border-radius: 8px;
    font-size: 0.84rem;
    padding: 0.3rem 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: transform 0.14s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(11, 57, 107, 0.24);
}

.btn-sm {
    min-height: 29px;
    border-radius: 6px;
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
}

.btn:active {
    transform: scale(0.97);
}

.form-control, .form-select {
    min-height: 34px;
    border-radius: 8px;
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    border-color: var(--ehr-border);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--ehr-primary);
    box-shadow: 0 0 0 3px rgba(11, 57, 107, 0.12);
}

.form-control-sm, .form-select-sm {
    min-height: 29px;
    border-radius: 6px;
    font-size: 0.8rem;
    padding: 0.2rem 0.45rem;
}

.table > :not(caption) > * > * {
    padding: 0.38rem 0.5rem;
}

/* Android-style Bottom Navigation Bar */
.ehr-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #ffffff;
    border-top: 1px solid var(--ehr-border);
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
    z-index: 1040;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
}

.ehr-bottom-nav .bnav-item {
    flex: 1;
    text-decoration: none;
    color: var(--ehr-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 4px 2px;
    background: none;
    border: none;
}

.ehr-bottom-nav .bnav-item i {
    font-size: 1.15rem;
    margin-bottom: 2px;
}

.ehr-bottom-nav .bnav-item.active {
    color: var(--ehr-primary);
    font-weight: 700;
}

.ehr-bottom-nav .bnav-fab {
    background: var(--ehr-accent);
    color: #ffffff !important;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -18px;
    box-shadow: 0 4px 12px rgba(242, 101, 19, 0.4);
}

@media (max-width: 991.98px) {
    body {
        padding-bottom: 72px;
    }
    .form-control, .form-select {
        font-size: 16px;
    }
    .ehr-bottom-nav {
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

.timeline-item {
    border-left: 3px solid var(--ehr-primary);
    padding-left: 1rem;
    margin-bottom: 1rem;
    position: relative;
}

.timeline-item::before {
    content: '';
    width: 11px;
    height: 11px;
    background: var(--ehr-primary);
    border-radius: 50%;
    position: absolute;
    left: -7px;
    top: 6px;
}

.autocomplete-list {
    position: absolute;
    z-index: 1050;
    background: #ffffff;
    border: 1px solid var(--ehr-border);
    border-radius: 0.5rem;
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
}

.autocomplete-item:hover {
    background-color: var(--ehr-primary-light);
}

@media (max-width: 767.98px) {
    .dropdown-menu {
        max-width: calc(100vw - 16px) !important;
    }
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    .table-responsive-cards thead {
        display: none;
    }
    .table-responsive-cards tr {
        display: block;
        margin-bottom: 0.75rem;
        border: 1px solid var(--ehr-border);
        border-radius: 0.5rem;
        background: #ffffff;
        padding: 0.5rem;
    }
    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        border: none;
        padding: 0.35rem 0.5rem;
    }
    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--ehr-muted);
    }
}
