:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --ink: #16231b;
  --muted: #667269;
  --line: #dfe5df;
  --green: #276447;
  --green-light: #e3f0e8;
  --amber: #9a560d;
  --amber-light: #fff0d6;
  --red: #a53a32;
  --red-light: #fee9e6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  background: rgba(244, 246, 242, .92);
  backdrop-filter: blur(14px);
}

.eyebrow { margin: 0 0 3px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 0; font-size: 27px; letter-spacing: -.04em; }
h2 { margin: 0; }

main { width: min(100%, 680px); margin: 0 auto; padding: 8px 16px calc(34px + env(safe-area-inset-bottom)); }

.primary {
  border: 0;
  border-radius: 13px;
  padding: 13px 18px;
  background: var(--green);
  color: white;
  font-weight: 750;
}
.primary.compact { padding: 10px 15px; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.summary-card { padding: 15px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.summary-card.alert { border-color: #efd29c; background: var(--amber-light); }
.summary-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 650; }
.summary-value { font-size: 24px; font-weight: 800; }

.supplement-list { display: grid; gap: 12px; }
.card { overflow: hidden; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: 0 2px 10px rgba(30, 50, 38, .035); }
.card.needs-order { border-color: #ebbd70; }
.card-main { padding: 17px 17px 14px; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card h2 { font-size: 18px; letter-spacing: -.02em; }
.frequency { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.badge { flex: none; padding: 6px 9px; border-radius: 999px; background: var(--green-light); color: var(--green); font-size: 12px; font-weight: 800; }
.badge.warning { background: var(--amber-light); color: var(--amber); }
.badge.empty { background: var(--red-light); color: var(--red); }
.stock-line { display: flex; align-items: baseline; margin: 18px 0 14px; }
.stock-number { font-size: 34px; font-weight: 850; letter-spacing: -.05em; }
.stock-unit { margin-left: 5px; color: var(--muted); font-size: 13px; }
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: #edf0ed; }
.progress span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.needs-order .progress span { background: #d18127; }
.depleted .progress span { background: var(--red); }
.details { display: grid; grid-template-columns: 1fr 1fr; margin-top: 15px; }
.detail + .detail { padding-left: 14px; border-left: 1px solid var(--line); }
.detail span { display: block; color: var(--muted); font-size: 11px; }
.detail strong { display: block; margin-top: 3px; font-size: 14px; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.card-actions button { min-height: 47px; border: 0; background: white; color: var(--green); font-weight: 750; }
.card-actions button + button { border-left: 1px solid var(--line); }

.empty-state { margin-top: 44px; padding: 24px; text-align: center; }
.empty-icon { margin-bottom: 12px; color: #83a18e; font-size: 54px; line-height: 1; }
.empty-state h2 { font-size: 20px; }
.empty-state p { max-width: 340px; margin: 10px auto 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }

dialog { width: min(100%, 620px); max-height: 92vh; margin: auto auto 0; padding: 0; border: 0; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(15, 25, 18, .42); backdrop-filter: blur(2px); }
.dialog-header { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.dialog-header h2 { font-size: 17px; }
.text-button { padding: 5px 0; border: 0; background: none; color: var(--muted); text-align: left; }
.text-button.save { color: var(--green); font-weight: 800; text-align: right; }
.form-body { display: grid; gap: 14px; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field, fieldset { min-width: 0; }
.field span, legend { display: block; margin: 0 0 7px; color: #435148; font-size: 13px; font-weight: 700; }
.field small { color: var(--muted); font-weight: 500; }
.field input { width: 100%; min-height: 48px; padding: 11px 12px; border: 1px solid #d7ded8; border-radius: 12px; outline: none; background: white; color: var(--ink); font-size: 16px; }
.field input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(39, 100, 71, .1); }
fieldset { margin: 2px 0 0; padding: 0; border: 0; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 12px; background: #e5e9e5; }
.segmented input, .weekday-picker input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 10px 4px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 700; text-align: center; }
.segmented input:checked + span { background: white; color: var(--green); box-shadow: 0 1px 4px rgba(20,40,27,.12); }
.weekday-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.weekday-picker span { display: grid; aspect-ratio: 1; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--muted); font-size: 13px; font-weight: 700; }
.weekday-picker input:checked + span { border-color: var(--green); background: var(--green); color: white; }
.people-section { margin-top: 2px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.outline-button { flex: none; padding: 8px 10px; border: 1px solid #b9cbbf; border-radius: 10px; background: white; color: var(--green); font-size: 12px; font-weight: 750; }
.people-list { display: grid; gap: 11px; }
.person-card { display: grid; gap: 13px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.person-card-header { display: flex; justify-content: space-between; align-items: center; }
.person-number { font-size: 14px; }
.remove-person { padding: 3px 0; border: 0; background: transparent; color: var(--red); font-size: 12px; }
.interval-settings { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }
.input-with-unit { display: flex; align-items: center; gap: 7px; }
.input-with-unit input { min-width: 0; }
.input-with-unit span { flex: none; margin: 0; color: var(--muted); font-size: 12px; }
.people-summary { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.danger-button { margin-top: 8px; padding: 13px; border: 0; background: transparent; color: var(--red); font-weight: 700; }
.backup-panel { margin-top: 26px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.backup-panel h2 { font-size: 16px; }
.backup-panel p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.backup-actions button { flex: 1 1 220px; min-height: 48px; font-size: 14px; }
#backupStatus { color: var(--green); overflow-wrap: anywhere; }
[hidden] { display: none !important; }

@media (min-width: 621px) {
  .app-header { width: min(100%, 720px); margin: 0 auto; }
  dialog { margin: auto; border-radius: 22px; }
}

@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: slide-up .22s ease-out; }
  @keyframes slide-up { from { transform: translateY(24px); opacity: .5; } }
}
