/* ═══════════════════════════════════════════════════════
   diárias. — DESIGN SYSTEM v2
   Conceito: uma FOLHA DE LIVRO-CAIXA sobre uma mesa — não um
   dashboard de app. Navegação = abas/índice coloridas que saem
   da folha, como um fichário. Totais = faixa de totalizador
   tipográfico. Dias = linhas de lançamento, não cards soltos.
═══════════════════════════════════════════════════════ */

:root {
  --font-display: 'Fraunces', 'Iowan Old Style', serif;
  --font-sans: 'Archivo', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* fundo — azul-acinzentado bem claro (não branco puro) */
  --desk:      oklch(93% 0.02 255);
  --desk2:     oklch(89% 0.03 255);

  /* folha (papel) — branco levemente frio */
  --paper:     oklch(99.5% 0.003 255);
  --paper2:    oklch(97% 0.008 255);
  --paper3:    oklch(94% 0.014 255);
  --rule:      oklch(88% 0.02 255 / 0.9);
  --rule2:     oklch(78% 0.03 255 / 0.85);

  /* tinta — azul-marinho profundo */
  --ink:  oklch(28% 0.06 255);
  --ink2: oklch(45% 0.05 255);
  --ink3: oklch(60% 0.04 255);

  /* marca — azul */
  --brand:      oklch(55% 0.17 255);
  --brand-ink:  oklch(40% 0.15 258);
  --brand-soft: oklch(55% 0.17 255 / 0.13);

  /* semântico */
  --rust:        oklch(55% 0.18 25);
  --rust-soft:   oklch(55% 0.18 25 / 0.13);
  --forest:      oklch(52% 0.13 165);
  --forest-soft: oklch(52% 0.13 165 / 0.14);
  --amber:       oklch(70% 0.15 70);
  --amber-ink:   oklch(48% 0.12 65);
  --amber-soft:  oklch(70% 0.15 70 / 0.18);

  --shadow:    0 1px 2px oklch(40% 0.05 255 / 0.08), 0 10px 30px oklch(40% 0.08 255 / 0.1);
  --shadow-lg: 0 20px 60px oklch(35% 0.08 255 / 0.2);

  --z-tabs: 40;
  --z-modal: 200;
  --z-toast: 300;
}

/* ═══════════════════════════════════════
   RESET
═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background: var(--desk);
  background-image:
    radial-gradient(oklch(50% 0.08 255 / 0.07) 1px, transparent 1px),
    linear-gradient(180deg, var(--desk2), var(--desk) 240px);
  background-size: 20px 20px, 100% 100%;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
img { max-width: 100%; display: block; }

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

/* ═══════════════════════════════════════
   DESK — cenário externo à folha
═══════════════════════════════════════ */
.desk { min-height: 100dvh; padding: 12px 0 40px; }

.brand-mark {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-family: var(--font-display);
  font-size: 19px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--brand-ink);
  margin-bottom: 10px;
}
.brand-mark img { border-radius: 7px; }
.brand-dot { color: var(--brand); }

