:root,
body.theme-teal {
    /* Theme 1: Teal (default) */
    --teal: #128a84;
    --teal-dark: #0e736e;
    --teal-deep: #0b5f5b;
    --teal-light: #16a39b;
    --teal-rgb: 18, 138, 132;
    --pill: #0b6b66;
    --tint: #e7f4f3;
    --ink: #1f2a37;
    --muted: #6b7f8a;
    --bg: #eef3f6;
    --surface: #ffffff;
    --surface-2: #f3f8f8;
    --border: #e3ebee;
    --track: #edf2f3;
    --heading: #4a6270;
    --shadow: rgba(20, 40, 50, .06);
}

/* Theme 2: Royal Blue */
body.theme-royal {
    --teal: #2563c9;
    --teal-dark: #1d4fa6;
    --teal-deep: #173f85;
    --teal-light: #3b82f6;
    --teal-rgb: 37, 99, 201;
    --pill: #173f85;
    --tint: #e8f0fd;
    --ink: #1e293b;
    --muted: #64748b;
    --bg: #eef2f9;
    --surface: #ffffff;
    --surface-2: #f2f6fc;
    --border: #e2e8f2;
    --track: #e9eef6;
    --heading: #3d4f6b;
    --shadow: rgba(20, 35, 70, .07);
}

