/* ============================================================
   theme.css — Carepoint HMS
   Matches Medflex visual system exactly.
   Used by all 43 modules.
   ============================================================ */

/* ---------- Google Font (Medflex uses system sans + Nunito) ---------- */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700&display=swap');

/* ---------- CSS Variables ----------
   Colors matched to Medflex's actual compiled palette
   (assets/css/main.min.css --bs-primary / --bs-success / etc.)
   so custom shell + component colors stay consistent with
   Bootstrap components (.btn-primary, badges, alerts, ...). */
:root {
    --primary:        #116aef;
    --primary-subtle: #e3eefd;
    --success:        #0ebb13;
    --success-subtle: #e9fdea;
    --danger:         #ff5a39;
    --danger-subtle:  #ffefec;
    --warning:        #eebb30;
    --warning-subtle: #fefaf1;
    --info:           #039ce0;
    --info-subtle:    #e8f8ff;

    --sidebar-bg:     #1a2942;
    --sidebar-hover:  rgba(255,255,255,.07);
    --sidebar-active: #116aef;
    --sidebar-text:   rgba(255,255,255,.75);
    --sidebar-width:  260px;
    --sidebar-collapsed: 70px;

    --header-height:  60px;
    --header-bg:      #ffffff;
    --header-border:  #dde2ee;

    --body-bg:        #f2f2f9;
    --card-bg:        #ffffff;
    --card-border:    #dde2ee;
    --card-radius:    10px;

    --text-primary:   #272727;
    --text-muted:     rgba(39,39,39,.75);

    --font-main:      'Nunito', sans-serif;
    --font-size-base: 14px;
}

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

body {
    font-family: var(--font-main);
    font-size: var(--font-size-base);
    background: var(--body-bg);
    color: var(--text-primary);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; }

/* ---------- Loading Spinner (Medflex style) ---------- */
#loading-wrapper {
    position: fixed; inset: 0; background: #fff;
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; transition: opacity .3s;
}
#loading-wrapper.hidden { opacity: 0; pointer-events: none; }
.spin-wrapper { display: flex; gap: 6px; }
.spin {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--primary); animation: spin-bounce 1.2s infinite ease-in-out;
}
.spin:nth-child(2) { animation-delay: .1s; }
.spin:nth-child(3) { animation-delay: .2s; }
.spin:nth-child(4) { animation-delay: .3s; }
.spin:nth-child(5) { animation-delay: .4s; }
.spin:nth-child(6) { animation-delay: .5s; }
@keyframes spin-bounce {
    0%,80%,100% { transform: scale(0); }
    40%          { transform: scale(1); }
}

/* ---------- Page Wrapper ---------- */
.page-wrapper { display: flex !important; flex-direction: column !important; min-height: 100vh; }

/* ---------- App Header (Topbar) ----------
   Sticky (not fixed) so it reserves its own space in normal flow —
   .main-container below never needs a manually-matched margin/padding
   offset to avoid sliding underneath it. */
.app-header {
    height: var(--header-height) !important;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    padding: 0 16px !important;
    position: sticky !important; top: 0 !important;
    z-index: 1030;
    display: flex !important; align-items: center; gap: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    flex-shrink: 0;
}

.toggle-sidebar, .pin-sidebar {
    background: none; border: none; padding: 6px 8px;
    font-size: 20px; color: var(--text-muted); cursor: pointer; border-radius: 6px;
}
.toggle-sidebar:hover, .pin-sidebar:hover {
    background: var(--body-bg); color: var(--text-primary);
}

