/* ====================================================================
   LIVRO — sistema de design
   Conceito: caderno de contas. Sóbrio, com peso editorial.
   Tipografia: Fraunces (display, serifada, com caráter) + Inter (corpo/UI).
   Paleta: fundo papel quente, tinta quase-preta, verde-azeitona (receita),
   terracota (dívida), e um traço de "carimbo" dourado-baixo como acento raro.
   ==================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* paleta nomeada */
  --paper:        #F6F1E7;
  --paper-raised: #FFFFFF;
  --ink:          #2B2620;
  --ink-soft:     #6B6358;
  --line:         #E2D9C8;

  --olive:        #4B5D3A;
  --olive-deep:   #38462C;
  --olive-wash:   #E7EBDD;

  --rust:         #A4452B;
  --rust-deep:    #7E3320;
  --rust-wash:    #F3E3DA;

  --gold:         #B08A3E;
  --gold-wash:    #F1E6CC;

  /* tipografia */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* layout */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --sidebar-w: 280px;
  --shadow-card: 0 1px 2px rgba(43, 38, 32, 0.04), 0 4px 16px rgba(43, 38, 32, 0.06);
  --shadow-raised: 0 2px 8px rgba(43, 38, 32, 0.08), 0 8px 24px rgba(43, 38, 32, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

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

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

/* ====================================================================
   SHELL
   ==================================================================== */

.shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar (lista de meses) ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--paper-raised);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__brand {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--line);
}

.sidebar__brand-mark {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.sidebar__brand-mark span {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar__close {
  display: none;
  position: absolute;
  top: 20px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
}

.sidebar__close svg { width: 20px; height: 20px; }

.sidebar__months {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 24px;
}

.sidebar__year {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  padding: 16px 12px 8px;
}

.sidebar__year:first-child { padding-top: 4px; }

.month-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  text-align: left;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
  position: relative;
}

.month-item:hover { background: var(--olive-wash); }

.month-item.is-active {
  background: var(--olive-deep);
  color: var(--paper-raised);
}

.month-item__name { text-transform: capitalize; }

.month-item__balance {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  opacity: 0.8;
}

.month-item.is-active .month-item__balance { opacity: 0.9; }

.month-item__balance.is-negative { color: var(--rust); }
.month-item.is-active .month-item__balance.is-negative { color: #F3CABA; }

.sidebar__add-month {
  margin: 8px 0 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border: 1.5px dashed var(--line);
  background: transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
}

.sidebar__add-month:hover {
  border-color: var(--olive);
  color: var(--olive-deep);
  background: var(--olive-wash);
}

.sidebar__add-month svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar__footer {
  border-top: 1px solid var(--line);
  padding: 12px;
}

.sidebar__logout {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
}

.sidebar__logout:hover {
  background: var(--rust-wash);
  color: var(--rust-deep);
}

.sidebar__logout svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- Overlay (mobile) ---------- */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.45);
  z-index: 35;
  opacity: 0;
  transition: opacity 0.28s ease;
}

/* ---------- Main ---------- */

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__menu {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink);
}

.topbar__menu svg { width: 19px; height: 19px; }

.topbar__title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  text-transform: capitalize;
}

.content {
  flex: 1;
  padding: 36px 40px 60px;
  max-width: 920px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 30px;
  text-transform: capitalize;
}

.page-header__eyebrow {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

/* ====================================================================
   CARDS DE TOTAIS
   ==================================================================== */

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 36px;
}

.total-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  box-shadow: var(--shadow-card);
}

.total-card__label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.total-card__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.total-card--receitas .total-card__dot { background: var(--olive); }
.total-card--dividas .total-card__dot { background: var(--rust); }
.total-card--saldo .total-card__dot { background: var(--gold); }

