/* ═══════════════════════════════════════════════════════════════
   PRAS Field — App Shell (Phase 3A)
   ───────────────────────────────────────────────────────────────
   Sidebar nav (desktop) + icon rail (tablet) + bottom nav + drawer
   (phone). The legacy top .tab-bar is preserved in the DOM but
   hidden — every IIFE that calls switchTab('<id>') still works
   because we kept .tab-btn[data-tab=<id>] handlers. The sidebar
   and bottom nav dispatch to the same switchTab() by clicking the
   matching legacy tab button, so the router is backwards-compatible
   and zero-touch for every existing view.

   Breakpoints (declarative, match tokens.css documentation):
     < 768px   — phone: sidebar hidden, bottom nav visible, drawer opens on More
     768-1023  — tablet: icon-rail sidebar (no labels, no toggle)
     ≥ 1024px  — desktop: full sidebar, toggle collapses to icon rail
   ═══════════════════════════════════════════════════════════════ */

/* ══════════ Shell layout ═══════════════════════════════════════ */

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

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  flex: 1;
  min-height: calc(100vh - var(--header-height));
}

.app-main {
  padding: var(--space-5) var(--space-4);
  overflow-x: hidden;
  background: var(--color-50);
}

.app-main .tab-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0;
}

/* ══════════ Sidebar ════════════════════════════════════════════ */

.app-sidebar {
  background: var(--color-900);
  color: var(--color-100);
  border-right: 1px solid rgba(201, 168, 76, 0.12);
  padding: var(--space-4) 0;
  position: sticky;
  top: var(--header-height);
  align-self: start;
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.app-sidebar__section-title {
  padding: var(--space-4) var(--space-5) var(--space-1);
  color: var(--color-400);
  font-family: var(--font-header);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.app-sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  min-height: var(--touch-pref);
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  color: var(--color-100);
  font-family: var(--font-header);
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease-out, color 120ms ease-out, border-color 120ms ease-out;
}

.app-sidebar__item:hover {
  background: rgba(201, 168, 76, 0.08);
  color: var(--color-gold);
}

.app-sidebar__item.active {
  background: rgba(201, 168, 76, 0.12);
  color: var(--color-gold);
  border-left-color: var(--color-gold);
}

.app-sidebar__item:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: -2px;
}

.app-sidebar__icon {
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1;
}

.app-sidebar__label {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.app-sidebar__badge {
  background: var(--color-gold);
  color: var(--color-900);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  min-width: 22px;
  text-align: center;
}

.app-sidebar__spacer {
  flex: 1;
}

/* Version + environment strip at bottom of sidebar (nice touch for admin sanity) */
.app-sidebar__footer {
  padding: var(--space-3) var(--space-5);
  color: var(--color-500);
  font-size: var(--text-xs);
  text-align: center;
  border-top: 1px solid rgba(201, 168, 76, 0.08);
  margin-top: var(--space-4);
}

/* ══════════ Header tweaks (sidebar-toggle + future search) ════ */

.app-sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: var(--radius);
  color: var(--color-gold);
  cursor: pointer;
  margin-right: var(--space-3);
  font-size: 1.1rem;
  line-height: 1;
}

.app-sidebar-toggle:hover {
  background: rgba(201, 168, 76, 0.08);
}

.app-sidebar-toggle:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 1px;
}

/* ══════════ Bottom nav (phone) + drawer ═══════════════════════ */

.app-bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-nav-height);
  background: var(--color-900);
  border-top: 1px solid rgba(201, 168, 76, 0.18);
  z-index: var(--z-sticky);
  padding-bottom: env(safe-area-inset-bottom);
}

.app-bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  color: var(--color-400);
  font-family: var(--font-header);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  min-height: var(--touch-pref);
  padding: var(--space-2);
}

.app-bottom-nav__item.active {
  color: var(--color-gold);
}

.app-bottom-nav__icon {
  font-size: 1.4rem;
  line-height: 1;
}

/* Drawer overlay for mobile "More" menu */
.app-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13, 13, 10, 0.6);
  z-index: var(--z-overlay);
}

.app-drawer-overlay.open {
  display: block;
}

