:root {
  color-scheme: light dark;
  --bg: #edf3f0;
  --surface: #ffffff;
  --surface-strong: #f7fbf9;
  --text: #1b2724;
  --muted: #65736f;
  --line: #d8e2de;
  --primary: #08766b;
  --primary-dark: #075e55;
  --danger: #a12c32;
  --tab-active-bg: #e4f1ed;
  --tab-pulse-hot: #bcefe4;
  --tab-height: 78px;
  --shadow: 0 14px 32px rgba(21, 47, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) var(--tab-height);
  background: var(--bg);
}

.tab-stage {
  min-height: 0;
  overflow: hidden;
}

.tab-screen {
  display: none;
  height: 100%;
  overflow: hidden;
}

.active-screen {
  display: block;
}

.patient-view {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 12px 16px 22px;
}

.active-view {
  display: block;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1.08;
}

h2 {
  font-size: 1.75rem;
  line-height: 1.12;
}

.icon-action,
.floating-action {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1;
}

.floating-action {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tab-height) + 18px);
  z-index: 5;
  width: 58px;
  height: 58px;
  box-shadow: 0 14px 28px rgba(8, 118, 107, 0.28);
}

.app-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 42px 68px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 10px 14px 12px;
  background: linear-gradient(180deg, rgba(237, 243, 240, 0.98) 0%, rgba(237, 243, 240, 0.88) 76%, rgba(237, 243, 240, 0) 100%);
  pointer-events: none;
}

.app-topbar[hidden] {
  display: none;
}

.app-topbar > * {
  pointer-events: auto;
}

.app-topbar.meds-mode {
  grid-template-columns: 42px 68px minmax(0, 1fr) minmax(112px, auto);
  grid-template-rows: auto auto;
  row-gap: 3px;
}

.gear-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(21, 47, 42, 0.08);
}

.gear-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.top-initials,
.top-search {
  min-height: 42px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 18px rgba(21, 47, 42, 0.08);
}

.top-initials {
  padding: 9px 8px;
  text-align: center;
  font-weight: 900;
}

.top-search {
  padding: 9px 12px;
  text-align: center;
  font-size: 1.05rem;
}

.top-search::placeholder {
  color: #7e8d89;
}

.app-topbar:not(.meds-mode) .period-toggle {
  display: none;
}

.app-topbar:not(.meds-mode) .topbar-summary,
.app-topbar:not(.meds-mode) .topbar-date {
  display: none;
}

.topbar-summary,
.topbar-date {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.topbar-summary {
  grid-column: 3;
  text-align: center;
}

.topbar-date {
  grid-column: 4;
  text-align: center;
}

#patientListView {
  padding-top: 68px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  background: rgba(237, 243, 240, 0.94);
  padding: 12px 0 10px;
  backdrop-filter: blur(12px);
}

.search {
  display: grid;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

#searchInput {
  min-height: 46px;
  font-size: 1.15rem;
  text-align: center;
}

#searchInput::placeholder {
  color: #7e8d89;
}

textarea {
  min-height: 44px;
  resize: none;
  overflow: hidden;
}

#treatmentLog {
  max-height: 86px;
  overflow-y: auto;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 118, 107, 0.15);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 13px;
  box-shadow: 0 8px 20px rgba(21, 47, 42, 0.06);
}

.stats strong {
  display: block;
  font-size: 1.55rem;
}

.stats span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.patient-list {
  display: grid;
  gap: 10px;
}

.patient-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px 9px 9px;
  text-align: left;
  box-shadow: 0 10px 26px rgba(21, 47, 42, 0.08);
}

.patient-card:active,
.patient-card.active {
  border-color: rgba(8, 118, 107, 0.42);
}

.patient-thumb {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: #dfeae6;
  color: var(--primary-dark);
  font-size: 1.25rem;
  font-weight: 900;
  overflow: hidden;
}

