/* =========================================================================
   ORGANIZAÇÃO DE ROTINA — design tokens
   Graphite base, mint accent, amber highlight — fiel às referências aprovadas.
   ========================================================================= */
:root {
  --bg: #0B0C12;
  --surface: #14151F;
  --surface-2: #1A1B27;
  --surface-3: #20212F;
  --border: #272935;
  --border-soft: #1E2029;

  --text-primary: #F2F3F7;
  --text-secondary: #9A9CAD;
  --text-muted: #6B6D7E;

  --mint: #7FE8B0;
  --mint-strong: #5FE0A0;
  --mint-ink: #07271A;
  --mint-soft: rgba(127, 232, 176, 0.12);

  --amber: #F2B807;
  --amber-ink: #241900;

  --danger: #FF7A7A;
  --danger-soft: rgba(255, 122, 122, 0.12);

  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;
  --radius-pill: 999px;

  --font-display: 'Manrope', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;

  --shell-max: 760px;
  --sidebar-w: 264px;
  --topbar-h: 56px;
  --bottombar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; }

button { font-family: inherit; }

input, select, textarea { font-family: inherit; }

a { color: inherit; }

svg { display: block; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* =========================================================================
   APP ROOT / VISIBILITY STATES
   ========================================================================= */
[hidden] { display: none !important; }

.app-shell {
  min-height: 100vh;
}

/* =========================================================================
   AUTH SCREEN
   ========================================================================= */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% -10%, rgba(127, 232, 176, 0.08), transparent 45%),
    radial-gradient(circle at 100% 110%, rgba(127, 232, 176, 0.05), transparent 40%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 26px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-brand .brand-mark { width: 34px; height: 34px; }

.auth-brand strong {
  font-family: var(--font-display);
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.auth-card .auth-sub {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0 0 24px;
}

.auth-card .auth-sub strong { color: var(--text-primary); font-weight: 600; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.field input,
.field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  color: var(--text-primary);
  font-size: 0.95rem;
  width: 100%;
  min-height: 46px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.field input::placeholder { color: var(--text-muted); }

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft);
}

.field-hint {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.mono-input { font-family: 'JetBrains Mono', 'Courier New', monospace; letter-spacing: 0.02em; }

.password-field {
  position: relative;
}

.password-field input { padding-right: 44px; }

.field-icon-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.field-icon-btn svg { width: 18px; height: 18px; }

.field-icon-btn:hover { color: var(--text-primary); background: var(--surface-3); }

.auth-foot-actions-center {
  justify-content: center;
  gap: 18px;
}

.recovery-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--mint-soft);
  color: var(--mint);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.recovery-code-box {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px dashed var(--mint);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 14px;
  user-select: all;
  line-height: 1.6;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: 46px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .15s ease, opacity .15s ease, transform .05s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--mint);
  color: var(--mint-ink);
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

.btn-block { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-muted); }

.btn-text {
  background: none;
  border: none;
  color: var(--mint);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 0;
  min-height: 0;
}

.auth-form-step { display: flex; flex-direction: column; }

.auth-foot-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.form-message {
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 2px 0 16px;
  line-height: 1.4;
}

.form-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-message.success {
  background: var(--mint-soft);
  color: var(--mint);
}

.form-message[hidden] { display: none; }

/* =========================================================================
   APP SHELL — layout
   ========================================================================= */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar (desktop) ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--mint);
  color: var(--mint-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark svg { width: 18px; height: 18px; }

.brand strong {
  font-family: var(--font-display);
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }

.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }

.nav-item[aria-current="page"] {
  background: var(--mint-soft);
  color: var(--mint);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px;
}

.account-pill {
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn svg { width: 15px; height: 15px; }

.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

/* ---- Topbar (mobile) ---- */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.topbar .brand strong { font-size: 0.92rem; }

/* ---- Main content ---- */
.content {
  flex: 1;
  min-width: 0;
  padding: 40px 44px 56px;
}

.content-inner {
  max-width: var(--shell-max);
}

.view[hidden] { display: none; }

.page-header { margin-bottom: 22px; }

.page-header h1 {
  font-size: 1.7rem;
  letter-spacing: -0.015em;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-secondary);
  margin: 0;
  font-size: 0.92rem;
}

/* =========================================================================
   CARDS
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.card-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--mint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-icon svg { width: 16px; height: 16px; }

.card-head h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

/* ---- Gastos do mês (Hoje) ---- */
.btn-add-expense { width: auto; }

