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

/* Main content */
#main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-md);
  padding-bottom: calc(var(--nav-height) + var(--space-lg));
}

/* Hide sidebar brand on mobile */
.sidebar-brand {
  display: none;
}

/* Respect hidden attribute on nav */
.bottom-nav[hidden] {
  display: none;
}

/* Bottom navigation — mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xs);
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  transition: color var(--duration-fast) var(--ease-out);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

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

.nav-item--active {
  color: var(--color-accent);
}

.nav-icon {
  width: 24px;
  height: 24px;
}

.nav-label {
  font-weight: var(--weight-medium);
}

/* Hide desktop-only nav items on mobile (moved under Settings) */
.nav-item--desktop-only {
  display: none;
}

/* Nav spacer — pushes settings to bottom on desktop */
.nav-spacer {
  display: none;
}

/* Desktop sidebar — ≥1024px */
@media (min-width: 1024px) {
  #app {
    flex-direction: row;
  }

  .bottom-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: auto;
    width: var(--sidebar-width);
    height: 100%;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: var(--space-xl) var(--space-md);
    gap: var(--space-xs);
    border-top: none;
    border-right: 1px solid var(--color-border);
  }

  .nav-item--desktop-only {
    display: flex;
  }

  .nav-spacer {
    display: block;
    flex: 1;
  }

  .sidebar-brand {
    display: block;
    font-family: var(--font-heading);
    font-size: var(--text-h3);
    font-weight: var(--weight-bold);
    color: var(--color-text);
    margin-bottom: var(--space-xl);
    padding: 0 var(--space-sm);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--text-body-sm);
  }

  .nav-item:hover {
    background: var(--color-surface-2);
  }

  .nav-item--active {
    background: var(--color-accent-dim);
    color: var(--color-accent);
  }

  #main {
    margin-left: var(--sidebar-width);
    padding: var(--space-xl) var(--space-2xl);
    padding-bottom: var(--space-xl);
  }

  /* Remove sidebar margin when nav is hidden (not logged in) */
  #app:has(.bottom-nav[hidden]) #main {
    margin-left: 0;
  }
}

/* Wide mode — stats, history */
#main.main--wide {
  max-width: 1100px;
}

/* Table mode — full width */
#main.main--table {
  max-width: none;
}

@media (min-width: 1024px) {
  #main.main--table {
    padding: var(--space-md) var(--space-lg);
  }
}

/* Page header */
.page-header {
  margin-bottom: var(--space-lg);
}

@media (min-width: 768px) {
  .page-header {
    margin-bottom: var(--space-xl);
  }
}

.page-title {
  font-size: var(--text-h2);
  margin-bottom: var(--space-xs);
}

.page-subtitle {
  font-size: var(--text-body-sm);
  color: var(--color-text-muted);
}

/* Loading state */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60dvh;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
