/* ==========================================================================
   Calculadora de Compras com Orçamento — estilos
   Mobile-first, sem dependências externas, apenas fontes do sistema.
   ========================================================================== */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #16202a;
  --text-soft: #51606e;
  --border: #d4dde4;
  --brand: #0f766e;
  --brand-strong: #0b5d56;
  --brand-soft: #e3f2f0;
  --ok: #156e3f;
  --ok-soft: #e4f4ea;
  --warn: #8a5a00;
  --warn-soft: #fcf1dc;
  --danger: #b3261e;
  --danger-soft: #fce9e7;
  --focus: #1769ff;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .08), 0 6px 18px rgba(16, 32, 48, .06);
  --tap: 46px;
  --maxw: 760px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --surface: #1a2128;
    --surface-2: #222b33;
    --text: #e9eef2;
    --text-soft: #a3b1bd;
    --border: #313c46;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #16302e;
    --ok: #6ee7a8;
    --ok-soft: #14301f;
    --warn: #fbbf5b;
    --warn-soft: #33260e;
    --danger: #ff9f96;
    --danger-soft: #3a1a17;
    --focus: #8ab4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: break-word;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.25; }

/* Acessibilidade -------------------------------------------------------- */

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  padding: .7rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:where(a, button, input, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Barra superior -------------------------------------------------------- */

.appbar {
  background: var(--brand);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.appbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: .55rem .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.appbar__brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: .45rem;
  font-weight: 700;
  font-size: 1.02rem;
  flex: 1 1 auto;
  min-width: 0;
}
.appbar__mark { display: inline-flex; }
.appbar__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar__actions { display: flex; gap: .25rem; flex: 0 0 auto; }
.appbar .btn--ghost { color: #fff; border-color: rgba(255, 255, 255, .5); }
.appbar .btn--ghost:hover { background: rgba(255, 255, 255, .14); }

/* Layout ---------------------------------------------------------------- */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 .9rem 2rem;
}

.page-title {
  font-size: 1.35rem;
  margin: 1.1rem 0 .4rem;
}
.page-intro {
  margin: 0 0 1rem;
  color: var(--text-soft);
  font-size: .95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card__title { font-size: 1.05rem; margin: 0 0 .75rem; }
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.card__head .card__title { margin: 0; }

/* Resumo financeiro (fixo) ---------------------------------------------- */

.summary {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--brand-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .7rem .8rem;
  margin: 0 0 1rem;
}

.summary__grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem .8rem;
  text-align: center;
}
.metric { min-width: 0; }
.metric__label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-soft);
  font-weight: 600;
}
.metric__value {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.metric--balance { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: .35rem; }
.metric__value--big { font-size: 1.5rem; }

/* Input de orçamento inline no resumo */
.metric--budget-input .metric__value { margin: 0; }
.metric--total-input .metric__value { margin: 0; }
.metric__input {
  width: 100%;
  padding: .2rem .4rem;
  font-size: .95rem;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 32px;
  text-align: center;
}
.metric__input[readonly] {
  background: var(--surface-2);
  cursor: default;
}
.metric__input::placeholder { font-weight: 400; color: var(--text-soft); }
.metric--budget-input .field__error { font-size: .75rem; margin-top: .2rem; }

.summary[data-state="positive"] .metric--balance .metric__value { color: var(--ok); }
.summary[data-state="negative"] .metric--balance .metric__value { color: var(--danger); }

.status {
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  margin: .5rem 0 0;
  font-size: .9rem;
  font-weight: 600;
  padding: .4rem .55rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.status__icon { flex: 0 0 auto; line-height: 1.5; }
.summary[data-state="positive"] .status { background: var(--ok-soft); color: var(--ok); }
.summary[data-state="negative"] .status { background: var(--danger-soft); color: var(--danger); }
.summary[data-state="zero"]     .status { background: var(--warn-soft); color: var(--warn); }

/* Campos ---------------------------------------------------------------- */

.field { margin-bottom: .85rem; }
.field:last-child { margin-bottom: 0; }

.field__label {
  display: block;
  font-size: .87rem;
  font-weight: 600;
  margin-bottom: .3rem;
}
.field__input {
  width: 100%;
  min-height: var(--tap);
  padding: .6rem .7rem;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field__input--money { font-variant-numeric: tabular-nums; }
.field__input[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }

.field__hint { margin: .3rem 0 0; font-size: .8rem; color: var(--text-soft); }
.field__error { margin: .3rem 0 0; font-size: .82rem; font-weight: 600; color: var(--danger); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }

.subtotal-preview {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  margin: .25rem 0 .85rem;
}
.subtotal-preview__label { font-size: .8rem; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.subtotal-preview__value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.form-actions { display: grid; gap: .5rem; }

/* Botões ---------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: var(--tap);
  padding: .55rem .9rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: .3rem .6rem; font-size: .85rem; }

.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--brand-strong); border-color: var(--brand-strong); }
@media (prefers-color-scheme: dark) {
  .btn--primary { color: #06211f; }
}

.btn--ghost { background: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn--danger { color: #2a0c0a; } }

.btn--danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger); }

.btn--link {
  background: none; border: 0; padding: .2rem 0; min-height: 0;
  color: var(--brand); text-decoration: underline; cursor: pointer;
}

a { color: var(--brand); }

/* Lista de itens -------------------------------------------------------- */

.list-loading { margin: 0; color: var(--text-soft); font-size: .9rem; }

.empty-state {
  margin: 0;
  padding: 1.2rem .8rem;
  text-align: center;
  color: var(--text-soft);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: .92rem;
}
.empty-state__icon { display: block; font-size: 1.8rem; margin-bottom: .3rem; }
.empty-state strong { display: block; color: var(--text); margin-bottom: .2rem; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  background: var(--surface);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .2rem .6rem;
  align-items: start;
}

.item__name { font-weight: 600; margin: 0; min-width: 0; }
.item__meta { margin: 0; font-size: .85rem; color: var(--text-soft); font-variant-numeric: tabular-nums; display: inline; }

/* Controles de quantidade */
.item__qty-controls {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
.item__qty {
  min-width: 2rem;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.btn--qty {
  min-height: 26px;
  min-width: 26px;
  padding: .15rem;
  border-radius: 50%;
}

.item__price-input {
  display: inline-block;
  width: 70px;
  padding: .15rem .3rem;
  font-size: .85rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: right;
}
.item__price-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.item__subtotal {
  grid-column: 2; grid-row: 1 / span 2;
  margin: 0;
  font-weight: 700; font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.item__actions { grid-column: 2; grid-row: 3; display: flex; gap: .4rem; justify-content: flex-end; }

/* Botão de ícone */
.btn--icon {
  min-height: 32px;
  min-width: 32px;
  padding: .3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Conteúdo informativo -------------------------------------------------- */

.prose { font-size: .95rem; color: var(--text-soft); }
/* Em como-funciona.html os subtítulos são h3 dentro de seções com h2;
   a regra cobre os dois níveis para manter a mesma densidade tipográfica. */
.prose h3, .prose h4 { font-size: 1rem; color: var(--text); margin: 1.1rem 0 .3rem; }
.prose h3:first-of-type { margin-top: .2rem; }
.prose p { margin: .3rem 0; }
.prose__steps { margin: 0; padding-left: 1.2rem; display: grid; gap: .3rem; }
.prose__steps strong, .prose__faq dt { color: var(--text); }
.prose__faq { margin: .3rem 0 0; }
.prose__faq dt { font-weight: 600; margin-top: .6rem; }
.prose__faq dd { margin: .1rem 0 0; }

/* Justificar textos em páginas informativas, exceto títulos */
.prose p,
.prose li,
.prose dd {
  text-align: justify;
}

.page-cta { margin: 0 0 1rem; }
.page-cta .btn { width: 100%; }
@media (min-width: 30rem) {
  .page-cta .btn { width: auto; min-width: 16rem; }
}

.footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem .9rem 2rem;
  font-size: .85rem;
  color: var(--text-soft);
  border-top: 1px solid var(--border);
}
.footer p { margin: .3rem 0; }

.noscript {
  max-width: var(--maxw);
  margin: 0 auto 1rem;
  padding: .8rem .9rem;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}

/* Modais ---------------------------------------------------------------- */

.modal {
  width: min(28rem, calc(100vw - 1.6rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  overflow: auto;
}
.modal::backdrop { background: rgba(8, 14, 20, .55); }
.modal__box { padding: 1.1rem; margin: 0; }
.modal__title { font-size: 1.1rem; margin: 0 0 .5rem; text-align: center}
.modal__text { margin: 0 0 .8rem; font-size: .93rem; color: var(--text-soft); }

.modal__notice {
  margin: 0 0 .8rem;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: .85rem;
  font-weight: 600;
}

.pix {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  margin-bottom: .9rem;
}
.pix__row { margin: .25rem 0; display: grid; gap: .1rem; }
.pix__label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); font-weight: 700; }
.pix__value { font-weight: 600; }
.pix__key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95rem;
  word-break: break-all;
  user-select: all;
}

.modal__actions { display: grid; gap: .5rem; }
.modal__feedback { margin: .6rem 0 0; min-height: 1.2em; font-size: .88rem; font-weight: 600; color: var(--ok); }
.modal__fineprint { margin: .6rem 0 0; font-size: .75rem; color: var(--text-soft); }

/* Avisos temporários ---------------------------------------------------- */

.toast-region {
  position: fixed;
  left: .7rem; right: .7rem;
  bottom: calc(.7rem + env(safe-area-inset-bottom));
  z-index: 50;
  display: grid;
  gap: .4rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  font-size: .9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  box-shadow: var(--shadow);
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
}
.toast__action {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  padding: .25rem .6rem;
  min-height: 34px;
  cursor: pointer;
}

/* Estado de carregamento ------------------------------------------------ */

.is-booting #item-form,
.is-booting #input-budget { opacity: .6; pointer-events: none; }

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