.patient-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.patient-card-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.patient-card-copy strong,
.patient-card-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patient-card-copy strong {
  font-size: 1.02rem;
}

.patient-card-copy span {
  color: var(--muted);
  font-size: 0.9rem;
}

.patient-card-chevron {
  color: #8a9995;
  font-size: 1.7rem;
}

.detail-view {
  padding: 0 0 22px;
}

.compact-button,
.primary-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 13px;
  font-weight: 900;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.danger-button {
  background: #f8e5e6;
  color: var(--danger);
}

.patient-hero {
  position: relative;
  width: 92px;
  aspect-ratio: 1 / 1;
  min-height: 0;
  margin: 0;
  border: 1.5px dashed #a9bbb5;
  border-radius: 8px;
  background: #f5faf8;
  overflow: hidden;
  cursor: pointer;
}

.patient-hero img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.patient-hero img[hidden] {
  display: none;
}

.patient-hero figcaption {
  padding: 12px 16px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.patient-hero.has-image {
  border-style: solid;
  background: #dfeae6;
}

.image-empty-state,
.image-edit-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--primary-dark);
}

.image-empty-state svg,
.image-edit-overlay svg {
  width: 46px;
  height: 46px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.image-edit-overlay {
  background: rgba(8, 34, 30, 0.34);
  color: #fff;
  opacity: 0;
  transition: opacity 140ms ease;
}

.patient-hero.has-image .image-empty-state {
  display: none;
}

.patient-hero:hover .image-edit-overlay,
.patient-hero:focus-visible .image-edit-overlay {
  opacity: 1;
}

.patient-hero:not(.has-image) .image-edit-overlay {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.detail-form {
  margin: 14px 16px 0;
}

.detail-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: start;
  gap: 12px;
  padding: 16px 16px 2px;
}

.treatment-detail-heading {
  grid-template-columns: minmax(0, 1fr) minmax(136px, 38%);
}

.detail-heading-copy {
  min-width: 0;
}

.detail-title-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.inline-back-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  color: var(--primary-dark);
  font-size: 1.15rem;
  font-weight: 900;
}

.detail-title-row h2 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-heading p {
  margin-top: 5px;
  padding-left: 42px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.35;
}

.treatment-patient-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 7px;
  text-align: left;
  box-shadow: 0 8px 18px rgba(21, 47, 42, 0.08);
}

.treatment-patient-thumb {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #dfeae6;
  color: var(--primary-dark);
  font-weight: 900;
  overflow: hidden;
}

.treatment-patient-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.treatment-patient-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.treatment-patient-copy strong,
.treatment-patient-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.treatment-patient-copy strong {
  font-size: 0.9rem;
}

.treatment-patient-copy span {
  color: var(--muted);
  font-size: 0.74rem;
}

.detail-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.treatment-section {
  clear: both;
  margin: 14px 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading-row h3 {
  font-size: 1.1rem;
}

.section-heading-row p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
}

.small-icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
}

.treatment-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.treatment-list-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px;
  color: var(--text);
  text-align: left;
}

.treatment-list-card.active-treatment {
  border-color: rgba(8, 118, 107, 0.36);
  background: #f0faf7;
}

.treatment-card-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.treatment-card-main strong,
.treatment-card-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.treatment-card-main span {
  color: var(--muted);
  font-size: 0.78rem;
}

.treatment-toggle {
  justify-self: start;
  border-radius: 999px;
  background: #e8ecea;
  color: #586763;
  padding: 4px 8px;
  font-size: 0.7rem;
  font-weight: 900;
}

.treatment-toggle.is-active {
  background: #d9efe9;
  color: var(--primary-dark);
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
}

.toggle-field input {
  width: 18px;
  height: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 8px;
}

label {
  position: relative;
  display: grid;
  padding-top: 8px;
  color: #33413e;
  font-weight: 900;
}