.app-drawer {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 84%;
  max-width: 320px;
  background: var(--color-900);
  color: var(--color-100);
  padding: var(--space-4) 0 calc(var(--bottom-nav-height) + var(--space-4));
  transform: translateX(-100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  z-index: var(--z-modal);
  overflow-y: auto;
}

.app-drawer.open {
  transform: translateX(0);
}

.app-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(201, 168, 76, 0.12);
  margin-bottom: var(--space-4);
}

.app-drawer__title {
  color: var(--color-gold);
  font-family: var(--font-header);
  font-size: var(--text-base);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.app-drawer__close {
  background: transparent;
  border: 0;
  color: var(--color-100);
  font-size: 1.5rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
}

/* ══════════ Collapsed sidebar (desktop toggle) ════════════════ */

.app-shell[data-sidebar="collapsed"] .app-body {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

.app-shell[data-sidebar="collapsed"] .app-sidebar__label,
.app-shell[data-sidebar="collapsed"] .app-sidebar__section-title,
.app-shell[data-sidebar="collapsed"] .app-sidebar__footer,
.app-shell[data-sidebar="collapsed"] .app-sidebar__badge {
  display: none;
}

.app-shell[data-sidebar="collapsed"] .app-sidebar__item {
  justify-content: center;
  padding: var(--space-3) 0;
  gap: 0;
}

.app-shell[data-sidebar="collapsed"] .app-sidebar__item.active {
  /* No left border on icon rail — just the bg tint */
  border-left-color: var(--color-gold);
}

/* ══════════ Hide legacy top tab bar (nav replaced) ═══════════ */
/* Preserved in DOM for switchTab() backwards-compat. */

.tab-bar {
  display: none !important;
}

/* ══════════ Responsive ═══════════════════════════════════════ */

/* Tablet: always icon rail, no labels, no desktop toggle */
@media (max-width: 1023px) {
  .app-body {
    grid-template-columns: var(--sidebar-width-collapsed) 1fr;
  }
  .app-sidebar__label,
  .app-sidebar__section-title,
  .app-sidebar__footer,
  .app-sidebar__badge {
    display: none;
  }
  .app-sidebar__item {
    justify-content: center;
    padding: var(--space-3) 0;
    gap: 0;
  }
  .app-sidebar-toggle {
    display: none;
  }
}

/* Phone: sidebar replaced by bottom nav + drawer */
@media (max-width: 767px) {
  .app-body {
    grid-template-columns: 1fr;
  }
  .app-sidebar {
    display: none;
  }
  .app-main {
    padding: var(--space-3);
    padding-bottom: calc(var(--bottom-nav-height) + var(--space-8));
  }
  .app-bottom-nav {
    display: flex;
  }
  /* Show hamburger toggle in header to open drawer */
  .app-sidebar-toggle {
    display: inline-flex;
  }
  /* Trim the big navbar title so the nav fits one row with hamburger + user */
  .navbar-title {
    font-size: 1.35rem !important;
    margin-left: var(--space-2) !important;
    letter-spacing: 0.05em !important;
  }
  .navbar-logo {
    height: 32px !important;
  }
  .navbar-logo-fgr {
    height: 28px !important;
  }
  .navbar-divider {
    height: 26px !important;
  }
  /* Consume less header real estate for user badge on small screens */
  .navbar-user .user-title {
    display: none;
  }
}

/* ══════════ Settings view (Phase 3A) ══════════════════════════ */

.settings-layout {
  display: grid;
  gap: var(--space-6);
  max-width: 720px;
  margin: 0 auto;
}

.settings-card {
  background: var(--color-0);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.settings-card h3 {
  margin: 0 0 var(--space-2);
  color: var(--color-700);
  font-family: var(--font-header);
  font-size: var(--text-xl);
}

.settings-card__hint {
  color: var(--color-600);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  line-height: var(--line-height-relaxed);
}

.settings-field {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.settings-field:last-child {
  margin-bottom: 0;
}

.settings-field label {
  font-weight: var(--font-weight-semibold);
  color: var(--color-700);
  font-size: var(--text-sm);
}

.settings-save-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.settings-save-status {
  color: var(--color-success-fg);
  font-size: var(--text-sm);
  opacity: 0;
  transition: opacity 200ms;
}

.settings-save-status.visible {
  opacity: 1;
}

.settings-save-status.error {
  color: var(--color-danger-fg);
}
