:root {
    /* Blue (primary) + green (accent) on white */
    --brand: #1e63d6;
    --brand-600: #174fae;
    --brand-50: #eef4ff;
    --brand-100: #dbe7fd;
    --green: #16a34a;
    --green-600: #12843c;
    --green-50: #ecfaf1;
    --grad: linear-gradient(135deg, #16a34a 0%, #0ea5a0 45%, #1e63d6 100%);
    --side-bg: #ffffff;
    --side-fg: #334155;
    --side-muted: #94a3b8;
    --bg: #f3f7fb;
    --card: #ffffff;
    --line: #e3eaf3;
    --ink: #0f1f33;
    --muted: #64748b;
    --side-w: 260px;
    --side-w-collapsed: 76px;
    --bs-primary: #1e63d6;
    --bs-primary-rgb: 30, 99, 214;
    --bs-link-color: #1e63d6;
    --bs-link-hover-color: #174fae;
}

* { -webkit-font-smoothing: antialiased; }
body { font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); font-size: .9rem; }
.np, .nepali { font-family: 'Mukta', 'Inter', sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }

/* ---------- Bootstrap brand overrides ---------- */
.btn-primary { background-image: linear-gradient(135deg, #1e63d6, #1857c2); --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); }
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus { border-color: #8db3f0; box-shadow: 0 0 0 .2rem rgba(30, 99, 214, .14); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.page-link { color: var(--brand); }
.active > .page-link, .page-link.active { background-color: var(--brand); border-color: var(--brand); }
.form-label { font-weight: 500; font-size: .82rem; color: #3b4a5e; margin-bottom: .3rem; }
.form-control, .form-select { font-size: .88rem; border-color: #d6dfea; }
.table { --bs-table-hover-bg: #f5f9ff; font-size: .86rem; margin-bottom: 0; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f7fafd; border-bottom-color: var(--line); white-space: nowrap; }
.table td { vertical-align: middle; border-color: #edf2f7; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side-bg);
    border-right: 1px solid var(--line); box-shadow: 4px 0 24px rgba(15,31,51,.04);
    display: flex; flex-direction: column; z-index: 1040; transition: width .2s ease, transform .2s ease;
}
.sidebar::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad); }
.brand { display: flex; align-items: center; gap: .75rem; padding: 1.2rem 1.1rem 1.05rem; color: var(--ink); border-bottom: 1px solid var(--line); }
.brand:hover { color: var(--ink); }
.brand-mark { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 12px; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 1.2rem; box-shadow: 0 6px 14px rgba(30,99,214,.28); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; white-space: nowrap; }
.brand-text strong { font-size: .93rem; color: var(--ink); }
.brand-text small { color: var(--green-600); font-size: .7rem; font-weight: 600; letter-spacing: .02em; }

.side-nav { flex: 1; overflow-y: auto; padding: .5rem .8rem 1rem; scrollbar-width: thin; scrollbar-color: #d6e0ec transparent; }
.nav-label { color: var(--side-muted); font-size: .65rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; padding: 1.05rem .6rem .4rem; white-space: nowrap; display: flex; align-items: center; gap: .5rem; }
.nav-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.nav-link-item {
    display: flex; align-items: center; gap: .7rem; padding: .42rem .6rem; margin: 2px 0; border-radius: 10px;
    color: var(--side-fg); font-weight: 500; white-space: nowrap; position: relative; transition: background .15s, color .15s, transform .15s;
}
.nav-link-item i {
    font-size: 1rem; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px; display: grid; place-items: center;
    background: var(--brand-50); color: var(--brand); transition: background .15s, color .15s;
}
.nav-link-item:nth-of-type(odd) i { background: var(--green-50); color: var(--green); }
.nav-link-item:hover { background: #f4f8fe; color: var(--brand); transform: translateX(2px); }
.nav-link-item:hover i { background: var(--brand-100); color: var(--brand); }
.nav-link-item.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(22,163,74,.22), 0 2px 6px rgba(30,99,214,.22); transform: none; }
.nav-link-item.active i { background: rgba(255,255,255,.2); color: #fff; }
.nav-link-item.active::after { content: ''; position: absolute; right: .7rem; width: 6px; height: 6px; border-radius: 50%; background: #fff; }

.sidebar-foot { padding: .8rem; border-top: 1px solid var(--line); }
.today-bs { display: flex; gap: .65rem; align-items: center; color: var(--side-fg); white-space: nowrap; overflow: hidden; background: linear-gradient(135deg, var(--green-50), var(--brand-50)); border: 1px solid #d9eee2; border-radius: 12px; padding: .6rem .7rem; }
.today-bs > i { font-size: 1.15rem; color: var(--green); }
.today-bs .np { color: var(--ink); font-size: .98rem; font-weight: 600; line-height: 1.1; }
.today-bs small { color: var(--muted); font-size: .7rem; }

.main { flex: 1; margin-left: var(--side-w); min-width: 0; display: flex; flex-direction: column; transition: margin .2s ease; }
.topbar {
    position: sticky; top: 0; z-index: 1030; height: 62px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .8rem; padding: 0 1.25rem;
}
.btn-icon { width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; font-size: 1.35rem; color: var(--ink); }
.btn-icon:hover { background: var(--brand-50); }
.top-search { position: relative; align-items: center; width: min(420px, 40vw); }
.top-search i { position: absolute; left: .8rem; color: var(--muted); }
.top-search .form-control { padding-left: 2.2rem; background: #f1f5fa; border-color: transparent; border-radius: 8px; }
.badge-date { align-items: center; padding: .38rem .7rem; border-radius: 8px; background: var(--green-50); color: var(--green-600); font-weight: 600; font-size: .78rem; }
.user-btn { display: flex; align-items: center; gap: .55rem; border: 0; padding: .25rem .4rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; }

.content { padding: 1.4rem 1.5rem 2rem; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0; letter-spacing: -.01em; padding-left: .75rem; position: relative; }
.page-head h1::before { content: ''; position: absolute; left: 0; top: .2rem; bottom: .2rem; width: 4px; border-radius: 4px; background: var(--grad); }
.page-head p { padding-left: .75rem; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.app-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; padding: .9rem 1.5rem; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--line); background: #fff; }

/* Collapsed (desktop) */
.sidebar-collapsed .sidebar { width: var(--side-w-collapsed); }
.sidebar-collapsed .main { margin-left: var(--side-w-collapsed); }
.sidebar-collapsed .brand-text, .sidebar-collapsed .nav-link-item span, .sidebar-collapsed .today-bs div { display: none; }
.sidebar-collapsed .nav-label { font-size: 0; padding: .5rem 0; margin: .3rem .4rem 0; }
.sidebar-collapsed .nav-link-item.active::after { display: none; }
.sidebar-collapsed .today-bs { padding: .5rem; }
.sidebar-collapsed .nav-link-item { justify-content: center; padding: .6rem 0; }
.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar-collapsed .today-bs { justify-content: center; }

/* Mobile */
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); width: var(--side-w) !important; }
    .main, .sidebar-collapsed .main { margin-left: 0; }
    .sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,31,51,.4); z-index: 1035; }
    .sidebar-collapsed .brand-text, .sidebar-collapsed .nav-link-item span, .sidebar-collapsed .today-bs div { display: initial; }
    .content { padding: 1rem; }
    .topbar { padding: 0 .75rem; }
}

/* ---------- Components ---------- */
.card { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 3px rgba(15,31,51,.05); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); padding: .8rem 1.1rem; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-radius: 12px 12px 0 0 !important; }
.card-header .bi { color: var(--green); }
.card-body { padding: 1.1rem; }
.card-table .table thead th:first-child, .card-table .table td:first-child { padding-left: 1.1rem; }
.card-table .table thead th:last-child, .card-table .table td:last-child { padding-right: 1.1rem; }
.card-footer { background: #fff; border-top: 1px solid var(--line); }

.stat { display: flex; gap: .9rem; align-items: center; padding: 1rem 1.1rem; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; flex: 0 0 46px; }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.stat-label { color: var(--muted); font-size: .78rem; }
.tone-brand { background: var(--brand-50); color: var(--brand); }
.btn-success { --bs-btn-bg: var(--green); --bs-btn-border-color: var(--green); --bs-btn-hover-bg: var(--green-600); --bs-btn-hover-border-color: var(--green-600); }
.tone-blue { background: #eaf1fb; color: #2462a8; }
.tone-green { background: #e8f5ee; color: #1d7a4a; }
.tone-amber { background: #fdf4e3; color: #a86a0c; }
.tone-violet { background: #f1edfb; color: #5b3fae; }
.tone-teal { background: #e5f5f4; color: #13756f; }

.status { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-scheduled, .s-pending, .s-unpaid { background: #fdf4e3; color: #a86a0c; }
.s-checked_in, .s-sample_collected, .s-partial, .s-admitted { background: #eaf1fb; color: #2462a8; }
.s-completed, .s-paid, .s-discharged, .s-available { background: #e8f5ee; color: #1d7a4a; }
.s-cancelled, .s-occupied, .s-expired { background: #fbecec; color: #b42828; }
.s-maintenance { background: #eee; color: #555; }

.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 140px; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty i { font-size: 2rem; display: block; margin-bottom: .4rem; color: #b8c7da; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .8rem; font-size: .86rem; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; }
.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .6rem; }
.vital { background: #f7fafd; border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.vital small { color: var(--muted); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.vital strong { font-size: 1rem; }
.pre { white-space: pre-line; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-muted-2 { color: var(--muted); }

/* Bed board */
.bed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.bed { border: 1px solid var(--line); border-radius: 10px; padding: .65rem .75rem; background: #fff; position: relative; min-height: 84px; }
.bed .bed-no { font-weight: 700; display: flex; align-items: center; gap: .35rem; }
.bed.available { border-color: #bfe3cf; background: #f5fbf7; }
.bed.occupied { border-color: #f0c4c4; background: #fff7f7; }
.bed.maintenance { background: #f4f4f4; }
.bed small { display: block; color: var(--muted); font-size: .74rem; line-height: 1.3; }

/* Invoice item table */
.items-table td { padding: .35rem .4rem; }
.items-table .form-control, .items-table .form-select { padding: .3rem .5rem; }

/* Tom Select brand */
.ts-control { border-color: #d6dfea; font-size: .88rem; min-height: 38px; }
.focus .ts-control { border-color: #8db3f0; box-shadow: 0 0 0 .2rem rgba(30, 99, 214, .14); }
.ts-dropdown .active { background: var(--brand-50); color: var(--ink); }

/* ---------- Nepali date picker ---------- */
.bs-wrap { position: relative; }
.bs-wrap .form-control { padding-right: 2.2rem; }
.bs-wrap .bs-icon { position: absolute; right: .7rem; top: 50%; transform: translateY(-50%); color: var(--brand); pointer-events: none; }
.bs-ad-hint { font-size: .72rem; color: var(--muted); margin-top: .2rem; min-height: 1em; }
.ndp {
    position: absolute; z-index: 2000; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 12px 34px rgba(15,31,51,.16); width: 292px; padding: .7rem; user-select: none; font-size: .85rem;
}
.ndp-head { display: flex; align-items: center; gap: .3rem; margin-bottom: .5rem; }
.ndp-head select { flex: 1; border: 1px solid var(--line); border-radius: 7px; padding: .25rem .3rem; font-size: .82rem; background: #fff; }
.ndp-nav { border: 0; background: var(--brand-50); color: var(--brand); width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; }
.ndp-nav:hover { background: var(--brand-100); }
.ndp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.ndp-dow { font-size: .68rem; color: var(--muted); font-weight: 600; padding: .25rem 0; }
.ndp-dow.sat { color: #b42828; }
.ndp-day { border: 0; background: none; border-radius: 7px; padding: .38rem 0; font-size: .84rem; color: var(--ink); line-height: 1.05; }
.ndp-day small { display: block; font-size: .58rem; color: #aaa; }
.ndp-day:hover { background: var(--brand-50); }
.ndp-day.sat { color: #b42828; }
.ndp-day.today { box-shadow: inset 0 0 0 1px var(--brand); }
.ndp-day.sel { background: var(--grad); color: #fff; }
.ndp-day.sel small { color: #d6e4ff; }
.ndp-foot { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.ndp-foot button { border: 0; background: none; color: var(--brand); font-weight: 600; font-size: .8rem; }
.ndp-foot span { color: var(--muted); font-size: .74rem; }

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .app-footer, .page-actions, .no-print, .alert { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; }
    .card { border: 0; box-shadow: none; }
}