.field-label {
  position: absolute;
  top: 0;
  left: 10px;
  z-index: 1;
  max-width: calc(100% - 20px);
  background: var(--surface);
  color: var(--muted);
  padding: 0 4px;
  font-size: 0.64rem;
  line-height: 1;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.patient-bottom-actions {
  clear: both;
  margin: 14px 16px 0;
  padding-bottom: 8px;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
  background: rgba(13, 23, 21, 0.96);
  overflow: hidden;
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer-close {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-dark);
  font-size: 1.25rem;
  font-weight: 900;
}

.image-viewer-frame {
  display: grid;
  place-items: center;
  min-height: 0;
  max-height: calc(100dvh - 92px - env(safe-area-inset-bottom));
  padding: 18px 18px 10px;
  overflow: hidden;
}

.image-viewer-frame img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 120px - env(safe-area-inset-bottom));
  border-radius: 8px;
  object-fit: contain;
}

.viewer-empty-state {
  display: grid;
  place-items: center;
  width: min(74vw, 320px);
  aspect-ratio: 3 / 4;
  border: 1.5px dashed rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.8);
}

.viewer-empty-state svg {
  width: 58px;
  height: 58px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.image-viewer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 18px calc(18px + env(safe-area-inset-bottom));
}

.remove-record-button {
  min-height: 40px;
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  padding: 9px 0;
  font-weight: 900;
}

.form-actions .save-status {
  margin-left: auto;
}

.save-status {
  color: var(--muted);
  font-size: 0.88rem;
}

.bottom-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -12px 28px rgba(21, 47, 42, 0.08);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
}

.tab-button {
  display: grid;
  place-items: center;
  gap: 4px;
  min-width: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 8px 6px;
  font-size: 0.76rem;
  font-weight: 900;
}

.tab-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.tab-icon-stack {
  position: relative;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
}

.tab-icon-stack svg {
  grid-area: 1 / 1;
}

.tab-pulse-count {
  grid-area: 1 / 1;
  color: var(--primary-dark);
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0;
  transform: translateY(2px) scale(0.88);
}

.meds-logged-pulse .tab-icon-stack svg {
  animation: meds-icon-fade 1400ms ease-out;
}

.meds-logged-pulse .tab-pulse-count {
  animation: meds-count-fade 1400ms ease-out;
}

@keyframes meds-icon-fade {
  0%,
  100% {
    opacity: 1;
  }

  18%,
  78% {
    opacity: 0;
  }
}

@keyframes meds-count-fade {
  0%,
  100% {
    opacity: 0;
    transform: translateY(2px) scale(0.88);
  }

  18%,
  78% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.active-tab {
  background: var(--tab-active-bg);
  color: var(--primary-dark);
}

.meds-screen {
  overflow-y: auto;
  padding: 84px 12px 18px;
}

.meds-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  gap: 10px;
  background: rgba(237, 243, 240, 0.94);
  padding: 12px 4px 10px;
  backdrop-filter: blur(12px);
}

#medSearchInput {
  min-height: 46px;
  font-size: 1.15rem;
  text-align: center;
}

.meds-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.initials-field {
  padding-top: 8px;
}

.period-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 3px;
  box-shadow: 0 8px 18px rgba(21, 47, 42, 0.08);
}

.period-toggle button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.period-toggle .active-period {
  background: #dff0ec;
  color: var(--primary-dark);
}

.meds-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, 270px);
  column-gap: 10px;
  row-gap: 22px;
  justify-content: center;
  padding-top: 20px;
}

.med-card {
  display: grid;
  grid-template-rows: 38px 76px 36px;
  gap: 8px;
  width: 270px;
  height: 184px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 9px 9px;
  box-shadow: 0 8px 18px rgba(21, 47, 42, 0.08);
}

.med-card.done {
  border-color: #97cdbf;
  background: #e8f7f2;
}

.med-card.out {
  border-color: #e0a4a9;
  background: #fdebed;
}

