* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: #f2f4f7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: #1f2937;
}

/* ---------- Portrait mobile frame (role select + login) ---------- */
.phone {
  width: 390px;
  max-width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 32px 24px;
  justify-content: center;
}
#home h1 { text-align: center; font-size: 22px; margin: 0 0 28px; }

/* ---------- Brand header on the role-select screen ---------- */
.brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #1db39a);
  display: flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .25);
}
.brand-mark svg { width: 28px; height: 28px; }
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: .03em; color: #1f2937; line-height: 1.3; }
.brand-name span { display: block; font-size: 11px; font-weight: 600; color: #6b7280; letter-spacing: .08em; }

.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.buttons button, .buttons a.role-btn {
  padding: 26px 10px 20px; font-size: 15px; font-weight: 700; border: none;
  border-radius: 16px; cursor: pointer; color: #fff; text-align: center;
  text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform .15s ease, box-shadow .15s ease; box-shadow: 0 6px 16px rgba(0,0,0,.10);
}
.buttons button:hover, .buttons a.role-btn:hover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(0,0,0,.16); }
.role-btn-icon {
  width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: flex; align-items: center; justify-content: center;
}
.role-btn-icon svg { width: 24px; height: 24px; }
.role-btn-label { letter-spacing: .01em; }
.receptionist { background: linear-gradient(160deg, #3b82f6, #2563eb); }
.admin { background: linear-gradient(160deg, #8b5cf6, #6d28d9); }
.doctor { background: linear-gradient(160deg, #10b981, #047857); }
.lab { background: linear-gradient(160deg, #f59e0b, #d97706); }
.pharmacy { background: linear-gradient(160deg, #ec4899, #db2777); grid-column: 1 / -1; }

.login-screen { justify-content: flex-start; }
.back-btn {
  align-self: flex-start; background: none; border: none; color: #4b5563;
  font-size: 15px; cursor: pointer; padding: 6px 0 24px; text-decoration: none;
}
.role-badge {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 22px; font-weight: 700; margin: 0 auto 16px;
  box-shadow: 0 8px 18px rgba(0,0,0,.15);
}
.role-badge svg { width: 30px; height: 30px; }
.login-screen h2 { text-align: center; margin: 0 0 4px; font-size: 20px; }
.login-screen p.subtitle { text-align: center; margin: 0 0 28px; font-size: 13px; color: #9ca3af; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid #d1d5db;
  font-size: 15px; outline: none;
}
.field input:focus, .field select:focus { border-color: #3b82f6; }
.login-btn {
  margin-top: 8px; padding: 14px; border: none; border-radius: 10px; color: #fff;
  font-size: 16px; font-weight: 600; cursor: pointer; width: 100%;
}
.error-msg { color: #dc2626; font-size: 13px; text-align: center; margin-top: 14px; }

/* ---------- Desktop/tablet: role-select & login fill the whole screen -
   no boxed "card", just the branding and controls centered on a full-page
   background. Mobile view (below 700px) is untouched. ---------- */
body.auth-shell { min-height: 100vh; }
@media (min-width: 700px) {
  body.auth-shell {
    background: linear-gradient(160deg, #eef2ff 0%, #e6f5f2 100%);
  }
  .phone {
    width: 100%;
    max-width: 1000px;
    min-height: 100vh;
    margin: 0 auto;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }
  .screen { padding: 60px 40px; }

  /* Login form: keep it a sensible reading width, but no card box around it */
  .login-screen { max-width: 420px; width: 100%; margin: 0 auto; }

  /* Role-select buttons: one row across the screen instead of a 2-col
     grid that strands the 3rd button awkwardly on its own line */
  #home .buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 28px;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
  }
  #home .buttons a.role-btn { flex: 0 1 220px; padding: 34px 10px 26px; }
}

/* ---------- Wide admin/dashboard layout ---------- */
.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: #fff; padding: 14px 20px; border-radius: 12px; margin-bottom: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.topbar .who { font-size: 14px; color: #6b7280; }
.topbar .who b { color: #1f2937; }
.badge-role {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px;
  font-weight: 700; color: #fff; text-transform: uppercase; margin-left: 8px;
}
.badge-admin { background: #8b5cf6; }
.badge-receptionist { background: #3b82f6; }
.badge-doctor { background: #10b981; }
.badge-lab { background: #f59e0b; }
.badge-pharmacy { background: #ec4899; }

.card {
  background: #fff; border-radius: 14px; padding: 22px; margin-bottom: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.card h2, .card h3 { margin-top: 0; }

.grid-links { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-links a {
  display: block; padding: 22px; border-radius: 12px; background: #f9fafb;
  border: 1px solid #e5e7eb; text-decoration: none; color: #1f2937; font-weight: 600;
  transition: transform .15s ease;
}
.grid-links a:hover { transform: translateY(-2px); border-color: #8b5cf6; }
.grid-links a span.sub { display: block; font-weight: 400; font-size: 12px; color: #6b7280; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eef0f3; }
th { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #f9fafb; }

.btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; border: none;
  background: #8b5cf6; color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.danger { background: #dc2626; }
.btn.gray { background: #6b7280; }
.btn.green { background: #10b981; }
.btn.blue { background: #2563eb; }
.btn:hover { opacity: .9; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.form-row .field { flex: 1; min-width: 140px; margin-bottom: 0; }

.view-only-note {
  background: #fef3c7; color: #92400e; padding: 10px 14px; border-radius: 8px;
  font-size: 13px; margin-bottom: 16px;
}
.total-box {
  display: inline-block; background: #ecfdf5; color: #065f46; padding: 10px 16px;
  border-radius: 10px; font-weight: 700; margin-bottom: 16px;
}
.alert-success { background: #dcfce7; color: #166534; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ---------- Receptionist sidebar shell ---------- */
.rec-shell { display: flex; align-items: stretch; min-height: 100vh; }
.rec-sidebar {
  width: 240px; flex-shrink: 0; background: #1c2b45; color: #cbd5e1;
  display: flex; flex-direction: column; transition: margin-left .2s ease;
}
.rec-logo { text-align: center; padding: 28px 16px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.rec-logo .logo-circle {
  width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 10px;
  background: conic-gradient(from 180deg, #f59e0b, #ef4444, #8b5cf6, #3b82f6, #10b981, #f59e0b);
  box-shadow: 0 0 0 3px #1c2b45, 0 0 0 4px rgba(255,255,255,.14);
}
.rec-logo .rec-user-name { color: #fff; font-weight: 700; font-size: 15px; }
.rec-logo .rec-user-role { font-size: 11px; letter-spacing: .04em; color: #8b96b5; text-transform: uppercase; margin-top: 2px; }
.rec-logo .rec-hospital-name { color: #fff; font-weight: 700; font-size: 13px; line-height: 1.3; margin-bottom: 6px; }
.rec-logo .rec-user-spec { font-size: 10.5px; letter-spacing: .03em; color: #8b96b5; text-transform: uppercase; margin-top: 2px; }
.rec-nav { list-style: none; margin: 14px 0 0; padding: 0; flex: 1; }
.rec-nav li a {
  display: flex; align-items: center; gap: 12px; padding: 12px 22px; color: #aab4cc;
  text-decoration: none; font-size: 14px; border-left: 3px solid transparent;
}
.rec-nav li a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.rec-nav li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.rec-nav li a.active { background: rgba(255,255,255,.09); color: #fff; border-left-color: #10b981; font-weight: 600; }
.rec-sidebar-foot { padding: 16px 22px 22px; font-size: 11px; color: #64719a; border-top: 1px solid rgba(255,255,255,.08); }

.rec-main { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.rec-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.rec-hamburger {
  background: #10b981; border: none; width: 38px; height: 34px; border-radius: 8px;
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.rec-hamburger:hover { opacity: .9; }
.rec-hamburger svg { width: 18px; height: 18px; }

.opd-header-row { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.opd-register-btn {
  display: inline-flex; align-items: center; gap: 8px; background: #7c6fe8; color: #fff;
  padding: 12px 20px; border-radius: 10px; font-weight: 600; text-decoration: none;
  font-size: 14px; border: none; cursor: pointer; white-space: nowrap;
}
.opd-register-btn:hover { opacity: .92; }
.opd-register-btn svg { width: 16px; height: 16px; }
.opd-register-hint { color: #6b7280; font-size: 13px; }

.opd-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; cursor: pointer; user-select: none; }
.opd-card-head h3 { display: flex; align-items: center; gap: 8px; margin: 0; }
.opd-card-head h3 svg { width: 18px; height: 18px; color: #7c6fe8; }
.opd-card-head .chev { width: 18px; height: 18px; color: #9ca3af; transition: transform .2s ease; }
.opd-card-head.collapsed .chev { transform: rotate(-90deg); }
.opd-card-body { transition: none; }
.opd-card-body.hidden { display: none; }

.field.readonly-field input { background: #f3f4f6; color: #6b7280; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }
.icon-btn {
  width: 42px; flex-shrink: 0; border-radius: 10px; border: 1px solid #d1d5db; background: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center; color: #4b5563;
}
.icon-btn:hover { background: #f9fafb; }
.icon-btn svg { width: 16px; height: 16px; }
.field-hint { font-size: 11px; color: #9ca3af; margin-top: 4px; }
.contact-search-wrap { position: relative; }
.contact-results {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; margin-top: 4px; box-shadow: 0 8px 20px rgba(0,0,0,.08); z-index: 20;
  max-height: 220px; overflow: auto; display: none;
}
.contact-results div { padding: 10px 14px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f1f2f4; }
.contact-results div:last-child { border-bottom: none; }
.contact-results div:hover { background: #f9fafb; }

.placeholder-card { text-align: center; padding: 60px 20px; color: #6b7280; }
.placeholder-card .ph-icon { width: 56px; height: 56px; margin: 0 auto 16px; color: #c7cddb; }
.placeholder-card .ph-icon svg { width: 100%; height: 100%; }
.placeholder-card h3 { color: #374151; margin-bottom: 6px; }

@media (max-width: 860px) {
  .rec-sidebar { position: fixed; z-index: 50; height: 100vh; margin-left: -240px; }
  /* A plain fixed-position overlay is far cheaper for the browser to paint
     than a huge box-shadow spread (that old trick made resizing/dragging
     the window feel like it hangs, since the browser had to repaint a
     2000px shadow on every layout change). This ::after just dims the
     rest of the screen next to the open sidebar. */
  .rec-sidebar.mobile-open { margin-left: 0; }
  .rec-sidebar.mobile-open::after {
    content: '';
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 240px;
    background: rgba(0,0,0,.35);
    z-index: -1;
  }
  .rec-main { padding: 18px; }
}

/* ---------- Test Registration (lab tests bucket) ---------- */
.lab-no-box {
  background: #1c2b45; color: #34d399; border-radius: 8px; padding: 10px 14px;
  font-family: 'Courier New', monospace; font-weight: 800; font-size: 18px;
  letter-spacing: 1px; display: flex; align-items: center; gap: 8px; width: fit-content;
}
.lab-no-box .lab-no-tag { font-size: 10px; font-weight: 700; color: #93c5fd; letter-spacing: .04em; }
.test-entry-row { align-items: flex-end; }
.test-entry-row .field { min-width: 160px; }
.test-entry-row .btn-col { display: flex; gap: 8px; align-items: center; }

.test-bucket-layout { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 18px; }
.test-bucket-col { flex: 2; min-width: 300px; }
.test-calc-col { flex: 1; min-width: 240px; }
.test-bucket-col h4, .test-calc-col h4 {
  margin: 0 0 12px; font-size: 14px; display: flex; align-items: center; gap: 8px; color: #374151;
}
.test-bucket-col h4 svg, .test-calc-col h4 svg { width: 16px; height: 16px; color: #7c6fe8; }

.calc-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 12px; padding: 18px; }
.calc-total-tests { font-size: 22px; font-weight: 800; color: #1f2937; margin-bottom: 16px; }
.calc-total-tests span { color: #6b7280; font-size: 13px; font-weight: 600; display: block; margin-bottom: 2px; }
.calc-box .field { margin-bottom: 4px; }
.calc-box .btn.green { width: 100%; margin-top: 16px; text-align: center; padding: 13px; font-size: 15px; }

.reprint-row { display: flex; gap: 12px; align-items: flex-end; margin-top: 24px; padding-top: 18px; border-top: 1px solid #eef0f3; flex-wrap: wrap; }
.reprint-row .field { flex: 1; min-width: 180px; margin-bottom: 0; }

/* ---------- OT Registration (reuses the same bucket layout, orange accent) ---------- */
.ot-no-box {
  background: #1c2b45; color: #fb923c; border-radius: 8px; padding: 10px 14px;
  font-family: 'Courier New', monospace; font-weight: 800; font-size: 18px;
  letter-spacing: 1px; display: flex; align-items: center; gap: 8px; width: fit-content;
}
.ot-no-box .ot-no-tag { font-size: 10px; font-weight: 700; color: #93c5fd; letter-spacing: .04em; }
.calc-box .refund-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: #6b7280; margin-top: 10px; padding-top: 10px; border-top: 1px dashed #e5e7eb; }
.calc-box .refund-row b { color: #dc2626; font-size: 14px; }
.ot-charge-select optgroup { font-weight: 700; color: #7c6fe8; }

/* MR number box on printable slip */
.mr-label { font-weight: 700; font-size: 13px; color: #6b7280; margin-bottom: 6px; }
.mr-number-box {
  border: 2px solid #1f2937; border-radius: 6px; padding: 10px 16px; display: inline-block;
  font-size: 30px; font-weight: 800; letter-spacing: 4px; color: #1f2937; font-family: 'Courier New', monospace;
}

/* ---------- Lab Test Result Entry (lab/test_result_management.php) ---------- */
.test-panel { margin-bottom: 18px; border: 1px solid #e5e7eb; border-radius: 10px; overflow: hidden; }
.test-panel-head {
  background: linear-gradient(90deg, #0f766e, #14b8a6); color: #fff; padding: 10px 16px;
  font-weight: 700; font-size: 14px; letter-spacing: .2px;
}
.test-panel table { margin: 0; }
.test-panel table th { background: #f8fafc; }
.test-panel table td { vertical-align: middle; }

/* ---------- Admin dashboard (sidebar + stat cards + quick actions) ---------- */
.admin-logo { text-align: center; padding: 22px 16px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.admin-logo .admin-logo-badge {
  width: 46px; height: 46px; border-radius: 12px; margin: 0 auto 10px; background: #10b981;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .5px;
}
.admin-logo .rec-user-name { color: #fff; font-weight: 700; font-size: 14px; }
.admin-logo .rec-user-role { font-size: 11px; letter-spacing: .04em; color: #8b96b5; text-transform: uppercase; margin-top: 2px; }

.stat-card { background: #fff; border-radius: 12px; padding: 0; margin-bottom: 18px; box-shadow: 0 2px 10px rgba(0,0,0,.05); overflow: hidden; }
.stat-card .stat-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #eef0f3; }
.stat-card .stat-head span.stat-title { font-size: 16px; font-weight: 600; color: #374151; }
.stat-card .stat-total-pill { display: inline-block; padding: 4px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; }
.stat-card .stat-body { padding: 18px 20px 20px; }
.stat-card .stat-number { font-size: 34px; font-weight: 800; color: #1f2937; line-height: 1; }
.stat-card .stat-sub { color: #9ca3af; font-size: 13px; margin-top: 6px; }

.quick-actions-grid { display: flex; flex-direction: column; gap: 12px; }
.qa-btn {
  display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-radius: 10px; text-decoration: none;
  font-weight: 700; font-size: 15px; color: #fff; border: none; cursor: pointer;
}
.qa-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.qa-btn.qa-green  { background: #10b981; }
.qa-btn.qa-teal   { background: #14b8a6; }
.qa-btn.qa-blue   { background: #2563eb; }
.qa-btn.qa-purple { background: #8b5cf6; }
.qa-btn.qa-amber  { background: #f59e0b; }
.qa-btn.qa-gray   { background: #64748b; }
.qa-btn.qa-outline { background: #fff; color: #374151; border: 1px solid #d1d5db; }

.admin-footnote { text-align: center; font-size: 12px; color: #9ca3af; margin-top: 24px; line-height: 1.7; }

/* =====================================================================
   MOBILE RESPONSIVENESS -- applies site-wide (login, admin, receptionist,
   doctor, lab) since every page shares this one stylesheet. Kept as its
   own section at the end so it always wins and is easy to find/extend.
   ===================================================================== */

/* Any plain data table (patients, staff, sales, test/OT reports, etc.)
   becomes horizontally scrollable instead of squeezing/breaking the page.
   Scoped to .card/.wrap tables only -- the few admin pages that already
   wrap their own table in .tablewrap (Departments, Specializations, Lab
   Tests) handle their own scrolling and are left alone here. */
@media (max-width: 760px) {
  .card table, .wrap table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card table tr, .wrap table tr { white-space: nowrap; }
}

@media (max-width: 700px) {
  .wrap { padding: 14px 12px 40px; }
  .card { padding: 16px; border-radius: 12px; }
  .topbar { padding: 12px 14px; }
  .topbar .who { font-size: 13px; }

  /* Multi-field rows stack into one clean column per field on phones
     instead of trying to fit 2-3 narrow fields side by side. */
  .form-row .field,
  .test-entry-row .field,
  .reprint-row .field {
    min-width: 100%;
  }
  .test-entry-row .btn-col { width: 100%; justify-content: flex-start; }

  .grid-links { grid-template-columns: 1fr; }

  .test-bucket-layout { flex-direction: column; }
  .test-bucket-col, .test-calc-col { min-width: 100%; }

  .opd-header-row { flex-direction: column; align-items: stretch; }
  .opd-register-btn { justify-content: center; }

  h1 { font-size: 20px; }
  .card h2, .card h3 { font-size: 16px; }
}

@media (max-width: 420px) {
  .buttons { grid-template-columns: 1fr; }
  .phone { width: 100%; }
  .screen { padding: 26px 18px; }
  .lab-no-box, .ot-no-box { font-size: 15px; padding: 8px 12px; }
  .mr-number-box { font-size: 24px; letter-spacing: 2px; padding: 8px 12px; }
}

/* Admin/Lab/Receptionist sidebar shell: a touch more breathing room once
   it's a full-width mobile drawer rather than a fixed side column. */
@media (max-width: 860px) {
  .rec-topbar { gap: 10px; }
  .rec-sidebar { width: 240px; }
}

/* ---------- Searchable "type to search" dropdown (Test / OT Charge) ---------- */
.ss-wrap { position: relative; }
.ss-results {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; margin-top: 4px; box-shadow: 0 10px 24px rgba(0,0,0,.1); z-index: 30;
  max-height: 260px; overflow: auto; display: none;
}
.ss-results .ss-item {
  padding: 10px 14px; font-size: 13.5px; cursor: pointer; border-bottom: 1px solid #f1f2f4;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.ss-results .ss-item:last-child { border-bottom: none; }
.ss-results .ss-item .ss-fee { color: #6b7280; font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.ss-results .ss-item:hover, .ss-results .ss-item.active { background: #f3f4f6; }
.ss-results .ss-empty { padding: 14px; font-size: 13px; color: #9ca3af; text-align: center; }

/* Utility used by report/slip pages' Print buttons and topbars (was
   referenced already in Test Reports etc. but never actually defined). */
@media print {
  .no-print { display: none !important; }
}
