:root {
  --ink: #152028;
  --muted: #5a6a78;
  --line: #e2e8ed;
  --paper: #f3f6f8;
  --card: #ffffff;
  --teal: #0d6b66;
  --teal-soft: #e8f4f3;
  --teal-dark: #0a504c;
  --danger: #a12f2f;
  --shadow: 0 10px 30px rgba(21, 32, 40, 0.08);
  --sidebar-w: 280px;
  --nav-h: 56px;
  font-family: "Noto Sans Bengali", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body.booting .app { visibility: hidden; }
.boot-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(13, 107, 102, 0.14), transparent 46%),
    radial-gradient(ellipse at 90% 80%, rgba(13, 107, 102, 0.08), transparent 40%),
    var(--paper);
  pointer-events: none;
}
.boot-splash strong {
  font-size: clamp(28px, 6vw, 40px);
  letter-spacing: -0.03em;
  color: var(--ink);
  animation: boot-pulse 1.2s ease-in-out infinite;
}
body:not(.booting) .boot-splash { display: none; }
@keyframes boot-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
body {
  background:
    radial-gradient(ellipse at top left, rgba(13, 107, 102, 0.08), transparent 42%),
    var(--paper);
  color: var(--ink);
}
button, input { font: inherit; }
button { cursor: pointer; }

.app {
  min-height: 100dvh;
  width: 100%;
  margin: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
}

#screen-login {
  width: 100%;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(13, 107, 102, 0.14), transparent 46%),
    radial-gradient(ellipse at 90% 80%, rgba(13, 107, 102, 0.08), transparent 40%),
    var(--paper);
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: min(100%, 420px);
  padding: 32px 28px 36px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.login-card .brand {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 18px;
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 12px;
  font-weight: 700;
}
h1, h2 { margin: 0; font-weight: 700; }
h1 { font-size: clamp(34px, 6vw, 44px); }

.brand {
  --brand-size: clamp(42px, 8.5vw, 58px);
  position: relative;
  padding: 0 0 0.38em;
  font-size: var(--brand-size);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1;
  color: var(--ink);
}
.brand-title {
  display: block;
  white-space: nowrap;
  line-height: 1;
}
.brand-g {
  position: relative;
}
.brand-tag {
  position: absolute;
  left: 0;
  top: calc(var(--brand-size) * 0.9);
  display: block;
  margin: 0;
  padding: 0;
  color: var(--teal);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0;
  transform-origin: left top;
  pointer-events: none;
  opacity: 0;
}
.brand.is-ready .brand-tag {
  opacity: 1;
}

.lead { color: var(--muted); line-height: 1.55; margin: 10px 0 0; }
label { display: block; margin: 18px 0 6px; font-size: 14px; font-weight: 650; }
input[type="text"], input[type="tel"], #phone, #otp, #patient-phone, #patient-otp {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
}
input:focus { border-color: var(--teal); }
#login-btn, #patient-submit {
  width: 100%;
  margin-top: 18px;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  font-weight: 700;
  background: var(--teal);
  color: #fff;
}
#login-btn:disabled, #patient-submit:disabled, .add-rx-btn:has(input:disabled) { opacity: 0.6; }
.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.demo {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 700;
}