.med-card-header {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  margin-top: -18px;
  padding-top: 18px;
}

.med-card-header .med-thumb {
  transform: translateY(-18px);
  margin-bottom: -18px;
}

.med-card-header > div {
  min-width: 0;
  transform: translateY(-1px);
}

.med-thumb {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dfeae6;
  color: var(--primary-dark);
  font-size: 0.95rem;
  font-weight: 900;
  overflow: hidden;
  padding: 0;
}

.med-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.med-card p,
.med-card strong,
.med-card span {
  overflow-wrap: anywhere;
}

.med-patient-link,
.med-treatment-link {
  display: grid;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.med-patient-link {
  display: block;
  width: 100%;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 900;
  line-height: 1.12;
}

.med-patient-copy {
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(94px, 1.12fr);
  gap: 7px;
  align-items: start;
  min-width: 0;
  transform: translateY(-1px);
}

.med-patient-meta {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
  min-width: 0;
}

.med-patient-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.med-card p,
.med-card span {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.25;
}

.med-card-body {
  display: grid;
  grid-template-rows: 28px 42px;
  gap: 6px;
  min-height: 0;
}

.med-card-body strong {
  font-size: 0.98rem;
  line-height: 1;
}

.med-treatment-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  width: 100%;
  font-size: 1.14rem;
}

.med-treatment-line strong,
.med-treatment-name {
  color: var(--text);
  font-size: inherit;
  font-weight: 900;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.med-treatment-line strong {
  flex: 0 0 auto;
}

.med-treatment-name {
  flex: 0 1 auto;
  min-width: 0;
}

.med-treatment-concentration {
  flex: 0 1 auto;
  min-width: 0;
  color: var(--text);
  font-size: 0.68em;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.med-heart-float {
  position: fixed;
  z-index: 40;
  color: #d91f3f;
  font-size: 1.22rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(13, 23, 21, 0.22);
  transform: translate(-50%, -50%);
  animation: med-heart-float 1320ms ease-out forwards;
}

@keyframes med-heart-float {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.72);
  }

  18% {
    opacity: 1;
    transform: translate(calc(-50% + 4px), -64.2%) scale(0.94);
  }

  36% {
    opacity: 1;
    transform: translate(calc(-50% - 5px), -98.4%) scale(1);
  }

  54% {
    opacity: 1;
    transform: translate(calc(-50% + 6px), -132.6%) scale(1.06);
  }

  72% {
    opacity: 1;
    transform: translate(calc(-50% - 3px), -166.8%) scale(1.12);
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + 2px), -220%) scale(1.18);
  }
}

.med-log-grid {
  align-self: start;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  column-gap: 6px;
  row-gap: 2px;
  height: 42px;
  margin: 3px 3px 0;
  padding: 3px 4px;
  font-size: 0.62rem;
  line-height: 1.15;
  overflow: hidden;
}