/* ═══════════════════════════════════════
   ÍNDICE — abas coloridas tipo fichário, no topo da folha
═══════════════════════════════════════ */
.index-tabs {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  max-width: 980px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.index-tabs::-webkit-scrollbar { display: none; }

.index-tab {
  flex: 1 0 auto;
  display: flex; align-items: center; gap: 6px; justify-content: center;
  padding: 11px 14px 22px;
  font-size: 12.5px; font-weight: 700;
  color: var(--ink3);
  background: oklch(84% 0.04 255 / 0.7);
  border-radius: 10px 10px 0 0;
  white-space: nowrap;
  transform: translateY(6px);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s, color 0.18s;
}
.index-tab svg { width: 15px; height: 15px; opacity: 0.8; }
.index-tab.active {
  background: var(--paper);
  color: var(--brand-ink);
  transform: translateY(0);
  box-shadow: 0 -2px 10px oklch(40% 0.08 255 / 0.14);
}
.index-tab:not(.active):hover { background: oklch(88% 0.05 255 / 0.85); color: var(--ink2); }

/* ═══════════════════════════════════════
   FOLHA — a página em si, como papel sobre a mesa
═══════════════════════════════════════ */
.paper {
  max-width: 980px;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 0 14px 14px 14px;
  box-shadow: var(--shadow-lg);
  position: relative;
  min-height: 60vh;
}
.paper::before {
  /* friso perfurado no topo, como folha destacável de talão */
  content: '';
  position: absolute; top: -1px; left: 24px; right: 24px; height: 2px;
  background: repeating-linear-gradient(90deg, var(--rule2) 0 7px, transparent 7px 14px);
}

.paper-inner { padding: 18px 20px 32px; }
.paper-inner.wide { max-width: none; }

.page-head { margin-bottom: 16px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 38px);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.page-head .kicker { font-size: 12.5px; color: var(--ink3); margin-top: 3px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ═══════════════════════════════════════
   FAIXA TOTALIZADORA — números, não caixas
═══════════════════════════════════════ */
.tally {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  margin-bottom: 30px;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--rule);
}
@media (min-width: 620px) { .tally { grid-template-columns: repeat(4, 1fr); } }

.tally-item {
  padding: 14px 16px;
  border-right: 1px dashed var(--rule2);
  position: relative;
}
.tally-item:nth-child(2n) { border-right: none; }
@media (min-width: 620px) {
  .tally-item { border-right: 1px dashed var(--rule2); }
  .tally-item:last-child { border-right: none; }
}
.tally-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink3); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.tally-label::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--surface3, var(--rule2)); flex-shrink: 0; }
.tally-item.tone-rust .tally-label::before   { background: var(--rust); }
.tally-item.tone-amber .tally-label::before  { background: var(--amber); }
.tally-item.tone-forest .tally-label::before { background: var(--forest); }
.tally-item.tone-brand .tally-label::before  { background: var(--brand); }
.tally-val { font-family: var(--font-mono); font-size: clamp(18px, 3vw, 23px); font-weight: 700; letter-spacing: -0.02em; color: var(--ink); line-height: 1.1; }
.tally-val.rust { color: var(--rust); }
.tally-val.amber { color: var(--amber-ink); }
.tally-val.forest { color: var(--forest); }
.tally-val.brand { color: var(--brand-ink); }
.tally-sub { font-size: 10.5px; color: var(--ink3); margin-top: 3px; }

/* ═══════════════════════════════════════
   SEÇÃO
═══════════════════════════════════════ */
.section-label {
  font-size: 11px; font-weight: 700; color: var(--brand-ink);
  text-transform: uppercase; letter-spacing: 0.09em; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-label::before { content: ''; width: 16px; height: 2px; background: var(--brand); border-radius: 2px; }

/* ═══════════════════════════════════════
   FORM / CAMPOS
═══════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11.5px; font-weight: 700; color: var(--ink2); text-transform: uppercase; letter-spacing: 0.04em; }
.field input {
  height: 44px;
  background: var(--paper);
  border: none;
  border-bottom: 2px solid var(--rule2);
  color: var(--ink);
  font-size: 15px;
  padding: 0 2px;
  font-family: var(--font-sans);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--brand); }
.field input::placeholder { color: var(--ink3); }

/* ═══════════════════════════════════════
   BOTÕES
═══════════════════════════════════════ */
.btn {
  height: 44px; padding: 0 20px; border-radius: 9px; border: none;
  font-size: 14px; font-weight: 700; font-family: var(--font-sans);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity 0.15s, transform 0.1s, background 0.15s;
  white-space: nowrap; letter-spacing: -0.005em;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--ink); color: var(--paper); width: 100%; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: var(--paper2); color: var(--ink2); border: 1.5px solid var(--rule); }
.btn-ghost:hover { background: var(--paper3); color: var(--ink); }
.btn-danger { background: var(--rust-soft); color: var(--rust); border: 1.5px solid oklch(52% 0.17 32 / 0.25); }
.btn-success { background: var(--forest-soft); color: var(--forest); border: 1.5px solid oklch(45% 0.09 152 / 0.3); }
.btn-sm { height: 37px; font-size: 12.5px; padding: 0 13px; border-radius: 8px; }
.btn-xs { height: 30px; font-size: 11.5px; padding: 0 10px; border-radius: 7px; }

