/* Rotina - sistema visual proprio. Clean, calmo, denso sem parecer cheio. */

/* ---------- Tokens ---------- */
:root {
  --bg: #FBFBFA;
  --surface: #FFFFFF;
  --surface-2: #F2F2F0;
  --text: #17171A;
  --text-soft: #55555C;
  --muted: #8A8A93;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --accent: #2F6BFF;
  --accent-soft: rgba(47, 107, 255, 0.10);
  --positive: #1B7F4B;
  --negative: #B3392F;

  --radius-card: 14px;
  --radius-ctrl: 10px;
  --radius-pill: 999px;
  --pad-screen: 16px;
  --pad-card: 20px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --header-h: 52px;
  --tabbar-h: 56px;
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E0E10;
    --surface: #17171A;
    --surface-2: #1F1F23;
    --text: #F4F4F5;
    --text-soft: #B4B4BC;
    --muted: #78787F;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #6E9BFF;
    --accent-soft: rgba(110, 155, 255, 0.14);
    --positive: #4ECB84;
    --negative: #FF6B5E;
  }
}

:root[data-theme="dark"] {
  --bg: #0E0E10;
  --surface: #17171A;
  --surface-2: #1F1F23;
  --text: #F4F4F5;
  --text-soft: #B4B4BC;
  --muted: #78787F;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #6E9BFF;
  --accent-soft: rgba(110, 155, 255, 0.14);
  --positive: #4ECB84;
  --negative: #FF6B5E;
}

:root[data-theme="light"] {
  --bg: #FBFBFA;
  --surface: #FFFFFF;
  --surface-2: #F2F2F0;
  --text: #17171A;
  --text-soft: #55555C;
  --muted: #8A8A93;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --accent: #2F6BFF;
  --accent-soft: rgba(47, 107, 255, 0.10);
  --positive: #1B7F4B;
  --negative: #B3392F;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* impede zoom do Safari ao focar */
  color: inherit;
}

button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
img { max-width: 100%; }
svg { display: block; }

.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Shell ---------- */
#app {
  max-width: 640px;
  margin: 0 auto;
  padding-top: calc(var(--header-h) + var(--sat));
  padding-bottom: calc(var(--tabbar-h) + var(--sab) + 8px);
  min-height: 100vh;
}

#hdr {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  height: calc(var(--header-h) + var(--sat));
  padding: var(--sat) var(--pad-screen) 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

#hdr-title {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#hdr-title.long { font-size: 15px; font-weight: 600; text-transform: capitalize; }

#hdr-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  color: var(--text-soft);
}
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.75; fill: none; }
.icon-btn:active { background: var(--surface-2); }

.sync-ind {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  white-space: nowrap;
}
.sync-ind.pending { color: var(--negative); border-color: var(--negative); }
.sync-ind.offline { color: var(--muted); }

/* ---------- View ---------- */
#view {
  padding: 12px var(--pad-screen) 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.section-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.caption { font-size: 13px; color: var(--text-soft); }
.big-value {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.pos { color: var(--positive); }
.neg { color: var(--negative); }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--pad-card);
}
.card.tight { padding: 14px 16px; }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--surface-2); }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.row:first-child { border-top: none; }
.row .grow { flex: 1; min-width: 0; }
.row .row-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .row-sub { font-size: 13px; color: var(--muted); }
.row.done .row-title { text-decoration: line-through; opacity: .45; }
.row.done .row-sub { opacity: .45; }

/* checkbox grande */
.chk {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1.75px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: transparent;
  transition: background .15s ease-out, border-color .15s ease-out;
}
.chk svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2.5; fill: none; }
.chk.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tap-target { min-width: 44px; min-height: 44px; display: grid; place-items: center; }

/* ---------- Pills / chips ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  white-space: nowrap;
}
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.warn { border-color: var(--border-strong); color: var(--text-soft); }
.pill.pos { color: var(--positive); border-color: currentColor; }
.pill.neg { color: var(--negative); border-color: currentColor; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  font-size: 14px;
  color: var(--text-soft);
  white-space: nowrap;
}
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* ---------- Botoes ---------- */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--border-strong);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s ease-out, opacity .15s ease-out;
}
.btn:active { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:active { opacity: .85; background: var(--accent); }
.btn-ghost { border-color: transparent; color: var(--accent); }
.btn-danger { border-color: var(--negative); color: var(--negative); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .4; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.link-btn { color: var(--accent); font-weight: 600; font-size: 14px; min-height: 44px; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="url"], input:not([type]), select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-ctrl);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 72px; resize: vertical; line-height: 1.5; }
input:focus, select, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A8A93' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 34px;
}
.input-big { font-size: 30px !important; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 56px; }
.field-inline { display: flex; gap: 10px; }
.field-inline > .field { flex: 1; }