.med-log-grid span {
  color: var(--muted);
  font-size: inherit;
  line-height: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.med-log-grid .med-log-empty {
  grid-column: 1 / -1;
  white-space: normal;
}

.med-card-actions {
  align-self: end;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  min-height: 36px;
}

.med-card-actions button {
  min-height: 36px;
  height: 36px;
  border-radius: 8px;
  font-weight: 900;
}

.med-check {
  border: 1.5px solid #0f8f72;
  background: transparent;
  color: #0f8f72;
  font-size: 1.2rem;
}

.med-out {
  border: 1.5px solid #b9363f;
  background: transparent;
  color: #b9363f;
  font-size: 1.2rem;
}

.med-check:active {
  background: #0f8f72;
  color: #fff;
}

.med-out:active {
  background: #b9363f;
  color: #fff;
}

.med-undo {
  grid-column: 1 / -1;
  background: #fff;
  color: var(--primary-dark);
  border: 1px solid var(--line);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.utility-drawer {
  display: none;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(13, 23, 21, 0.42);
}

.settings-modal[hidden] {
  display: none;
}

.settings-panel {
  width: min(100%, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.settings-heading h2 {
  font-size: 1.25rem;
}

.settings-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 900;
}

.settings-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.settings-toggle strong,
.settings-toggle small {
  display: block;
}

.settings-toggle strong {
  font-size: 0.95rem;
  color: var(--text);
}

.settings-toggle small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
  margin-top: 2px;
}

.settings-toggle input {
  width: 46px;
  height: 26px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #dfeae6;
  padding: 2px;
}

.settings-toggle input::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(21, 47, 42, 0.2);
  transition: transform 160ms ease;
}

.settings-toggle input:checked {
  border-color: var(--primary);
  background: var(--primary);
}

.settings-toggle input:checked::before {
  transform: translateX(20px);
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 520px;
    margin: 0 auto;
    border-inline: 1px solid var(--line);
  }

  .floating-action {
    right: calc((100vw - 520px) / 2 + 18px);
  }

}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101816;
    --surface: #17221f;
    --surface-strong: #1d2a26;
    --text: #edf6f2;
    --muted: #a6b9b2;
    --line: #2d403a;
    --primary: #42c3ae;
    --primary-dark: #7ed9ca;
    --danger: #ff858d;
    --tab-active-bg: #1f3b35;
    --tab-pulse-hot: #316b5f;
    --shadow: 0 14px 32px rgba(0, 0, 0, 0.32);
  }

  body,
  .app-shell {
    background: var(--bg);
  }

  input,
  select,
  textarea,
  .gear-button,
  .top-initials,
  .top-search,
  .period-toggle,
  .med-undo {
    background: rgba(23, 34, 31, 0.96);
    color: var(--text);
  }

  .app-topbar {
    background: linear-gradient(180deg, rgba(16, 24, 22, 0.98) 0%, rgba(16, 24, 22, 0.88) 76%, rgba(16, 24, 22, 0) 100%);
  }

  .bottom-tabs {
    background: rgba(23, 34, 31, 0.96);
    box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.24);
  }

  .active-tab,
  .period-toggle .active-period {
    background: var(--tab-active-bg);
    color: var(--primary-dark);
  }

  .patient-thumb,
  .med-thumb,
  .treatment-thumb,
  .image-empty-state {
    background: #243631;
    color: var(--primary-dark);
  }

  .patient-card,
  .lookup-card,
  .treatment-card,
  .treatment-patient-card,
  .med-card,
  .stats div {
    background: var(--surface);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  }

  .med-card.done {
    border-color: #4e8d7c;
    background: #17352e;
  }

  .med-card.out {
    border-color: #8d4d56;
    background: #351b21;
  }

  .empty-state {
    background: rgba(23, 34, 31, 0.64);
  }

  .image-viewer-close {
    background: rgba(23, 34, 31, 0.92);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f0;
  --surface: #ffffff;
  --surface-strong: #f7fbf9;
  --text: #1b2724;
  --muted: #65736f;
  --line: #d8e2de;
  --primary: #08766b;
  --primary-dark: #075e55;
  --danger: #a12c32;
  --tab-active-bg: #e4f1ed;
  --tab-pulse-hot: #bcefe4;
  --shadow: 0 14px 32px rgba(21, 47, 42, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101816;
  --surface: #17221f;
  --surface-strong: #1d2a26;
  --text: #edf6f2;
  --muted: #a6b9b2;
  --line: #2d403a;
  --primary: #42c3ae;
  --primary-dark: #7ed9ca;
  --danger: #ff858d;
  --tab-active-bg: #1f3b35;
  --tab-pulse-hot: #316b5f;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.32);
}

:root[data-theme] body,
:root[data-theme] .app-shell {
  background: var(--bg);
}

:root[data-theme="light"] input,
:root[data-theme="light"] select,
:root[data-theme="light"] textarea,
:root[data-theme="light"] .gear-button,
:root[data-theme="light"] .top-initials,
:root[data-theme="light"] .top-search,
:root[data-theme="light"] .period-toggle,
:root[data-theme="light"] .med-undo {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .gear-button,
:root[data-theme="dark"] .top-initials,
:root[data-theme="dark"] .top-search,
:root[data-theme="dark"] .period-toggle,
:root[data-theme="dark"] .med-undo {
  background: rgba(23, 34, 31, 0.96);
  color: var(--text);
}

:root[data-theme="light"] .settings-toggle input {
  border-color: #6f9c91;
  background: #bdd7d1;
}

:root[data-theme="light"] .settings-toggle input::before {
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(21, 47, 42, 0.32);
}

:root[data-theme="light"] .settings-toggle input:checked {
  border-color: #075e55;
  background: #08766b;
}

:root[data-theme="dark"] .settings-toggle input {
  border-color: #6e8c84;
  background: #2f4740;
}

:root[data-theme="dark"] .settings-toggle input::before {
  background: #f4fffb;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.38);
}

:root[data-theme="dark"] .settings-toggle input:checked {
  border-color: #7ed9ca;
  background: #42c3ae;
}

:root[data-theme="light"] .app-topbar {
  background: linear-gradient(180deg, rgba(237, 243, 240, 0.98) 0%, rgba(237, 243, 240, 0.88) 76%, rgba(237, 243, 240, 0) 100%);
}

:root[data-theme="dark"] .app-topbar {
  background: linear-gradient(180deg, rgba(16, 24, 22, 0.98) 0%, rgba(16, 24, 22, 0.88) 76%, rgba(16, 24, 22, 0) 100%);
}

:root[data-theme="light"] .bottom-tabs {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -12px 28px rgba(21, 47, 42, 0.08);
}

:root[data-theme="dark"] .bottom-tabs {
  background: rgba(23, 34, 31, 0.96);
  box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.24);
}

:root[data-theme] .active-tab,
:root[data-theme] .period-toggle .active-period {
  background: var(--tab-active-bg);
  color: var(--primary-dark);
}

:root[data-theme="light"] .patient-thumb,
:root[data-theme="light"] .med-thumb,
:root[data-theme="light"] .treatment-thumb,
:root[data-theme="light"] .image-empty-state {
  background: #dfeae6;
  color: var(--primary-dark);
}

:root[data-theme="dark"] .patient-thumb,
:root[data-theme="dark"] .med-thumb,
:root[data-theme="dark"] .treatment-thumb,
:root[data-theme="dark"] .image-empty-state {
  background: #243631;
  color: var(--primary-dark);
}

:root[data-theme] .patient-card,
:root[data-theme] .lookup-card,
:root[data-theme] .treatment-card,
:root[data-theme] .treatment-patient-card,
:root[data-theme] .med-card,
:root[data-theme] .settings-panel,
:root[data-theme] .stats div {
  background: var(--surface);
}

:root[data-theme="light"] .med-card.done {
  border-color: #97cdbf;
  background: #e8f7f2;
}

:root[data-theme="light"] .med-card.out {
  border-color: #e0a4a9;
  background: #fdebed;
}

:root[data-theme="dark"] .med-card.done {
  border-color: #4e8d7c;
  background: #17352e;
}

:root[data-theme="dark"] .med-card.out {
  border-color: #8d4d56;
  background: #351b21;
}

@media (max-width: 420px) {
  .meds-list {
    grid-template-columns: 270px;
  }

  .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .detail-heading {
    grid-template-columns: minmax(0, 1fr) 84px;
  }

  .treatment-detail-heading {
    grid-template-columns: minmax(0, 1fr) minmax(120px, 40%);
  }

  .patient-hero {
    width: 84px;
  }

  h1 {
    font-size: 1.75rem;
  }
}
