/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 16px; }
ul, ol { list-style: none; }
img { display: block; max-width: 100%; }

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--clr-accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: 4px; }
html { scrollbar-width: thin; scrollbar-color: var(--clr-border) transparent; }

/* ============================================================
   LAYOUT SHELL
   ============================================================ */
.app-shell {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
}

/* TOP HEADER (mobile) */
.top-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--clr-border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  background: var(--clr-header-bg, var(--clr-bg));
}

.top-header__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.02em;
}

.top-header__brand-icon {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  overflow: hidden;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  -webkit-flex-shrink: 0; flex-shrink: 0;
}
.top-header__brand-icon img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}

.top-header__month-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.month-nav__btn {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid var(--clr-border);
  color: var(--clr-text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  font-size: 14px;
}
.month-nav__btn:hover { background: var(--clr-surface); color: var(--clr-text); }

.month-nav__label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--clr-text);
  min-width: 100px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* MAIN CONTENT AREA */
.main-content {
  flex: 1;
  padding: var(--sp-4) var(--sp-4) calc(var(--bottom-nav-h) + var(--sp-4));
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--bottom-nav-h);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: stretch;
  align-items: stretch;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav__brand {
  display: none; /* shown on desktop via media query */
}

.bottom-nav__item {
  flex: 1;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  gap: 4px;
  padding: var(--sp-2) 0;
  color: var(--clr-text-dim);
  transition: color var(--t-fast);
  font-size: .625rem;
  font-weight: 500;
  letter-spacing: .03em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.bottom-nav__item.is-active { color: var(--clr-accent); }
.bottom-nav__item:hover { color: var(--clr-text-muted); }

.bottom-nav__icon {
  font-size: 20px;
  line-height: 1;
}

/* PAGE SECTIONS */
.page { display: none; }
.page.is-active { display: block; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

.fade-in { animation: fadeIn var(--t-base) ease forwards; }

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

/* ============================================================
   DESKTOP RESPONSIVE (min-width: 768px)
   ============================================================ */
@media (min-width: 768px) {
  .app-shell {
    flex-direction: row;
  }

  .top-header {
    display: none;
  }

  .bottom-nav {
    position: fixed;
    left: 0; top: 0; bottom: 0; right: auto;
    width: 240px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-top: none;
    border-right: 1px solid var(--clr-border);
    padding: var(--sp-6) var(--sp-4) var(--sp-6);
  }

  .bottom-nav__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -.02em;
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-5);
    border-bottom: 1px solid var(--clr-border);
    padding-bottom: var(--sp-5);
  }

  .bottom-nav__brand-icon {
    width: 40px; height: 40px;
  }

  .bottom-nav__item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--sp-3);
    padding: 11px var(--sp-4);
    border-radius: var(--r-md);
    font-size: .875rem;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 500;
    margin-bottom: 2px;
  }

  .bottom-nav__item.is-active {
    background: var(--clr-accent-bg);
  }

  .bottom-nav__icon { font-size: 18px; }

  .main-content {
    margin-left: 240px;
    max-width: 1200px;
    padding: var(--sp-8) var(--sp-10) calc(var(--sp-10) + env(safe-area-inset-bottom, 0px));
  }

  .balance-hero {
    padding: var(--sp-8) var(--sp-10);
  }

  .balance-hero__amount {
    font-size: 3.5rem;
  }

  .fab {
    bottom: var(--sp-6);
    right: var(--sp-6);
  }

  .lgpd-banner {
    bottom: var(--sp-4);
    left: 260px;
    right: var(--sp-4);
  }
}

/* ============================================================
   SKELETON LOADER
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg, var(--clr-surface) 25%, var(--clr-surface-2) 50%, var(--clr-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
}

/* ============================================================
   SMOOTH THEME TRANSITION
   ============================================================ */
body, .card, .drawer, .bottom-nav, .top-header,
.balance-hero, .tx-item, .goal-card, .debt-item,
.overlay, .lgpd-banner, .fab, .btn, .form-control,
.tx-filter-chip, .tx-filter-select, .tab-bar,
.tab-bar__tab, .backup-btn, .theme-btn {
  transition-property: background-color, border-color, color;
  transition-duration: 300ms;
  transition-timing-function: ease;
}

/* ============================================================
   SR-ONLY & UTILITY CLASSES
   ============================================================ */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.text-green  { color: var(--clr-green) !important; }
.text-red    { color: var(--clr-red)   !important; }
.text-amber  { color: var(--clr-amber) !important; }
.text-muted  { color: var(--clr-text-muted); }
.text-mono   { font-family: var(--font-mono); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }

.divider {
  height: 1px;
  background: var(--clr-border);
  margin: var(--sp-4) 0;
}