/* CareLedger phone layout (loaded last): app bar, bottom tabs, compact tiles and list rows, bottom-sheet forms. */
@media (max-width: 720px) {
  body { display: block; font-size: 14px; background: #f2f6fc; padding-top: calc(56px + env(safe-area-inset-top)); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.drawer-open { overflow: hidden; }

  /* App bar */
  .mobile-bar { display: flex; align-items: center; gap: 10px; position: fixed; z-index: 30; top: 0; left: 0; right: 0; height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 100%); color: #fff; box-shadow: 0 2px 12px rgba(11, 35, 80, .2); }
  .menu-button { width: 38px; height: 38px; display: grid; place-content: center; gap: 4px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .1); cursor: pointer; }
  .menu-button span { display: block; width: 18px; height: 2px; border-radius: 2px; background: #fff; transition: transform .2s ease, opacity .2s ease; }
  body.drawer-open .menu-button span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  body.drawer-open .menu-button span:nth-child(2) { opacity: 0; }
  body.drawer-open .menu-button span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .mobile-brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; }
  .mobile-brand .brand-mark { width: 30px; height: 30px; display: grid; place-items: center; flex: none; background: #fff; color: var(--teal); border-radius: 9px; }
  .mobile-brand .brand-mark svg { width: 18px; height: 18px; }
  .mobile-brand div { display: grid; min-width: 0; line-height: 1.15; }
  .mobile-brand strong { font: 700 15px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-brand small { color: #9fb4dc; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-avatar { width: 34px; height: 34px; flex: none; border: 0; border-radius: 50%; background: linear-gradient(135deg, #8fd3ff, #fff); color: var(--navy); font: 800 12px var(--ui); cursor: pointer; }

  /* Bottom tab bar + floating add button */
  .tab-bar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; padding: 6px 4px env(safe-area-inset-bottom); background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(15, 31, 61, .06); }
  .tab-item { display: grid; justify-items: center; gap: 2px; padding: 5px 2px 7px; border: 0; background: none; color: #7d8ca5; font: 600 10.5px var(--ui); cursor: pointer; }
  .tab-icon { display: grid; place-items: center; width: 44px; height: 26px; border-radius: 13px; font-size: 16px; transition: background .15s; }
  .tab-item.active { color: var(--teal); }
  .tab-item.active .tab-icon { background: var(--teal-soft); }
  .fab { display: grid; place-items: center; position: fixed; z-index: 24; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border: 0; border-radius: 18px; background: linear-gradient(135deg, var(--teal) 0%, #2f8cff 100%); color: #fff; font-size: 26px; box-shadow: 0 10px 24px rgba(14, 99, 214, .35); cursor: pointer; }
  #paymentsView .list-actions .primary-button, #doctorPaymentsView .list-actions .primary-button { display: none; }
  body[data-screen="patients"] .fab, body[data-screen="setup"] .fab, body.drawer-open .fab { display: none; }

  /* Drawer */
  .sidebar { position: fixed; z-index: 40; top: 0; left: 0; bottom: 0; width: min(84vw, 310px); height: 100%; min-height: 0; padding: calc(20px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; transform: translateX(-102%); transition: transform .25s ease; box-shadow: 12px 0 40px rgba(0, 0, 0, .3); }
  body.drawer-open .sidebar { transform: none; }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(11, 35, 80, .5); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar .brand { font-size: 19px; padding: 0 8px 18px; }
  .practice-switcher { display: block; margin-bottom: 18px; }
  .nav-item, .nav-sub .nav-item { font-size: 14px; justify-content: flex-start; padding: 10px 12px; }
  .nav-sub .nav-item { font-size: 13.5px; padding: 9px 10px; }
  .nav-item .nav-count { display: inline-block; }
  .nav-group-title { display: flex; }
  .nav-group { margin-top: 12px; }
  .nav-sub { margin-left: 18px; padding-left: 10px; border-left: 1px solid rgba(255, 255, 255, .14); }
  .nav-group.collapsed .nav-sub { max-height: 0; opacity: 0; }
  .sidebar-bottom { display: block; margin-top: 20px; }
  .sync-status { display: flex; }
  .user-chip { flex-direction: row; gap: 4px; }
  .user-chip .avatar { display: grid; }
  .user-profile { justify-content: flex-start; padding: 7px 8px; }
  .user-profile > div { display: grid; }

  /* Page chrome */
  .main-content { padding: 14px 12px 24px; max-width: none; }
  .page-watermark { width: 260px; height: 260px; right: -60px; bottom: 40px; opacity: .035; }
  .topbar { display: none; }
  .workspace-toggle { display: grid; grid-template-columns: 1fr 1fr; width: 100%; margin: 0 0 14px; padding: 4px; border-radius: 11px; }
  .workspace-toggle-button { padding: 8px; font-size: 13px; border-radius: 8px; }
  .section-intro { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
  .section-intro > div:first-child { flex: 1; min-width: 0; }
  .section-intro h2 { font-size: 18px; margin: 0; }
  .overview-pane > .section-intro h2 { display: none; }
  #doctorPane > .section-intro > .primary-button { flex: 1; justify-content: center; }
  .section-intro p { display: none; }
  .section-intro > .primary-button, .section-intro > .secondary-button { padding: 9px 12px; font-size: 13px; }
  .list-actions { flex: 1 1 100%; display: flex; flex-direction: row; gap: 8px; }
  .list-actions .primary-button { padding: 0 12px; font-size: 13px; white-space: nowrap; }
  .list-actions .primary-button span { font-size: 16px; }
  .search-box { flex: 1; min-width: 0; padding: 0 12px; border-radius: 11px; }
  .search-box input { width: 100%; font-size: 16px; padding: 10px 0; }
  .date-filter { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 11px; font-size: 12.5px; }
  .date-filter select { flex: 1; max-width: 62%; padding: 7px 10px; font-size: 15px !important; }

  /* Stat tiles: three compact tiles in a row */
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
  .stat-card { padding: 11px 10px 10px 13px; border-radius: 12px; min-height: 0; }
  .stat-card::before { width: 3px; }
  .stat-head { font-size: 10.5px; line-height: 1.25; align-items: flex-start; }
  .stat-head > span:first-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .stat-icon { display: none; }
  .stat-card > strong { font-size: 16px !important; letter-spacing: -.3px !important; margin: 6px 0 0; white-space: nowrap; }
  .doctor-settlement { display: none; }
  .stat-foot { margin-top: 6px; display: block; }
  .stat-foot > span { display: none; }
  .stat-foot .text-button { font-size: 11.5px; }
  .stat-card:not(:has(.text-button)) .stat-foot { display: none; }

  .filter-tabs { gap: 8px; margin-bottom: 12px; border: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .filter-tab { flex: none; padding: 7px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; font-size: 12.5px; white-space: nowrap; }
  .filter-tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }
  .filter-tab.active span { background: rgba(255, 255, 255, .2); color: #fff; }

  .content-grid { grid-template-columns: 1fr; gap: 12px; }
  .panel, .report-card { border-radius: 14px; }
  .panel-header { padding: 12px 14px; align-items: center; }
  .panel-header h3 { font-size: 14.5px; margin: 0; }
  .panel-header p { display: none; }
  .panel-header .text-button { white-space: nowrap; font-size: 12.5px; }
  .activity-list { padding: 2px 14px 6px; }
  .activity-item { padding: 10px 0; }
  .report-cards { grid-template-columns: 1fr; gap: 12px; }
  .report-card { padding: 14px; }
  .report-total { font-size: 22px !important; margin: 12px 0 8px; }

  /* Tables → slim list rows */
  .table-panel, .patient-list-panel { overflow: hidden; }
  .table-wrap { overflow: visible; padding: 0; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 3px; align-items: center; padding: 11px 14px; border-bottom: 1px solid #eef2f8; }
  .table-wrap tbody tr:last-child { border-bottom: 0; }
  .table-wrap td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; font-size: 13px; background: none !important; }
  .table-wrap td::before { display: none; }
  .table-wrap .visit-month { display: none; }
  .patient-name { font-size: 14.5px; gap: 10px; }
  .patient-avatar { width: 28px; height: 28px; flex: none; }
  .row-action { width: 30px; height: 30px; padding: 0; border-radius: 9px; background: var(--teal-soft); color: var(--teal); font-size: 13px; font-weight: 700; }
  .row-action + .row-action { margin-left: 4px; }
  .status-select { padding: 5px 24px 5px 10px; font-size: 12px; background-position: right 8px center; }
  .indent { padding-left: 38px !important; }

  /* Patient register */
  #patientsTable tr { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "name name status" "treat treat due" "paid pend act"; }
  #patientsTable td:nth-child(1) { grid-area: name; }
  #patientsTable td:nth-child(8) { grid-area: status; justify-self: end; }
  #patientsTable td:nth-child(2) { grid-area: treat; padding-left: 38px; color: var(--muted); font-size: 12.5px; }
  #patientsTable td:nth-child(5) { grid-area: due; justify-self: end; font-size: 14px; }
  #patientsTable td:nth-child(5)::before { display: inline; content: "Due "; color: var(--muted); font: 500 11.5px var(--ui); }
  #patientsTable td:nth-child(4) { grid-area: paid; padding-left: 38px; color: var(--muted); font-size: 12px; white-space: nowrap; }
  #patientsTable td:nth-child(4)::before { display: inline; content: "Paid "; }
  #patientsTable td:nth-child(6) { grid-area: pend; padding-left: 8px; font-size: 12px; white-space: nowrap; }
  #patientsTable td:nth-child(6)::after { content: " pending"; color: var(--muted); font-weight: 500; }
  #patientsTable td:nth-child(9) { grid-area: act; justify-self: end; white-space: nowrap; }
  #patientsTable td:nth-child(3), #patientsTable td:nth-child(7) { display: none; }

  /* Overview: updated patients */
  #overviewTable tr { grid-template-areas: "p amt" "t a"; }
  #overviewTable td:nth-child(2) { grid-area: p; }
  #overviewTable td:nth-child(4) { grid-area: amt; justify-self: end; font-size: 14px; }
  #overviewTable td:nth-child(3) { grid-area: t; padding-left: 38px; color: var(--muted); font-size: 12.5px; }
  #overviewTable td:nth-child(7) { grid-area: a; justify-self: end; }
  #overviewTable td:nth-child(1), #overviewTable td:nth-child(5), #overviewTable td:nth-child(6) { display: none; }

  /* Payment history */
  #paymentsTable tr { grid-template-areas: "p amt" "d a" "n a"; }
  #paymentsTable td:nth-child(2) { grid-area: p; }
  #paymentsTable td:nth-child(4) { grid-area: amt; justify-self: end; font-size: 14px; }
  #paymentsTable td:nth-child(1) { grid-area: d; padding-left: 38px; font-size: 12px; }
  #paymentsTable td:nth-child(1) strong { font-weight: 600; }
  #paymentsTable td:nth-child(6) { grid-area: n; padding-left: 38px; color: var(--muted); font-size: 12px; }
  #paymentsTable td:nth-child(7) { grid-area: a; justify-self: end; align-self: center; }
  #paymentsTable td:nth-child(3), #paymentsTable td:nth-child(5) { display: none; }

  /* Doctor payments */
  #doctorPaymentsTable tr, #overviewDoctorTable tr { grid-template-areas: "v amt" "r a" "n a"; }
  #doctorPaymentsTable td:nth-child(1), #overviewDoctorTable td:nth-child(1) { grid-area: v; font-size: 14px; }
  #doctorPaymentsTable td:nth-child(1)::before, #overviewDoctorTable td:nth-child(1)::before { display: inline; content: "Visit "; color: var(--muted); font: 500 12px var(--ui); }
  #doctorPaymentsTable td:nth-child(3), #overviewDoctorTable td:nth-child(3) { grid-area: amt; justify-self: end; font-size: 14px; }
  #doctorPaymentsTable td:nth-child(2), #overviewDoctorTable td:nth-child(2) { grid-area: r; font-size: 12px; color: var(--muted); }
  #doctorPaymentsTable td:nth-child(2)::before, #overviewDoctorTable td:nth-child(2)::before { display: inline; content: "Recorded "; }
  #doctorPaymentsTable td:nth-child(2) strong, #overviewDoctorTable td:nth-child(2) strong { font-weight: 600; color: var(--ink); }
  #doctorPaymentsTable td:nth-child(4), #overviewDoctorTable td:nth-child(4) { grid-area: n; color: var(--muted); font-size: 12px; }
  #doctorPaymentsTable td:nth-child(5), #overviewDoctorTable td:nth-child(5) { grid-area: a; justify-self: end; }

  /* Plans & statuses */
  .setup-grid { gap: 12px; }
  .setup-form { padding: 14px; gap: 12px; }
  .setup-form input:not([type=radio]) { font-size: 16px; }
  .setup-list { padding: 2px 14px 8px; }
  .setup-form-actions button { flex: 1; justify-content: center; padding: 11px; }

  /* Forms → bottom sheets */
  .modal-backdrop { z-index: 50; align-items: end; padding: 0; }
  .modal { width: 100%; max-height: 90vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: sheet-in .22s ease-out; }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; margin: -6px auto 12px; border-radius: 2px; background: #d5deec; }
  .modal-header { margin-bottom: 14px; }
  .modal-header h2 { font-size: 19px; }
  .modal form { gap: 13px; }
  .form-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; padding: 11px 12px; }
  .form-actions { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); margin: 0 -16px -18px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
  .form-actions button { flex: 1; justify-content: center; padding: 13px; font-size: 15px; }
  .toast { z-index: 60; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); text-align: center; }
}
@media (max-width: 360px) {
  .form-row { grid-template-columns: 1fr; }
  .stat-card > strong { font-size: 14px !important; }
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Native app feel (phones) ---- */
@media (max-width: 720px) {
  html, body { overscroll-behavior-y: none; }
  body { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
  button, .tab-item, .sheet-item, a { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
  button:active, .sheet-item:active, .pay-button:active { transform: scale(.97); }
  .tab-item:active .tab-icon { transform: scale(.9); }
  .view.active-view { animation: screen-in .18s ease-out; }

  /* Tabs + sheet replace the drawer */
  .menu-button, .sidebar, .drawer-backdrop { display: none !important; }
  .mobile-bar { padding-left: 16px; }
  .mobile-brand .brand-mark { width: 32px; height: 32px; }
  .mobile-brand strong { font-size: 17px; letter-spacing: -.2px; }
  .section-intro h2 { display: none; }
  .section-intro:not(:has(.list-actions, .primary-button, .date-filter)) { display: none; }

  .tab-icon svg { width: 22px; height: 22px; }
  .tab-item:not(.active) .tab-icon svg { opacity: .85; }

  /* More sheet */
  .sheet-backdrop { display: flex; align-items: flex-end; position: fixed; inset: 0; z-index: 45; background: rgba(11, 35, 80, .45); animation: fade-in .18s ease-out; }
  .sheet-backdrop.hidden { display: none !important; }
  .sheet { width: 100%; max-height: 88vh; overflow-y: auto; padding: 8px 14px calc(16px + env(safe-area-inset-bottom)); background: #f2f6fc; border-radius: 22px 22px 0 0; animation: sheet-in .22s ease-out; }
  .sheet-handle { width: 40px; height: 4px; margin: 4px auto 14px; border-radius: 2px; background: #cfd9e8; }
  .sheet-profile { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px; margin-bottom: 12px; border: 0; border-radius: 16px; background: linear-gradient(120deg, var(--navy) 0%, var(--teal) 100%); color: #fff; text-align: left; cursor: pointer; }
  .sheet-profile .avatar { width: 44px; height: 44px; font-size: 15px; }
  .sheet-profile div { flex: 1; min-width: 0; display: grid; gap: 2px; }
  .sheet-profile strong { font: 700 16px var(--display); }
  .sheet-profile small { color: rgba(255, 255, 255, .75); font-size: 12.5px; }
  .sheet-profile .sheet-chev { color: rgba(255, 255, 255, .7); }
  .sheet-clinic { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin-bottom: 12px; background: #fff; border-radius: 14px; color: var(--muted); font: 600 13px var(--ui); }
  .sheet-clinic select { flex: 1; max-width: 62%; -webkit-appearance: none; appearance: none; border: 0; background: var(--teal-soft); color: var(--teal); border-radius: 10px; padding: 9px 12px; font: 700 15px var(--display); text-align: right; }
  .sheet-list { margin-bottom: 12px; overflow: hidden; background: #fff; border-radius: 14px; }
  .sheet-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px; border: 0; border-bottom: 1px solid #eef2f8; background: #fff; color: var(--ink); font: 600 15px var(--ui); text-align: left; text-decoration: none; cursor: pointer; }
  .sheet-item:last-child { border-bottom: 0; }
  .sheet-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; background: var(--teal-soft); color: var(--teal); }
  .sheet-icon svg { width: 19px; height: 19px; }
  .sheet-chev { margin-left: auto; color: #b3bfd1; font-size: 22px; line-height: 1; }
  .sheet-item.danger { color: var(--coral); }
  .sheet-item.danger .sheet-icon { background: var(--coral-soft); color: var(--coral); }
  body.sheet-open { overflow: hidden; }
  body.sheet-open .fab { display: none; }

  /* Settlement rows: "02 Aswin 2083 · Due NPR 420 · [Pay]" */
  .settlement-panel { margin-bottom: 12px; }
  .settlement-due strong { font-size: 14px; }
  #settlementTable tr, #overviewSettlementTable tr { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "d due act" "s r act"; }
  #settlementTable td:nth-child(1), #overviewSettlementTable td:nth-child(1) { grid-area: d; font-size: 14.5px; }
  #settlementTable td:nth-child(5), #overviewSettlementTable td:nth-child(5) { grid-area: due; justify-self: end; font-size: 14.5px; }
  #settlementTable td:nth-child(3), #overviewSettlementTable td:nth-child(3) { grid-area: s; color: var(--muted); font-size: 12px; }
  #settlementTable td:nth-child(3)::before, #overviewSettlementTable td:nth-child(3)::before { display: inline; content: "Share "; }
  #settlementTable td:nth-child(4), #overviewSettlementTable td:nth-child(4) { grid-area: r; justify-self: end; font-size: 12px; }
  #settlementTable td:nth-child(4)::before, #overviewSettlementTable td:nth-child(4)::before { display: inline; content: "Paid "; color: var(--muted); font-weight: 500; }
  #settlementTable td:nth-child(6), #overviewSettlementTable td:nth-child(6) { grid-area: act; align-self: center; padding-left: 4px; }
  #settlementTable td:nth-child(2), #overviewSettlementTable td:nth-child(2) { display: none; }
  .pay-button { padding: 9px 16px; font-size: 13px; }

  /* Treatments on phones */
  .treatments-editor { padding: 12px; }
  .treatment-row { grid-template-columns: minmax(0, 1fr) 92px 30px; grid-template-areas: "plan plan plan" "name cost rm"; row-gap: 6px; padding-bottom: 8px; border-bottom: 1px dashed #d5deec; }
  .treatment-row:last-child { border-bottom: 0; padding-bottom: 0; }
  .treatment-row .t-plan { grid-area: plan; }
  .treatment-row .t-name { grid-area: name; }
  .treatment-row .t-cost { grid-area: cost; }
  .treatment-row .t-remove { grid-area: rm; }
  .treatment-row select, .treatment-row input { font-size: 16px; padding: 10px; }
  .treatment-list { display: block; }
  .treatment-list span { display: inline; }
  .treatment-list span + span::before { content: " + "; }
  .treatment-list b { display: none; }
}
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
