/* =====================================================================
   TOKENS
   ===================================================================== */
:root {
  --bg: #14171c;
  --surface: #1c2129;
  --surface-raised: #242a34;
  --border: #2e3542;
  --text: #ecead5;
  --text-muted: #8b92a0;

  --amber: #e8a33d;
  --amber-ink: #221704;
  --sage: #6fa287;
  --sage-ink: #0d1712;
  --terracotta: #d97d7d;
  --terracotta-ink: #200909;
  --blue: #5b8fae;
  --blue-ink: #071219;

  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;

  --font-display: "Manrope", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 {
  font-family: var(--font-display);
  margin: 0;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
}

p { margin: 0; line-height: 1.5; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* evita zoom automático no iOS */
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 10px 12px;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

a { color: inherit; }

/* =====================================================================
   LAYOUT
   ===================================================================== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  padding: 20px 20px 8px;
}

.topbar__greeting {
  font-size: 1.5rem;
}

.topbar__date {
  color: var(--text-muted);
  margin-top: 2px;
  font-size: 0.92rem;
  text-transform: capitalize;
}

main {
  flex: 1;
  padding: 8px 20px 100px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fadein 0.18s ease-out; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Navegação inferior (mobile) */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tabbar__item {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: var(--radius-s);
  font-size: 0.68rem;
}

.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__item.active { color: var(--amber); }

/* Navegação lateral (desktop) */
.sidebar { display: none; }

@media (min-width: 860px) {
  #app { flex-direction: row; }
  .tabbar { display: none; }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    padding: 24px 14px;
    border-right: 1px solid var(--border);
    gap: 2px;
  }
  .sidebar__brand {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.25rem;
    padding: 0 12px 20px;
  }
  .sidebar__item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    color: var(--text-muted);
    padding: 11px 12px;
    border-radius: var(--radius-s);
    font-size: 0.95rem;
    text-align: left;
  }
  .sidebar__item svg { width: 20px; height: 20px; }
  .sidebar__item.active { color: var(--text); background: var(--surface-raised); }
  main { padding: 32px 40px 60px; max-width: 720px; margin: 0; }
  .topbar { display: none; }
}

/* =====================================================================
   COMPONENTES
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 16px;
}

.section-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 24px 0 10px;
  padding: 0 2px;
}
.section-title:first-child { margin-top: 4px; }

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

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 13px 14px;
}

.item__check {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid var(--text-muted);
  background: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}
.item__check.done {
  background: var(--sage);
  border-color: var(--sage);
  color: var(--sage-ink);
}

.item__body { flex: 1; min-width: 0; }
.item__title { font-size: 0.96rem; }
.item__title.done { color: var(--text-muted); text-decoration: line-through; }
.item__meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.item__accent { width: 4px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.item__accent--amber { background: var(--amber); }
.item__accent--blue { background: var(--blue); }
.item__accent--sage { background: var(--sage); }
.item__accent--terracotta { background: var(--terracotta); }

.badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-muted);
  flex-shrink: 0;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 86px;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-2);
  z-index: 15;
}
.fab svg { width: 24px; height: 24px; }

@media (min-width: 860px) {
  .fab { bottom: 40px; right: 40px; width: 58px; height: 58px; }
  .fab svg { width: 26px; height: 26px; }
}

.btn {
  padding: 11px 18px;
  border-radius: var(--radius-s);
  font-size: 0.92rem;
  font-weight: 600;
  background: var(--surface-raised);
  color: var(--text);
}
.btn--primary { background: var(--amber); color: var(--amber-ink); }
.btn--danger { background: transparent; color: var(--terracotta); }
.btn--block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.82rem; color: var(--text-muted); }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Modal / folha inferior */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: none;
}
.sheet-backdrop.open { display: block; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  z-index: 31;
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  max-height: 85dvh;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }

.sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 0 auto 16px;
}

.sheet__title { font-size: 1.15rem; margin-bottom: 16px; }

/* Resumo financeiro */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}
.summary-card { padding: 14px; }
.summary-card__label { font-size: 0.78rem; color: var(--text-muted); }
.summary-card__value { font-family: var(--font-display); font-size: 1.35rem; margin-top: 4px; }
.summary-card__value.positive { color: var(--sage); }
.summary-card__value.negative { color: var(--terracotta); }

/* Hábitos */
.habit-row { display: flex; align-items: center; gap: 12px; }
.habit-row__progress {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.habit-row__streak {
  font-size: 0.78rem;
  color: var(--amber);
  flex-shrink: 0;
}

/* Login */
.login-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px;
  max-width: 400px;
  margin: 0 auto;
}
.login-view h1 { font-size: 1.7rem; margin-bottom: 6px; }
.login-view p.subtitle { color: var(--text-muted); margin-bottom: 28px; }
.login-error {
  color: var(--terracotta);
  font-size: 0.85rem;
  margin: -6px 0 14px;
  min-height: 1em;
}
.login-toggle {
  text-align: center;
  margin-top: 18px;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.login-toggle button { background: none; color: var(--amber); font-weight: 600; padding: 4px; }

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