@media (max-width: 1023px) {
  .btn-add-expense { width: 100%; }
}

.spend-total {
  font-family: var(--font-display);
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin: 0 0 18px;
}

/* ---- Tarefas card ---- */
.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--border-soft);
}

.task-row:first-of-type { border-top: none; }

.task-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1.5px solid var(--text-muted);
  background: transparent;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  padding: 0;
}

.task-check svg { width: 13px; height: 13px; }

.task-check[aria-checked="true"] {
  background: var(--mint);
  border-color: var(--mint);
  color: var(--mint-ink);
}

.task-label {
  flex: 1;
  font-size: 0.93rem;
  min-width: 0;
}

.task-row[data-done="true"] .task-label {
  color: var(--text-muted);
  text-decoration: line-through;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  white-space: nowrap;
}

.badge-neutral { background: var(--surface-3); color: var(--text-secondary); }
.badge-amber { background: var(--amber); color: var(--amber-ink); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 14px;
  background: none;
  border: none;
  color: var(--mint);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  padding: 0;
}

.card-link svg { width: 15px; height: 15px; }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 28px 10px;
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-state .empty-icon svg { width: 20px; height: 20px; }

.empty-state h3 {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 320px;
  margin: 0 auto;
}

/* =========================================================================
   GASTOS — formulário e listas
   ========================================================================= */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.form-grid .field { margin-bottom: 0; }

.category-chooser {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover { color: var(--text-primary); border-color: var(--text-muted); }

.chip[aria-pressed="true"] {
  background: var(--mint-soft);
  border-color: var(--mint);
  color: var(--mint);
}

.chip-new {
  border-style: dashed;
}

.amount-field {
  position: relative;
}

.amount-field .prefix {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.95rem;
  pointer-events: none;
}

.amount-field input { padding-left: 38px; }

.list {
  display: flex;
  flex-direction: column;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 2px;
  border-top: 1px solid var(--border-soft);
}

.list-row:first-child { border-top: none; }

.list-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
  flex-shrink: 0;
}

.list-row .meta {
  flex: 1;
  min-width: 0;
}

.list-row .meta .name {
  font-size: 0.92rem;
  font-weight: 600;
}

.list-row .meta .sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.list-row .amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.category-total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 11px 2px;
  border-top: 1px solid var(--border-soft);
}

.category-total-row:first-child { border-top: none; }

.category-total-row .cat-name { font-weight: 600; font-size: 0.92rem; }

.category-total-row .cat-total {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* =========================================================================
   MODAL (atalho adicionar gasto / escolher categoria)
   ========================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 9, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

.modal-backdrop[hidden] { display: none; }

.modal-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 22px 20px calc(22px + var(--safe-b));
  max-height: 86vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 { font-size: 1.08rem; }

.modal-close {
  background: var(--surface-2);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close svg { width: 14px; height: 14px; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal-sheet { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); padding: 24px; }
}

/* =========================================================================
   BOTTOM NAV (mobile)
   ========================================================================= */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border-soft);
  padding: 8px 10px calc(8px + var(--safe-b));
  z-index: 20;
}

.bottom-nav ul {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
}

.bottom-nav li { flex: 1; }

.bottom-nav .nav-item {
  flex-direction: column;
  gap: 3px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  text-align: center;
  justify-content: center;
}

.bottom-nav .nav-item svg { width: 20px; height: 20px; }

.bottom-nav .nav-item[aria-current="page"] { background: transparent; }

/* =========================================================================
   TOAST
   ========================================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottombar-h) + var(--safe-b) + 18px);
  transform: translateX(-50%) translateY(12px);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error { border-color: var(--danger); color: var(--danger); }

.toast svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--mint); }

.toast-error svg { color: var(--danger); }

@media (min-width: 1024px) {
  .toast { bottom: 24px; }
}

/* =========================================================================
   RESPONSIVE — mobile layout (<1024px)
   ========================================================================= */
@media (max-width: 1023px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .bottom-nav { display: block; }

  .layout { flex-direction: column; }

  .content {
    padding: 20px 16px calc(var(--bottombar-h) + var(--safe-b) + 28px);
  }

  .page-header h1 { font-size: 1.5rem; }

  .spend-total { font-size: 2rem; }
}

@media (min-width: 1024px) {
  .btn-block-mobile-only { width: auto; }
}
