/* Nexipe - Financas Pessoais — identidade Rota da Clareza.
 *
 * Paleta oficial: Tinta Azul, Cobalto Norte, Tangerina Viva e Gelo.
 * Titulos serifados, superficies editoriais, cores chapadas e sombra seca.
 * Sem neon, gradiente de assinatura, preto puro ou metafora bancaria obvia.
 */

:root {
  --ink: #17203a;
  --cobalt: #2742d7;
  --tangerine: #ff8a3d;
  --ice: #f4f7ff;
  --surface: #ffffff;
  --mist: #e8ecff;
  --warm-tint: #fff0d8;
  --muted: #64708a;
  --success: #1f7a68;
  --danger: #c2415d;
  --line: rgba(23, 32, 58, 0.18);
  --shadow: 6px 6px 0 rgba(23, 32, 58, 0.1);
  --shadow-sm: 3px 3px 0 rgba(23, 32, 58, 0.1);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--ice);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Premium troca o plano de fundo para Tinta Azul, sem neon nem gradiente. */
body[data-plan="premium"] {
  background: var(--ink);
  color: var(--ice);
}
body[data-plan="premium"] .surface {
  background: var(--surface);
  color: var(--ink);
}
body[data-plan="premium"] .app-header,
body[data-plan="premium"] .app-nav {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(244, 247, 255, 0.25);
}
body[data-plan="premium"] .app-header .brand-name,
body[data-plan="premium"] .app-nav button {
  color: var(--ice);
}
body[data-plan="premium"] .app-nav button[aria-current="page"] {
  background: var(--tangerine);
  color: var(--ink);
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}
h1 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.1rem); }
h2 { font-size: clamp(1.2rem, 1.05rem + 0.7vw, 1.5rem); }
h3 { font-size: 1.05rem; }

/* ------------------------------------------------------------- acessibilidade */

:focus-visible {
  outline: 3px solid var(--tangerine);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--cobalt);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 100;
}
.skip-link:focus {
  left: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* -------------------------------------------------------------------- layout */

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* A nav vem antes do main no DOM, que e o que leitores de tela esperam, mas
 * no celular ela precisa aparecer no rodape. As linhas explicitas resolvem
 * isso sem inverter a ordem do documento. */
.app-header { grid-row: 1; }
.app-main { grid-row: 2; }
.app-nav { grid-row: 3; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.brand img {
  width: 34px;
  height: 34px;
  flex: none;
}
.brand-text {
  min-width: 0;
}
.brand-name {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-tagline {
  font-size: 0.72rem;
  color: var(--muted);
}

.plan-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.25rem 0.6rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  white-space: nowrap;
}
.plan-badge[data-tier="premium"] {
  background: var(--tangerine);
  border-color: var(--tangerine);
}

.app-main {
  padding: 1.1rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* Navegacao inferior no celular, lateral no desktop. */
.app-nav {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-auto-flow: column;
  gap: 0.25rem;
  padding: 0.4rem;
  background: var(--surface);
  border-top: 2px solid var(--line);
  overflow-x: auto;
}
.app-nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.5rem 0.3rem;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  gap: 0.15rem;
  justify-items: center;
  min-width: 62px;
}
.app-nav button[aria-current="page"] {
  background: var(--cobalt);
  color: #fff;
}
.app-nav .nav-icon {
  font-size: 1.05rem;
  line-height: 1;
}

@media (min-width: 900px) {
  .app {
    grid-template-columns: 232px 1fr;
    grid-template-rows: auto 1fr;
  }
  .app-header {
    grid-row: 1;
    grid-column: 1 / -1;
  }
  .app-main {
    grid-row: 2;
    grid-column: 2;
  }
  .app-nav {
    grid-row: 2;
    grid-column: 1;
    position: sticky;
    top: 0;
    align-self: start;
    grid-auto-flow: row;
    border-top: 0;
    border-right: 2px solid var(--line);
    height: calc(100vh - 64px);
    padding: 1rem 0.6rem;
    gap: 0.2rem;
  }
  .app-nav button {
    grid-auto-flow: column;
    justify-items: start;
    justify-content: start;
    gap: 0.6rem;
    font-size: 0.9rem;
    padding: 0.6rem 0.8rem;
    width: 100%;
  }
  .app-main {
    padding: 1.6rem 2rem;
  }
}

/* ------------------------------------------------------------------ surfaces */

.surface {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 1.1rem;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
}

.stat {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: var(--mist);
}
.stat .stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat .stat-value {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin-top: 0.2rem;
  /* Numero longo nao pode empurrar o layout. */
  overflow-wrap: anywhere;
}
.stat[data-tone="positive"] .stat-value { color: var(--success); }
.stat[data-tone="negative"] .stat-value { color: var(--danger); }

/* -------------------------------------------------------------------- forms */

form .field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
}
label {
  font-size: 0.82rem;
  font-weight: 600;
}
.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  width: 100%;
  /* 16px evita o zoom automatico do iOS ao focar o campo. */
  font-size: 16px;
}
input:focus,
select:focus {
  border-color: var(--cobalt);
}
input[aria-invalid="true"] {
  border-color: var(--danger);
}

