:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #edf4f2;
  --ink: #19322e;
  --muted: #6f817d;
  --line: #dce6e3;
  --primary: #2f776b;
  --primary-dark: #235c53;
  --primary-soft: #dcece8;
  --danger: #a74646;
  --danger-soft: #f8e9e7;
  --shadow: 0 10px 30px rgba(34, 71, 64, 0.08);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 0%, rgba(166, 207, 196, 0.24), transparent 34%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 640px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 16px calc(36px + var(--safe-bottom));
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 4px 20px;
}

.hero__icon {
  display: grid;
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  place-items: center;
  border: 1px solid rgba(47, 119, 107, 0.12);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 26px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 3px;
  font-size: clamp(28px, 8vw, 36px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.eyebrow,
.label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--primary);
}

.hero__caption {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.68);
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(34, 71, 64, 0.08);
}

.view {
  animation: reveal 180ms ease-out;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid rgba(220, 230, 227, 0.9);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card--flat {
  box-shadow: none;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 13px;
  padding-bottom: 13px;
}

.profile-row > div {
  min-width: 0;
  flex: 1;
}

.profile-row select {
  max-width: 100%;
  padding: 0 28px 0 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
}

.icon-button,
.close-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--surface-soft);
  cursor: pointer;
}

.latest-card {
  display: flex;
  min-height: 146px;
  align-items: flex-end;
  justify-content: space-between;
  overflow: hidden;
  background:
    radial-gradient(circle at 88% 18%, rgba(255, 255, 255, 0.28), transparent 23%),
    linear-gradient(145deg, #2f776b, #438b7d);
  color: #fff;
}

.latest-card .label {
  color: rgba(255, 255, 255, 0.72);
}

.latest-card__value {
  display: block;
  font-size: clamp(48px, 16vw, 72px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.065em;
}

.latest-card__time {
  max-width: 42%;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  line-height: 1.4;
  text-align: right;
}

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

.primary-action,
.secondary-action,
.submit-button,
.danger-action,
.confirm-action {
  min-height: 52px;
  padding: 12px 15px;
  border-radius: 16px;
  font-weight: 750;
  cursor: pointer;
}

.primary-action {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.secondary-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary-action span,
.secondary-action span {
  display: inline-block;
  margin-right: 4px;
  font-size: 18px;
}

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

.section-heading--outside {
  margin: 22px 4px 10px;
}

.count-pill {
  display: grid;
  min-width: 32px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
}

#temperature-chart {
  display: block;
  width: 100%;
  height: 172px;
  overflow: visible;
}

.chart-grid {
  stroke: #e6eeec;
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 10px;
}

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-dot {
  fill: #fff;
  stroke: var(--primary);
  stroke-width: 2.5;
}

.history-list {
  display: grid;
  gap: 9px;
}

.history-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.75);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.history-item:focus-visible {
  outline: 3px solid rgba(47, 119, 107, 0.18);
  outline-offset: 2px;
}

.history-item:active {
  background: var(--surface-soft);
}

.history-item__icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 14px;
  background: var(--primary-soft);
  font-size: 20px;
}

.history-item--medication .history-item__icon {
  background: #f0ecdf;
}

.history-item__content {
  min-width: 0;
}

.history-item__title {
  display: block;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item__meta,
.history-item__note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.history-item__note {
  overflow-wrap: anywhere;
}

.edit-entry {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  color: var(--primary-dark);
  font-size: 19px;
}

.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  align-content: center;
  padding: 22px;
  border: 1px dashed #cedbd7;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state span {
  margin-bottom: 8px;
  font-size: 28px;
}

.empty-state strong {
  color: var(--ink);
}

.empty-state p {
  margin: 5px 0 0;
  font-size: 13px;
}

.empty-state--compact {
  min-height: 118px;
  padding: 16px;
  font-size: 13px;
}

.text-button {
  padding: 5px;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.text-button--danger {
  color: var(--danger);
}

.info-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--primary-soft);
}

.info-card__icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
}

.info-card p,
.legal-card p,
.support-card p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.stacked-actions {
  display: grid;
  gap: 8px;
}