/* ═══════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════ */
.empty-state { text-align: center; padding: 48px 20px; color: var(--ink3); border: 1.5px dashed var(--rule2); border-radius: 10px; }
.empty-icon { font-size: 38px; margin-bottom: 12px; display: block; }
.empty-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; color: var(--ink2); margin-bottom: 5px; }
.empty-sub { font-size: 13.5px; }

/* ═══════════════════════════════════════
   MODAL / TOAST
═══════════════════════════════════════ */
.modal-overlay { display: none; position: fixed; inset: 0; background: oklch(30% 0.06 255 / 0.55); backdrop-filter: blur(6px); z-index: var(--z-modal); align-items: center; justify-content: center; padding: 24px; }
.modal-overlay.open { display: flex; animation: fadeIn 0.15s ease; }
.modal { background: var(--paper); border-radius: 16px; padding: 26px 24px 22px; max-width: 360px; width: 100%; box-shadow: var(--shadow-lg); animation: modalUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.modal-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin-bottom: 8px; }
.modal-body { font-size: 14px; color: var(--ink2); margin-bottom: 22px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalUp { from { opacity: 0; transform: scale(0.94) translateY(10px); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); border-radius: 10px; color: var(--paper);
  font-size: 13.5px; font-weight: 600; padding: 12px 20px; z-index: var(--z-toast);
  box-shadow: var(--shadow-lg);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s, visibility 0.25s;
  white-space: nowrap; pointer-events: none;
  /* invisível de verdade quando não há mensagem: sem isso, a caixa escura
     vazia ficava plantada no rodapé e cobria o item "Pagos" da barra. */
  opacity: 0; visibility: hidden;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

/* ═══════════════════════════════════════
   LEDGER LINE — cada "dia" é uma linha de lançamento,
   não um card. Traço pontilhado liga nome ao valor.
═══════════════════════════════════════ */
.ledger {
  border-top: 1px solid var(--rule);
  /* Rola dentro de si mesma quando há muitos lançamentos, em vez de
     esticar a página infinitamente pra baixo (vale mobile e desktop). */
  max-height: 56vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--rule2) transparent;
  /* degradê no fim sinalizando que há mais conteúdo rolável */
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(to bottom, black calc(100% - 22px), transparent 100%);
  padding-right: 6px;
}
.ledger::-webkit-scrollbar { width: 8px; }
.ledger::-webkit-scrollbar-track { background: transparent; }
.ledger::-webkit-scrollbar-thumb { background: var(--rule2); border-radius: 8px; }
.ledger-line { border-bottom: 1px solid var(--rule); padding: 14px 2px; }

.ll-row { display: flex; align-items: baseline; gap: 10px; }
.ll-nome { font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--ink); flex-shrink: 0; }
.ll-leader { flex: 1; border-bottom: 1px dotted var(--rule2); position: relative; top: -4px; min-width: 20px; }
.ll-total { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: var(--ink); flex-shrink: 0; }
.ll-total.rust { color: var(--rust); }
.ll-total.forest { color: var(--forest); }

.ll-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 7px; }
.ll-tag {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 20px;
}
.ll-tag.rust   { color: var(--rust);   background: var(--rust-soft); }
.ll-tag.forest { color: var(--forest); background: var(--forest-soft); }
.ll-tag.amber  { color: var(--amber-ink); background: var(--amber-soft); }
.ll-tag.neu    { color: var(--ink3); background: var(--paper2); }
.ll-detail { font-size: 12px; color: var(--ink3); font-family: var(--font-mono); }
.ll-detail b { color: var(--ink2); font-weight: 600; }

/* Controles em linha própria, sempre à direita — antes ficavam dentro do
   .ll-meta e só "caíam" pra baixo quando o texto era comprido o bastante,
   o que deixava cada lançamento com um layout diferente. */
