:root{
  --mh-blue:#0d3b8c;
  --mh-blue-dark:#0a2e6e;
  --mh-blue-light:#e8f0ff;
  --mh-red:#d21f1f;
  --mh-red-light:#fdeaea;
  --mh-neutral:#4a5568;
  --mh-neutral-light:#eef1f4;
  --mh-bg:#f5f7fb;
  --mh-white:#ffffff;
  --mh-border:#d7dfec;
  --mh-text:#1c2536;
  --mh-muted:#6b7686;
  --mh-green:#1a9e5c;
  --mh-yellow:#d9a51c;
  --radius:8px;
  --shadow:0 1px 3px rgba(15,35,80,.08);
}

*{box-sizing:border-box;}
body{
  background:var(--mh-bg);
  color:var(--mh-text);
  font-family:"Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,Arial,sans-serif;
}

/* ---------- Top bar / brand ---------- */
.mh-topbar{
  background:var(--mh-white);
  border-bottom:3px solid var(--mh-blue);
  padding:.6rem 1.2rem;
  display:flex;
  align-items:center;
  justify-content:space-between;
  box-shadow:var(--shadow);
}
.mh-brand{display:flex;align-items:center;gap:.6rem;}
.mh-brand img{height:42px;max-width:190px;object-fit:contain;}
.mh-brand-text{line-height:1.1;}
.mh-brand-text strong{color:var(--mh-red);font-size:1.05rem;letter-spacing:.3px;}
.mh-brand-text span{display:block;font-size:.72rem;color:var(--mh-muted);}
.mh-role-badge{
  font-size:.7rem;
  padding:.15rem .55rem;
  border-radius:20px;
  background:var(--mh-blue-light);
  color:var(--mh-blue);
  font-weight:600;
  margin-left:.5rem;
}
.mh-site-footer{
  display:flex;
  justify-content:center;
  align-items:center;
  flex-wrap:wrap;
  gap:.35rem 1rem;
  padding:.75rem 1rem;
  color:var(--mh-muted);
  font-size:.78rem;
  text-align:center;
}
.mh-site-footer a{color:#168c4b;text-decoration:none;font-weight:600;}
.mh-site-footer a:hover{text-decoration:underline;}
.mh-whatsapp-icon{display:inline-flex;align-items:center;justify-content:center;width:1.15rem;height:1.15rem;border-radius:50%;background:#25d366;color:#fff;font-size:.72rem;vertical-align:-1px;}

/* ---------- Sidebar ---------- */
.mh-sidebar{
  background:var(--mh-blue-dark);
  min-height:100vh;
  padding-top:1rem;
}
.mh-sidebar a{
  display:flex;align-items:center;gap:.6rem;
  color:#cfe0ff;
  padding:.65rem 1.1rem;
  text-decoration:none;
  font-size:.92rem;
  border-left:3px solid transparent;
}
.mh-sidebar a:hover,.mh-sidebar a.active{
  background:rgba(255,255,255,.08);
  color:#fff;
  border-left-color:var(--mh-red);
}
.mh-sidebar .mh-sidebar-toggle{display:none;}

@media (max-width:767px){
  .mh-sidebar{min-height:auto;padding-top:0;}
  .mh-sidebar-body{display:none;}
  .mh-sidebar-body.open{display:block;}
  .mh-sidebar .mh-sidebar-toggle{
    display:flex;justify-content:space-between;align-items:center;
    color:#fff;padding:.7rem 1.1rem;cursor:pointer;
  }
}

/* ---------- Cards / sections ---------- */
.mh-card{
  background:var(--mh-white);
  border:1px solid var(--mh-border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  margin-bottom:1rem;
}
.mh-card-header{
  padding:.6rem 1rem;
  font-weight:600;
  font-size:.92rem;
  border-bottom:1px solid var(--mh-border);
  display:flex;align-items:center;justify-content:between;
  border-radius:var(--radius) var(--radius) 0 0;
}
.mh-card-body{padding:1rem;}

.mh-card-header.blue{background:var(--mh-blue);color:#fff;}
.mh-card-header.red{background:var(--mh-red);color:#fff;}
.mh-card-header.neutral{background:var(--mh-neutral);color:#fff;}
.mh-card-header.plain{background:var(--mh-blue-light);color:var(--mh-blue-dark);}

.mh-stat{
  background:var(--mh-white);
  border:1px solid var(--mh-border);
  border-radius:var(--radius);
  padding:.9rem 1rem;
  box-shadow:var(--shadow);
}
.mh-stat .num{font-size:1.6rem;font-weight:700;color:var(--mh-blue);}
.mh-stat .lbl{font-size:.78rem;color:var(--mh-muted);}

/* ---------- Buttons ---------- */
.btn-mh-blue{background:var(--mh-blue);border-color:var(--mh-blue);color:#fff;}
.btn-mh-blue:hover{background:var(--mh-blue-dark);color:#fff;}
.btn-mh-red{background:var(--mh-red);border-color:var(--mh-red);color:#fff;}
.btn-mh-red:hover{background:#a91616;color:#fff;}
.btn-mh-outline{background:#fff;border:1px solid var(--mh-blue);color:var(--mh-blue);}
.btn-mh-outline:hover{background:var(--mh-blue-light);}

/* ---------- Status pills ---------- */
.pill{font-size:.72rem;font-weight:600;padding:.2rem .6rem;border-radius:20px;display:inline-block;}
.pill-waiting{background:#fff3d6;color:#946200;}
.pill-progress{background:#dbeafe;color:#0d3b8c;}
.pill-completed{background:#dcf7e3;color:#157a3d;}
.pill-cancelled{background:#fde2e2;color:#a91616;}
.pill-pending{background:#fff3d6;color:#946200;}
.pill-admitted{background:#dbeafe;color:#0d3b8c;}
.pill-discharged{background:#fde2e2;color:#a91616;}

/* usage status */
.usage-green{color:var(--mh-green);font-weight:700;}
.usage-yellow{color:var(--mh-yellow);font-weight:700;}
.usage-red{color:var(--mh-red);font-weight:700;}

/* ---------- Medicine autocomplete ---------- */
.mh-autocomplete{position:relative;}
.mh-suggestions{
  position:absolute;z-index:50;background:#fff;
  border:1px solid var(--mh-border);border-radius:6px;
  width:100%;max-height:220px;overflow-y:auto;
  box-shadow:0 6px 16px rgba(15,35,80,.15);
}
.mh-suggestions .item{
  padding:.5rem .7rem;cursor:pointer;font-size:.87rem;
  border-bottom:1px solid #f0f2f6;
}
.mh-suggestions .item:hover{background:var(--mh-blue-light);}
.mh-suggestions .item small{display:block;color:var(--mh-muted);}
.mh-suggestions .empty{padding:.5rem .7rem;color:var(--mh-muted);font-size:.85rem;}

/* recently used chips */
.chip{
  display:inline-block;background:var(--mh-blue-light);color:var(--mh-blue-dark);
  font-size:.78rem;padding:.25rem .6rem;border-radius:20px;margin:.15rem;
  cursor:pointer;border:1px solid transparent;
}
.chip:hover{border-color:var(--mh-blue);}

/* ---------- Prescription table ---------- */
table.mh-rx-table{width:100%;font-size:.9rem;}
table.mh-rx-table th{background:var(--mh-blue);color:#fff;font-size:.8rem;padding:.5rem;}
table.mh-rx-table td{padding:.45rem .5rem;vertical-align:middle;border-bottom:1px solid var(--mh-border);}
table.mh-rx-table .group-row td{background:var(--mh-blue-light);font-weight:700;color:var(--mh-blue-dark);font-size:.8rem;}

/* ---------- A4 print document ---------- */
.a4-page{
  width:100%;min-height:297mm;max-width:210mm;background:#fff;margin:0 auto 12px;
  padding:10mm 12mm;box-shadow:0 0 8px rgba(0,0,0,.12);
  font-size:12px;color:#111;
  box-sizing:border-box;
  page-break-after:avoid;
  page-break-inside:avoid;
}
.a4-header{display:flex;justify-content:space-between;align-items:flex-start;border-bottom:2px solid var(--mh-blue);padding-bottom:6px;margin-bottom:8px;}
.a4-header .mh-name{color:var(--mh-red);font-weight:800;font-size:26px;line-height:1;}
.a4-header .mh-name small{display:block;color:var(--mh-red);font-size:20px;font-weight:800;}
.a4-header img.emblem{width:150px;height:auto;max-height:70px;object-fit:contain;object-position:right top;}
.a4-meta{display:flex;flex-wrap:wrap;gap:0 18px;font-size:11.5px;border:1px solid var(--mh-border);padding:5px 8px;margin-bottom:6px;}
.a4-meta b{color:var(--mh-blue);}
.a4-row{font-size:12px;padding:2px 0;}
.a4-row b{color:var(--mh-blue);}
.a4-section-title{background:var(--mh-blue);color:#fff;font-size:11.5px;font-weight:700;padding:3px 8px;margin:8px 0 4px;}
.a4-section-title.red{background:var(--mh-red);}
.a4-section-title.neutral{background:var(--mh-neutral);}
.a4-box{border:1px solid var(--mh-border);padding:6px 8px;margin-bottom:6px;}
.a4-box.blue{border-color:var(--mh-blue);}
.a4-box.red{border-color:var(--mh-red);}
table.a4-table{width:100%;border-collapse:collapse;font-size:11.5px;margin-bottom:6px;}
table.a4-table th{background:var(--mh-blue);color:#fff;padding:3px 5px;text-align:left;}
table.a4-table td{padding:3px 5px;border-bottom:1px solid #e3e8f0;}
table.a4-table .grp td{background:var(--mh-blue-light);font-weight:700;}
.a4-footer{border-top:1px solid var(--mh-border);margin-top:8px;padding-top:5px;font-size:10.5px;color:var(--mh-muted);display:flex;justify-content:space-between;}
.a4-footer .mh-powered{font-size:8.5px;white-space:nowrap;}
.a4-sign{display:flex;justify-content:space-between;margin-top:18px;text-align:center;font-size:11px;}
.a4-referral{font-size:11px;padding:10mm 12mm;}
.a4-referral-image{font-family:Arial,sans-serif;color:#111;padding:9mm 12mm 7mm;}
.a4-referral-brand{text-align:center;height:25mm;border-bottom:1px solid #333;margin-bottom:0;}
.a4-referral-brand img{width:178mm;height:23mm;object-fit:contain;object-position:center bottom;}
.a4-referral-title{text-align:center;font-weight:700;border:1px solid #555;padding:4px;margin-bottom:0;}
.a4-referral-title span{font-weight:400;}
table.a4-referral-fields{width:100%;border-collapse:collapse;font-size:10.5px;table-layout:fixed;}
table.a4-referral-fields th,table.a4-referral-fields td{border:1px solid #777;padding:4px;vertical-align:top;}
table.a4-referral-fields th{font-weight:600;text-align:left;width:16%;}
table.a4-referral-fields td{width:34%;height:24px;}
.a4-referral-block{border:1px solid #777;border-top:0;padding:4px 5px;min-height:25px;}
.a4-referral-block b{display:block;font-weight:600;}
.a4-referral-block div{min-height:15px;white-space:pre-wrap;}
.a4-referral-tall{min-height:22mm;}
.a4-referral-tall div{min-height:16mm;}
.a4-referral-diagnosis th{width:16%;}
.a4-referral-diagnosis td{height:9mm;}
.a4-referral-status th{text-align:center;background:#fff;}
.a4-referral-status td{height:15mm;font-size:9.5px;vertical-align:middle;}
.referral-check{font-size:14px;line-height:1;vertical-align:-1px;}
.a4-referral-table-title{text-align:center;font-weight:700;border:1px solid #777;border-top:0;padding:3px;}
table.a4-referral-medicines{table-layout:fixed;font-size:9px;}
table.a4-referral-medicines th,table.a4-referral-medicines td{border:1px solid #777;padding:4px 3px;word-wrap:break-word;}
table.a4-referral-medicines th{text-align:center;}
table.a4-referral-medicines td{height:24px;}
.a4-referral-notes{min-height:22mm;}
.a4-referral-notes div{min-height:16mm;}
.a4-referral-line{min-height:38px;}
.a4-referral-sign{margin-top:8px;}
.a4-referral-sign td{height:8mm;}

.a4-pdf-export .a4-page{min-height:0;margin:0;page-break-inside:auto;break-inside:auto;}
.a4-pdf-export .a4-page+.a4-page{page-break-before:always;break-before:page;}

/* Tell the browser not to add its own page margins on top of the
   already-297mm-tall .a4-page — that extra browser margin is what was
   pushing a single record onto a mostly-empty second printed page. */
@page{ size:A4; margin:0; }

@media print{
  html, body{ margin:0 !important; padding:0 !important; height:auto !important; }
  .no-print{ display:none !important; }
  /* Printing always goes through a dedicated #printRoot node that is a
     direct child of <body> (see print-preview.html + js/print.js). Hiding
     every OTHER top-level element with display:none (not visibility, which
     still reserves layout space) is what stops the leftover app chrome
     from pushing the printout onto a second, mostly-empty page. */
  body > *:not(#printRoot){ display:none !important; }
  #printRoot{ display:block !important; margin:0 !important; padding:0 !important; }
  .a4-page{ width:210mm; max-width:210mm; box-shadow:none; margin:0 auto; min-height:0; }
  .a4-referral{break-before:page;}
}

.no-print{}
