@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&family=Noto+Sans+Kannada:wght@400;500;600;700&display=swap');

:root {
  --bg: #EEF4F3;
  --surface: #FFFFFF;
  --surface-2: #F5F9F8;
  --primary: #14746F;
  --primary-dark: #0B4F4B;
  --primary-tint: #E3EFEE;
  --accent: #D99A4E;
  --accent-tint: #FBF0DF;
  --text: #172624;
  --muted: #5C7370;
  --border: #DCE7E5;
  --danger: #B84A3B;
  --danger-tint: #F8E7E3;
  --success: #2F7D5B;
  --success-tint: #E4F3EA;
  --warning: #B4791F;
  --warning-tint: #FBF0DA;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 40, 38, 0.06), 0 6px 20px rgba(15, 40, 38, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
a, button, input, select, textarea, label, summary { touch-action: manipulation; }
button, .btn, .nav-link { -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
  color: var(--primary-dark);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.01em; }

/* ---------------------------------------------------------------- shell */
.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  background: linear-gradient(180deg, var(--primary-dark), #0A423E 85%);
  color: #E8F2F0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar .brand .pulse {
  width: 30px; height: 30px;
  flex-shrink: 0;
}

.sidebar .brand-text {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 17px;
  color: #fff;
  line-height: 1.15;
}
.sidebar .brand-text span { display:block; font-family:'Inter',sans-serif; font-weight: 500; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: #9FC6C0; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: #7FADA6; margin: 12px 10px 6px; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #D9EAE7;
  font-size: 13.5px;
  font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.nav-link.active { background: var(--accent); color: #2B1D0C; }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 14px;
  font-size: 12.5px;
  color: #9FC6C0;
}
.sidebar-footer strong { color: #fff; display: block; font-size: 13px; }

/* ---------------------------------------------------------------- main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 44px; height: 44px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--primary-dark);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.nav-scrim { display: none; }

.topbar form.search { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; max-width: 460px; }
.topbar input[type="search"], .topbar input[type="text"] {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  width: 100%; min-width: 0; flex: 1;
}

.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--primary-tint);
  color: var(--primary-dark);
}

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 14px;
}
.logout-btn {
  border: none; background: none; color: var(--muted); font-size: 13px; cursor: pointer;
  padding: 6px 8px;
}
.logout-btn:hover { color: var(--danger); }

.content { padding: 26px 28px 60px; padding-left: max(28px, env(safe-area-inset-left)); padding-right: max(28px, env(safe-area-inset-right)); padding-bottom: max(60px, env(safe-area-inset-bottom)); max-width: 1240px; width: 100%; margin: 0 auto; }
.page-head > div[style*="display:flex"] { flex-wrap: wrap; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head .eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 4px; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; align-items: stretch; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .num { font-family: 'Fraunces', serif; font-size: 30px; font-weight: 600; color: var(--primary-dark); line-height: 1; }
.stat-card .label { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.stat-card.alert { padding: 16px 18px; margin-bottom: 0; border-radius: var(--radius); font-size: inherit; background: var(--surface); color: inherit; }
.stat-card.alert .num { color: var(--danger); }
.two-col > .card + .card, .two-col > .card { margin-top: 0; }
.two-col { align-items: start; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 13.8px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state h3 { color: var(--text); }

/* ---------------------------------------------------------------- sortable tables */
table[data-sortable-table] th.sortable {
  cursor: pointer;
  user-select: none;
  padding-right: 20px;
  position: relative;
}
table[data-sortable-table] th.sortable:hover { color: var(--primary); }
table[data-sortable-table] th.sortable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sort-indicator {
  display: inline-block;
  width: 12px;
  margin-left: 4px;
  opacity: 0.35;
  font-size: 10px;
}
.sort-indicator::after { content: '\2195'; }
th.sort-asc .sort-indicator, th.sort-desc .sort-indicator { opacity: 1; color: var(--primary); }
th.sort-asc .sort-indicator::after { content: '\2191'; }
th.sort-desc .sort-indicator::after { content: '\2193'; }

/* ---------------------------------------------------------------- alarms */
@keyframes alarmBlink {
  0%, 100% { background: var(--danger-tint); }
  50% { background: #FFFFFF; }
}
tr.alarm-row { animation: alarmBlink 1s ease-in-out infinite; }
tr.alarm-row td { position: relative; }
.alarm-badge { display: inline-block; margin-right: 6px; margin-bottom: 4px; }

/* ---------------------------------------------------------------- voice input */
.voice-toolbar { display: flex; align-items: flex-start; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.voice-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.voice-btn:hover { border-color: var(--primary); color: var(--primary); }
.voice-btn.recording {
  background: var(--danger-tint);
  color: var(--danger);
  border-color: var(--danger);
  animation: voicePulse 1.4s ease-in-out infinite;
}
.voice-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.voice-status { font-size: 12.5px; color: var(--muted); padding-top: 6px; }
.voice-status:empty { display: none; }
.voice-status-error {
  color: var(--danger);
  font-weight: 600;
  background: var(--danger-tint);
  border: 1px solid rgba(184, 74, 59, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  max-width: 440px;
  line-height: 1.4;
}
@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(184, 74, 59, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(184, 74, 59, 0); }
}

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.single { grid-template-columns: 1fr; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.field textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.field textarea.ta-sm { min-height: 80px; }
.field textarea.ta-md { min-height: 110px; }
.field textarea.ta-lg { min-height: 120px; }

/* Clinical forms: comfortable reading width, and use spare width in landscape. */
.form-card { max-width: 760px; }
@media (min-width: 1000px) {
  .form-card { max-width: 960px; }
  .form-card .kv { grid-template-columns: 130px 1fr 130px 1fr; }
}
.hint { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-accent { background: var(--accent); color: #2B1D0C; }
.btn-accent:hover { filter: brightness(0.95); text-decoration: none; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px; text-transform: capitalize; }
.badge-admitted, .badge-scheduled, .badge-pending, .badge-draft { background: var(--warning-tint); color: var(--warning); }
.badge-discharged, .badge-completed, .badge-paid, .badge-approved { background: var(--success-tint); color: var(--success); }
.badge-cancelled { background: var(--danger-tint); color: var(--danger); }
.badge-partial { background: var(--accent-tint); color: var(--accent); }
.badge-ready { background: var(--accent-tint); color: var(--accent); }
.badge-started { background: var(--primary-tint); color: var(--primary-dark); }

/* ---------------------------------------------------------------- auth */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1B7A73 0%, var(--primary-dark) 55%, #06302D 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  width: 100%; max-width: 380px;
  border-radius: 14px;
  padding: 34px 30px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-card .brand-text { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600; color: var(--primary-dark); }
.auth-card .brand-text span { display: block; font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.auth-demo { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.auth-demo table { font-size: 12px; }
.auth-demo td { padding: 3px 6px; border: none; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }
.alert-danger { background: var(--danger-tint); color: var(--danger); }
.alert-success { background: var(--success-tint); color: var(--success); }
.alert-warning { background: var(--warning-tint); color: var(--warning); font-weight: 600; }

.muted { color: var(--muted); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 26px 0 10px; }
.section-title:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 7px 10px; font-size: 13.8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-clean li:last-child { border-bottom: none; }

.item-row { display: grid; grid-template-columns: 3fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 10px; }
@media (max-width: 700px) { .item-row { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tablet & narrower: off-canvas nav drawer
   Below 1100px (all 11-13" tablets in portrait, and small tablets) the sidebar
   becomes a drawer opened from the menu button, so pages get the full width
   and navigation is never lost. */
@media (max-width: 1099px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 300px; max-width: 86vw; height: auto;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    box-shadow: none;
  }
  .nav-open .sidebar { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,0.3); }
  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(8, 30, 28, 0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .nav-open, .nav-open body { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .content { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
  .kv { grid-template-columns: 112px 1fr; }
}
@media (max-width: 720px) {
  .user-chip .user-name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-scrim { transition: none; }
}

/* ---------------------------------------------------------------- touch (tablets): finger/stylus-sized targets
   Keyed off the input type rather than screen width so desktop mouse users
   keep the compact layout. Minimum 44px targets; 16px inputs stop iPadOS
   from zooming the page when a field is focused. */
@media (pointer: coarse) {
  body { font-size: 16px; }
  .btn { min-height: 44px; padding: 10px 18px; font-size: 15px; }
  .btn-sm { min-height: 44px; padding: 8px 15px; font-size: 14px; }
  .logout-btn { min-height: 44px; padding: 8px 12px; font-size: 14px; }
  .nav-link { min-height: 48px; font-size: 15.5px; padding: 10px 12px; }
  .topbar input[type="search"], .topbar input[type="text"] { min-height: 44px; font-size: 16px; }
  .field { margin-bottom: 18px; }
  .field label { font-size: 13.5px; }
  .field input, .field select, .field textarea { min-height: 48px; font-size: 16px; padding: 11px 13px; }
  .field textarea.ta-sm { min-height: 110px; }
  .field textarea.ta-md { min-height: 150px; }
  .field textarea.ta-lg { min-height: 170px; }
  table { font-size: 15px; }
  th, td { padding: 14px 12px; }
  th { font-size: 12px; }
  table[data-sortable-table] th.sortable { padding-right: 24px; }
  .list-clean li { padding: 13px 0; }
  .voice-btn { min-height: 44px; padding: 8px 18px; font-size: 14px; }
  .voice-toolbar { gap: 12px; margin-top: 8px; }
  tbody tr:hover { background: none; }
  .btn-row { gap: 12px; }
}

/* Landscape tablets: give forms with several long fields two columns of breathing room. */
@media (min-width: 1000px) and (pointer: coarse) {
  .form-card .field textarea.ta-lg { min-height: 190px; }
}

/* ---------------------------------------------------------------- OPD waiting-room kiosk display */
.kiosk-wrap { min-height: 100vh; background: var(--bg); display: flex; flex-direction: column; }
/* Kannada glyphs have a smaller visual size than Latin glyphs at the same
   font-size, so every Kannada run is scaled up (--kn-scale) to look as big
   as the English text. Tune the one number below if your kiosk's font
   renders larger or smaller. */
.kiosk-wrap { --kn-scale: 1.3; }
.kiosk-wrap .kn,
.kiosk-wrap[lang="kn"] .kiosk-table th,
.kiosk-wrap[lang="kn"] .kiosk-status-pill,
.kiosk-wrap[lang="kn"] .kiosk-empty,
.kiosk-wrap[lang="kn"] .kiosk-header .brand-text span,
.kiosk-wrap[lang="kn"] .kiosk-audio-overlay h2,
.kiosk-wrap[lang="kn"] .kiosk-audio-overlay p {
  font-family: 'Noto Sans Kannada', 'Nirmala UI', 'Tunga', 'Kedage', 'Inter', sans-serif;
  line-height: 1.45;
}
.kiosk-wrap .kn { font-size: calc(1em * var(--kn-scale)); }
.kiosk-wrap[lang="kn"] .kiosk-table th { font-size: calc(14px * var(--kn-scale)); text-transform: none; letter-spacing: 0; }
.kiosk-wrap[lang="kn"] .kiosk-status-pill { font-size: calc(13px * var(--kn-scale)); text-transform: none; letter-spacing: 0; }
.kiosk-wrap[lang="kn"] .kiosk-empty { font-size: calc(20px * var(--kn-scale)); }
.kiosk-wrap[lang="kn"] .kiosk-header .brand-text span { text-transform: none; letter-spacing: 0.02em; font-size: calc(13px * var(--kn-scale)); }
.kiosk-wrap[lang="kn"] .kiosk-audio-overlay h2 { font-size: calc(28px * var(--kn-scale)); }
.kiosk-wrap[lang="kn"] .kiosk-audio-overlay p { font-size: calc(16px * var(--kn-scale)); max-width: 620px; }
.kiosk-header {
  background: linear-gradient(120deg, var(--primary-dark), #0A423E 85%);
  color: #fff;
  padding: 22px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kiosk-header .brand { display: flex; align-items: center; gap: 14px; }
.kiosk-header .brand-text { font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; }
.kiosk-header .brand-text span { display: block; font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500; color: #9FC6C0; letter-spacing: 0.08em; text-transform: uppercase; }
.kiosk-clock { font-family: 'IBM Plex Mono', monospace; font-size: 28px; font-weight: 500; letter-spacing: 0.02em; }

.kiosk-title { text-align: center; padding: 28px 20px 8px; }
.kiosk-title h1 { font-size: 34px; margin-bottom: 4px; }
.kiosk-title p { color: var(--muted); font-size: 16px; }

.kiosk-body { flex: 1; padding: 20px 20px 40px; width: 100%; } /* full-width table: no side gutters */

.kiosk-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.kiosk-table th {
  background: var(--surface-2);
  text-align: left;
  padding: 16px 22px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.kiosk-table td { padding: 20px 22px; font-size: 22px; border-top: 1px solid var(--border); }
.kiosk-table tr:first-child td { border-top: none; }
.kiosk-row-waiting td { color: var(--text); }
.kiosk-row-started td { color: var(--muted); font-style: italic; }
.kiosk-row-ready td { font-weight: 700; }
.kiosk-row-ready { animation: kioskBlink 1s ease-in-out infinite; }
@keyframes kioskBlink {
  0%, 100% { background: var(--accent-tint); }
  50% { background: #FFFFFF; }
}
.kiosk-status-pill {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kiosk-status-pill.waiting { background: var(--surface-2); color: var(--muted); }
.kiosk-status-pill.ready { background: var(--accent); color: #2B1D0C; }
.kiosk-status-pill.started { background: var(--primary-tint); color: var(--primary-dark); }

.kiosk-empty { text-align: center; padding: 80px 20px; color: var(--muted); font-size: 20px; }

.kiosk-audio-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 79, 75, 0.94);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 999;
  cursor: pointer;
  text-align: center;
  padding: 20px;
}
.kiosk-audio-overlay .icon { font-size: 60px; }
.kiosk-audio-overlay h2 { color: #fff; font-size: 28px; }
.kiosk-audio-overlay p { color: #BFE0DB; font-size: 16px; max-width: 480px; }

/* ---------------------------------------------------------------- handwriting sheet (stylus -> text) */
html.hw-open, html.hw-open body { overflow: hidden; }
.hw-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 30, 28, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
.hw-overlay[hidden] { display: none; }
.hw-sheet {
  background: var(--surface);
  width: 100%; max-width: 1180px;
  height: min(94vh, 940px); height: min(94dvh, 940px);
  border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  padding: 16px 20px max(16px, env(safe-area-inset-bottom));
  gap: 12px;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.25);
  outline: none;
}
@media (min-width: 900px) and (orientation: landscape) {
  .hw-overlay { align-items: center; padding: 16px; }
  .hw-sheet { border-radius: 18px; height: min(96vh, 900px); height: min(96dvh, 900px); }
}
.hw-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hw-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.hw-title { font-size: 22px; margin: 2px 0 0; }
.hw-close {
  width: 44px; height: 44px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  font-size: 18px; cursor: pointer;
}

.hw-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hw-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.hw-tool, .hw-tool-btn {
  min-height: 44px; padding: 8px 16px;
  border: none; background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.hw-tool + .hw-tool { border-left: 1px solid var(--border); }
.hw-tool.active { background: var(--primary); color: #fff; }
.hw-tool-btn { border: 1px solid var(--border); border-radius: 10px; }
.hw-tool-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.hw-finger { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 6px; font-size: 14px; color: var(--muted); margin-left: auto; }
.hw-finger input { width: 22px; height: 22px; }

.hw-canvas-wrap {
  position: relative; flex: 1; min-height: 200px;
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background-color: #FFFEFA;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 55px, #D5E2E0 55px, #D5E2E0 56px);
  background-position: 0 8px;
}
.hw-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: crosshair;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.hw-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #9DB3B0; font-size: 20px; pointer-events: none;
}
.hw-placeholder[hidden] { display: none; }

.hw-result-wrap[hidden] { display: none; }
.hw-result-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.hw-result {
  width: 100%; min-height: 96px; max-height: 24vh;
  border: 1px solid var(--primary); border-radius: 10px;
  padding: 11px 13px; font: inherit; font-size: 16px; line-height: 1.5;
  background: var(--primary-tint); color: var(--text); resize: vertical;
}
.hw-warning { font-size: 12.5px; color: var(--warning); margin-top: 5px; }

.hw-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hw-status { font-size: 14px; color: var(--muted); flex: 1; min-width: 180px; }
.hw-status:empty { display: none; }
.hw-status-error { color: var(--danger); font-weight: 600; }
.hw-foot-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.hw-btn { border-color: var(--accent); }

/* ---------------------------------------------------------------- patient hospital card (85.6 x 53.98 mm) */
.hc-page { background: var(--bg); }
.hc-toolbar { max-width: 960px; margin: 0 auto; padding: 20px 20px 4px; }
.hc-toolbar-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hc-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hc-stage { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; padding: 20px; }
/* On screen the card is shown larger; printing always uses the true size. */
.hc-zoom { zoom: 2.6; }
.hc-sheet .hc-zoom { zoom: 1.5; }

.hc {
  width: 85.6mm; height: 53.98mm; box-sizing: border-box; overflow: hidden;
  background: #fff; color: #172624; border-radius: 3mm; border: 0.2mm solid #C9DAD7;
  display: flex; flex-direction: column; position: relative;
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif; line-height: 1.2;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.hc-head { background: #0B4F4B; color: #fff; height: 8.6mm; padding: 0 3.2mm; display: flex; align-items: center; gap: 2mm; flex: none; }
.hc-logo { width: 5.6mm; height: 5.6mm; flex: none; }
.hc-hospital { font-family: 'Fraunces', serif; font-weight: 600; font-size: 9pt; flex: 1; white-space: nowrap; }
.hc-kind { font-size: 5.2pt; letter-spacing: 0.14em; text-transform: uppercase; color: #F0C888; font-weight: 700; white-space: nowrap; }

.hc-body { flex: 1; display: flex; gap: 2.4mm; padding: 2.2mm 3.2mm 0; min-height: 0; }
.hc-info { flex: 1; min-width: 0; }
.hc-name { font-size: 10.5pt; font-weight: 700; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hc-name-kn { font-family: 'Noto Sans Kannada', 'Nirmala UI', 'Tunga', sans-serif; font-size: 9.5pt; font-weight: 600; line-height: 1.35; color: #0B4F4B; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hc-id { display: inline-block; margin: 0.8mm 0 1.2mm; font-family: 'IBM Plex Mono', monospace; font-size: 8pt; font-weight: 500; color: #0B4F4B; background: #E3EFEE; border-radius: 1mm; padding: 0.3mm 1.6mm; }
.hc-grid { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.9mm 2mm; }
.hc-grid > div { min-width: 0; }
.hc-wide { grid-column: 1 / -1; }
.hc-grid dt { font-size: 4.6pt; text-transform: uppercase; letter-spacing: 0.08em; color: #5C7370; font-weight: 700; }
.hc-grid dd { margin: 0; font-size: 6.4pt; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-grid dd.hc-clamp { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-weight: 500; }

.hc-qr { width: 23mm; flex: none; text-align: center; }
.hc-qr-svg { width: 23mm; height: 23mm; display: block; border: 0.2mm solid #DCE7E5; border-radius: 1mm; }
.hc-qr-cap { font-size: 4.8pt; color: #5C7370; margin-top: 0.8mm; font-weight: 600; letter-spacing: 0.02em; }

.hc-foot { flex: none; font-size: 4.8pt; color: #5C7370; text-align: center; padding: 0.6mm 0 1.4mm; }

@media print {
  .no-print, .hc-toolbar { display: none !important; }
  html, body, .hc-page { background: #fff !important; }
  .hc-zoom { zoom: 1 !important; }
  .hc-stage { display: block; padding: 0; }
  .hc { border-radius: 0; border: 0; }
  /* one card per page for card printers */
  .hc-cards .hc-cell { break-after: page; page-break-after: always; }
  .hc-cards .hc-cell:last-child { break-after: auto; page-break-after: auto; }
  /* 2 x 5 grid on A4 with dashed cut guides */
  .hc-sheet .hc-stage { display: grid; grid-template-columns: repeat(2, 85.6mm); gap: 2mm; justify-content: center; }
  .hc-sheet .hc-cell { break-inside: avoid; }
  .hc-sheet .hc { border: 0.2mm dashed #888; }
}

/* ================================================================ PHONES
   Screens narrower than 600px (phones). Tablets are 600px and wider, so nothing
   in this section applies to them. It is also `screen`-only so printing (e.g.
   the card-sized @page for hospital cards) is never affected.

   Elements that exist only for phones are hidden by default here and switched
   on inside the phone query below. */
.sidebar-signout { display: none; }
.rt-sort { display: none; }

@media screen and (max-width: 599px) {
  html { scroll-padding-top: 76px; }

  /* ---- top bar: one compact row  [menu] [search ........] [avatar] ---- */
  .topbar {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 10px;
  }
  .topbar form.search { max-width: none; gap: 0; }
  .topbar form.search .btn { display: none; } /* the keyboard's Search key submits */
  .topbar form.search input[type="search"] {
    padding-left: 38px;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235C7370' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center / 18px;
  }
  .user-chip { gap: 0; }
  .user-chip .role-badge, .user-chip form { display: none; } /* role + sign out live in the menu drawer */

  .sidebar-signout { display: block; }
  .sidebar-signout button {
    width: 100%; min-height: 46px;
    border: 1px solid rgba(255,255,255,0.28); border-radius: 8px;
    background: transparent; color: #fff;
    font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  }
  .sidebar-signout button:active { background: rgba(255,255,255,0.1); }

  /* ---- page frame ---- */
  .content {
    padding: 16px 14px 40px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 14px; }
  .page-head h1 { font-size: 27px; line-height: 1.15; margin: 0; }
  .page-head > div[style*="display:flex"] { width: 100%; gap: 8px !important; }
  .page-head > div[style*="display:flex"] > .btn { flex: 1 1 calc(50% - 4px); justify-content: center; text-align: center; }
  .page-head > div[style*="display:flex"] > form { flex: 1 1 100%; }
  .page-head > div[style*="display:flex"] > form .btn { width: 100%; justify-content: center; }

  /* ---- cards & grids ---- */
  .card { padding: 16px; border-radius: 12px; }
  .card h3 { font-size: 19px; }
  .card + .card, .two-col + .two-col, .card + .two-col, .two-col + .card { margin-top: 14px; }
  .two-col { gap: 14px; }
  .two-col > * { min-width: 0; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
  .stat-card, .stat-card.alert { padding: 12px 14px; }
  .stat-card .num { font-size: 26px; }
  .stat-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }

  .kv { grid-template-columns: 104px minmax(0, 1fr); gap: 8px 10px; }
  .kv dd { overflow-wrap: anywhere; }
  .list-clean li > div[style*="display:flex"] { flex-wrap: wrap; gap: 6px 10px; }

  /* ---- filter chips: one swipeable row instead of 3 wrapped lines ---- */
  .card > div[style*="display:flex"]:has(> a.btn-sm) {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    margin-left: -16px; margin-right: -16px;
    padding: 0 16px 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .card > div[style*="display:flex"]:has(> a.btn-sm)::-webkit-scrollbar { display: none; }
  .card > div[style*="display:flex"]:has(> a.btn-sm) > .btn { flex: none; white-space: nowrap; }

  /* ---- tables become one card per row (labels come from the column headings;
          see sortable-table.js). Without JS they simply scroll sideways. ---- */
  /* plain (non-card) tables keep sideways scrolling as a safety net, with tighter cells */
  .table-wrap table:not(.rt) th, .table-wrap table:not(.rt) td { padding: 10px 8px; }
  table.rt, table.rt tbody { display: block; }
  table.rt thead { display: none; }
  table.rt tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 2px 14px 12px; margin-bottom: 12px;
  }
  table.rt tbody tr:last-child { margin-bottom: 0; }
  table.rt tbody tr:hover { background: var(--surface); }
  table.rt td {
    display: block; min-width: 0;
    padding: 9px 0 0; border: 0;
    overflow-wrap: anywhere;
  }
  table.rt td[style] { max-width: none !important; white-space: normal !important; }
  table.rt td::before {
    content: attr(data-label);
    display: block; margin-bottom: 2px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--muted);
  }
  table.rt td:not([data-label])::before, table.rt td[data-label=""]::before { display: none; }
  table.rt:not(.rt-has-title) td:first-child, table.rt td.rt-title {
    grid-column: 1 / -1;
    padding: 10px 0; margin-bottom: 2px;
    font-size: 16px;
    border-bottom: 1px solid var(--border);
  }
  table.rt td.rt-title { order: -1; }
  table.rt:not(.rt-has-title) td:first-child::before, table.rt td.rt-title::before { display: none; }
  table.rt td.rt-wide { grid-column: 1 / -1; }
  table.rt td.rt-actions {
    grid-column: 1 / -1;
    display: flex; flex-wrap: wrap; gap: 8px;
    padding-top: 12px;
  }
  table.rt td.rt-actions > * { flex: 1 1 auto; }
  table.rt td.rt-actions .btn { justify-content: center; text-align: center; }
  table.rt td.rt-actions form .btn { width: 100%; }
  table.rt td.alarm-cell:not(:has(*)) { display: none; }

  /* sort control that replaces the (hidden) column headings */
  .rt-sort { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
  .rt-sort label { font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
  .rt-sort select {
    flex: 1; min-width: 0; min-height: 44px;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; font: inherit; font-size: 16px;
    background: var(--surface); color: var(--text);
  }
  .rt-sort button {
    flex: none; min-width: 44px; min-height: 44px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--primary-dark);
    font: inherit; font-size: 17px; cursor: pointer;
  }

  /* ---- forms ---- */
  .form-card { max-width: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid > * { min-width: 0; }
  .field { margin-bottom: 14px; }
  .field input, .field select, .field textarea { font-size: 16px; } /* stops iOS zooming on focus */
  .btn-row { margin-top: 16px; }
  .btn-row .btn { flex: 1 1 auto; justify-content: center; text-align: center; }
  .field > div[style*="display:flex"] > .btn { flex: none; white-space: nowrap; }
  .field > div[style*="display:flex"] > input { min-width: 0; }

  /* inline forms (search boxes, payment, stock in/out, date filter) wrap instead of overflowing */
  .content form[style*="display:flex"] { flex-wrap: wrap; }
  .content form[style*="display:flex"] > input[type="text"] {
    flex: 1 1 150px !important; min-width: 0; min-height: 44px; font-size: 16px;
  }
  .content form[style*="display:flex"]:has(> .field) > .field { flex: 1 1 100% !important; min-width: 0; }
  .content form[style*="display:flex"] > .field input[style*="width"] { width: 100% !important; }
  .content form[style*="display:flex"]:has(> .field) > .btn { flex: 1 1 calc(50% - 6px); justify-content: center; }

  /* billing line items */
  .item-row {
    grid-template-columns: 1fr 1fr; gap: 8px 10px;
    padding: 12px; margin-bottom: 12px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  }
  .item-row > * { min-width: 0; }
  .item-row input { width: 100%; min-width: 0; }
  .item-row > div:empty { display: none; }
  .item-row > :first-child, .item-row > .btn { grid-column: 1 / -1; }
  .item-row > .btn { justify-content: center; }

  /* ---- sign-in ---- */
  .auth-wrap { padding: 14px; }
  .auth-card { padding: 28px 22px; }

  /* ---- handwriting sheet ---- */
  .hw-sheet { padding: 12px 12px max(12px, env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; height: 96vh; height: 96dvh; }
  .hw-title { font-size: 19px; }
  .hw-finger { margin-left: 0; }
  .hw-foot-btns { width: 100%; margin-left: 0; }
  .hw-foot-btns .btn { flex: 1; justify-content: center; }

  /* ---- hospital card preview (shown at true size; the card is 85.6mm wide) ---- */
  .hc-toolbar { padding: 14px 14px 0; }
  .hc-toolbar-actions { width: 100%; }
  .hc-toolbar-actions .btn { flex: 1 1 auto; justify-content: center; }
  .hc-stage { padding: 12px; }
  .hc-zoom, .hc-sheet .hc-zoom { zoom: 1; }

  /* ---- OPD waiting-room display, if opened on a phone ---- */
  .kiosk-header { padding: 14px 16px; }
  .kiosk-header .brand { gap: 10px; }
  .kiosk-header .brand-text { font-size: 18px; }
  .kiosk-header .brand-text span { font-size: 10px; }
  .kiosk-clock { font-size: 18px; }
  .kiosk-title { padding: 18px 14px 4px; }
  .kiosk-title h1 { font-size: 24px; }
  .kiosk-title p { font-size: 14px; }
  .kiosk-body { padding: 12px 10px 28px; }
  .kiosk-table th { padding: 10px 6px; font-size: 10.5px; letter-spacing: 0.03em; }
  .kiosk-table td { padding: 12px 6px; font-size: 15px; overflow-wrap: anywhere; }
  .kiosk-status-pill { font-size: 11px; padding: 4px 9px; }
  .kiosk-empty { padding: 50px 14px; font-size: 17px; }
  .kiosk-audio-overlay h2 { font-size: 22px; }
  .kiosk-audio-overlay p { font-size: 14px; }
  .kiosk-wrap[lang="kn"] .kiosk-table th { font-size: calc(11px * var(--kn-scale)); }
  .kiosk-wrap[lang="kn"] .kiosk-status-pill { font-size: calc(11px * var(--kn-scale)); }
  .kiosk-wrap[lang="kn"] .kiosk-empty { font-size: calc(17px * var(--kn-scale)); }
  .kiosk-wrap[lang="kn"] .kiosk-header .brand-text span { font-size: calc(10px * var(--kn-scale)); }
  .kiosk-wrap[lang="kn"] .kiosk-audio-overlay h2 { font-size: calc(22px * var(--kn-scale)); }
  .kiosk-wrap[lang="kn"] .kiosk-audio-overlay p { font-size: calc(14px * var(--kn-scale)); }
}
@media screen and (min-width: 390px) and (max-width: 599px) {
  .hc-zoom, .hc-sheet .hc-zoom { zoom: 1.1; }
}
