:root {
  color-scheme: light;
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-soft: #eef7f3;
  --ink: #17332f;
  --muted: #61746f;
  --line: #dce8e4;
  --brand: #147d73;
  --brand-strong: #0b5f57;
  --accent: #f4b860;
  --danger: #bf3b36;
  --warning: #966a12;
  --ok: #16724a;
  --shadow: 0 18px 45px rgba(23, 51, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(20, 125, 115, 0.14), transparent 34rem),
    linear-gradient(180deg, #f7faf8 0%, #edf6f2 100%);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.6rem;
}

.brand-mark {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto;
  border-radius: 1.4rem;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 850;
  font-size: 2.2rem;
  box-shadow: var(--shadow);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 0.8rem;
  background: rgba(247, 250, 248, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(220, 232, 228, 0.7);
}

.brand {
  display: flex;
  gap: 0.7rem;
  align-items: center;
}

.brand-badge {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.75rem;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 850;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.05;
}

.brand p,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.main {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hero-row,
.toolbar,
.dose-actions,
.form-row,
.pill-row,
.card-title,
.auth-tabs,
.modal-actions,
.review-grid,
.setting-row {
  display: flex;
  gap: 0.75rem;
}

.hero-row,
.toolbar,
.card-title,
.setting-row {
  align-items: center;
  justify-content: space-between;
}

.toolbar {
  flex-wrap: wrap;
  margin: 1rem 0;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.segmented button,
.tab-btn {
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0.58rem 0.8rem;
  font-weight: 750;
  min-height: 2.45rem;
}

.segmented button.active,
.tab-btn.active {
  background: var(--brand);
  color: #fff;
}

.primary,
.secondary,
.ghost,
.danger,
.icon-button {
  min-height: 2.85rem;
  border-radius: 0.85rem;
  padding: 0.72rem 1rem;
  font-weight: 800;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary {
  color: #fff;
  background: var(--brand);
  box-shadow: 0 10px 22px rgba(20, 125, 115, 0.24);
}

.secondary {
  color: var(--brand-strong);
  background: var(--surface-soft);
}

.ghost {
  color: var(--brand-strong);
  background: transparent;
}

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

.icon-button {
  width: 2.85rem;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

button:active {
  transform: translateY(1px);
}

.card,
.dose-card,
.empty,
.notice,
.auth-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  box-shadow: 0 10px 30px rgba(23, 51, 47, 0.06);
}

.card,
.empty,
.notice,
.auth-card {
  padding: 1rem;
}

.stack {
  display: grid;
  gap: 0.75rem;
}

.dose-card {
  padding: 0.9rem;
  display: grid;
  grid-template-columns: 5.8rem minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
}

.dose-time {
  display: grid;
  place-items: center;
  min-height: 4.2rem;
  border-radius: 0.8rem;
  background: var(--surface-soft);
  font-weight: 850;
  color: var(--brand-strong);
  white-space: nowrap;
  font-size: 0.95rem;
}

.dose-body h3,
.card h3,
.auth-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.02rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  border-radius: 999px;
  padding: 0.24rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
}

.status.pending {
  color: #205a89;
  background: #e8f3ff;
}

.status.now {
  color: #6c4300;
  background: #fff1cc;
}

.status.unregistered,
.status.review {
  color: var(--warning);
  background: #fff5df;
}

.status.taken {
  color: var(--ok);
  background: #e7f7ef;
}

.status.skipped,
.status.cancelled {
  color: var(--danger);
  background: #fdeceb;
}

.dose-actions {
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.2rem;
  padding: 0.45rem 0.6rem max(0.45rem, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.nav-item {
  display: grid;
  gap: 0.15rem;
  place-items: center;
  min-height: 3.2rem;
  border-radius: 0.8rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.nav-item.active {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.nav-icon {
  font-size: 1.2rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field label {
  color: var(--ink);
  font-weight: 780;
  font-size: 0.88rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 2.85rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 0.72rem 0.8rem;
  color: var(--ink);
  background: #fff;
}

.field textarea {
  min-height: 5rem;
  resize: vertical;
}

.form-row {
  align-items: start;
}

.form-row > * {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: end;
  background: rgba(18, 42, 38, 0.42);
}

.modal.open {
  display: flex;
}

.modal-panel {
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  border-radius: 1.3rem 1.3rem 0 0;
  background: var(--bg);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.modal-panel.wide {
  max-width: 860px;
  margin: 0 auto;
  border-radius: 1.3rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.18rem;
}

.modal-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.auth-wrap {
  min-height: 100vh;
  padding: 1rem;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(460px, 100%);
}

.auth-tabs {
  margin: 1rem 0;
}

.auth-tabs button {
  flex: 1;
}

.prescription-img {
  width: 100%;
  max-height: 18rem;
  object-fit: contain;
  border-radius: 0.8rem;
  border: 1px solid var(--line);
  background: #fff;
}

.review-grid {
  flex-wrap: wrap;
}

.review-grid .field {
  min-width: min(100%, 14rem);
  flex: 1;
}

.medication-editor {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.85rem;
  background: #fff;
}

.fab {
  position: fixed;
  right: 1rem;
  bottom: 5.1rem;
  z-index: 20;
  border-radius: 999px;
  padding: 0 1.1rem;
  min-height: 3.3rem;
  box-shadow: 0 15px 30px rgba(20, 125, 115, 0.28);
}

.toast-root {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 5.4rem;
  z-index: 50;
  display: grid;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  margin: 0 auto;
  width: min(520px, 100%);
  padding: 0.8rem 0.9rem;
  border-radius: 0.9rem;
  background: #17332f;
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.skeleton {
  min-height: 4.5rem;
  border-radius: 0.9rem;
  background: linear-gradient(90deg, #eef7f3, #ffffff, #eef7f3);
  background-size: 180% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    background-position: -180% 0;
  }
}

@media (min-width: 760px) {
  .main {
    padding-bottom: 2rem;
  }

  .bottom-nav {
    left: 50%;
    right: auto;
    bottom: 1rem;
    width: min(620px, calc(100% - 2rem));
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 1.2rem;
    box-shadow: var(--shadow);
  }

  .fab {
    right: calc((100% - min(980px, 100%)) / 2 + 1rem);
    bottom: 1.3rem;
  }

  .modal {
    align-items: center;
    padding: 1rem;
  }

  .modal-panel {
    max-width: 720px;
    margin: 0 auto;
    border-radius: 1.3rem;
  }
}