.shell {
  position: relative;
  overflow: visible;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 24, 32, 0.35);
  z-index: 8;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(var(--sidebar-w), 86vw);
  background: #fff;
  border-right: 1px solid var(--line);
  z-index: 9;
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.shell.sidebar-open .sidebar { transform: translateX(0); }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  height: var(--nav-h);
  min-height: var(--nav-h);
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}
.sidebar-top strong { font-size: 16px; }
.add-patient-btn {
  border: 0;
  background: var(--teal-soft);
  color: var(--teal-dark);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.patient-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.patient-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 12px;
  padding: 10px 8px 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.patient-item:hover { background: var(--paper); }
.patient-item.active {
  background: var(--teal-soft);
  color: var(--teal-dark);
}
.patient-item .pinfo {
  min-width: 0;
  display: grid;
  gap: 2px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  color: inherit;
  cursor: pointer;
}
.patient-item strong {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.patient-item span {
  color: var(--muted);
  font-size: 12px;
}
.patient-item.active span { color: var(--teal); }
.patient-action {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.patient-action:hover { background: #fff; color: var(--ink); }
.patient-action.danger:hover { background: #fdecec; color: var(--danger); }
.patient-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: var(--nav-h);
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}
.nav strong { text-align: center; font-size: 17px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  border-radius: 12px;
}
.icon-btn:hover { background: var(--paper); }
.nav svg, .modal-head svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.more-menu {
  position: absolute;
  top: calc(var(--nav-h) - 4px);
  right: 10px;
  min-width: 140px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 6;
}
.more-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--danger);
  font-weight: 700;
  text-align: left;
}
.more-menu button:hover { background: #fdecec; }

.content {
  flex: 1;
  overflow: auto;
  padding: 16px 14px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.patient-card {
  background: linear-gradient(160deg, #fff 0%, var(--teal-soft) 140%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.role-badge {
  display: inline-block;
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 999px;
  padding: 2px 8px;
  line-height: 1.4;
  white-space: nowrap;
}
.role-badge.own {
  background: var(--teal-soft);
  color: var(--teal-dark);
}
.role-badge.helper {
  background: #eef2f6;
  color: var(--muted);
}
button.role-badge {
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.02em;
  align-self: start;
  padding: 2px 8px;
}
button.adder-btn:hover {
  background: #e2e8ed;
  color: var(--ink);
}
.patient-card .who {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.patient-card .meta-row {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.patient-card .problems {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid rgba(13, 107, 102, 0.15);
  line-height: 1.5;
}
.patient-card .problems span {
  display: block;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.add-rx-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 14px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.add-rx-btn:active { transform: scale(0.99); }

.status {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 700;
}
.status.error { background: #fdecec; color: var(--danger); }

.report-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.report {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.visit-head {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: 14px;
}
.visit-toggle {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  display: grid;
  gap: 3px;
  color: inherit;
  cursor: pointer;
}
.visit-head > .role-badge {
  margin-top: 1px;
  flex-shrink: 0;
}
.visit-toggle strong { font-size: 15px; }
.visit-toggle span,
.visit-toggle .visit-reason {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  line-height: 1.4;
}
.visit-body { display: none; padding: 0 14px 14px; }
.report.open .visit-body { display: block; }
.field { margin: 0 0 8px; line-height: 1.45; }
.field span { display: block; color: var(--teal); font-size: 12px; font-weight: 700; }
.section { margin: 12px 0 8px; font-size: 13px; font-weight: 700; color: var(--teal); }
.rx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.rx-table th,
.rx-table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}
.rx-table th {
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}
.rx-table tr:last-child td { border-bottom: 0; }
.rx-table td:first-child { width: 42%; font-weight: 650; }
.rx-table td:last-child { color: var(--ink); }
.report-add {
  display: inline-block;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
}
.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.thumb {
  width: 72px;
  height: 72px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(10, 16, 22, 0.92);
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 12px;
  touch-action: none;
}
.lightbox-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 44px;
  height: 56px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 32px;
  line-height: 1;
}
.lightbox-nav.prev { left: 8px; }
.lightbox-nav.next { right: 8px; }
.lightbox-stage {
  width: min(100%, 960px);
  height: min(78dvh, 860px);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-count {
  margin: 0;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  font-weight: 700;
}
.report img { width: 100%; border-radius: 10px; margin-top: 10px; }
.empty {
  color: var(--muted);
  text-align: center;
  margin: 28px 0 0;
  line-height: 1.5;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 24, 32, 0.4);
  display: grid;
  place-items: center;
  padding: 18px;
}
#confirm-modal { z-index: 30; }
.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.modal-head h2 { font-size: 18px; }
.viewer-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.viewer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.viewer-info { min-width: 0; display: grid; gap: 2px; }
.viewer-row strong { font-size: 14px; }
.viewer-row span { color: var(--muted); font-size: 12px; }
.viewer-row button {
  border: 0;
  background: #fdecec;
  color: var(--danger);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
}
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}
.confirm-actions:has(#confirm-yes[hidden]) {
  grid-template-columns: 1fr;
}
.confirm-actions button {
  border: 0;
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
}
.confirm-actions .no { background: var(--paper); color: var(--ink); }
.confirm-actions .yes { background: var(--danger); color: #fff; }
.modal-lead { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }

@media (min-width: 768px) {
  .shell {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    overflow: visible;
    height: auto;
    min-height: 100dvh;
    max-height: none;
    width: 100%;
    background: transparent;
  }
  .sidebar-backdrop { display: none !important; }
  .sidebar {
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    z-index: 1;
    align-self: flex-start;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    flex: 0 0 auto;
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    max-width: var(--sidebar-w);
    overflow: hidden;
    transform: none !important;
    margin: 0;
    border-right: 1px solid var(--line);
    background: #fff;
    transition:
      width 0.28s ease,
      min-width 0.28s ease,
      max-width 0.28s ease,
      border-right-width 0.28s ease;
  }
  .shell:not(.sidebar-open) .sidebar {
    width: 0;
    min-width: 0;
    max-width: 0;
    border-right-width: 0;
    pointer-events: none;
  }
  .shell.sidebar-open .sidebar {
    pointer-events: auto;
  }
  .sidebar-top,
  .patient-list {
    width: var(--sidebar-w);
    box-sizing: border-box;
  }
  .main {
    flex: 1 1 auto;
    display: block;
    background: var(--card);
    height: auto;
    min-height: 100dvh;
    min-width: 0;
    overflow: visible;
  }
  .nav {
    position: sticky;
    top: 0;
    padding: 0 16px;
  }
  .content {
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding: 20px 28px 40px;
  }
}

@media (max-width: 767px) {
  #screen-profile.shell {
    background: var(--card);
  }
  .main {
    min-height: 100dvh;
    overflow: visible;
  }
  .nav {
    position: sticky;
    top: 0;
    z-index: 5;
  }
}
