/* app-shell.css — Barrix HRMS
 * Clean rewrite — no conflicting rules, matches actual DOM IDs in index.html
 *
 * DOM structure (from index.html):
 *   #app-page.app-shell
 *     #sidebar.sidebar          — position:fixed, width:220px (index.html inline CSS)
 *     #mainContent.main-content — margin-left:220px (index.html inline CSS)
 *     #mobile-header-bar
 *     #mobile-nav
 */

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── App page wrapper ───────────────────────────────────────── */
#app-page {
  display: block;
  width: 100%;
  min-height: 100vh;
}
#app-page[style*="display:none"],
#app-page[style*="display: none"] {
  display: none !important;
}

body.auth-view #app-page,
body.auth-view #sidebar,
body.auth-view #mainContent,
body.auth-view #mobile-header-bar,
body.auth-view #mobile-nav,
body.auth-view #session-bar {
  display: none !important;
}

/* ── Sidebar collapse (desktop) ─────────────────────────────── */
#sidebar.collapsed {
  width: 60px !important;
  min-width: 60px !important;
}
#sidebar.collapsed .nav-label {
  display: none;
}

/* ── Drawer overlay (mobile) ────────────────────────────────── */
#drawer-overlay,
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 250;
}
#drawer-overlay.open,
.drawer-overlay.open {
  display: block;
}

/* ── Sidebar drawer (mobile slide-in) ───────────────────────── */
#sidebar-drawer,
.sidebar-drawer {
  display: none;
}

/* ══════════════════════════════════════════════════════════════
   DESKTOP — 769px and above
   The sidebar is position:fixed at 220px width (set in index.html).
   The main content has margin-left:220px (set in index.html).
   This file must NOT override those values on desktop.
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) {

  #app-page.app-shell:not([style*="display:none"]):not([style*="display: none"]) {
    display: flex !important;
    align-items: stretch !important;
    width: 100% !important;
    min-height: 100vh !important;
  }

  #sidebar,
  .sidebar {
    position: sticky !important;
    top: 0 !important;
    left: auto !important;
    bottom: auto !important;
    width: 220px !important;
    min-width: 220px !important;
    height: 100vh !important;
    flex: 0 0 220px !important;
  }

  #mainContent,
  .main-content {
    margin-left: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 auto !important;
    overflow-x: hidden !important;
  }

  /* Hide mobile-only elements on desktop */
  #mobile-header-bar {
    display: none !important;
  }

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

/* ══════════════════════════════════════════════════════════════
   TABLET — 769px to 1024px — slightly narrower sidebar
   ══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  #sidebar,
  .sidebar {
    width: 200px !important;
    min-width: 200px !important;
    flex-basis: 200px !important;
  }
  #mainContent,
  .main-content {
    margin-left: 0 !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE — 768px and below
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Hide desktop sidebar */
  #sidebar,
  .sidebar {
    display: none !important;
  }

  /* Full width main content — remove sidebar margin */
  #mainContent,
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding-top: calc(56px + 14px) !important;
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px) + 14px) !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Show mobile header */
  #mobile-header-bar {
    display: flex !important;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    z-index: 300;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
  }

  /* Show mobile bottom nav */
  #mobile-nav {
    display: block !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 300;
  }

  #session-bar {
    display: none !important;
  }

  #mobile-nav-inner {
    justify-content: flex-start !important;
    gap: 4px !important;
    padding: 0 8px !important;
    height: 68px !important;
  }

  .mnav-btn {
    flex: 0 0 72px !important;
    min-width: 72px !important;
    max-width: 72px !important;
    padding: 6px 4px !important;
  }

  .mnav-label {
    display: block !important;
    font-size: 9px !important;
    line-height: 1.05 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
  }

  .mnav-icon {
    font-size: 18px !important;
    line-height: 1 !important;
  }

  /* Mobile drawer */
  #sidebar-drawer,
  .sidebar-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    z-index: 280;
    background: var(--surface, #ffffff);
    overflow-y: auto;
    transition: left 0.25s ease;
  }

  #sidebar-drawer.open,
  .sidebar-drawer.open {
    left: 0;
  }

  /* Prevent horizontal overflow on mobile */
  .section-card,
  .stat-card {
    max-width: 100%;
    overflow-x: hidden;
  }

  #tab-content,
  #tab-content > * {
    width: 100% !important;
    max-width: 100% !important;
  }

  #tab-content > div[style*="grid-template-columns:repeat(4,1fr)"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #tab-content .section-card > div[style*="grid-template-columns:repeat(4,1fr)"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  table {
    min-width: 480px;
  }
}