.total-card__value {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.total-card--receitas .total-card__value { color: var(--olive-deep); }
.total-card--dividas .total-card__value { color: var(--rust-deep); }

.total-card--saldo {
  background: var(--ink);
  border-color: var(--ink);
}

.total-card--saldo .total-card__label { color: rgba(246, 241, 231, 0.65); }
.total-card--saldo .total-card__value { color: var(--paper-raised); }
.total-card--saldo.is-negative .total-card__value { color: #F3A98E; }

/* ====================================================================
   SEÇÕES (Receitas / Dívidas)
   ==================================================================== */

.section {
  margin-bottom: 32px;
}

.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section__title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 600;
}

.section__title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.section--receitas .dot { background: var(--olive); }
.section--dividas .dot { background: var(--rust); }

.section__add {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.section__add:hover { border-color: var(--ink); }
.section__add svg { width: 15px; height: 15px; }

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.item-card__check {
  width: 40px;
  height: 40px;
  margin: -9px 0 -9px -10px;
  border-radius: 50%;
  border: none;
  background: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  position: relative;
}

.item-card__check span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-card__check svg { width: 13px; height: 13px; }

.item-card.is-paid .item-card__check span {
  background: var(--olive);
  border-color: var(--olive);
  color: var(--paper-raised);
}

.item-card__body {
  flex: 1;
  min-width: 0;
}

.item-card__name {
  font-weight: 600;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.item-card.is-paid .item-card__name { color: var(--ink-soft); }

.item-card__meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-recorrente {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gold);
  background: var(--gold-wash);
  padding: 2px 7px;
  border-radius: 100px;
}

.badge-recorrente svg { width: 10px; height: 10px; }

.badge-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 100px;
}

.badge-status--pendente {
  color: var(--rust-deep);
  background: var(--rust-wash);
}

.badge-status--vencida {
  color: #fff;
  background: var(--rust-deep);
}

.item-card__value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.section--receitas .item-card__value { color: var(--olive-deep); }
.section--dividas .item-card__value { color: var(--rust-deep); }
.item-card.is-paid .item-card__value { color: var(--ink-soft); }

.item-card__menu {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-card__menu:hover { background: var(--paper); color: var(--ink); }
.item-card__menu svg { width: 18px; height: 18px; }

.empty-state {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
}

/* ====================================================================
   FAB (mobile add)
   ==================================================================== */

.fab {
  display: none;
  position: fixed;
  bottom: 22px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper-raised);
  border: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-raised);
  z-index: 30;
}

.fab svg { width: 24px; height: 24px; }

/* ====================================================================
   RESPONSIVE
   ==================================================================== */

@media (max-width: 880px) {
  .sidebar {
    transform: translateX(-100%);
    width: 84%;
    max-width: 320px;
    box-shadow: var(--shadow-raised);
  }

  .shell.sidebar-open .sidebar { transform: translateX(0); }

  .shell.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
  }

  .sidebar__close { display: flex; }

  .main { margin-left: 0; }

  .topbar { display: flex; }

  .content { padding: 22px 16px 90px; }

  .page-header { display: none; }

  .totals {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .total-card--saldo {
    grid-column: 1 / -1;
  }

  .total-card { padding: 16px 16px 14px; }
  .total-card__value { font-size: 23px; }

  .section__add span { display: none; }
  .section__add { padding: 8px 10px; }

  .fab { display: flex; }
}

@media (max-width: 420px) {
  .totals { grid-template-columns: 1fr; }
  .total-card--saldo { grid-column: auto; }
}

/* ====================================================================
   MODAL (form de novo item)
   ==================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.5);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--paper-raised);
  width: 100%;
  max-width: 460px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(16px);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.is-open .modal { transform: translateY(0); }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius-lg); padding: 28px; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal__title { font-size: 19px; }

.modal__close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--paper);
  border-radius: 50%;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close svg { width: 16px; height: 16px; }

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--paper-raised);
  color: var(--ink);
}

.field input:focus,
.field select:focus {
  border-color: var(--olive);
  outline: none;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field { flex: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 4px;
}

.toggle-row label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.toggle-row__hint {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 400;
  margin-top: 2px;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch__track {
  position: absolute;
  inset: 0;
  background: var(--line);
  border-radius: 100px;
  transition: background 0.2s;
}

.switch__track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .switch__track { background: var(--olive); }
.switch input:checked + .switch__track::before { transform: translateX(18px); }

.modal__submit {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--paper-raised);
  font-size: 15px;
  font-weight: 700;
  margin-top: 6px;
}

.modal__submit:hover { background: var(--olive-deep); }

.modal__type-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--paper);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.modal__type-btn {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.modal__type-btn.is-active {
  background: var(--paper-raised);
  box-shadow: var(--shadow-card);
  color: var(--ink);
}