.form-row {
  display: grid;
  gap: 0.8rem;
}
@media (min-width: 620px) {
  .form-row {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

button.action {
  appearance: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  background: var(--cobalt);
  color: #fff;
  box-shadow: var(--shadow-sm);
  /* Alvo de toque confortavel no celular. */
  min-height: 44px;
}
button.action:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 rgba(23, 32, 58, 0.14);
}
button.action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
button.action[data-variant="ghost"] {
  background: transparent;
  color: var(--ink);
}
button.action[data-variant="danger"] {
  background: var(--danger);
}
button.action[data-variant="quiet"] {
  background: var(--mist);
  color: var(--ink);
  box-shadow: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* ------------------------------------------------------------------- listas */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.list .item-main {
  flex: 1 1 190px;
  min-width: 0;
}
.list .item-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.list .item-meta {
  font-size: 0.78rem;
  color: var(--muted);
}
.list .item-amount {
  font-family: var(--serif);
  font-size: 1.05rem;
  white-space: nowrap;
}
.list .item-amount[data-tone="income"] { color: var(--success); }
.list .item-amount[data-tone="expense"] { color: var(--danger); }

.bar {
  height: 8px;
  background: var(--mist);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--cobalt);
}

/* ------------------------------------------------------- estados de interface */

.state {
  text-align: center;
  padding: 1.6rem 1rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}
.state h3 {
  color: var(--ink);
}

.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 0.6rem;
  border: 3px solid var(--mist);
  border-top-color: var(--cobalt);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.state[data-kind="error"] {
  border-color: var(--danger);
  border-style: solid;
  background: rgba(194, 65, 93, 0.06);
  color: var(--ink);
}
.state[data-kind="premium"] {
  border-color: var(--tangerine);
  border-style: solid;
  background: var(--warm-tint);
  color: var(--ink);
}

.banner {
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.banner[data-kind="offline"] { background: var(--warm-tint); }
.banner[data-kind="success"] { background: rgba(31, 122, 104, 0.12); }
.banner[data-kind="error"] {
  background: rgba(194, 65, 93, 0.1);
  border-color: var(--danger);
}

/* --------------------------------------------------------------- confirmacao */

dialog.confirm {
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 1.2rem;
  max-width: 380px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);
  color: var(--ink);
  background: var(--surface);
}
dialog.confirm::backdrop {
  background: rgba(23, 32, 58, 0.45);
}
dialog.confirm .button-row {
  margin-top: 1rem;
  justify-content: flex-end;
}

/* ---------------------------------------------------------------- entrada */

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.2rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
}
.auth-brand {
  text-align: center;
  margin-bottom: 1.2rem;
}
.auth-brand img {
  width: 64px;
  height: 64px;
}
.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: space-between;
  margin-top: 0.9rem;
}
.auth-links button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--cobalt);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* ------------------------------------------------------------------ conversa */

.chat-surface {
  display: grid;
  gap: 0.9rem;
}

.chat-thread {
  display: grid;
  gap: 0.7rem;
  /* Altura limitada com rolagem propria: o campo de escrita fica sempre
   * visivel, sem o usuario ter que rolar a pagina inteira. */
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.chat-msg {
  display: grid;
  gap: 0.2rem;
  max-width: 88%;
}
.chat-msg[data-from="user"] {
  justify-self: end;
  justify-items: end;
}

.chat-author {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.chat-bubble {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  background: var(--mist);
  /* A resposta do assistente vem com quebras de linha significativas. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg[data-from="user"] .chat-bubble {
  background: var(--cobalt);
  color: #fff;
  border-color: var(--cobalt);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.chat-form input {
  flex: 1 1 auto;
}
.chat-form button.action {
  flex: none;
}

.chat-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.chip {
  appearance: none;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  background: var(--surface);
  color: var(--ink);
}
.chip:hover {
  border-color: var(--cobalt);
}

/* ---------------------------------------------------------------- onboarding */

.onb-progress {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.onb-dot {
  width: 34px;
  height: 6px;
  border-radius: 999px;
  background: var(--mist);
}
.onb-dot[data-active] {
  background: var(--cobalt);
}

.onb-step {
  text-align: center;
  padding: 0.4rem 0 0.8rem;
}
.onb-icon {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 0.5rem;
  color: var(--tangerine);
}

.onb-actions {
  justify-content: space-between;
}