.list-action {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 12px 8px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.list-action:first-child {
  border-top: 0;
}

.list-action strong,
.list-action small {
  display: block;
}

.list-action small {
  margin-top: 3px;
  color: var(--muted);
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 13px;
}

.legal-links a {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}

.danger-action {
  width: 100%;
  border: 1px solid #ebccca;
  background: var(--danger-soft);
  color: var(--danger);
}

.sheet {
  width: min(100% - 20px, 600px);
  max-height: calc(100dvh - 20px);
  margin: auto auto 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -20px 60px rgba(25, 50, 46, 0.16);
}

.sheet::backdrop {
  background: rgba(19, 38, 35, 0.4);
  backdrop-filter: blur(2px);
}

.sheet form {
  padding: 8px 18px calc(24px + var(--safe-bottom));
}

.sheet__handle {
  width: 42px;
  height: 4px;
  margin: 4px auto 13px;
  border-radius: 999px;
  background: #d4ddda;
}

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

.close-button {
  font-size: 27px;
  font-weight: 300;
}

.field {
  display: block;
  margin-bottom: 15px;
}

.field > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 720;
}

.field em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: #fbfcfc;
  color: var(--ink);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 119, 107, 0.11);
}

.field small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.temperature-field input {
  height: 68px;
  font-size: 30px;
  font-weight: 730;
  text-align: center;
}

.submit-button {
  width: 100%;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.editor-delete-button {
  width: 100%;
  min-height: 48px;
  margin-top: 9px;
  padding: 11px 15px;
  border: 1px solid #ebccca;
  border-radius: 16px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 750;
  cursor: pointer;
}

.form-error {
  margin: -3px 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
}

.form-hint {
  margin: -2px 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.profiles-list {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.profile-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
}

.profile-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-item__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.profile-item button {
  padding: 7px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.profile-item button.profile-item__edit {
  color: var(--accent-dark);
}

.inline-form {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.inline-form .secondary-action {
  width: 100%;
}

.sheet--confirm {
  width: min(100% - 20px, 480px);
}

.confirm-message {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.confirm-actions {
  display: grid;
  gap: 9px;
}

.confirm-actions button {
  width: 100%;
}

.confirm-action {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.confirm-action.is-danger {
  border-color: var(--danger);
  background: var(--danger);
}

.toast {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  left: 20px;
  max-width: 500px;
  margin: 0 auto;
  padding: 13px 16px;
  border-radius: 15px;
  background: #173b35;
  color: #fff;
  box-shadow: 0 12px 30px rgba(15, 39, 35, 0.25);
  font-size: 13px;
  text-align: center;
}

.print-layout {
  display: none;
}

.document-page {
  width: min(100% - 32px, 720px);
  margin: 0 auto;
  padding: 34px 0 60px;
}

.document-page__back {
  display: inline-block;
  margin-bottom: 24px;
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.document-page .card {
  padding: clamp(20px, 6vw, 38px);
}

.document-page h1 {
  margin-bottom: 12px;
}

.document-page h2 {
  margin: 28px 0 8px;
}

.document-page p,
.document-page li {
  color: #415651;
  font-size: 15px;
  line-height: 1.65;
}

.document-page li + li {
  margin-top: 7px;
}

.document-meta {
  margin-bottom: 24px;
  color: var(--muted) !important;
  font-size: 13px !important;
}

@media (max-width: 390px) {
  .action-grid {
    grid-template-columns: 1fr;
  }

  .latest-card {
    min-height: 134px;
  }

  .history-item {
    grid-template-columns: 40px minmax(0, 1fr) 34px;
    gap: 9px;
  }

  .history-item__icon {
    width: 40px;
    height: 40px;
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 36px;
  }

  .sheet {
    margin: auto;
    border-radius: 26px;
  }
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  .app-shell,
  dialog,
  .toast {
    display: none !important;
  }

  .print-layout {
    display: block;
    padding: 10mm;
  }

  .print-layout h1 {
    margin-bottom: 5mm;
    font-size: 22pt;
  }

  .print-layout p {
    margin: 0 0 2mm;
    font-size: 10pt;
  }

  .print-layout table {
    width: 100%;
    margin-top: 7mm;
    border-collapse: collapse;
    font-size: 9pt;
  }

  .print-layout th,
  .print-layout td {
    padding: 2.5mm;
    border: 0.3mm solid #bbb;
    text-align: left;
    vertical-align: top;
  }

  .print-disclaimer {
    margin-top: 7mm !important;
    color: #555;
    font-size: 8pt !important;
  }
}
