/* ================================================================
   LAYOUT.CSS — App shell, header, footer, navigation, containers
   Part of the RustyBlade BootCamp stylesheet, split for maintainability.
   Load AFTER base.css.
   ================================================================ */

/* ================================================================
   SECTION 6: HEADER COMPONENTS
   ================================================================ */

.settings-gear {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-size: 1rem;
}
.settings-gear:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: transparent;
}
.settings-gear:active {
  transform: scale(0.95);
}
.settings-gear:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-size: 1rem;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-text);
  background: transparent;
}
.theme-toggle:active {
  transform: scale(0.95);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ================================================================
   SECTION 7: BOTTOM NAVIGATION
   ================================================================ */

.bottom-nav {
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 20px);
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 1px;
  padding: 5px 6px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  transition: opacity 0.2s, transform 0.2s;
}
.bottom-nav.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
}

.bottom-nav.hide-on-home {
  display: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
  padding: 3px 2px;
  border-radius: 12px;
  min-height: 40px;
  min-width: 36px;
  justify-content: center;
  gap: 0px;
  font-family: var(--font);
}
.nav-item span:first-child {
  font-size: 1.0625rem;
}
.nav-item.active {
  color: var(--nav-text);
  background: var(--accent-nav);
  font-weight: 600;
}
.nav-item .nav-label {
  font-size: 0.5rem;
  line-height: 1.1;
  margin-top: 1px;
}


/* ================================================================
   SECTION 8: APP HEADER (deprecated – kept for backward compatibility)
   ================================================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  margin-bottom: 6px;
  flex-wrap: nowrap;
  gap: 6px;
  min-height: 56px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 1;
  min-width: 0;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}
.header-right .btn {
  font-size: 0.6875rem;
  padding: 4px 10px;
  min-height: 34px;
  min-width: 34px;
}


/* ================================================================
   SECTION 29: ACCESSIBILITY
   ================================================================ */

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

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

.settings-page a:focus-visible,
.settings-page button:focus-visible,
.settings-page input:focus-visible,
.settings-page select:focus-visible,
.settings-page .theme-card:focus-visible,
.settings-gear:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.settings-page .theme-card:focus-visible {
  border-color: var(--accent);
}

.skip-link {
  position: absolute;
  top: -9999px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  padding: 8px 16px;
  z-index: 10000;
  border-radius: 0 0 8px 8px;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 0.875rem;
}
.skip-link:focus {
  top: 0;
}

.settings-page,
.logbook-page,
.admin-container,
.track-container {
  overscroll-behavior: contain;
}


/* ================================================================
   SECTION 31: APP LOADING OVERLAY
   ================================================================ */

#loadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  font-family: var(--font);
  opacity: 1;
  transition: opacity 0.35s ease;
  pointer-events: auto;
}
#loadingOverlay.fade-out {
  opacity: 0;
  pointer-events: none;
}
#loadingOverlay .spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
#loadingOverlay .load-text {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}


/* ================================================================
   SECTION 32: FIXED APP SHELL LAYOUT – AUTHORITATIVE
   ================================================================ */

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#app {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  height: 100vh; /* fallback */
  height: 100dvh; /* FIX: Safari iOS dynamic toolbar — dvh tracks the real visible viewport */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#dashboard {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  position: relative; /* anchors #pullToRefreshIndicator below */
}

/* FIX (feature request): pull-to-refresh indicator, no manual button —
   sits just above the content, initially translated out of view. main.js
   drives --pull-distance as the user drags; "active" adds a spin while a
   refresh is actually in flight, "releasing" gives a smooth snap-back
   instead of an abrupt jump when the gesture ends below the threshold. */
#pullToRefreshIndicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, calc(-100% + var(--pull-distance, 0px)));
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  z-index: 5;
  opacity: var(--pull-opacity, 0);
}
#pullToRefreshIndicator.releasing {
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#pullToRefreshIndicator.active {
  transform: translate(-50%, 12px);
  opacity: 1;
}
#pullToRefreshIndicator.active svg {
  animation: spin 0.8s linear infinite;
}

#pageContent {
  flex: 1 1 auto;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  min-height: 0;
  overscroll-behavior: contain;
  transition: transform 0.25s ease;
}

.app-header {
  flex-shrink: 0;
}


/* ================================================================
   APP HEADER – matches landing page (new)
   ================================================================ */

.app-header {
  height: 66px;
  width: 100%;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.app-brand {
  display: flex;
  align-items: center;
}
.app-logo {
  height: 42px;
  width: auto;
  display: block;
}
.app-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
  flex-shrink: 1;
}
.app-actions .nav-divider {
  height: 18px;
  width: 1px;
  background: var(--line);
}
.logout-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--red);
  color: var(--foreground);
  font-size: 10px;
  letter-spacing: 0.14em;
  background: transparent;
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}
.logout-button:hover {
  background: var(--red);
  color: #fff;
}
.theme-toggle {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}
.theme-toggle:hover {
  color: var(--text);
}


/* ================================================================
   APP HEADER – redesigned (final)
   ================================================================ */

.app-header {
  /* FIX (PWA safe-area): height and padding-top both grow by the same
     safe-area amount, so the header gets taller to accommodate a
     notch/status bar rather than the fixed 66px shrinking its own
     content area if only padding were added. env() with a fallback
     resolves to 0px on any browser without safe-area support. */
  height: calc(66px + env(safe-area-inset-top, 0px));
  width: 100%;
  padding: 0 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px)); /* added extra space above the header */
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.app-header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.app-brand {
  display: flex;
  align-items: center;
}
.app-logo {
  height: 38px;
  width: auto;
  display: block;
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.header-icon-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 1.1rem;
  padding: 0;
}
.header-icon-btn:hover {
  background: var(--surface-variant);
  color: var(--text);
}
.header-icon-btn:active {
  transform: scale(0.92);
}
.logout-button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 6px;
  font-family: var(--font);
  text-transform: uppercase;
}
.logout-button:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.logout-button:active {
  transform: scale(0.95);
}
.logout-button svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
}