.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-ctrl);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  min-height: 38px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.04); }

/* ---------- Progresso ---------- */
.bar {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width .2s ease-out;
}

/* ---------- Meta numerica (Hoje) ---------- */
.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.goal-card.met { background: var(--accent-soft); border-color: transparent; }
.goal-top { display: flex; align-items: center; gap: 12px; }
.goal-info { flex: 1; min-width: 0; }
.goal-name { font-size: 15px; font-weight: 600; }
.goal-count { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.goal-count small { font-size: 13px; font-weight: 500; color: var(--muted); }
.goal-btns { display: flex; align-items: center; gap: 8px; }
.round-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  border: 1.75px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 22px;
  font-weight: 500;
}
.round-btn.plus { background: var(--accent); border-color: var(--accent); color: #fff; }
.round-btn.minus { width: 36px; height: 36px; font-size: 18px; color: var(--muted); }
.round-btn:active { opacity: .8; }
.round-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.5; fill: none; }

.ticks { display: flex; gap: 4px; }
.ticks > i {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.ticks > i.on { background: var(--accent); border-color: var(--accent); }
.goal-card.met .ticks > i { background: var(--accent); border-color: var(--accent); opacity: .5; }
.goal-card.met .ticks > i.on { opacity: 1; }

/* ---------- Grid de historico (Habitos) ---------- */
.hgrid { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; }
.hgrid > i {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: transparent;
}
.hgrid > i.full { background: var(--accent); border-color: var(--accent); }
.hgrid > i.part { background: var(--accent); border-color: var(--accent); }
.hgrid > i.future { border-color: var(--border); opacity: .4; }

.stat-pair { display: flex; gap: 20px; }
.stat { flex: 1; }
.stat .stat-num { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .stat-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- Barras por categoria (Grana) ---------- */
.catbars { display: flex; flex-direction: column; gap: 10px; }
.catbar { display: flex; flex-direction: column; gap: 5px; }
.catbar.dim { opacity: .4; }
.catbar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.catbar-top .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.catbar-track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.catbar-track > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- Resumo 4 numeros ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini {
  background: var(--surface-2);
  border-radius: var(--radius-ctrl);
  padding: 12px 14px;
}
.mini .mini-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mini .mini-val { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -0.01em; }

/* ---------- Month picker ---------- */
.monthnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.monthnav .mlabel { font-size: 16px; font-weight: 600; text-transform: capitalize; }
.monthnav button { width: 44px; height: 44px; display: grid; place-items: center; color: var(--text-soft); border-radius: var(--radius-pill); }
.monthnav button:active { background: var(--surface-2); }
.monthnav button svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; }

/* ---------- Calendario ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .dow {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 4px 0;
}
.cal .day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.cal .day.other { opacity: .3; }
.cal .day.today { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.cal .day.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal .day.empty { visibility: hidden; }

/* ---------- Banner ---------- */
.banner {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-card);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.banner svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.75; fill: none; flex-shrink: 0; margin-top: 1px; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  max-width: 640px;
  margin: 0 auto;
  height: calc(var(--tabbar-h) + var(--sab));
  padding-bottom: var(--sab);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}
#tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  position: relative;
  min-height: 44px;
}
#tabbar a svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.75; fill: none; }
#tabbar a.active { color: var(--accent); }
#tabbar a .badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 8px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: max(var(--pad-screen), calc((100vw - 640px) / 2 + var(--pad-screen)));
  bottom: calc(var(--tabbar-h) + var(--sab) + 16px);
  z-index: 45;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  transition: transform .15s ease-out;
}
.fab:active { transform: scale(0.92); }
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.25; fill: none; }

/* ---------- Sheet ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity .2s ease-out;
}
.scrim.show { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 8px var(--pad-screen) calc(var(--sab) + 20px);
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .22s ease-out;
  -webkit-overflow-scrolling: touch;
}
.sheet.show { transform: translateY(0); }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 6px auto 14px; }
.sheet h2 { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.sheet .field { margin-bottom: 14px; }
.sheet-tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.sheet-tabs::-webkit-scrollbar { display: none; }
.sheet-tabs button {
  flex: 1;
  min-width: max-content;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
}
.sheet-tabs button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.45);
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  padding: 22px;
  max-width: 380px;
  width: 100%;
}
.modal-box h3 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: var(--text-soft); margin-bottom: 18px; }
.modal-box .btn-row { margin-top: 4px; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--sab) + 84px);
  z-index: 70;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding: 0 var(--pad-screen);
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-pill);
  padding: 10px 8px 10px 18px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: toast-in .2s ease-out;
}
.toast button {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

/* ---------- Util ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.rowflex { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.muted { color: var(--muted); }
.soft { color: var(--text-soft); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }
.divlist > * + * { border-top: 1px solid var(--border); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