.app-brand a {
    font-size: 18px; font-weight: 700;
    color: var(--primary); white-space: nowrap;
}
.brand-text i { font-size: 20px; vertical-align: middle; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search-container { position: relative; }
.search-container .form-control {
    width: 240px; padding-left: 36px; border-radius: 8px;
    border: 1px solid var(--card-border); background: var(--body-bg);
    font-size: 13px;
}
.search-container .form-control:focus { width: 300px; transition: width .2s; box-shadow: none; border-color: var(--primary); }
.search-container i {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 15px;
}

/* Icon-only header buttons (notifications, messages, user menu) stay a
   fixed square; buttons that also carry a text label (branch switcher)
   need to grow instead of clipping/overlapping their neighbor — hence
   min-width + auto width rather than a hard-fixed width. */
.header-icon {
    min-width: 36px; height: 36px; width: auto; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: var(--text-muted); position: relative;
    border: 1px solid var(--card-border); background: var(--body-bg);
    white-space: nowrap;
}
.header-icon:hover { background: var(--primary-subtle); color: var(--primary); }
.count-label {
    position: absolute; top: 4px; right: 4px;
    width: 8px; height: 8px; border-radius: 50%; border: 2px solid #fff;
}
.count-label.warning { background: var(--warning); }
.count-label.danger  { background: var(--danger); }

.avatar-box {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; position: relative;
}
.avatar-box .status {
    position: absolute; bottom: 1px; right: 1px;
    width: 8px; height: 8px; border-radius: 50%; border: 2px solid #fff;
}
.avatar-box .status.online { background: var(--success); }
.avatar-box .status.busy   { background: var(--danger); }

/* ---------- Main Container ---------- */
.main-container {
    display: flex !important;
    align-items: flex-start;
    padding: 0 !important;
    flex: 1 1 auto;
}

/* ---------- Sidebar ----------
   `position: sticky` + being a real flex child (not `fixed`, which is
   pulled out of flow) means it reserves its own width automatically —
   .app-container never has to manually match a margin-left to it. */
.sidebar-wrapper {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width) !important;
    background: var(--sidebar-bg);
    position: sticky !important; top: var(--header-height) !important;
    align-self: flex-start;
    height: calc(100vh - var(--header-height));
    overflow: hidden; display: flex !important; flex-direction: column;
    border-radius: 0 !important; box-shadow: none;
    transition: flex-basis .25s ease, width .25s ease; z-index: 1020;
}