/* Theme 3: Dark */
body.theme-dark {
    --teal: #1fb3a9;
    --teal-dark: #17202b;
    --teal-deep: #5fd6cd;
    --teal-light: #1fb3a9;
    --teal-rgb: 31, 179, 169;
    --pill: #243140;
    --tint: #1d3a3d;
    --ink: #e2e8ee;
    --muted: #93a3b0;
    --bg: #0f151c;
    --surface: #18212b;
    --surface-2: #202b37;
    --border: #2a3644;
    --track: #2a3644;
    --heading: #c4d0da;
    --shadow: rgba(0, 0, 0, .35);
    --bs-body-bg: #18212b;
    --bs-body-color: #e2e8ee;
    --bs-border-color: #2a3644;
    --bs-tertiary-bg: #202b37;
    --bs-secondary-bg: #202b37;
}
body.theme-dark .navbar-clinic { background: #131b24; border-bottom: 1px solid var(--border); }
body.theme-dark .nav-links a.active { border-bottom-color: var(--teal); color: var(--teal); }
body.theme-dark .table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--border); }
body.theme-dark .btn-teal { color: #0f151c; font-weight: 600; }
body.theme-dark .btn-teal:hover { background: #3fc7be; color: #0f151c; }
body.theme-dark a:not(.btn):not(.nav-links a) { color: #5fd6cd; }
body.theme-dark .text-muted { color: var(--muted) !important; }
body.theme-dark .patient-hero { background: linear-gradient(135deg, #17423f, #1c5e59); }
body.theme-dark .btn-outline-secondary { --bs-btn-color: #c4d0da; --bs-btn-border-color: #3d4b5c; --bs-btn-hover-bg: #2a3644; --bs-btn-hover-border-color: #4a5a6c; --bs-btn-hover-color: #fff; }
body.theme-dark .table-danger { --bs-table-bg: #3a1f24; --bs-table-color: #f3c9cd; --bs-table-border-color: #4d2a30; }
body.theme-dark .table-warning { --bs-table-bg: #3a3119; --bs-table-color: #f1dfaa; --bs-table-border-color: #4d4122; }
body.theme-dark .table-success { --bs-table-bg: #173326; --bs-table-color: #bfe8cf; --bs-table-border-color: #22453a; }
body.theme-dark .table-light { --bs-table-bg: #202b37; --bs-table-color: #e2e8ee; }
body.theme-dark .alert-info { --bs-alert-bg: #163540; --bs-alert-color: #bfe6f0; --bs-alert-border-color: #23515f; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body.app-body {
    margin: 0;
    font-family: "Segoe UI", "Noto Sans", sans-serif;
    background: var(--bg);
    color: var(--ink);
}

.topbar {
    background: var(--teal-dark);
    color: #fff;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.brand img {
    height: 46px;
    width: auto;
    background: transparent;
    padding: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 18px; font-weight: 700; }
.brand-text span { font-weight: 400; font-size: 12px; opacity: .92; }
.top-right { display: flex; align-items: center; gap: 18px; }
.phone-pill {
    background: var(--pill);
    border-radius: 22px;
    padding: 7px 14px;
    display: flex; align-items: center; gap: 8px; font-weight: 600;
}
.bell { font-size: 20px; opacity: .95; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: #fff; color: var(--teal-dark);
    display: grid; place-items: center; font-weight: 800;
}

.navbar-clinic {
    background: var(--teal);
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0 10px 0 8px;
    min-height: 74px;
}
.nav-links { display: flex; align-items: stretch; gap: 4px; flex-wrap: wrap; }
.nav-links a,
.nav-links .nav-logout button {
    color: #fff;
    text-decoration: none;
    min-width: 92px;
    padding: 12px 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 13px;
    line-height: 1.2;
    opacity: .92;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    font-family: inherit;
    cursor: pointer;
}
.nav-links a i,
.nav-links .nav-logout button i { font-size: 20px; }
.nav-links a.active,
.nav-links a:hover,
.nav-links .nav-logout button:hover {
    opacity: 1;
    background: rgba(255,255,255,.08);
    border-bottom-color: #fff;
    color: #fff;
}
.nav-logout {
    display: flex;
    align-items: stretch;
    margin: 0;
    padding: 0;
}

.page-wrap { padding: 18px 22px 40px; }
.page-title { color: var(--heading); font-size: 20px; font-weight: 600; margin: 0 0 16px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
}
.stat-card {
    border-radius: 10px;
    color: #fff;
    min-height: 148px;
    padding: 18px 12px 14px;
    text-align: center;
    box-shadow: 0 8px 18px rgba(16, 50, 60, .12);
}
.stat-card i { font-size: 34px; opacity: .95; }
.stat-card .label { margin-top: 10px; font-size: 15px; }
.stat-card .value { margin-top: 6px; font-size: 32px; font-weight: 700; }
.bg-teal { background: var(--teal); }
.bg-sky { background: #2aa3e0; }
.bg-rose { background: #e24c3f; }
.bg-gold { background: #d39b22; }
.bg-purple { background: #8a63c8; }
.bg-green { background: #43b36a; }

.panel {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    padding: 16px;
    margin-top: 16px;
}
.panel h5 { margin: 0 0 12px; color: var(--teal-deep); font-weight: 700; }
.print-switch {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.print-switch.off { box-shadow: inset 0 0 0 2px #e7b3b3, 0 8px 24px var(--shadow); }
.print-switch .form-check-input { width: 2.7rem; height: 1.4rem; cursor: pointer; }
.print-switch .form-check-input:checked { background-color: var(--teal); border-color: var(--teal); }
.print-switch .form-check-input:focus { box-shadow: 0 0 0 .2rem rgba(var(--teal-rgb), .25); }

.btn-teal { background: var(--teal); color: #fff; border: 0; }
.btn-teal:hover { background: var(--teal-dark); color: #fff; }
.table thead th { background: var(--surface-2); color: var(--heading); font-size: 13px; }
.badge-wait { background: #f59e0b; }
.badge-doc { background: #2aa3e0; }
.badge-ready { background: #8a63c8; }
.badge-done { background: #43b36a; }
.badge-cancel { background: #9aa5ad; }

.login-wrap {
    min-height: 100vh;
    background: linear-gradient(160deg, var(--teal-dark), var(--teal-light));
    display: grid; place-items: center; padding: 24px;
}
.login-card {
    width: 100%; max-width: 420px; background: var(--surface); border-radius: 16px;
    padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.18);
}
.search-box {
    position: relative;
}
.search-results {
    position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    max-height: 240px; overflow: auto; display: none;
}
.search-results button {
    display: block; width: 100%; text-align: left; border: 0; background: var(--surface); color: var(--ink);
    padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.search-results button:hover { background: var(--tint); }
.cart-table input { max-width: 90px; }
.print-sheet { width: 80mm; margin: 0 auto; font-family: Arial, sans-serif; color: #000; }
.print-sheet h2, .print-sheet h3 { margin: 0; text-align: center; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    body.theme-dark {
        --ink: #000; --muted: #444; --heading: #222; --surface: #fff; --surface-2: #f3f3f3; --border: #ccc; --track: #eee; --tint: #eee;
        --bs-body-bg: #fff; --bs-body-color: #000; --bs-border-color: #ccc; color: #000;
    }
}

.patient-hero {
    background: linear-gradient(135deg, var(--teal-dark), var(--teal-light));
    color: #fff;
    border-radius: 14px;
    padding: 22px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 24px rgba(var(--teal-rgb), .22);
}
.patient-hero-main { display: flex; align-items: center; gap: 16px; }
.patient-avatar {
    width: 72px; height: 72px; border-radius: 18px;
    background: #fff; color: var(--teal-dark);
    display: grid; place-items: center; font-size: 26px; font-weight: 800;
}
.patient-mr { opacity: .85; font-size: 13px; letter-spacing: .4px; }
.patient-name { margin: 2px 0 8px; font-size: 28px; font-weight: 700; }
.patient-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; opacity: .95; }
.patient-meta span { background: rgba(255,255,255,.16); padding: 3px 10px; border-radius: 20px; }
.blood-pill { background: #e24c3f !important; }
.patient-hero-actions { display: flex; gap: 8px; }
.patient-stat-row {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 14px;
}
.patient-stat {
    background: var(--surface); border-radius: 12px; padding: 14px 16px;
    box-shadow: 0 8px 24px var(--shadow);
}
.patient-stat span { display: block; color: var(--muted); font-size: 12px; }
.patient-stat strong { font-size: 20px; color: var(--teal-deep); }
.info-list { margin: 0; }
.info-list > div { display: grid; grid-template-columns: 110px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-list dt { color: var(--muted); font-weight: 600; margin: 0; }
.info-list dd { margin: 0; }
.allergy-box {
    margin-top: 14px; border-radius: 10px; padding: 12px;
    display: flex; gap: 10px; background: var(--surface-2); color: var(--heading);
}
.allergy-box.has-allergy { background: #fff1f0; color: #9b2c2c; }
.allergy-box i { font-size: 20px; }
.visit-card {
    border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; background: var(--surface-2);
}
.visit-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.visit-token { font-size: 18px; font-weight: 800; color: var(--teal-deep); }
.visit-notes { background: var(--surface); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 14px; }
.visit-notes span { display: inline-block; min-width: 86px; color: var(--muted); font-weight: 600; }
.vital-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.vital-row span { background: var(--tint); color: var(--teal-deep); border-radius: 20px; padding: 2px 10px; font-size: 12px; }
.med-block { margin-top: 10px; }
.med-label { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.med-label.given { color: var(--teal-deep); }
.med-label.rx { color: #6b4ea3; }
.med-table { background: var(--surface); }
.empty-meds { font-size: 13px; color: var(--muted); }
.rx-list { margin: 0; padding-left: 18px; }
.rx-list li { margin-bottom: 4px; }
.rx-list span, .rx-list em { display: block; color: #5c6f79; font-size: 12px; font-style: normal; }
.visit-card-foot {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 13px;
}

@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
    .patient-stat-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .navbar-clinic { flex-direction: column; }
    .patient-hero { flex-direction: column; align-items: flex-start; }
}

/* ===================== Layouts (one per theme) ===================== */
.nav-toggle, .nav-brand, .nav-backdrop { display: none; }

/* --- Sidebar layout (Royal Sidebar): full menu on the left --- */
body.layout-sidebar { --side-w: 236px; }
body.layout-sidebar .navbar-clinic {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--side-w);
    flex-direction: column; padding: 0; min-height: 0; z-index: 40;
    background: linear-gradient(180deg, var(--teal-deep), var(--teal-dark));
    overflow-y: auto;
}
body.layout-sidebar .nav-brand {
    display: flex; align-items: center; gap: 10px; padding: 18px 16px 16px;
    color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.12);
}
.nav-logo {
    width: 40px; height: 40px; border-radius: 10px; flex: none;
    background: #fff; color: var(--teal-dark); font-weight: 800; font-size: 15px;
    display: grid; place-items: center; letter-spacing: .5px;
}
body.layout-sidebar .nav-brand-text { font-weight: 700; font-size: 15px; line-height: 1.2; }
body.layout-sidebar .nav-links { flex-direction: column; flex-wrap: nowrap; gap: 2px; padding: 12px 10px 20px; }
body.layout-sidebar .nav-links a,
body.layout-sidebar .nav-links .nav-logout button {
    flex-direction: row; justify-content: flex-start; gap: 12px; min-width: 0; width: 100%;
    padding: 10px 14px; font-size: 14px; border-radius: 8px; border-bottom: 0;
}
body.layout-sidebar .nav-links a i,
body.layout-sidebar .nav-links .nav-logout button i { font-size: 18px; width: 20px; text-align: center; }
body.layout-sidebar .nav-links a.active {
    background: #fff; color: var(--teal-dark); font-weight: 600; opacity: 1;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
body.layout-sidebar .nav-links a:not(.active):hover,
body.layout-sidebar .nav-links .nav-logout button:hover { background: rgba(255,255,255,.12); }
body.layout-sidebar .nav-logout { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 8px; }
body.layout-sidebar .topbar {
    margin-left: var(--side-w); background: var(--surface); color: var(--ink);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
    box-shadow: 0 2px 10px var(--shadow);
}
body.layout-sidebar .topbar .brand-text strong { font-size: 16px; color: var(--teal-deep); }
body.layout-sidebar .topbar .brand-text span { color: var(--muted); }
body.layout-sidebar .phone-pill { background: var(--tint); color: var(--teal-deep); }
body.layout-sidebar .page-wrap { margin-left: var(--side-w); padding: 22px 28px 40px; }
body.layout-sidebar .page-title { font-size: 22px; color: var(--ink); }

/* --- Rail layout (Dark Rail): slim icon menu on the left --- */
body.layout-rail { --side-w: 84px; }
body.layout-rail .navbar-clinic {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--side-w);
    flex-direction: column; align-items: stretch; padding: 0; min-height: 0; z-index: 40;
    background: #131b24; border-right: 1px solid var(--border); border-bottom: 0;
    overflow-y: auto; scrollbar-width: none;
}
body.layout-rail .navbar-clinic::-webkit-scrollbar { display: none; }
body.layout-rail .nav-brand { display: flex; justify-content: center; padding: 14px 0 10px; text-decoration: none; }
body.layout-rail .nav-logo { background: var(--teal); color: #0f151c; border-radius: 12px; }
body.layout-rail .nav-brand-text { display: none; }
body.layout-rail .nav-links { flex-direction: column; flex-wrap: nowrap; gap: 4px; padding: 6px 8px 16px; }
body.layout-rail .nav-links a,
body.layout-rail .nav-links .nav-logout button {
    min-width: 0; width: 100%; padding: 9px 2px 7px; font-size: 10.5px; gap: 3px;
    border-radius: 12px; border-bottom: 0; text-align: center; color: var(--muted); opacity: 1;
}
body.layout-rail .nav-links a i,
body.layout-rail .nav-links .nav-logout button i { font-size: 19px; }
body.layout-rail .nav-links a:hover,
body.layout-rail .nav-links .nav-logout button:hover { background: var(--surface-2); color: var(--ink); }
body.layout-rail .nav-links a.active { background: var(--tint); color: var(--teal); border-bottom: 0; }
body.layout-rail .nav-logout { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 6px; }
body.layout-rail .topbar {
    margin-left: var(--side-w); background: var(--bg); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30; min-height: 60px;
}
body.layout-rail .topbar .brand-text strong { font-size: 17px; }
body.layout-rail .topbar .brand-text span { color: var(--muted); }
body.layout-rail .phone-pill { background: var(--surface-2); border: 1px solid var(--border); }
body.layout-rail .page-wrap { margin-left: var(--side-w); padding: 22px 26px 40px; }
body.layout-rail .panel, body.layout-rail .rp-card, body.layout-rail .ms-card { border: 1px solid var(--border); border-radius: 16px; }
body.layout-rail .stat-card { border-radius: 16px; }
body.layout-rail .page-title { font-size: 24px; font-weight: 700; color: var(--ink); }

/* Small screens: side menus slide in from a menu button. */
@media (max-width: 992px) {
    body.layout-sidebar .nav-toggle, body.layout-rail .nav-toggle {
        display: grid; place-items: center; width: 40px; height: 40px; margin-right: 10px;
        border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: 24px;
    }
    body.layout-sidebar .navbar-clinic, body.layout-rail .navbar-clinic { transform: translateX(-100%); transition: transform .2s; }
    body.nav-open .navbar-clinic { transform: none !important; }
    body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
    body.layout-sidebar .topbar, body.layout-rail .topbar,
    body.layout-sidebar .page-wrap, body.layout-rail .page-wrap { margin-left: 0; }
    body.layout-sidebar .topbar, body.layout-rail .topbar { justify-content: flex-start; }
    body.layout-sidebar .top-right, body.layout-rail .top-right { margin-left: auto; }
    body.layout-sidebar .phone-pill, body.layout-rail .phone-pill { display: none; }
}

@media print {
    body.layout-sidebar .page-wrap, body.layout-rail .page-wrap { margin-left: 0; }
}
