:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --paper: #fff;
  --ink: #172536;
  --muted: #68747f;
  --line: #d8e0dc;
  --green: #2f8658;
  --blue: #294f8e;
  --orange: #bf6a1e;
  --red: #c44a3d;
  --gold: #987a18;
  font-size: 18px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(180deg, #fbfcf8, var(--bg));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; }
.app { width: min(920px, 100%); margin: 0 auto; padding: 18px 14px 36px; }
.top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
h1 { margin: 0; color: var(--blue); font-size: clamp(2.2rem, 9vw, 4rem); line-height: 1.05; }
h2 { margin: 0 0 6px; font-size: 1.35rem; }
#today, .checkin p, .count, .form-msg { color: var(--muted); margin: 6px 0 0; }
.home-actions {
  display: grid;
  gap: 10px;
  margin: 18px 0 12px;
}
.home-action {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 84px;
  padding: 14px;
  text-align: left;
}
.home-action b {
  font-size: 1.25rem;
  line-height: 1.2;
}
.home-action span {
  color: var(--muted);
}
.search-action { border-left: 7px solid var(--blue); }
.check-action { border-left: 7px solid var(--green); }
.med-action { border-left: 7px solid var(--orange); }
.refresh-msg {
  min-height: 1.4em;
  margin: 4px 0 0;
  color: var(--green);
  font-weight: 760;
}
.quiet, .search-row button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  min-height: 48px;
  padding: 0 14px;
}
.refresh-btn {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 850;
}
.notice-grid { display: grid; gap: 12px; margin: 18px 0; }
.notice {
  border: 2px solid;
  border-radius: 8px;
  padding: 14px;
  background: var(--paper);
  line-height: 1.65;
}
.notice p { margin: 6px 0 0; }
.notice.good { border-color: #58ad78; background: #f0fbf4; }
.notice.bad { border-color: #ef6b5a; background: #fff3f1; }
.compact-notice { margin: 12px 0 16px; }
.med-card {
  display: grid;
  gap: 12px;
  align-items: center;
  margin: 16px 0;
  border: 2px solid #88a7d8;
  border-radius: 8px;
  background: #eef5ff;
  padding: 14px;
}
.med-card.due {
  border-color: #ef6b5a;
  background: #fff3f1;
}
.med-card.soon {
  border-color: #e5b350;
  background: #fff8e8;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-weight: 850;
}
.med-date {
  justify-self: start;
  min-width: 112px;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--blue);
  font-size: 1.35rem;
  font-weight: 900;
  text-align: center;
}
.med-card.due .med-date { color: var(--red); }
.med-card.soon .med-date { color: var(--orange); }
.calendar-card {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}
.calendar-card summary, .category-details summary {
  cursor: pointer;
  font-weight: 850;
  color: var(--blue);
}
.calendar-card[open] summary, .category-details[open] summary { margin-bottom: 10px; }
.calendar-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 10px;
}
.calendar-title p { margin: 0; color: var(--muted); }
.dose-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.cal-head {
  color: var(--muted);
  text-align: center;
  font-weight: 800;
  font-size: .9rem;
}
.cal-day {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fafbf8;
  font-weight: 760;
}
.cal-day.window {
  border-color: #e5b350;
  background: #fff8d8;
}
.cal-day.dose {
  border-color: var(--green);
  background: #eaf6ee;
  color: var(--green);
  box-shadow: inset 0 0 0 2px rgba(47, 134, 88, .25);
}
.search-box {
  position: static;
  padding: 10px 0 12px;
  background: transparent;
}
.search-row { display: grid; gap: 8px; }
.search-row input, label input, label textarea, label select {
  width: 100%;
  border: 2px solid #cdd8d2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
}
label textarea { min-height: 86px; resize: vertical; }
.button-block {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.75);
}
.button-block.blue { background: rgba(234,243,251,.78); }
.group-label { margin: 0 0 6px; font-weight: 850; }
.group-label span { color: var(--muted); font-weight: 500; font-size: .92rem; }
.chips, .tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  min-height: 40px;
  padding: 0 14px;
  color: var(--ink);
}
.chip.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  font-weight: 850;
}
.tab.active { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 800; }
.selected-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
}
.selected-filters:empty { display: none; }
.selected-filters b { color: var(--ink); }
.selected-filters span {
  border-radius: 999px;
  background: #eaf6ee;
  color: var(--green);
  padding: 7px 10px;
  font-weight: 850;
}
.results { display: grid; gap: 12px; margin-top: 14px; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 7px solid var(--green);
  border-radius: 8px;
  padding: 14px;
}
.card.limit { border-left-color: var(--orange); }
.card.avoid { border-left-color: var(--red); }
.card.note { border-left-color: var(--gold); }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 1.22rem; }
.category { color: var(--muted); margin: 4px 0 0; }
.badge { border-radius: 999px; padding: 7px 10px; white-space: nowrap; font-weight: 800; background: #eef5f1; color: var(--green); }
.badge.limit { background: #fff3e4; color: var(--orange); }
.badge.avoid { background: #fff0ee; color: var(--red); }
.badge.note { background: #fbf6df; color: var(--gold); }
.info { margin-top: 12px; display: grid; gap: 8px; line-height: 1.6; }
.info b { display: block; color: var(--muted); }
.checkin {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}
.checkin form, .admin-grid section { display: grid; gap: 10px; }
.quick-checkin {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.quick-checkin button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 0 13px;
}
.quick-checkin button.picked {
  border-color: var(--green);
  background: #eaf6ee;
  color: var(--green);
  font-weight: 850;
}
label { display: grid; gap: 6px; font-weight: 760; }
.primary {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  min-height: 50px;
  padding: 0 16px;
  font-weight: 850;
}
dialog {
  width: min(960px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 16px;
}
dialog::backdrop { background: rgba(23,37,54,.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.admin-grid, .admin-actions { display: grid; gap: 12px; }
.admin-list { display: grid; gap: 8px; margin-top: 10px; max-height: 360px; overflow: auto; }
.admin-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; }
.med-admin {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}
.med-admin h3 { margin: 0; }
.two-cols {
  display: grid;
  gap: 10px;
}
.dose-add {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.dose-list {
  display: grid;
  gap: 8px;
}
.dose-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}
.dose-row span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}
.dose-row button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-height: 38px;
  padding: 0 10px;
}
.footer-actions {
  display: flex;
  justify-content: center;
  margin: 24px 0 4px;
}
.install-tip {
  display: grid;
  gap: 6px;
  margin: 22px 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
  padding: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.install-tip[hidden] { display: none; }
.install-tip b { color: var(--ink); }
.install-tip button {
  justify-self: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
}
.admin-link {
  color: var(--muted);
  min-height: 42px;
  font-size: .95rem;
}
@media (min-width: 720px) {
  .home-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .notice-grid, .results, .admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .med-card { grid-template-columns: 1fr auto; }
  .two-cols, .dose-add { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-row, .admin-actions { grid-template-columns: 1fr auto; }
}
@media (max-width: 719px) {
  html {
    scroll-padding-bottom: 132px;
  }
  body {
    padding-bottom: calc(132px + env(safe-area-inset-bottom));
  }
  .app {
    padding-bottom: calc(160px + env(safe-area-inset-bottom));
  }
  .search-box {
    padding-top: 4px;
  }
  .results {
    margin-top: 18px;
    scroll-margin-top: 12px;
  }
  .checkin {
    margin-top: 18px;
  }
}
