/* Gaffer IQ — layout.css
   App shell: sticky nav, module sections, horizon switcher.
   No component-specific styles here — those belong in components.css.
   All values reference var(--…) from base.css. */

/* ─── App shell ──────────────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Top nav ────────────────────────────────────────────────────────────── */

.app-nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-6);
  height: 52px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.app-nav__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--color-text);
  flex-shrink: 0;
}

.app-nav__logo {
  font-size: var(--font-size-lg);
  line-height: 1;
}

.app-nav__title {
  font-size: var(--font-size-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* ─── Module navigation ──────────────────────────────────────────────────── */

.module-nav {
  display: flex;
  gap: 0;
  flex: 1;
}

.module-nav__item {
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  height: 52px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.module-nav__item:hover {
  color: var(--color-text);
}

.module-nav__item.is-active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.module-nav__item--inactive {
  opacity: 0.35;
  pointer-events: none;
}

/* ─── Horizon switcher ───────────────────────────────────────────────────── */

.horizon-switcher {
  display: flex;
  gap: var(--space-1);
  margin-left: auto;
  flex-shrink: 0;
}

.horizon-switcher__btn {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.horizon-switcher__btn:hover {
  background: var(--color-surface-raised);
  color: var(--color-text);
  border-color: var(--color-muted);
}

.horizon-switcher__btn.is-active {
  background: var(--color-accent-muted);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ─── Main content ───────────────────────────────────────────────────────── */

.app-main {
  flex: 1;
  padding: var(--space-6);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ─── Module sections ────────────────────────────────────────────────────── */

.module-view {
  display: none;
}

.module-view.is-active {
  display: block;
}

/* ─── Error banner ───────────────────────────────────────────────────────── */

.app-error-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--band-brutal-bg);
  border: 1px solid var(--band-brutal);
  border-radius: var(--radius-md);
  color: var(--band-brutal);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-4);
}

/* The HTML `hidden` attribute applies `display: none` via the user-agent
   stylesheet, but the author rule above (`display: flex`) overrides it.
   Restore the expected behaviour so the banner stays hidden until an error
   actually fires. */
.app-error-banner[hidden] {
  display: none;
}

.app-error-banner__retry {
  background: none;
  border: 1px solid var(--band-brutal);
  border-radius: var(--radius-sm);
  color: var(--band-brutal);
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-family: var(--font-sans);
  padding: 2px var(--space-2);
  flex-shrink: 0;
  transition: background 0.15s;
}

.app-error-banner__retry:hover {
  background: var(--band-brutal-bg);
}

/* ─── Module loading / placeholder ──────────────────────────────────────── */

.app-status {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  color: var(--color-muted);
  font-size: var(--font-size-md);
}

.coming-soon {
  color: var(--color-muted);
  font-size: var(--font-size-md);
  padding: var(--space-8) 0;
  text-align: center;
}

/* ─── Responsive fallback ────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app-nav {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-2);
  }

  .module-nav {
    order: 3;
    width: 100%;
    border-top: 1px solid var(--color-border);
  }

  .module-nav__item {
    height: 40px;
    padding: 0 var(--space-3);
    font-size: var(--font-size-xs);
  }

  .horizon-switcher {
    margin-left: 0;
  }

  .horizon-switcher__btn {
    font-size: var(--font-size-xs);
    padding: 2px var(--space-2);
  }

  .app-main {
    padding: var(--space-4);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE LAYOUT  ≤ 768px — Phase 4-5
   All desktop rules above are completely untouched; this block is purely
   additive. Overrides the 900px breakpoint where needed.
   Test breakpoints: 375px (iPhone SE), 390px (iPhone 14), 768px (tablet).
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ─── App shell ────────────────────────────────────────────────────────── */

  /* Reserve space for the fixed bottom tab bar (56px) plus system safe-area
     (home indicator on iPhone 14 etc.) so the last content row is never
     hidden behind the tab bar. */
  .app-main {
    padding: var(--space-3);
    padding-bottom: calc(56px + var(--space-4) + env(safe-area-inset-bottom, 0px));
  }

  /* ─── Top nav — slimmed to brand + horizon switcher only ──────────────── */

  /* The module nav is fixed to the bottom (see below), so it no longer takes
     up space here. The app-nav becomes a single-row brand + switcher bar. */
  .app-nav {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    align-items: center;
  }

  .app-nav__title {
    font-size: var(--font-size-sm);
  }

  /* ─── Bottom tab bar — replaces the inline module nav ─────────────────── */

  /* position:fixed removes the element from the app-nav flex flow, making the
     app-nav naturally show only brand + horizon switcher. The tab bar sits
     above the system home indicator via env(safe-area-inset-bottom). */
  .module-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    flex-direction: row;
    order: unset;
    width: 100%;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    border-bottom: none;
    /* Push tabs above the iOS home indicator */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .module-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 56px total: 44px tap target + breathing room. */
    height: 56px;
    min-height: 44px;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 600;
    /* Active indicator moves from bottom underline to top accent bar. */
    border-bottom: none;
    border-top: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
  }

  .module-nav__item.is-active {
    color: var(--color-accent);
    border-bottom-color: transparent;
    border-top-color: var(--color-accent);
  }

  /* ─── Horizon switcher — full width below brand ────────────────────────── */

  .horizon-switcher {
    width: 100%;
    margin-left: 0;
    display: flex;
    justify-content: stretch;
  }

  .horizon-switcher__btn {
    flex: 1;
    text-align: center;
    /* 44px minimum tap target */
    min-height: 44px;
    padding: var(--space-2);
    font-size: var(--font-size-xs);
  }
}