.sidebar-profile {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-profile .avatar-box { background: rgba(255,255,255,.15); font-size: 12px; }
.profile-name { color: #fff; font-size: 13px; max-width: 160px; }

.sidebarMenuScroll { flex: 1; overflow-y: auto; padding: 8px 0; scrollbar-width: thin; }
.sidebarMenuScroll::-webkit-scrollbar { width: 4px; }
.sidebarMenuScroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

/* Section labels */
.sidebar-menu .menu-label {
    padding: 12px 16px 4px;
    list-style: none;
}
.sidebar-menu .menu-label span {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
    color: rgba(255,255,255,.35); font-weight: 600;
}

/* Nav items */
.sidebar-menu { list-style: none; margin: 0; padding: 0 8px; }
.sidebar-menu li { position: relative; }
.sidebar-menu li > a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 8px;
    color: var(--sidebar-text); font-size: 13.5px; font-weight: 400;
    transition: background .15s, color .15s; margin-bottom: 2px;
    white-space: nowrap; overflow: hidden;
}
/* main.min.css gives these icons a light-blue "chip" background sized
   for a light sidebar theme — with our dark navy sidebar + white icon
   color that chip made the glyph invisible (white-on-near-white).
   Strip it back to a plain transparent icon. */
.sidebar-menu li > a i {
    font-size: 17px; width: 20px; height: auto; text-align: center;
    flex-shrink: 0; opacity: .9;
    background: transparent !important; border-radius: 0 !important;
    color: inherit;
}
.sidebar-menu li > a .menu-text { overflow: hidden; text-overflow: ellipsis; }
.sidebar-menu li > a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-menu li.active > a,
.sidebar-menu li.current-page > a {
    background: var(--sidebar-active); color: #fff;
    box-shadow: 0 2px 8px rgba(17,106,239,.35);
}
/* Higher specificity than the plain :hover rule above, so hovering the
   already-active item keeps its blue highlight instead of the hover
   rule's fainter background making it look like it "disappeared". */
.sidebar-menu li.active > a:hover,
.sidebar-menu li.current-page > a:hover {
    background: var(--sidebar-active); color: #fff; filter: brightness(1.12);
}
.sidebar-menu li.active > a i,
.sidebar-menu li.current-page > a i { opacity: 1; }
/* Left accent bar on the active item — common modern-admin pattern */
.sidebar-menu > li.active::before,
.sidebar-menu > li.current-page::before {
    content: ''; position: absolute; left: -8px; top: 6px; bottom: 6px;
    width: 3px; border-radius: 0 3px 3px 0; background: #fff;
}

/* Treeview expand/collapse arrow — main.min.css already renders this via
   `.sidebar-menu > li.treeview::after` (content + rotate-on-active are
   handled there). We only need to recolor it: its default is black,
   invisible against our dark navy sidebar. Do NOT add a second ::after
   here — .sidebar-menu li.treeview > a::after previously duplicated it,
   producing two overlapping arrows per item. */
.sidebar-menu > li.treeview::after { color: rgba(255,255,255,.4) !important; }
.sidebar-menu > li.treeview.active::after,
.sidebar-menu > li.treeview.current-page::after { color: #fff !important; }

.treeview-menu {
    display: none; list-style: none; padding: 4px 0 4px 30px; margin: 0;
}
.sidebar-menu li.treeview.active .treeview-menu,
.sidebar-menu li.treeview.current-page .treeview-menu { display: block; }
.treeview-menu li a {
    display: block; padding: 7px 10px; border-radius: 6px;
    color: rgba(255,255,255,.6); font-size: 13px;
    transition: background .15s, color .15s; margin-bottom: 1px;
}
.treeview-menu li a:hover { background: var(--sidebar-hover); color: #fff; }
.treeview-menu li a.active-sub { color: #fff; background: rgba(255,255,255,.1); }

/* Sidebar bottom contact strip */
.sidebar-contact {
    padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08);
    color: rgba(255,255,255,.6); font-size: 12px;
    display: flex; flex-direction: column; position: relative; flex-shrink: 0;
}
.sidebar-contact i { position: absolute; right: 16px; top: 14px; font-size: 20px; color: var(--primary); }

/* Sidebar collapsed state (desktop pin) */
.sidebar-wrapper.pinned { flex-basis: var(--sidebar-collapsed); width: var(--sidebar-collapsed) !important; }
.sidebar-wrapper.pinned .menu-text,
.sidebar-wrapper.pinned .menu-label,
.sidebar-wrapper.pinned .sidebar-contact p,
.sidebar-wrapper.pinned .sidebar-contact h5,
.sidebar-wrapper.pinned .profile-name,
.sidebar-wrapper.pinned .treeview-menu { display: none !important; }
.sidebar-wrapper.pinned li > a { justify-content: center; padding: 10px; }
.sidebar-wrapper.pinned li.treeview::after { display: none; }

/* ---------- App Container (right of sidebar) ----------
   No margin-left math needed — it simply fills the remaining flex space
   next to the sidebar, so it can never drift out of sync with sidebar width. */
.app-container {
    flex: 1 1 0%; min-width: 0;
    display: flex !important; flex-direction: column;
}

/* Breadcrumb bar */
.app-hero-header {
    padding: 10px 20px !important; background: #fff;
    border-bottom: 1px solid var(--card-border);
}
.breadcrumb { margin: 0; font-size: 13px; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }

/* App body */
.app-body { flex: 1 1 auto; padding: 20px !important; }

/* App footer */
.app-footer {
    padding: 12px 20px !important; border-top: 1px solid var(--card-border);
    font-size: 12.5px; color: var(--text-muted);
}

/* ---------- Cards ---------- */
.card {
    border-radius: var(--card-radius);
    transition: box-shadow .18s ease;
}
.card:hover { box-shadow: 0 6px 20px rgba(40,90,185,.14); }
.card-header {
    background: transparent; border-bottom: 1px solid var(--card-border);
    padding: 14px 18px; font-weight: 600;
}
.card-body { padding: 18px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; }

/* Colored card backgrounds (bg-2 hero banner already handled by main.min.css) */
.bg-primary-card { background: linear-gradient(135deg, var(--primary), #0a4fc4); color: #fff; }
.bg-success-card { background: linear-gradient(135deg, var(--success), #0a8f0e); color: #fff; }
.bg-danger-card  { background: linear-gradient(135deg, var(--danger), #d43f22); color: #fff; }
.bg-warning-card { background: linear-gradient(135deg, var(--warning), #cf9a15); color: #fff; }

/* Stat / metric cards */
.metric-card .card-body { padding: 16px 18px; }
.metric-icon {
    width: 42px; height: 42px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.metric-icon.bordered { border: 2px solid; }
.metric-value { font-size: 28px; font-weight: 700; line-height: 1; }
.metric-label { font-size: 13px; color: var(--text-muted); }

/* Icon boxes (Medflex icon-box class) */
.icon-box { display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-box.sm  { width: 28px; height: 28px; border-radius: 6px; }
.icon-box.md  { width: 40px; height: 40px; border-radius: 8px; }
.icon-box.lg  { width: 52px; height: 52px; border-radius: 10px; }

/* NOTE: .table, .btn, .badge, .form-control/.form-select, .dropdown-menu,
   .modal-content and .alert are already fully styled by the compiled
   Medflex bundle (assets/css/main.min.css) with proper Bootstrap CSS
   variables — intentionally NOT overridden here to avoid fighting that
   design system with different paddings/radii/shadows. Only genuinely
   bespoke pieces (not part of the original template) are defined below. */

/* Action buttons inside tables (icon-only — our own pattern for CRUD rows) */
.btn-action {
    width: 30px; height: 30px; padding: 0; display: inline-flex;
    align-items: center; justify-content: center; border-radius: 6px;
    font-size: 14px; border: 1px solid var(--card-border);
    background: #fff; color: var(--text-muted); transition: all .15s;
}
.btn-action:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-subtle); }
.btn-action.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-subtle); }

/* ---------- Status Pills (semantic states used across modules) ---------- */
.status-active    { background: var(--success-subtle); color: var(--success); }
.status-inactive  { background: #f0f2f5; color: var(--text-muted); }
.status-waiting   { background: var(--warning-subtle); color: #856404; }
.status-progress  { background: var(--primary-subtle); color: var(--primary); }
.status-completed { background: var(--success-subtle); color: var(--success); }
.status-cancelled { background: var(--danger-subtle); color: var(--danger); }
.status-paid      { background: var(--success-subtle); color: var(--success); }
.status-partial   { background: var(--warning-subtle); color: #856404; }
.status-unpaid    { background: var(--danger-subtle); color: var(--danger); }
.status-admitted  { background: var(--primary-subtle); color: var(--primary); }
.status-discharged{ background: var(--success-subtle); color: var(--success); }

/* ---------- Day filter pills (dashboard header) ---------- */
.day-sorting .btn {
    border: 1px solid var(--card-border); background: #fff; color: var(--text-muted);
    border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 500;
}
.day-sorting .btn.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }

/* dropdown-200 doesn't exist in the compiled bundle (only -300/-mini do) */
.dropdown-200 { min-width: 200px; }

/* ---------- Utility ---------- */
.text-truncate-2 {
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.cursor-pointer { cursor: pointer; }
.rounded-img { border-radius: 50%; object-fit: cover; }

/* ---- Photo/avatar in lists ---- */
.img-3x { width: 36px; height: 36px; }
.img-shadow { box-shadow: 0 2px 6px rgba(0,0,0,.12); }

/* ---------- Responsive ----------
   Below 992px the sidebar switches from a sticky flex sibling to a
   fixed off-canvas drawer. Being `position:fixed` pulls it out of the
   flex flow entirely, so .app-container (the only remaining flex
   child) automatically fills 100% width — no override needed. */
@media (max-width: 991.98px) {
    .sidebar-wrapper {
        position: fixed !important; top: var(--header-height) !important;
        left: calc(-1 * var(--sidebar-width)) !important;
        flex-basis: var(--sidebar-width); width: var(--sidebar-width) !important;
        transition: left .25s ease;
    }
    .sidebar-wrapper.mobile-open { left: 0 !important; box-shadow: 4px 0 24px rgba(0,0,0,.15); }
    .app-body { padding: 14px !important; }
    .search-container { display: none !important; }
}

@media (max-width: 575.98px) {
    .app-hero-header { padding: 8px 14px !important; }
    .card-body { padding: 14px; }
    .table td, .table th { padding: 8px; }
}

/* ---------- Backdrop (mobile sidebar overlay) ---------- */
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 1019; display: none;
}
.sidebar-backdrop.show { display: block; }

/* ---------- Back to top ---------- */
.back-to-top {
    position: fixed; right: 24px; bottom: 24px;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; line-height: 1; cursor: pointer;
    box-shadow: 0 4px 14px rgba(17,106,239,.35);
    opacity: 0; visibility: hidden; transform: translateY(10px);
    transition: opacity .2s, transform .2s, visibility .2s;
    z-index: 1020;
}
.back-to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: #0e58c9; }
@media (max-width: 575.98px) {
    .back-to-top { right: 16px; bottom: 16px; width: 40px; height: 40px; font-size: 18px; }
}
