/**
 * css/layout.css  -  Page structure, wrappers, and grid helpers
 *
 * Load order: AFTER base.css, BEFORE components.css
 * Scope: structural selectors only  -  no visual decoration here
 */

/* ── Page wrapper ─────────────────────────────────────── */

.l-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

.l-page--wide {
  max-width: 1280px;
}

/* ── Section spacing ─────────────────────────────────── */

.l-section {
  margin-bottom: 24px;
}

.l-section + .l-section {
  padding-top: 8px;
  border-top: 1px solid var(--theme-border-color, #e5e7eb);
}

/* ── Flex row helpers ────────────────────────────────── */

.l-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.l-row--between {
  justify-content: space-between;
}

.l-row--end {
  justify-content: flex-end;
}

/* ── Grid helpers ────────────────────────────────────── */

.l-grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

/* ── AdminLTE-compatible wrappers (AdminLTE removed; these are now layout.css) ── */
/* Pages use .wrapper + .content-wrapper as structural containers. Definitions
   previously came from dist/css/adminlte.min.css  -  now owned here. */

.wrapper {
  position: relative;
  min-height: 100vh;
}

.content-wrapper {
  min-height: 100vh;
  padding: 0;
  background: var(--theme-bg-base);
}

/* ── Sidebar layout  -  desktop only ───────────────────── */

:root {
  --rail-width: 52px;
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 52px;
  --top-nav-height: 56px;
}

@media (min-width: 769px) {
  /* Top navbar becomes fixed, shifted right of the sidebar */
  .top-navbar {
    position: fixed !important;
    top: 0;
    left: calc(var(--rail-width) + var(--sidebar-width));
    right: 0;
    width: auto !important;
    z-index: 1001 !important;
  }

  /* All page content shifts right + has top padding for fixed navbar */
  body {
    padding-top: var(--top-nav-height) !important;
    padding-left: calc(var(--rail-width) + var(--sidebar-width)) !important;
    padding-bottom: 0 !important;
    transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .bottom-navbar {
    left: var(--rail-width) !important;
  }

  /* Collapsed sidebar layout shifts */
  html.sidebar-collapsed .top-navbar {
    left: calc(var(--rail-width) + var(--sidebar-collapsed-width));
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  html.sidebar-collapsed body {
    padding-left: calc(var(--rail-width) + var(--sidebar-collapsed-width)) !important;
    transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Smooth transition when expanding too */
  .top-navbar {
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  /* Remove the old bottom-nav bottom padding from l-page */
  .l-page {
    padding-bottom: 24px;
  }

  /* Common content containers  -  ensure they're not double-shifted */
  .wrapper,
  .content-wrapper {
    margin-left: 0;
  }

  /* Hide top-navbar brand on desktop  -  sidebar brand replaces it */
  .top-navbar .navbar-brand {
    display: none !important;
  }

  /* Sidebar badge count helpers */
  .sidebar-badge {
    margin-left: auto;
    font-size: 0.625rem;
    font-weight: 700;
    background: var(--brand-primary);
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    flex-shrink: 0;
  }

  .sidebar-dot {
    margin-left: auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--theme-danger, #ef4444);
    flex-shrink: 0;
  }
}

/* ── Module Rail ─────────────────────────────────────────── */

.module-rail { display: none; }

@media (min-width: 769px) {
  .module-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--rail-width);
    z-index: 1002;
    background: var(--navbar-bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    border-right: 1px solid var(--navbar-border);
    padding: 10px 0;
    gap: 2px;
  }

  .module-rail__item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--navbar-text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    flex-shrink: 0;
  }

  .module-rail__item:hover {
    background: var(--navbar-item-hover);
    color: var(--navbar-text);
  }

  .module-rail__item--active {
    background: hsla(35, 98%, 55%, 0.12);
    color: var(--brand-primary) !important;
  }

  .module-rail__divider {
    width: 28px;
    height: 1px;
    background: var(--navbar-border);
    margin: 4px 0;
    flex-shrink: 0;
  }

  .module-rail__item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--theme-bg-card, #fff);
    color: var(--theme-text-primary, #1a1a1a);
    border: 1px solid var(--navbar-border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .module-rail__item:hover::after { opacity: 1; }

  /* Spacer pushes logout to bottom */
  .module-rail__spacer {
    flex: 1;
  }

  /* Logout item subtle danger tint on hover */
  .module-rail__item--logout:hover {
    background: hsla(0, 80%, 55%, 0.1);
    color: var(--theme-danger, #ef4444) !important;
  }

  /* ── Rail "more" button ───────────────────────────────── */
  .module-rail__more {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
  }

  .module-rail__more.is-active {
    background: var(--navbar-item-hover);
    color: var(--navbar-text) !important;
  }

  .module-rail__more.is-active i {
    transform: rotate(45deg);
    transition: transform 0.2s ease;
  }

  .module-rail__more i {
    transition: transform 0.2s ease;
  }

  /* ── Collapsible others ───────────────────────────────── */
  .module-rail__others {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .module-rail__others.is-open {
    max-height: 600px;
  }

  /* Once fully expanded (post-transition), allow item tooltips to escape
     the panel bounds instead of being clipped by the collapse overflow */
  .module-rail__others.module-rail__others--settled {
    overflow: visible;
  }
}

