/* ── Design tokens ───────────────────────────────────────── */
:root {
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 28px rgba(15, 23, 42, 0.12);
  --gap: clamp(6px, 1.2vh, 10px);
  --value-size: clamp(1.25rem, 5.2vw, 1.65rem);
  --value-total-size: clamp(1.5rem, 7vw, 2rem);
  color-scheme: light dark;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-input: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #059669;
  --accent-soft: rgba(5, 150, 105, 0.12);
  --accent-secondary: #6366f1;
  --accent-secondary-soft: rgba(99, 102, 241, 0.12);
  --gradient: linear-gradient(160deg, #ecfdf5 0%, #f0f9ff 50%, #f8fafc 100%);
  --header-gradient: linear-gradient(135deg, #059669, #0d9488);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-elevated: #151d2e;
  --bg-input: #0f172a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #1e293b;
  --accent: #34d399;
  --accent-soft: rgba(52, 211, 153, 0.15);
  --accent-secondary: #818cf8;
  --accent-secondary-soft: rgba(129, 140, 248, 0.15);
  --gradient: linear-gradient(160deg, #0b1120 0%, #0f172a 40%, #111827 100%);
  --header-gradient: linear-gradient(135deg, #059669, #14b8a6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --bg-elevated: #151d2e;
    --bg-input: #0f172a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --accent: #34d399;
    --accent-soft: rgba(52, 211, 153, 0.15);
    --accent-secondary: #818cf8;
    --accent-secondary-soft: rgba(129, 140, 248, 0.15);
    --gradient: linear-gradient(160deg, #0b1120 0%, #0f172a 40%, #111827 100%);
    --header-gradient: linear-gradient(135deg, #059669, #14b8a6);
  }
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f1f5f9;
    --bg-elevated: #ffffff;
    --bg-input: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --accent: #059669;
    --accent-soft: rgba(5, 150, 105, 0.12);
    --accent-secondary: #6366f1;
    --accent-secondary-soft: rgba(99, 102, 241, 0.12);
    --gradient: linear-gradient(160deg, #ecfdf5 0%, #f0f9ff 50%, #f8fafc 100%);
    --header-gradient: linear-gradient(135deg, #059669, #0d9488);
  }
}

/* Telas muito baixas (ex: iPhone SE) */
@media (max-height: 640px) {
  :root {
    --gap: 5px;
    --value-size: clamp(1.1rem, 4.8vw, 1.4rem);
    --value-total-size: clamp(1.35rem, 6.5vw, 1.75rem);
  }
}

/* ── Reset & base ────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--gradient);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

/* ── App shell (sem scroll) ────────────────────────────────── */
.app {
  max-width: 440px;
  margin: 0 auto;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    max(env(safe-area-inset-top), 6px)
    max(env(safe-area-inset-right), 12px)
    max(env(safe-area-inset-bottom), 6px)
    max(env(safe-area-inset-left), 12px);
  overflow: hidden;
}

/* ── Header compacto ───────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--gap);
  flex-shrink: 0;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header__logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--header-gradient);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 2px 10px rgba(5, 150, 105, 0.3);
}

.header__logo svg {
  width: 20px;
  height: 20px;
}

.header__text {
  min-width: 0;
}

.header__title {
  font-size: clamp(0.95rem, 4vw, 1.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header__subtitle {
  display: none;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.header__actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}

.btn-icon:active {
  transform: scale(0.94);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

/* ── Main (preenche o espaço restante) ─────────────────────── */
.main {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--gap);
  min-height: 0;
  overflow: hidden;
}

/* ── Painel de inputs (único bloco) ─────────────────────────── */
.panel-inputs {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(8px, 1.5vh, 12px);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  min-width: 0;
  max-width: 100%;
}

.panel-inputs__row {
  display: grid;
  grid-template-columns: 1fr minmax(88px, 32%);
  gap: 8px;
  min-width: 0;
}

.input-cell {
  min-width: 0;
  max-width: 100%;
}

.input-cell__label {
  display: block;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.input-money,
.input-percent {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-money:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-percent:focus-within {
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px var(--accent-secondary-soft);
}

.input-money__prefix {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

.input-money__field {
  flex: 1 1 0;
  width: 100%;
  max-width: 100%;
  border: none;
  background: transparent;
  font-size: clamp(1.1rem, 4.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 8px 0;
  outline: none;
  min-width: 0;
}

.input-money__field::placeholder {
  color: var(--text-muted);
  opacity: 0.45;
}

.input-percent__field {
  flex: 1 1 0;
  width: 100%;
  max-width: 100%;
  border: none;
  background: transparent;
  font-size: clamp(1.1rem, 4.5vw, 1.35rem);
  font-weight: 700;
  padding: 8px 0;
  outline: none;
  min-width: 0;
  text-align: center;
  -moz-appearance: textfield;
}

.input-percent__field::-webkit-outer-spin-button,
.input-percent__field::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-percent__suffix {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chips {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  flex: 1;
  padding: 6px 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.chip--active {
  background: var(--accent-secondary-soft);
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
}

/* ── Resultados em grade (2 + total) ─────────────────────────── */
.results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  align-content: start;
  gap: var(--gap);
  min-height: 0;
  min-width: 0;
  max-width: 100%;
}

.result {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(10px, 2vh, 14px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-self: start;
  min-height: 0;
}

.result.is-updated {
  animation: pulse 0.35s ease;
}

@keyframes pulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

.result__header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}

.result__badge {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.result__badge--accent {
  background: var(--accent-secondary-soft);
  color: var(--accent-secondary);
}

.result__badge--total {
  background: var(--accent);
  color: #fff;
}

.result__name {
  font-size: clamp(0.7rem, 2.8vw, 0.8125rem);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result__percent {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.result__value {
  font-size: var(--value-size);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result--secondary .result__value {
  color: var(--accent-secondary);
}

/* Total — linha horizontal, número grande à direita */
.result--total {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--bg-elevated), var(--accent-soft));
  padding: clamp(10px, 2vh, 14px) clamp(12px, 3vw, 16px);
}

.result__total-info {
  min-width: 0;
  flex: 1;
}

.result__total-info .result__percent {
  margin-bottom: 0;
  font-size: 0.625rem;
}

.result__value--total {
  font-size: var(--value-total-size);
  font-weight: 800;
  color: var(--accent);
  flex-shrink: 0;
  text-align: right;
  line-height: 1.1;
}

[data-theme="dark"] .result__value--total {
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .result__value--total {
    color: #fff;
  }
}

[data-theme="light"] .result__value--total {
  color: var(--accent);
}

/* ── Footer mínimo ───────────────────────────────────────────── */
.footer {
  display: flex;
  justify-content: center;
  padding-top: var(--gap);
  flex-shrink: 0;
}

.btn-install {
  padding: 6px 14px;
  border-radius: 999px;
  border: none;
  background: var(--header-gradient);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-install:not([hidden]) {
  display: block;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE — tela cheia, conteúdo do topo, números grandes
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  :root {
    --gap: 12px;
    --value-size: clamp(1.5rem, 7vw, 2rem);
    --value-total-size: clamp(1.75rem, 8.5vw, 2.35rem);
  }

  .app {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    width: 100%;
    max-width: none;
    margin: 0;
    height: 100dvh;
    max-height: 100dvh;
    padding:
      max(env(safe-area-inset-top), 10px)
      max(env(safe-area-inset-right), 16px)
      max(env(safe-area-inset-bottom), 10px)
      max(env(safe-area-inset-left), 16px);
    gap: var(--gap);
    grid-template-rows: unset;
  }

  .header {
    flex-shrink: 0;
    padding-bottom: 4px;
  }

  .header__title {
    font-size: 1.1rem;
  }

  .main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    width: 100%;
    min-height: 0;
  }

  .panel-inputs {
    padding: 14px;
    flex-shrink: 0;
    width: 100%;
  }

  /* Valor e % lado a lado — usa a largura da tela */
  .panel-inputs__row {
    grid-template-columns: 1fr minmax(100px, 34%);
    gap: 10px;
  }

  .input-money__field,
  .input-percent__field {
    font-size: 1.4rem;
    padding: 8px 0;
  }

  .input-percent__field {
    text-align: center;
  }

  .chips {
    margin-top: 10px;
    gap: 8px;
  }

  .chip {
    padding: 10px 0;
    font-size: 0.8125rem;
  }

  .results {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    align-content: start;
    gap: var(--gap);
    width: 100%;
  }

  .result {
    padding: 14px;
    width: 100%;
  }

  .result__name {
    font-size: 0.8125rem;
  }

  .result__value {
    font-size: var(--value-size);
    margin-top: 6px;
    overflow: visible;
    text-overflow: unset;
  }

  .result--total {
    padding: 16px;
  }

  .result__value--total {
    font-size: var(--value-total-size);
    overflow: visible;
    text-overflow: unset;
  }

  /* Botão instalar gruda no rodapé; o vazio fica só acima dele */
  .footer {
    flex-shrink: 0;
    width: 100%;
    padding: 0;
    margin-top: auto;
  }

  .footer:has(.btn-install[hidden]) {
    display: none;
    margin-top: 0;
  }

  .btn-install:not([hidden]) {
    width: 100%;
    max-width: 280px;
    padding: 12px 24px;
    font-size: 0.875rem;
  }
}

/* ══════════════════════════════════════════════════════════════
   DESKTOP — card centralizado, duas colunas (inputs | resultados)
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  html {
    overflow: auto;
    height: auto;
  }

  body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
  }

  .app {
    max-width: 780px;
    width: 100%;
    height: auto;
    min-height: unset;
    overflow: visible;
    padding: 28px 32px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    gap: 20px;
  }

  .header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 18px;
  }

  .header__logo {
    width: 44px;
    height: 44px;
  }

  .header__logo svg {
    width: 24px;
    height: 24px;
  }

  .header__title {
    font-size: 1.35rem;
    overflow: visible;
    white-space: normal;
  }

  .header__subtitle {
    display: block;
  }

  .btn-icon {
    width: 42px;
    height: 42px;
  }

  .main {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    grid-template-rows: 1fr;
    gap: 24px;
    min-height: 280px;
    overflow: hidden;
    align-items: stretch;
  }

  .panel-inputs {
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    width: 100%;
    align-self: stretch;
    overflow: hidden;
  }

  .results {
    grid-template-rows: 1fr auto;
    align-content: stretch;
  }

  .result {
    justify-content: center;
    align-self: stretch;
  }

  .panel-inputs__row {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    width: 100%;
  }

  .input-money:focus-within {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent-soft);
  }

  .input-percent:focus-within {
    border-color: var(--accent-secondary);
    box-shadow: inset 0 0 0 1px var(--accent-secondary-soft);
  }

  .input-cell__label {
    font-size: 0.6875rem;
    margin-bottom: 6px;
  }

  .input-money__field,
  .input-percent__field {
    font-size: 1.35rem;
    padding: 10px 0;
  }

  .input-percent__field {
    text-align: left;
  }

  .chips {
    margin-top: 0;
    gap: 8px;
  }

  .chip {
    padding: 10px 0;
    font-size: 0.8125rem;
  }

  .chip:hover {
    border-color: var(--accent-secondary);
    color: var(--accent-secondary);
  }

  .results {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
    gap: 14px;
    min-height: 280px;
  }

  .result {
    padding: 20px 22px;
    overflow: visible;
  }

  .result__name {
    font-size: 0.9375rem;
    overflow: visible;
  }

  .result__percent {
    font-size: 0.8125rem;
    margin-bottom: 8px;
  }

  .result__value {
    font-size: 1.85rem;
    word-break: normal;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .result--total {
    padding: 20px 24px;
    gap: 20px;
  }

  .result__total-info .result__percent {
    font-size: 0.8125rem;
  }

  .result__value--total {
    font-size: 2.25rem;
    min-width: 0;
    max-width: 55%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .footer {
    padding-top: 4px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
  }
}

@media (min-width: 1024px) {
  .app {
    max-width: 860px;
    padding: 32px 40px 28px;
  }

  .main {
    grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
    gap: 32px;
    min-height: 300px;
  }

  .result__value {
    font-size: 2rem;
  }

  .result__value--total {
    font-size: 2.5rem;
    max-width: none;
    overflow: visible;
    text-overflow: unset;
  }
}

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}