*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    repeating-linear-gradient(0deg, transparent 0 11px, rgb(var(--shadow-color) / 0.016) 11px 12px),
    repeating-linear-gradient(90deg, transparent 0 11px, rgb(var(--shadow-color) / 0.012) 11px 12px);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: var(--ink);
}

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

a {
  color: var(--primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img,
svg {
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  line-height: var(--leading-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
  letter-spacing: -0.025em;
}

h2 {
  font-size: var(--text-xl);
  letter-spacing: -0.015em;
}

h3 {
  font-size: var(--text-lg);
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 200;
  transform: translateY(-180%);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 650;
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
}

.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;
}

.noscript {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  max-width: 32ch;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  text-align: center;
}

/* ---------- Estructura de la app ---------- */

.app {
  min-height: 100dvh;
}

.app-frame {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
  max-width: var(--frame-w);
  margin: 0 auto;
  position: relative;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--header-h);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 48px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--primary);
  flex: none;
}

.brand-mark .cord-side {
  opacity: 0.55;
}

.brand-mark .knot-a {
  fill: var(--accent);
}

.brand-mark .knot-b {
  fill: var(--expense);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.chakana-band {
  display: block;
  width: 100%;
  height: 12px;
  color: var(--primary);
  flex: none;
}

.app-main {
  flex: 1;
  width: 100%;
  padding: var(--space-4);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 96px);
  outline: none;
}

.app-aside {
  display: none;
}

/* ---------- Navegación inferior ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  max-width: var(--frame-w);
  min-height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding: var(--space-1) var(--space-2) env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgb(var(--shadow-color) / 0.08);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  padding: 4px 2px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 28px;
  border-radius: var(--radius-pill);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-icon svg {
  width: 22px;
  height: 22px;
}

.nav-item:hover {
  color: var(--ink);
}

.nav-item[aria-current="page"] {
  color: var(--primary);
}

.nav-item[aria-current="page"] .nav-icon {
  background: var(--surface-2);
}

/* ---------- Botones flotantes ---------- */

.fab-cluster {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  justify-content: center;
  gap: var(--space-6);
  width: 100%;
  max-width: var(--frame-w);
  padding: 0 var(--space-4);
  pointer-events: none;
}

.fab {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--on-expense);
  box-shadow: var(--shadow-2);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

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

.fab-expense {
  background: var(--expense);
}

.fab-income {
  background: var(--income);
  color: var(--on-income);
}

.fab:hover {
  transform: translateY(-2px);
}

.fab:active {
  transform: translateY(0) scale(0.96);
}

/* ---------- Escritorio ---------- */

@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--frame-w) var(--aside-w);
    gap: var(--space-8);
    align-items: start;
    justify-content: center;
    max-width: calc(var(--frame-w) + var(--aside-w) + var(--space-16));
    margin: 0 auto;
    padding: 0 var(--space-8);
  }

  .app-frame {
    min-height: 100dvh;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 55%, transparent);
  }

  .app-aside {
    display: block;
    position: sticky;
    top: var(--space-8);
    padding-top: var(--space-4);
  }

  .bottom-nav,
  .fab-cluster {
    left: calc(50% - (var(--aside-w) + var(--space-8)) / 2);
  }
}

/* ---------- Sesión / acceso ---------- */

body[data-auth="true"] .app-header,
body[data-auth="true"] .chakana-band,
body[data-auth="true"] .bottom-nav,
body[data-auth="true"] .fab-cluster,
body[data-auth="true"] .app-aside {
  display: none;
}

body[data-route="more"] .fab-cluster {
  display: none;
}

body.sheet-open {
  overflow: hidden;
}

body[data-auth="true"] .app {
  display: block;
  max-width: none;
  padding: 0;
}

body[data-auth="true"] .app-frame {
  max-width: none;
  min-height: 100dvh;
  border: 0;
  background: transparent;
}

body[data-auth="true"] .app-main {
  padding: 0;
}

/* ---------- Movimiento ---------- */

.view-enter {
  animation: view-in var(--dur) var(--ease-out) both;
}

@keyframes view-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
