/* ==========================================
   BENEFIQ — APP LAYOUT
   ========================================== */

@layer base {

  /* ==========================================
     APP SHELL
     ========================================== */

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

  /* ==========================================
     SIDEBAR — Icon Rail (Desktop)
     Narrow, icon-only, blends with warm bg
     ========================================== */
  .sidebar {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: transparent;
    z-index: var(--z-fixed);
    overflow: visible;
  }

  /* 3D shelf shadow — tight edge on the right */
  .sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: -12px;
    width: 12px;
    pointer-events: none;
    background: linear-gradient(to right,
      rgba(0, 0, 0, 0.08) 0%,
      rgba(0, 0, 0, 0.04) 30%,
      rgba(0, 0, 0, 0.01) 60%,
      transparent 100%
    );
  }

  @media (min-width: 1024px) {
    .sidebar {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: var(--space-4) 0;
    }

    .main {
      margin-left: var(--sidebar-width);
    }

    .mobile-nav {
      display: none !important;
    }
  }

  /* Sidebar Brand — logo container (SVG carries its own coral fill) */
  .sidebar-brand {
    padding: var(--space-2) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 0 var(--space-2);
  }

  .sidebar-brand-logo {
    width: 36px;
    max-width: none;
    height: auto;
  }

  /* Sidebar Navigation — centered icons */
  .sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    position: relative;
  }

  /* Sliding indicator pill — animated via GSAP */
  .sidebar-nav-indicator {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--surface-700);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 0;
    pointer-events: none;
    will-change: transform, border-radius;
  }

  .sidebar-nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    transition: color var(--transition-base);
    position: relative;
    cursor: pointer;
    z-index: 1;
  }

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

  .sidebar-nav-item.active {
    color: #FFFFFF;
  }

  .sidebar-nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .sidebar-nav-item.active svg {
    stroke: #FFFFFF;
  }

  /* Sidebar tooltip on hover */
  .sidebar-nav-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-800, #1a1a1a);
    color: #fff;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1000;
  }

  .sidebar-nav-item:hover::after {
    opacity: 1;
  }

  /* Hide tooltip on mobile/touch or when title is empty */
  @media (hover: none) {
    .sidebar-nav-item::after {
      display: none;
    }
  }

  /* Logo uses SVG's native coral+white colors — no filter needed */

  /* Sidebar Footer — settings icon */
  .sidebar-footer {
    padding: var(--space-3) 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  /* ==========================================
     TOP BAR — notifications, profile
     ========================================== */
  .top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    padding-bottom: 0;
  }

  .top-bar-title {
    font-size: var(--text-xl);
  }

  @media (min-width: 1024px) {
    .top-bar {
      padding: var(--space-8);
      padding-top: 1.75rem;
      padding-bottom: 0;
    }

    .top-bar-title {
      font-size: var(--text-3xl);
    }
  }

  .top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
  }

  .top-bar-title {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--surface-900);
  }

  .top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .top-bar-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--surface-200);
    color: var(--surface-600);
    cursor: pointer;
    transition: all var(--transition-base);
    border: none;
  }

  .top-bar-icon:hover {
    background: var(--surface-300);
    color: var(--surface-900);
  }

  .top-bar-icon svg {
    width: 18px;
    height: 18px;
  }

  .top-bar-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--surface-200);
    color: var(--surface-600);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-base);
    border: none;
  }

  .top-bar-avatar:hover {
    background: var(--surface-300);
    color: var(--surface-900);
    cursor: pointer;
  }

  /* Hide avatar on mobile (settings accessible via bottom nav) */
  @media (max-width: 768px) {
    .top-bar-avatar {
      display: none;
    }
  }

  /* ==========================================
     MOBILE BOTTOM NAV
     ========================================== */
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.10);
    display: flex;
    align-items: stretch;
    z-index: var(--z-fixed);
    padding-bottom: env(safe-area-inset-bottom, 0);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .mobile-nav--minimized {
    transform: translateY(100%);
  }

  .mobile-nav-scroll {
    flex: 1;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .mobile-nav-scroll::-webkit-scrollbar { display: none; }

  .mobile-nav-item {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: var(--weight-medium);
    transition: color var(--transition-base);
    padding: var(--space-2) var(--space-4);
    scroll-snap-align: start;
    min-width: 64px;
  }
  /* First 5 items fill visible width evenly; items 6+ scroll offscreen */
  .mobile-nav-item:nth-child(-n+5) {
    flex: 0 0 calc(100% / 5);
    min-width: 0;
  }

  .mobile-nav-item svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.5;
  }

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

  .mobile-nav-item.active svg {
    stroke-width: 2;
  }

  /* Minimize button (chevron down) — coral bg, light icon */
  .mobile-nav-minimize {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    color: var(--surface-50);
    border-left: 1px solid var(--border);
    background: var(--brand-500);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-minimize svg {
    width: 18px;
    height: 18px;
  }

  /* Restore handle — visible only when nav minimized */
  .mobile-nav-restore {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    z-index: var(--z-fixed);
    background: var(--brand-500);
    border: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 6px var(--space-6);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-restore.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .mobile-nav-restore-pill {
    display: block;
    width: 40px;
    height: 3px;
    background: var(--surface-50);
    border-radius: var(--radius-full);
  }
  }

  /* Hide restore handle and minimize on desktop */
  @media (min-width: 1024px) {
    .mobile-nav-restore,
    .mobile-nav-minimize {
      display: none !important;
    }
  }

  /* ==========================================
     MAIN CONTENT
     ========================================== */
  .main {
    flex: 1;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0) + var(--space-4));
  }

  @media (min-width: 1024px) {
    .main {
      padding-bottom: var(--space-8);
    }
  }

  /* ==========================================
     PAGES
     ========================================== */
  .page {
    display: none;
    padding: var(--space-5);
    max-width: var(--content-width);
    margin: 0 auto;
  }

  .page.active {
    display: block;
    animation: fade-in var(--transition-base) ease;
  }

  @media (min-width: 1024px) {
    .page {
      padding: var(--space-8);
      max-width: 1200px;
    }
  }

  /* Page Header — clean, no subtitles */
  .page-header {
    margin-bottom: var(--space-6);
  }

  .page-header h1 {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
  }

  @media (min-width: 1024px) {
    .page-header h1 {
      font-size: var(--text-3xl);
    }
  }

  /* ==========================================
     SECTION
     ========================================== */
  .section {
    margin-bottom: var(--space-8);
  }

  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
  }

  .section-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
  }

  /* ==========================================
     LISTS
     ========================================== */
  .list {
    display: flex;
    flex-direction: column;
  }

  .list-item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
    transition: background var(--transition-base);
  }

  .list-item:last-child {
    border-bottom: none;
  }

  .list-item:hover {
    background: var(--bg-sunken);
  }

  .list-item-content {
    flex: 1;
    min-width: 0;
  }

  .list-item-title {
    font-weight: var(--weight-medium);
    color: var(--text);
  }

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

  .list-item-action {
    flex-shrink: 0;
  }

  /* Card List */
  .card-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  /* ==========================================
     GRID LAYOUTS
     ========================================== */
  .grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
  }

  .grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
  }

  @media (max-width: 640px) {
    .grid-3 {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  /* ==========================================
     CHIP SCROLL
     ========================================== */
  .chip-scroll {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-2);
    margin: 0 calc(var(--space-5) * -1);
    padding-left: var(--space-5);
    padding-right: var(--space-5);
    scrollbar-width: none;
  }

  .chip-scroll::-webkit-scrollbar {
    display: none;
  }

  /* ==========================================
     PULL-TO-REFRESH INDICATOR
     ========================================== */
  .pull-refresh-indicator {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elevated);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
  }

  .pull-refresh-indicator svg {
    width: 20px;
    height: 20px;
    color: var(--color-accent);
  }

  .pull-refresh-indicator.refreshing svg {
    animation: ptr-spin 0.8s linear infinite;
  }

  @keyframes ptr-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

  @media (prefers-reduced-motion: reduce) {
    .pull-refresh-indicator.refreshing svg {
      animation: none;
    }
  }

  /* Touch target compliance (44px minimum) */
  @media (pointer: coarse) {
    .top-bar-icon {
      width: 44px;
      height: 44px;
    }
    .mobile-nav-item {
      min-height: 44px;
    }
    .mobile-nav-minimize {
      min-width: 44px;
    }
    .mobile-nav-restore {
      min-height: 44px;
    }
  }

}
