/* Responsive Design - Mobile First */

/* Global sidebar z-index for desktop */
.sidebar {
  z-index: 2000;
}

/* Mobile Styles (default) */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --spacing-md: 0.75rem;
    --spacing-lg: 1rem;
    --spacing-xl: 1.5rem;
  }

  /* B-01 (phase 4): the phone layout is a plain block flow, not a grid.
     .mobile-header carries no grid-area, so under `grid-template-areas: "main"`
     auto-placement dropped it into an implicit row *after* .main-content — it
     rendered ~1,500-2,250px down the document and `position: sticky` could not
     rescue it, because a grid item's sticky rectangle is its own auto-sized
     row. In block flow the header is simply the first child of the scrolling
     document, so sticky does what it says. The sidebar and the overlay are
     position: fixed at this width, so nothing else needs the grid. */
  .app-container {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 100%;
    max-width: 100%;
    z-index: 2000;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    max-height: 100vh;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--theme-overlay);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
  }

  .main-content {
    margin-left: 0;
  }

  /* Hide floating toggle on mobile */
  .sidebar-edge-toggle {
    display: none !important;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    /* B-01: was `space-between`, which parked the logo at the right edge —
       x 267..366 in a 390px viewport. `.floating-actions` is position: fixed at
       top 20 / right 20 and occupies x 241..370, so the notification bell, the
       avatar and any page action painted straight on top of the logo the moment
       the header became visible at the top of the document. Left-aligning the
       logo next to the hamburger leaves the right-hand band to the floating
       actions, which then read as part of the header instead of debris on it. */
    justify-content: flex-start;
    gap: var(--spacing-md);
    padding: var(--spacing-lg) var(--spacing-lg);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 56px;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
  }

  .mobile-menu-btn:hover {
    background-color: var(--bg-hover);
  }

  .content-body {
    padding: var(--spacing-lg);
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-md);
  }

  .page-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--spacing-md);
  }

  .table th,
  .table td {
    padding: var(--spacing-sm);
  }

  .actions {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .form-group {
    margin-bottom: var(--spacing-md);
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-section-title {
    font-size: var(--font-size-base);
  }
  
  .form-actions {
    flex-direction: column-reverse;
  }
  
  .form-actions .btn {
    width: 100%;
  }

  .modal {
    margin: var(--spacing-sm);
    max-width: calc(100vw - var(--spacing-md));
    max-height: calc(100vh - var(--spacing-md));
  }
  
  .modal-body {
    padding: var(--spacing-md);
  }
  
  .modal-header,
  .modal-footer {
    padding: var(--spacing-md);
  }
}

/* B-02 (phase 4): everything above the phone breakpoint has the real sidebar,
   so the mobile header and its overlay must be gone from 769px up — not from
   1025px up. Between 769 and 1024 .mobile-header had no `display` rule at all
   (the `flex` sat inside the max-width:768px query, the `none` inside the
   min-width:1025px one), so it computed to `block`, was auto-placed into the
   `sidebar` grid column and stretched the full document height — a 2,721px
   blank block sitting on top of the navigation. .sidebar-overlay had the same
   hole: its only styling lives in the phone query, so at tablet width it was
   an unstyled div taking a grid cell. */
@media (min-width: 769px) {
  .mobile-header {
    display: none;
  }

  .sidebar-overlay {
    display: none;
  }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }

  .content-body {
    padding: var(--spacing-lg) var(--spacing-xl);
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  /* Show floating toggle on tablet for manual sidebar control */
  .sidebar-edge-toggle {
    display: flex;
  }
}

/* Desktop Styles */
@media (min-width: 1025px) {
  /* .mobile-header / .sidebar-overlay are hidden from 769px up — see B-02 above.
     The duplicates that used to live here were removed with that fix. */
  .sidebar-edge-toggle {
    display: flex;
  }
}

/* Large Desktop */
@media (min-width: 1200px) {
  :root {
    --content-max-width: 1400px;
  }
}

/* Print Styles */
@media print {
  .sidebar,
  .mobile-header,
  .page-actions,
  .actions {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }

  .content-body {
    padding: 0;
  }

  .table {
    border: 1px solid var(--neutral-1000);
  }

  .table th,
  .table td {
    border: 1px solid var(--neutral-1000);
  }
}

/* Utility classes for responsive design */
.hide-mobile {
  display: none;
}

.show-mobile {
  display: block;
}

@media (min-width: 769px) {
  .hide-mobile {
    display: block;
  }

  .show-mobile {
    display: none;
  }
}

/* Accessible focus indicators */
@media (prefers-reduced-motion: no-preference) {
  .sidebar {
    transition: left 0.3s ease;
  }

  .sidebar-overlay {
    transition: all 0.3s ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-overlay {
    transition: none;
  }
}
