/**
 * Layout Shell — Phase 5 (Top Nav Redesign)
 *
 * Top Nav (phase-grouped) + Sub-tabs + Bottom Tab Bar (mobile) + Content Area
 * Uses semantic tokens from tokens.css exclusively.
 */

/* ============================================================
   App Shell — root layout container
   ============================================================ */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

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

/* ============================================================
   Top Nav — Primary row (phase tabs)
   ============================================================ */

.topnav-wrap {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky, 200);
  flex-shrink: 0;
}

.topnav {
  display: flex;
  align-items: center;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border, var(--border));
  padding: 0 var(--space-3);
  height: 44px;
}

.topnav__brand {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.03em;
  padding: 0 var(--space-3) 0 var(--space-1);
  color: var(--primary);
  text-decoration: none;
  flex-shrink: 0;
}

.topnav__tab {
  padding: 0 var(--space-3);
  height: 44px;
  display: flex;
  align-items: center;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  font-family: var(--font-sans);
  color: var(--nav-text);
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--transition-fast);
}

.topnav__tab:hover {
  color: var(--text-secondary);
}

.topnav__tab--active {
  color: var(--primary);
  font-weight: var(--font-semibold);
  border-bottom-color: var(--primary);
}

.topnav__spacer { flex: 1; }

.topnav__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--nav-text);
  cursor: pointer;
  border-radius: var(--radius-md);
  border: none;
  background: none;
  flex-shrink: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
  position: relative;
}

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

.topnav__icon--active {
  color: var(--primary);
}

/* Settings dropdown */
.topnav__settings-wrap {
  position: relative;
  display: inline-flex;
}

.settings-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: var(--z-dropdown, 100);
  min-width: 200px;
  padding: var(--space-1);
  background: var(--surface-raised, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.settings-dropdown__group-label {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: background var(--transition-fast);
}

.settings-dropdown__item:hover {
  background: var(--nav-item-hover);
}

.settings-dropdown__item--active {
  color: var(--primary);
  background: var(--primary-subtle);
}

.settings-dropdown__badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: var(--font-semibold);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-subtle);
  color: var(--accent);
}

.settings-dropdown__divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-1) 0;
}

/* ============================================================
   Sub Nav — Second row (page tabs)
   ============================================================ */

.subnav {
  display: flex;
  align-items: center;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border, var(--border));
  padding: 0 var(--space-3);
  height: 34px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.subnav::-webkit-scrollbar { display: none; }

.subnav__tab {
  padding: 0 var(--space-3);
  height: 26px;
  display: flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--nav-text);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-sans);
  white-space: nowrap;
  border-radius: var(--radius-md);
  margin: 0 1px;
  text-decoration: none;
  transition: color var(--transition-fast), background var(--transition-fast);
}

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

.subnav__tab--active {
  color: var(--text);
  background: var(--surface-alt);
  font-weight: var(--font-semibold);
}

/* ============================================================
   Notification bell badge (positioned on the icon)
   ============================================================ */

.notification-bell__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: var(--font-bold);
  background: var(--danger);
  color: #fff;
  border-radius: var(--radius-pill);
  line-height: 1;
}

/* ============================================================
   Notification Panel
   ============================================================ */

.notification-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: var(--z-dropdown, 100);
  width: 340px;
  max-height: 440px;
  background: var(--surface-raised, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.notification-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.notification-panel__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
}

.notification-panel__mark-read {
  font-size: var(--text-xs);
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
}

.notification-panel__mark-read:hover { text-decoration: underline; }

.notification-panel__list {
  overflow-y: auto;
  flex: 1;
}

.notification-panel__group-label {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-alt);
}

.notification-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-subtle);
}

.notification-item:hover { background: var(--nav-item-hover); }

.notification-item--unread { background: var(--primary-subtle); }

.notification-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
  margin-top: 1px;
}

.notification-item__icon svg { width: 18px; height: 18px; }