.ll-controls { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.ll-actions { display: flex; gap: 4px; }
.ll-actions button {
  width: 27px; height: 27px; border-radius: 7px; background: none;
  border: 1px solid var(--rule); color: var(--ink3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  transition: all 0.15s; flex-shrink: 0;
}
.ll-actions button:hover.ll-edit { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); }
.ll-actions .ll-del:hover { background: var(--rust-soft); border-color: var(--rust); color: var(--rust); }
.ll-actions .ll-edit:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); }

.ll-pay-btn {
  background: var(--ink); color: var(--paper); border: none;
  height: 30px; padding: 0 12px; border-radius: 7px;
  font-size: 11.5px; font-weight: 700; cursor: pointer; transition: background 0.15s;
}
.ll-pay-btn:hover { background: var(--brand-ink); }

.ll-form { margin-top: 10px; display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; padding-top: 10px; border-top: 1px dashed var(--rule2); }
.ll-form .field { flex: 1; min-width: 130px; }
.ll-form .field input { height: 38px; font-size: 13px; }

/* ═══════════════════════════════════════
   MOBILE — as abas viram barra fixa inferior (dock), sempre
   com os 5 destinos visíveis, sem rolagem que escondia o Config.
═══════════════════════════════════════ */
@media (max-width: 699px) {
  .desk { padding: 10px 0 calc(70px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* folha ocupa a largura toda no celular, com cantos só no topo */
  .paper { border-radius: 14px 14px 0 0; margin: 0 8px; min-height: auto; }
  .paper::before { left: 16px; right: 16px; }

  /* ── compactação mobile: mais conteúdo visível por tela ── */
  .brand-mark { font-size: 17px; margin-bottom: 8px; }
  .paper-inner { padding: 14px 14px 24px; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 25px; }
  .page-head .kicker { font-size: 11.5px; }

  .tally { margin-bottom: 18px; }
  .tally-item { padding: 9px 10px; }
  .tally-label { font-size: 9px; margin-bottom: 3px; letter-spacing: 0.06em; }
  .tally-label::before { width: 6px; height: 6px; }
  .tally-val { font-size: 17px; }
  .tally-sub { font-size: 9.5px; margin-top: 2px; }

  .section-label { margin-bottom: 8px; font-size: 10px; }
  .field input { height: 40px; font-size: 14.5px; }
  .field label { font-size: 10.5px; }
  .btn { height: 42px; font-size: 13.5px; }

  .ledger-line { padding: 11px 2px; }
  .ll-nome { font-size: 15.5px; }
  .ll-total { font-size: 16px; }
  .ll-meta { margin-top: 5px; }
  .ll-detail { font-size: 11px; }
  .ll-controls { margin-top: 7px; }

  .index-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: var(--z-tabs);
    gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    max-width: none;
    overflow: visible;
    background: oklch(30% 0.07 258 / 0.97);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border-top: 1px solid oklch(55% 0.1 255 / 0.4);
    box-shadow: 0 -6px 24px oklch(30% 0.08 255 / 0.35);
  }
  .index-tab {
    flex: 1 1 0;
    flex-direction: column;
    gap: 3px;
    padding: 7px 2px 6px;
    font-size: 10px;
    letter-spacing: 0.01em;
    background: transparent;
    border-radius: 12px;
    transform: none;
    color: oklch(90% 0.03 255 / 0.7);
  }
  .index-tab svg { width: 21px; height: 21px; opacity: 1; }
  .index-tab.active {
    background: var(--brand);
    color: oklch(99% 0.01 255);
    transform: none;
    box-shadow: none;
  }
  .index-tab:not(.active):hover { background: oklch(50% 0.08 255 / 0.4); color: oklch(95% 0.02 255 / 0.9); }
}

/* ═══════════════════════════════════════
   RESPONSIVO GERAL
═══════════════════════════════════════ */
@media (min-width: 700px) {
  .paper-inner { padding: 24px 44px 36px; }
  .ledger { max-height: 62vh; }
}
@media (min-width: 1100px) {
  .index-tabs, .paper { max-width: 1180px; }
  .paper-inner.wide { padding-left: 52px; padding-right: 52px; }
}
