:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #15201b;
  --muted: #64716b;
  --border: #dfe5e2;
  --accent: #16a34a;
  --accent-strong: #12823c;
  --accent-soft: #dcf3e4;
  --warn: #d97706;
  --warn-soft: #fdf0d9;
  --danger: #dc2626;
  --danger-soft: #fde4e4;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #18201c;
    --surface-2: #212b26;
    --text: #e8eeeb;
    --muted: #93a19a;
    --border: #2a3530;
    --accent: #22c55e;
    --accent-strong: #4ade80;
    --accent-soft: #163a25;
    --warn: #f59e0b;
    --warn-soft: #3b2d12;
    --danger: #f87171;
    --danger-soft: #3d1a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Desliga o zoom por toque duplo do Safari (pinça continua funcionando) */
html, body, button, a, label, input, select { touch-action: manipulation; }
/* Botões não selecionam texto nem abrem o menu de "copiar" ao segurar */
button, .tab, .dose, .cal-day, .list-row {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
em { font-style: normal; }

.page-header { padding: 8px 4px 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.stack > * + * { margin-top: 12px; }

/* Botões */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  min-height: 46px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; margin-top: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { flex: 1 1 0; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  border: 0; background: var(--surface-2);
  display: grid; place-items: center; flex: none;
}
.icon-btn:disabled { opacity: .3; }
.chip {
  border: 0; border-radius: 999px; padding: 6px 12px;
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; font-size: 14px;
  margin-left: auto;
}

/* Cabeçalho do dia */
.day-header { display: flex; align-items: center; gap: 12px; padding: 8px 0 16px; }
.day-heading { flex: 1; text-align: center; min-width: 0; }
.day-heading p { color: var(--muted); font-size: 15px; }

.progress-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px;
}
.progress-card p { color: var(--muted); font-size: 14px; }
.ring { position: relative; width: 56px; height: 56px; flex: none; }
.ring svg { width: 56px; height: 56px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .35s ease; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; }

/* Itens do dia */
.item-card { padding: 14px; }
.item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.item-emoji { font-size: 24px; width: 36px; text-align: center; }
.item-head h2 { font-size: 17px; }
.item-head .count { margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.doses { display: grid; gap: 8px; }
.dose {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 1.5px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 12px; text-align: left; min-height: 60px;
  transition: background .15s, border-color .15s;
}
.dose:active { transform: scale(.99); }
.dose-check {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); display: grid; place-items: center; color: transparent;
}
.dose-check svg { width: 18px; height: 18px; stroke-width: 3; }
.dose-text { display: flex; flex-direction: column; min-width: 0; }
.dose-text strong { font-size: 16px; }
.dose-text small { color: var(--muted); font-size: 13px; }
.dose.taken { background: var(--accent-soft); border-color: transparent; }
.dose.taken .dose-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.dose.taken small { color: var(--accent-strong); }
.dose.late:not(.taken) small { color: var(--warn); }

.empty-state { text-align: center; padding: 32px 16px; color: var(--muted); }

/* Histórico */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat strong { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.calendar-card { margin-bottom: 12px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-week span { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal-day {
  aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--surface-2);
  font-size: 15px; font-weight: 600; display: grid; place-items: center; padding: 0;
  font-variant-numeric: tabular-nums;
}
.cal-day.full { background: var(--accent); color: #fff; }
.cal-day.partial { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 2px var(--warn); }
.cal-day.empty { background: var(--danger-soft); color: var(--danger); }
.cal-day.before, .cal-day.future, .cal-day.none { background: transparent; color: var(--muted); font-weight: 400; }
.cal-day.future { opacity: .4; }
.cal-day.today { outline: 2px solid var(--text); outline-offset: 2px; }
.cal-day.blank { visibility: hidden; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.dot.full { background: var(--accent); }
.dot.partial { background: var(--warn-soft); box-shadow: inset 0 0 0 2px var(--warn); }
.dot.empty { background: var(--danger-soft); }

.adh-row { display: flex; align-items: center; gap: 10px; }
.adh-row + .adh-row { margin-top: 12px; }
.adh-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adh-row .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Ajustes */
.list { padding: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; border: 0; background: transparent; text-align: left; }
.list-row + .list-row { border-top: 1px solid var(--border); }
.list-row .item-emoji { font-size: 22px; }
.list-row .meta { flex: 1; min-width: 0; }
.list-row .meta small { display: block; color: var(--muted); font-size: 13px; }
.list-row .chev { color: var(--muted); width: 20px; height: 20px; }
.status { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status.on::before { background: var(--accent); }
.status.warn::before { background: var(--warn); }
.steps { margin: 8px 0 0; padding-left: 20px; font-size: 14px; }
.steps li + li { margin-top: 4px; }

/* Formulários e dialogs */
.sheet {
  border: 0; padding: 0; width: min(520px, calc(100% - 24px));
  background: var(--surface); color: var(--text); border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(10, 15, 12, .45); }
.sheet form { padding: 20px; }
.sheet h2 { font-size: 20px; margin-bottom: 4px; }
.field { display: block; margin-top: 16px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.field input, .field select {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--bg); padding: 10px 12px; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-row .field-emoji { flex: 0 0 76px; }
.field-emoji input { text-align: center; font-size: 22px; }
.times { display: grid; gap: 8px; }
.time-row { display: flex; align-items: center; gap: 8px; }
.time-row label { flex: 0 0 64px; font-size: 14px; color: var(--muted); }
.time-row input { flex: 1; width: auto; }
.time-row .icon-btn { width: 40px; height: 40px; }
.time-row .icon-btn svg { width: 18px; height: 18px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 186px; height: var(--tabbar-h); border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--accent); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; transition: opacity .2s, transform .2s; z-index: 20;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Telas cheias: boas-vindas e aviso do Instagram */
.overlay {
  position: fixed; inset: 0; z-index: 30; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.overlay-body { max-width: 480px; margin: 0 auto; text-align: center; }
.overlay-body > * + * { margin-top: 16px; }
.overlay-body .card, .overlay-body .features { text-align: left; }
.overlay-icon { width: 72px; height: 72px; border-radius: 18px; box-shadow: var(--shadow); }
.overlay h1 { font-size: 30px; }
.lead { font-size: 17px; color: var(--muted); }
.features { list-style: none; padding: 0; margin-left: auto; margin-right: auto; display: grid; gap: 10px; }
.features li { display: flex; gap: 12px; align-items: center; font-size: 16px; }
.features span { font-size: 22px; width: 28px; text-align: center; flex: none; }
.install-card h2 { font-size: 16px; margin-bottom: 8px; }
.install-card + .privacy-text { padding: 0 4px; }
.big-steps { font-size: 16px; padding-left: 22px; margin: 0; }
.big-steps li + li { margin-top: 10px; }
.kbd {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 8px;
  background: var(--surface-2); font-weight: 600; white-space: nowrap;
}
.kbd svg { width: 16px; height: 16px; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; font-size: 14px; padding: 12px; }
.privacy-text { line-height: 1.5; }