.notification-item__icon--nutrition { color: var(--carbs); }
.notification-item__icon--hydration { color: var(--fluids); }
.notification-item__icon--caffeine { color: var(--caffeine); }
.notification-item__icon--milestone { color: var(--success); }
.notification-item__icon--sync { color: var(--primary); }
.notification-item__icon--offline { color: var(--warning); }

.notification-item__body { flex: 1; min-width: 0; }

.notification-item__message {
  font-size: var(--text-sm);
  color: var(--text);
  line-height: 1.4;
}

.notification-item__time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.notification-item__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  margin-top: 6px;
}

.notification-panel__empty {
  padding: var(--space-8);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ============================================================
   Bottom Tab Bar — mobile (< 768px)
   ============================================================ */

.bottom-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky, 200);
  display: none; /* shown via media query */
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-tabs__bar {
  display: flex;
  align-items: stretch;
  height: 56px;
}

.bottom-tabs__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 10px;
  font-weight: var(--font-medium);
  padding: var(--space-1) 0;
  cursor: pointer;
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.bottom-tabs__item:hover,
.bottom-tabs__item:active {
  color: var(--text);
}

.bottom-tabs__item--active {
  color: var(--primary);
}

.bottom-tabs__item-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.bottom-tabs__item-label {
  line-height: 1;
}

/* ============================================================
   More Sheet — full nav on mobile
   ============================================================ */

.more-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-sticky, 200) + 1);
  background: rgba(0, 0, 0, 0.6);
}

.more-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: calc(var(--z-sticky, 200) + 2);
  background: var(--surface);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  max-height: 80vh;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0));
  box-shadow: var(--shadow-xl);
}

.more-sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--surface-alt);
  border-radius: var(--radius-pill);
  margin: 0 auto var(--space-4);
}

.more-sheet__section {
  margin-bottom: var(--space-4);
}

.more-sheet__section-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-2);
}

.more-sheet__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  font-size: var(--text-base);
  transition: background var(--transition-fast);
}

.more-sheet__item:hover,
.more-sheet__item:active {
  background: var(--nav-item-hover);
}

.more-sheet__item--active {
  color: var(--primary);
  background: var(--primary-subtle);
}

.more-sheet__item-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: var(--font-semibold);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-subtle);
  color: var(--accent);
}

/* ============================================================
   Labs badge (used in top bar breadcrumbs)
   ============================================================ */

.labs-badge {
  font-size: 10px;
  font-weight: var(--font-semibold);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-subtle);
  color: var(--accent);
  margin-left: var(--space-2);
}

/* ============================================================
   Responsive breakpoints
   ============================================================ */

/* Mobile: < 768px — bottom tabs, hide subnav, compact top nav */
@media (max-width: 767px) {
  .bottom-tabs {
    display: block;
  }

  .app-shell__content {
    padding: var(--space-4);
    padding-bottom: calc(56px + var(--space-4) + env(safe-area-inset-bottom, 0));
  }

  .topnav {
    height: 40px;
    padding: 0 var(--space-2);
  }

  .topnav__tab {
    height: 40px;
    padding: 0 var(--space-2);
    font-size: var(--text-xs);
  }

  .topnav__search-btn {
    display: none;
  }

  .subnav {
    height: 32px;
    padding: 0 var(--space-2);
  }
}

/* Desktop: >= 768px */
@media (min-width: 768px) {
  .bottom-tabs {
    display: none;
  }
}

/* ============================================================
   Transitions for sheets / panels
   ============================================================ */

.slide-up-enter-active,
.slide-up-leave-active {
  transition: transform var(--transition-slow) ease;
}

.slide-up-enter-from,
.slide-up-leave-to {
  transform: translateY(100%);
}

/* Fade for backdrop */
.fade-enter-active,
.fade-leave-active {
  transition: opacity var(--transition-normal) ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* ============================================================
   Legacy sidebar classes — hidden (backward compat)
   Old pages that still reference sidebar classes won't break.
   ============================================================ */

.sidebar { display: none !important; }
.app-shell--sidebar-expanded .app-shell__main,
.app-shell--sidebar-collapsed .app-shell__main {
  margin-left: 0;
}
