/* Mini App do Constâncio. Mobile-first; cores vêm do tema do Telegram
   (variáveis --tg-theme-*), com fallback em verde escuro do Clube. */

:root {
  --brand: #1b4d3e;
  --bg: var(--tg-theme-bg-color, #f4f6f5);
  --bg-2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15201c);
  --hint: var(--tg-theme-hint-color, #6b7a74);
  --link: var(--tg-theme-link-color, #1b4d3e);
  --button: var(--tg-theme-button-color, #1b4d3e);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section: var(--tg-theme-section-bg-color, var(--bg-2));
  --divider: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
  --ok: #2e8b57;
  --warn: #c0392b;
  --radius: 14px;
  --gap: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #10201a);
    --bg-2: var(--tg-theme-secondary-bg-color, #182d25);
    --text: var(--tg-theme-text-color, #eef3f0);
    --hint: var(--tg-theme-hint-color, #93a69e);
    --divider: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.1));
    --ok: #5fcf8f;
    --warn: #ff7b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 22px; }
h2 { font-size: 17px; margin-bottom: 8px; }
p { margin: 0 0 8px; }
.hint { color: var(--hint); font-size: 13px; }
.hidden { display: none !important; }

/* telas cheias */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.screen-card { text-align: center; max-width: 360px; }
.screen-card h1 { margin: 8px 0 12px; }
.screen-icon { font-size: 48px; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto 12px;
  border: 3px solid var(--divider); border-top-color: var(--button);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* layout principal */
#main { padding: 12px 16px calc(84px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; }
.page { padding: 12px 16px calc(24px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; }

/* cadastro (questionário de entrada) */
.q-block { scroll-margin-top: 12px; }
.q-block .q-text { display: block; font-weight: 600; margin-bottom: 6px; }
.q-block .q-help { margin: -2px 0 8px; white-space: pre-line; }
.q-block .q-help a { color: var(--link); }
.q-block.has-error { box-shadow: 0 0 0 2px var(--warn) inset; }
.q-block.has-error .input { border-color: var(--warn); }
.q-block .q-opt { color: var(--hint); font-weight: 500; font-size: 13px; }
.q-block.skipped .q-control { opacity: 0.45; pointer-events: none; }
.q-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn-link {
  background: none; border: 0; color: var(--link); font-size: 14px; font-weight: 600;
  padding: 6px 8px; min-height: 0; cursor: pointer;
}
textarea.input { min-height: 84px; resize: vertical; font-family: inherit; line-height: 1.35; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--divider); border-radius: 999px; background: var(--bg-2); color: var(--text);
  padding: 9px 14px; min-height: 42px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.chip.selected { background: var(--button); color: var(--button-text); border-color: var(--button); }
.chip.selected::before { content: "✓ "; }
.cadastro-intro h1 { margin-bottom: 6px; }
.cadastro-footer { text-align: center; margin: 4px 0 16px; }
.step-count { color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

/* Pix */
.pix-value { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 2px; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row .input { flex: 1; min-width: 0; font-size: 14px; word-break: break-all; }
.copy-row textarea.input { min-height: 96px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.copy-row .btn { flex: 0 0 auto; align-self: flex-start; }
.done-icon { font-size: 52px; text-align: center; margin: 8px 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.streak-pill {
  background: var(--button); color: var(--button-text);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.streak-pill.risk { background: var(--bg-2); color: var(--text); border: 1px solid var(--divider); }

.card {
  background: var(--section);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.card.accent { background: var(--button); color: var(--button-text); }
.card.accent .hint { color: inherit; opacity: 0.85; }
.summary-text { white-space: pre-line; font-size: 16px; }

/* formulário */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { margin-top: 4px; }
.input {
  width: 100%; font-size: 18px; padding: 12px 14px;
  border: 1px solid var(--divider); border-radius: 12px;
  background: var(--bg-2); color: var(--text); outline: none;
}
.input:focus { border-color: var(--button); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.input-row .btn { flex: 0 0 auto; }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented button {
  flex: 1 1 0; min-width: 72px; min-height: 46px; padding: 8px 10px;
  border: 1px solid var(--divider); border-radius: 12px;
  background: var(--bg-2); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer;
}
.segmented button.selected { background: var(--button); color: var(--button-text); border-color: var(--button); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 10px 18px; border-radius: 12px; border: 0;
  font-size: 17px; font-weight: 700; cursor: pointer;
  background: var(--bg-2); color: var(--text);
}
.btn-primary { background: var(--button); color: var(--button-text); width: 100%; }
.btn-secondary { border: 1px solid var(--divider); width: 100%; }
.btn-small { min-height: 40px; font-size: 15px; padding: 6px 14px; width: auto; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.actions { display: flex; gap: 8px; margin-top: 8px; }

/* cards de estatística */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-bottom: var(--gap); }
.stat { background: var(--section); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 2px; }
.stat .sub { color: var(--hint); font-size: 12px; }
.value.ok { color: var(--ok); }
.value.warn { color: var(--warn); }

/* listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--divider);
}
.list li:last-child { border-bottom: 0; }
.list .date { color: var(--hint); font-size: 14px; }
.list .val { font-weight: 700; }
.list .delta { color: var(--hint); font-size: 13px; margin-left: 8px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.kv .k { color: var(--hint); }
.kv .v { font-weight: 600; text-align: right; }

canvas.chart { width: 100%; height: 200px; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* abas */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--section);
  border-top: 1px solid var(--divider);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  z-index: 10;
}
.tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; color: var(--hint); font-size: 12px; font-weight: 600;
  padding: 6px 0; cursor: pointer; border-radius: 10px;
}
.tabs button.active { color: var(--button); }
.tab-icon { font-size: 20px; }

/* toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(90px + var(--safe-bottom));
  background: var(--text); color: var(--bg);
  padding: 12px 14px; border-radius: 12px; font-size: 15px; z-index: 20;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--warn); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.inline-error { color: var(--warn); font-size: 14px; margin-top: 6px; }
