:root {
  --brand: #0e7c74;
  --brand-600: #0b6660;
  --brand-50: #e8f5f3;
  --side: #0f2a2f;
  --ink: #14232b;
  --muted: #5b6b73;
  --line: #e3e8ea;
  --bg: #f4f7f8;
  --card: #ffffff;
  --danger: #b42318;
  --ok: #1e7a46;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
.muted { color: var(--muted); }

/* Layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: #cfe3e1; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 38px; height: 38px; border-radius: 9px; object-fit: cover; background: #fff; }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.brand-name { font-weight: 650; color: #fff; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: #8fb0ad; }
.nav { padding: 12px 10px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #cfe3e1; text-decoration: none; font-size: 14px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .dot { width: 26px; height: 26px; border-radius: 7px; background: rgba(255,255,255,.08); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.nav a.active .dot { background: rgba(255,255,255,.22); }
.nav .soon { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #6f918e; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 60px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1.3; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; font-weight: 700; }
.content { padding: 24px; max-width: 1200px; width: 100%; }
.menu-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; font-size: 18px; cursor: pointer; }
.backdrop { display: none; }

/* Building blocks */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mt { margin-top: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 2px; }
.stat .hint { font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-block { width: 100%; }
.sidebar .btn-ghost { color: #cfe3e1; border-color: rgba(255,255,255,.15); }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.06); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cdd6d9; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,116,.15); }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--danger); font-size: 13px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fdecea; color: #8a1f15; }
.alert-success { background: #e6f4ea; color: #1e5631; }
.alert-info { background: var(--brand-50); color: var(--brand-600); }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-50); color: var(--brand-600); }
.chip-off { background: #eef1f2; color: #7a878d; }

/* Login */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: linear-gradient(160deg, var(--side), var(--brand)); color: #e6f2f1; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h2 { font-size: 30px; line-height: 1.2; margin: 0 0 12px; color: #fff; max-width: 420px; }
.auth-side p { max-width: 420px; color: #cde4e1; }
.auth-form { display: grid; place-items: center; padding: 32px; background: #fff; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin: 0 0 4px; font-size: 26px; }
.auth-card .muted { margin: 0 0 24px; }

/* Phones and tablets */
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s ease; z-index: 30; }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .user-chip .who { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

/* ===== Top navbar layout ===== */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topnav { background: var(--side); color: #cfe3e1; position: sticky; top: 0; z-index: 10; }
.topnav-row { display: flex; align-items: center; gap: 10px; padding: 10px 24px; }
.topnav .brand { padding: 0; border: 0; }
.topnav .user-chip { color: #fff; }
.topnav .user-chip .muted { color: #8fb0ad; }
.topnav .avatar { background: var(--brand-50); color: var(--brand-600); }
.topnav .btn-ghost { color: #cfe3e1; border-color: rgba(255,255,255,.18); padding: 6px 12px; }
.topnav .btn-ghost:hover { background: rgba(255,255,255,.08); }
.menu-row { display: flex; gap: 4px; padding: 6px 18px; background: #0b3a3c; overflow-x: auto; scrollbar-width: none; }
.menu-row::-webkit-scrollbar { display: none; }
.menu-row a { white-space: nowrap; color: #cfe3e1; text-decoration: none; font-size: 14px; padding: 7px 12px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; }
.menu-row a:hover { background: rgba(255,255,255,.07); color: #fff; }
.menu-row a.active { background: var(--brand); color: #fff; }
.menu-row .soon { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #6f918e; }
.shell .content { margin: 0 auto; }
@media (max-width: 820px) {
  .topnav-row { padding: 10px 16px; }
  .menu-row { padding: 6px 10px; }
  .topnav .who { display: none; }
}

/* ===== Settings and forms ===== */
.link-card { text-decoration: none; color: inherit; display: block; transition: border-color .15s; }
.link-card:hover { border-color: var(--brand); }
.link-card p { margin: 0; }
.link-card.disabled { opacity: .6; }
.form-card { max-width: 680px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row:last-of-type { border-bottom: 0; }
.switch-row small { display: block; font-size: 12px; }
.switch-row input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 44px; height: 24px; border-radius: 999px; background: #cdd6d9; position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.switch-row input[type=checkbox]::before { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch-row input[type=checkbox]:checked { background: var(--brand); }
.switch-row input[type=checkbox]:checked::before { transform: translateX(20px); }
input[type=file] { font: inherit; }

/* ===== Staff accounts ===== */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.check-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-weight: 400; cursor: pointer; margin: 0; }
.check-chip:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.check-chip input { accent-color: var(--brand); width: 16px; height: 16px; margin: 0; }
.row-actions a { margin-left: 12px; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ===== Patients ===== */
.req { color: var(--danger); }
.form-section { margin-bottom: 16px; }
.form-section .grid { gap: 0 16px; }
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--brand-50); }
.info { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
.info dt { color: var(--muted); font-size: 13px; }
.info dd { margin: 0; }
.alert ul { margin: 8px 0 0; padding-left: 18px; }

/* ===== Error highlighting ===== */
.field:has(.errorlist) input, .field:has(.errorlist) select, .field:has(.errorlist) textarea { border-color: var(--danger); background: #fff8f7; }
.field:has(.errorlist) label { color: var(--danger); }
input:user-invalid { border-color: var(--danger); }

/* ===== Card frames (style A) ===== */
.card {
  --accent: #0e7c74; --accent-ring: #9fd0ca; --accent-wash: #e2f1ef;
  border: 2px solid var(--accent-ring);
  border-top: 6px solid var(--accent);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--accent-wash) 0, var(--card) 70px);
}
.grid-4 > .card:nth-child(4n+1) { --accent: #0e7c74; --accent-ring: #9fd0ca; --accent-wash: #e2f1ef; }
.grid-4 > .card:nth-child(4n+2) { --accent: #2563eb; --accent-ring: #a8c1f7; --accent-wash: #e4ecfc; }
.grid-4 > .card:nth-child(4n+3) { --accent: #d97706; --accent-ring: #f0c98a; --accent-wash: #fbf0dc; }
.grid-4 > .card:nth-child(4n+4) { --accent: #c2410c; --accent-ring: #e8a88e; --accent-wash: #f9e5dd; }
.stat .value { color: var(--accent); }
.link-card:hover { border-color: var(--accent); }

/* ===== Visits and queue ===== */
.btn-lg { padding: 12px 22px; font-size: 16px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.chip-on { background: var(--brand); color: #fff; }
.filter-chips { margin-bottom: 16px; }
.filter-chips a { text-decoration: none; }
.prio-1 { background: #fdecea; color: #8a1f15; }
.prio-2 { background: #fff4e0; color: #7a4a00; }
.prio-3 { background: #eef1f2; color: #5b6b73; }
.token { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand-600); white-space: nowrap; }
.patient-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.patient-row:last-child { border-bottom: 0; }
.patient-row .token { font-size: 20px; min-width: 90px; }
.grow { flex: 1; min-width: 200px; }

/* Waiting-area TV screen */
body.screen { background: var(--side); color: #fff; min-height: 100vh; }
.screen-head { display: flex; align-items: center; gap: 16px; padding: 20px 32px; border-bottom: 1px solid rgba(255,255,255,.1); }
.screen-head img { width: 56px; height: 56px; border-radius: 12px; background: #fff; object-fit: cover; }
.screen-title { font-size: 28px; font-weight: 700; }
.screen-sub { color: #8fb0ad; }
.screen-body { display: grid; grid-template-columns: 2fr 1fr; gap: 32px; padding: 32px; }
.screen-body h2 { font-size: 16px; text-transform: uppercase; letter-spacing: .08em; color: #8fb0ad; margin: 0 0 16px; }
.serving { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.serve-card { background: var(--brand); border-radius: 16px; padding: 24px; }
.serve-token { font-size: 56px; font-weight: 800; line-height: 1; }
.serve-where { margin-top: 8px; font-size: 18px; color: #e8f5f3; }
.next-list { list-style: none; padding: 0; margin: 0; }
.next-list li { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,.1); font-size: 24px; font-weight: 600; }
.screen-empty { color: #8fb0ad; font-size: 20px; }
@media (max-width: 820px) { .screen-body { grid-template-columns: 1fr; padding: 16px; } .serve-token { font-size: 40px; } }

/* ===== Waiting screen sound ===== */
.sound-btn { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 8px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.sound-btn.on { background: var(--brand); border-color: var(--brand); }
.screen-conn { color: #fbbf24; margin-right: 12px; }
.serve-card.fresh { animation: serve-pulse 1.2s ease-in-out 4; }
@keyframes serve-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } 50% { box-shadow: 0 0 0 10px rgba(255,255,255,.35); } }

/* ===== Consultation ===== */
.consult-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .consult-layout { grid-template-columns: 1fr; } }
textarea { min-height: 60px; resize: vertical; }
.vitals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.bmi-readout { font-weight: 600; color: var(--brand-600); }
.field.flag-high input { border-color: var(--danger); background: #fff1f0; color: var(--danger); font-weight: 700; }
.field.flag-high label::after { content: " \2191 high"; color: var(--danger); }
.field.flag-low input { border-color: #d97706; background: #fff7e8; color: #b45309; font-weight: 700; }
.field.flag-low label::after { content: " \2193 low"; color: #b45309; }
.is-invalid { border-color: var(--danger) !important; background: #fff8f7 !important; }
.save-bar { flex-wrap: wrap; position: sticky; bottom: 0; z-index: 4; display: flex; gap: 10px; align-items: center; padding: 12px 16px; margin-top: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 -2px 8px rgba(16,24,40,.06); }
.save-status { margin-right: auto; color: var(--muted); font-size: 13px; }
.save-status.error { color: var(--danger); font-weight: 600; }
.prev-visit { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.prev-visit:last-child { border-bottom: 0; }
.sub { font-size: 13px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.flag-chip-high { background: #fdecea; color: #8a1f15; }
.flag-chip-low { background: #fff4e0; color: #7a4a00; }

/* ===== Laboratory ===== */
.test-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.test-grid .check-chip { align-items: flex-start; }
.row-buttons { white-space: nowrap; }
.row-buttons form { display: inline; margin-left: 6px; }
.result-table input, .result-table select { max-width: 220px; }
.param-table input, .param-table select { min-width: 90px; padding: 6px 8px; font-size: 13px; }
.param-table td { vertical-align: top; padding: 6px 4px; }
.input-res-low, .input-res-high { border-color: #d97706 !important; background: #fff7e8 !important; color: #b45309; font-weight: 700; }
.input-res-critical-low, .input-res-critical-high { border-color: var(--danger) !important; background: #fdecea !important; color: var(--danger); font-weight: 700; }
.input-res-abnormal { border-color: var(--danger) !important; color: var(--danger); font-weight: 700; }
.res-low, .res-high { color: #b45309; }
.res-abnormal { color: var(--danger); }
.res-critical-low, .res-critical-high { color: #fff; background: var(--danger); padding: 1px 6px; border-radius: 4px; }
.res-chip-low, .res-chip-high { background: #fff4e0; color: #7a4a00; }
.res-chip-abnormal { background: #fdecea; color: #8a1f15; }
.res-chip-critical-low, .res-chip-critical-high { background: var(--danger); color: #fff; }
aside .card + .card { margin-top: 16px; }
.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.toast { background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--brand); border-radius: 10px; box-shadow: 0 8px 24px rgba(16,24,40,.18); padding: 14px 16px; }
.toast.toast-alert { border-left-color: var(--danger); }
.toast h3 { margin: 0 0 4px; font-size: 15px; }
.toast-flag { color: var(--danger); font-weight: 600; margin-top: 4px; }
.toast .actions { display: flex; gap: 8px; margin-top: 10px; }
@media print { .topnav, .no-print, .toast-stack, .btn { display: none !important; } .content { padding: 0; } }

/* ===== Name in the top bar ===== */
.topnav .user-chip .who { display: block; text-align: right; line-height: 1.25; }
.who-full { font-size: 14px; }
.who-short { display: none; font-size: 14px; }
.who-roles { display: block; max-width: 260px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 820px) {
  .topnav .user-chip .who { display: block; }
  .who-full, .who-roles { display: none; }
  .who-short { display: inline; }
}

/* ===== Roles visible on small screens too ===== */
@media (max-width: 820px) {
  .who-roles { display: block; max-width: 140px; font-size: 11px; }
}

/* ===== Full name on small screens too ===== */
@media (max-width: 820px) {
  .who-full { display: inline; font-size: 13px; }
  .who-short { display: none; }
  .topnav .user-chip .who { max-width: 170px; white-space: normal; }
  .topnav .brand-sub { display: none; }
}

/* ===== Sliding menu row ===== */
.menu-wrap { position: relative; background: #0b3a3c; }
.menu-arrow { display: none; position: absolute; top: 0; bottom: 0; width: 44px; border: 0; color: #fff; font-size: 24px; line-height: 1; cursor: pointer; z-index: 2; }
.menu-arrow-left { left: 0; text-align: left; padding-left: 12px; background: linear-gradient(90deg, #0b3a3c 55%, rgba(11, 58, 60, 0)); }
.menu-arrow-right { right: 0; text-align: right; padding-right: 12px; background: linear-gradient(270deg, #0b3a3c 55%, rgba(11, 58, 60, 0)); }
.menu-wrap.can-left .menu-arrow-left, .menu-wrap.can-right .menu-arrow-right { display: block; }
.menu-arrow:hover { color: #9fe1cb; }

/* ===== Lab result-line table: fit each column to its content ===== */
.param-table { table-layout: auto; min-width: 1100px; }
.param-table input[name$="-name"] { min-width: 190px; }
.param-table select[name$="-result_type"] { min-width: 150px; }
.param-table input[name$="-units"] { min-width: 90px; }
.param-table input[name$="_low"], .param-table input[name$="_high"] { min-width: 80px; width: 80px; }
.param-table input[name$="-options"], .param-table input[name$="-abnormal_options"] { min-width: 210px; }
.param-table input[name$="-order"] { min-width: 56px; width: 56px; }

/* ===== Diagnosis and prescription ===== */
.dx-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.dx-list { margin: 0 0 12px; padding-left: 18px; }
.rx-table { min-width: 1050px; }
.rx-table td { vertical-align: top; padding: 8px 4px; }
.rx-table .rx-drug { min-width: 260px; }
.rx-table input[name$="-dose"] { width: 70px; }
.rx-table select[name$="-frequency"] { min-width: 150px; }
.rx-table input[name$="-days"], .rx-table input[name$="-quantity"] { width: 70px; }
.rx-table input[name$="-instructions"] { min-width: 170px; }
.rx-dose { white-space: nowrap; }
.rx-dose input { display: inline-block; }
.rx-allergy td { background: #fdecea; }
.rx-warn { color: var(--danger); font-size: 12px; font-weight: 600; margin-top: 4px; }
.allergy-confirm { border-color: var(--danger); margin-top: 8px; }

/* ===== Scrollable tables: both scrollbars always in view ===== */
.table-wrap { max-height: 70vh; overflow: auto; }
.table-wrap thead th { position: sticky; top: 0; z-index: 3; background: #fff; box-shadow: inset 0 -1px 0 var(--line); }
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: #b9c7cb; border-radius: 8px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #8fa4aa; }
.table-wrap::-webkit-scrollbar-track { background: #eef3f4; border-radius: 8px; }
.table-wrap { scrollbar-width: thin; scrollbar-color: #b9c7cb #eef3f4; }

/* ===== Table box height: 30% of the window ===== */
.table-wrap { max-height: max(30vh, 220px); }

/* ===== Keep the page inside the window; wide tables scroll in their own box ===== */
.shell .content { min-width: 0; }
.shell { min-width: 0; max-width: 100vw; }

/* ===== Taller table boxes, first column fixed ===== */
.table-wrap { max-height: max(60vh, 440px); }
.table-wrap .table th:first-child,
.table-wrap .table td:first-child { position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: inset -1px 0 0 var(--line); }
.table-wrap thead th:first-child { z-index: 4; }
.table-wrap .table tr.clickable:hover td:first-child { background: var(--brand-50); }
.table-wrap .rx-allergy td:first-child { background: #fdecea; }

/* ===== Cashier ===== */
.bill-table tfoot td { padding: 8px 10px; border-top: 1px solid var(--line); }
.bill-balance td { font-size: 17px; font-weight: 700; }
.line-cancelled td { text-decoration: line-through; color: var(--muted); }
.line-cancelled td:last-child { text-decoration: none; }
.method-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.diff-short { color: var(--danger); font-weight: 700; }
.diff-over { color: #b45309; font-weight: 700; }
.receipt { max-width: 340px; margin: 0 auto; background: #fff; border: 1px dashed #b9c7cb; padding: 18px 16px; font-size: 13px; color: #000; }
.receipt-head { text-align: center; margin-bottom: 8px; }
.receipt-head img { width: 56px; height: 56px; object-fit: contain; }
.receipt-clinic { font-size: 16px; font-weight: 700; }
.receipt-title { text-align: center; font-weight: 700; letter-spacing: .05em; margin: 10px 0; }
.receipt-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.receipt-row span:last-child { text-align: right; white-space: nowrap; }
.receipt-strong { font-weight: 700; font-size: 14px; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 8px 0; }
.receipt-foot { text-align: center; margin-top: 10px; }
@media print {
  body { background: #fff; }
  .content { max-width: none; }
  .receipt { border: 0; max-width: 80mm; padding: 0; margin: 0; }
  .alert { display: none; }
}

/* ===== Priority dropdown ===== */
.prio-form { display: inline-block; margin: 0; }
select.prio-select { width: auto; padding: 3px 26px 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; cursor: pointer; }
select.prio-select:focus { box-shadow: 0 0 0 3px rgba(14,124,116,.2); }

/* ===== Pharmacy ===== */
.dispense-table input[type=number] { width: 90px; }
.dispense-table input[type=text] { min-width: 200px; }
.short-row td { background: #fff7e8; }
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.med-label { background: #fff; border: 1px dashed #8fa4aa; border-radius: 6px; padding: 12px 14px; font-size: 13px; color: #000; break-inside: avoid; }
.med-clinic { font-size: 11px; color: #444; border-bottom: 1px solid #ddd; padding-bottom: 4px; margin-bottom: 6px; }
.med-patient { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.med-patient span { font-weight: 400; color: #444; }
.med-drug { font-size: 15px; font-weight: 700; margin-top: 6px; }
.med-directions { font-size: 15px; margin: 6px 0; }
.med-qty { color: #333; }
.med-note { color: #8a1f15; font-weight: 600; margin-top: 4px; }
.med-next { margin-top: 8px; padding-top: 6px; border-top: 1px solid #ddd; font-weight: 700; }
@media print { .labels { grid-template-columns: repeat(2, 1fr); } }

/* ===== Patient search in the top bar ===== */
.top-search { position: relative; flex: 1; max-width: 420px; margin: 0 12px; }
.top-search input[type=search] { width: 100%; padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.1); color: #fff; font: inherit; font-size: 14px; }
.top-search input[type=search]::placeholder { color: #9fbfbc; }
.top-search input[type=search]:focus { outline: none; background: #fff; color: var(--ink); border-color: #fff; }
.top-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60; max-height: 60vh; overflow-y: auto; background: #fff; border-radius: 10px; box-shadow: 0 10px 28px rgba(16,24,40,.25); }
.top-item { display: block; padding: 10px 14px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.top-item:last-child { border-bottom: 0; }
.top-item span { display: block; font-size: 12px; color: var(--muted); }
.top-item:hover, .top-item.on { background: var(--brand-50); }
.top-empty { padding: 12px 14px; color: var(--muted); }
@media (max-width: 820px) {
  .topnav-row { flex-wrap: wrap; }
  .top-search { order: 10; flex-basis: 100%; max-width: none; margin: 4px 0 0; }
}

/* ===== Clinic branding ===== */
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; padding-bottom: 18px; border-bottom: 3px solid var(--brand); }
.auth-brand img { width: 64px; height: 64px; object-fit: contain; border-radius: 12px; background: #fff; }
.auth-brand .brand-mark { width: 64px; height: 64px; font-size: 28px; border-radius: 12px; flex: none; }
.auth-brand-name { font-size: 20px; font-weight: 700; color: var(--brand-600); line-height: 1.2; }
.auth-brand .muted { font-size: 13px; }
input[type=color] { width: 90px; height: 44px; padding: 3px; cursor: pointer; }
.preset-row { margin-top: 2px; }
.preset-chip { border: 0; color: #fff; border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.preset-chip:hover { outline: 3px solid rgba(0,0,0,.15); }

/* ===== Installable app ===== */
.install-box { margin-top: 14px; }
.install-hint { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--brand-50); color: var(--brand-600); font-size: 13px; }
.qr-box { background: #fff; padding: 10px; border-radius: 10px; text-align: center; }
.qr-box svg { width: 220px; height: 220px; max-width: 100%; }
