/* ============================================
   SIDEBAR STYLES
   ============================================ */

/* Sidebar styles */
/* Small screens: hidden by default, open via `.sidebar-open` */
#sidebar {
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.16);
  transition:
    transform 240ms ease,
    opacity 200ms ease,
    width 200ms ease;
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  z-index: 14040;
  height: 100vh;
  transform: translateX(-100%);
  opacity: 0;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Smooth transition for app-body padding when sidebar collapses/expands */
.app-body {
  transition: padding-left 200ms ease;
}

/* Open for overlay (small screens) */
.sidebar-open {
  transform: translateX(0) !important;
  opacity: 1 !important;
}

/* Collapsed state (sidebar visuals apply when floating too) */
#sidebar.sidebar-collapsed {
  width: 72px !important;
}
#sidebar.sidebar-collapsed .link-text {
  display: none !important;
}
#sidebar.sidebar-collapsed .sidebar-header .d-none.d-md-block {
  display: none !important;
}
#sidebar.sidebar-collapsed .nav-link {
  justify-content: center;
  position: relative;
}
#sidebar.sidebar-collapsed .nav-link i {
  margin-right: 0 !important;
}
#sidebar.sidebar-collapsed .nav-link .position-relative.d-inline-flex {
  justify-content: center;
  width: 100%;
}
#sidebar.sidebar-collapsed .sidebar-badge {
  position: absolute;
  top: 6px;
  right: 10px;
  transform: translateX(50%);
}

/* Medium and up: make the sidebar sit below the navbar on the left (overlay for small, aligned for larger screens) */
@media (min-width: 768px) {
  /* Floating sidebar initial state on md+ is slightly raised and transparent to allow a slide/fade-in */
  #sidebar {
    transform: translateY(-6px);
    opacity: 0;
    position: fixed;
    /* place below the navbar; use the navbar bottom coordinate when available */
    top: calc(var(--navbar-bottom, var(--navbar-height, 64px)) + 1rem);
    /* align sidebar left with navbar content area using computed var */
    left: var(--sidebar-left, 1rem);
    /* sidebar width uses CSS var from :root, set per breakpoint */
    width: var(--sidebar-width, 200px);
    height: calc(100vh - (var(--navbar-height, 64px)) - 1rem);
    border-radius: 0.5rem;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.1);
    z-index: 1090;
  }
  /* when JS adds has-sidebar the sidebar will slide/fade into place */
  body.has-sidebar #sidebar {
    transform: translateY(0);
    opacity: 1;
  }
}

/* When the sidebar is present and NOT collapsed on larger screens, avoid overlaying content by adding left padding */
/* On medium screens (tablets) ensure content is inset when sidebar is visible and not collapsed */
@media (min-width: 768px) and (max-width: 991px) {
  :root {
    --sidebar-width: 200px;
  }
  /* shift the app body to the right when the sidebar is present; keep navbar outside this area */
  body.has-sidebar .app-body {
    padding-left: calc(var(--sidebar-width) + var(--sidebar-left, 1rem) + 1rem);
  }
  /* when collapsed keep a smaller inset so icons do not overlay content */
  body.has-sidebar.sidebar-collapsed .app-body {
    padding-left: calc(72px + var(--sidebar-left, 1rem) + 0.5rem);
  }
  /* spacer for md screens */
  body.has-sidebar .sidebar-spacer {
    width: var(--sidebar-width, 200px);
    min-width: var(--sidebar-width, 200px);
  }
  body.has-sidebar.sidebar-collapsed .sidebar-spacer {
    width: 72px;
    min-width: 72px;
  }
}

/* On larger screens ensure content is inset appropriately using the larger sidebar width */
@media (min-width: 992px) {
  :root {
    --sidebar-width: 350px;
  }
  #sidebar {
    left: var(--sidebar-left, 0.75rem);
    width: var(--sidebar-width);
  }
  /* shift the app body to the right when the sidebar is present on large screens */
  body.has-sidebar .app-body {
    padding-left: calc(var(--sidebar-width) + var(--sidebar-left, 0.75rem));
  }
  /* when collapsed keep a smaller inset so icons do not overlay content */
  body.has-sidebar.sidebar-collapsed .app-body {
    padding-left: calc(72px + var(--sidebar-left, 0.75rem) + 0.5rem);
  }
  /* spacer for large screens */
  body.has-sidebar .sidebar-spacer {
    width: var(--sidebar-width, 350px);
    min-width: var(--sidebar-width, 350px);
  }
  body.has-sidebar.sidebar-collapsed .sidebar-spacer {
    width: 72px;
    min-width: 72px;
  }
}

/* Collapsed sidebar: center only the navigation icons (not the header) so avatar and collapse
   controls keep their original positions while link icons below are centered. */
#sidebar.sidebar-collapsed .sidebar-items .nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 0.6rem !important;
  padding-right: 0.6rem !important;
}
#sidebar.sidebar-collapsed .sidebar-items .nav-link .link-text {
  display: none !important;
}
#sidebar.sidebar-collapsed .sidebar-items .nav-link .bi {
  margin-right: 0 !important;
  font-size: 1.15rem;
}

/* Keep the sidebar header layout unchanged so avatar and collapse/expand button remain as before. */
#sidebar.sidebar-collapsed .sidebar-header .d-none.d-md-block {
  display: none !important;
}

/* Default: no spacer on small screens. The spacer is applied when `body.has-sidebar` is present on md+. */
.sidebar-spacer {
  width: 0;
  min-width: 0;
}

/* Sidebar active link highlighting */
#sidebar .nav-link.active {
  background: rgba(99, 102, 241, 0.08);
  border-radius: 0.5rem;
  color: #0f1720 !important;
}
#sidebar .nav-link.active i {
  color: #4f46e5;
}
#sidebar.sidebar-collapsed .nav-link.active {
  background: transparent;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.12) inset;
  border-radius: 0.375rem;
}

/* Main content with sidebar */
@media (min-width: 768px) {
  main.with-sidebar {
    margin-left: var(--sidebar);
    width: auto;
    max-width: none;
    min-width: 0;
  }
}

/* ============================================
   LEGACY SIDEBAR LAYOUT (Class-based)
   ============================================ */



@media (min-width: 1200px) {
  .main {
    margin-left: var(--sidebar);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }
}

/* The tenant sidebar is hidden below md (every view wraps it in
   `.d-none.d-md-block .sidebar-container`). Scoped to that wrapper on purpose:
   the platform-owner console renders `<aside class="sidebar owner-sidebar">`
   without it, and it turns the sidebar into a slide-in drawer below md
   instead of hiding it. */
@media (max-width: 767.98px) {
  .sidebar-container .sidebar {
    display: none !important;
  }
  /* ~17 page stylesheets offset the content with `margin-left: var(--sidebar)`
     and none of them guard it with a media query, so on phones the layout kept a
     phantom 220px gutter for a sidebar that was not rendered — pushing the whole
     page sideways and causing horizontal scroll. `!important` is required because
     those page stylesheets are linked after this file. */
  .container.with-sidebar,
  main.container.with-sidebar,
  main.with-sidebar,
  .main {
    margin-left: 0 !important;
  }
}

.sidebar {
  width: var(--sidebar);
  background: var(--charcoal);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  height: 100vh;
  /* The full admin list is ~15 rows + the identity card: on a short viewport
     (600px-tall tablet/desktop windows) the last rows and the user card used to
     fall off the bottom with no way to reach them. */
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.sidebar-logo {
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -1px;
  padding: 0 24px;
  margin-bottom: 14px;
  margin-top: 12px;
}

.sidebar-logo .ova {
  color: var(--amber);
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
  padding: 0 15px;
  margin: 1px 0 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 24px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  margin: 1px 0;
}

.nav-item:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: var(--amber);
  background: rgba(249, 115, 22, 0.08);
  border-left-color: var(--amber);
}

.sidebar-toast {
  padding: 0 20px 16px;
}

.sidebar-toast-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.nav-item .badge {
  margin-left: auto;
  font-size: 11px;
  padding: 0.35em 0.65em;
}

.nav-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 0 16px;
}

.user-card {
  background: var(--graphite);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: var(--amber);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--black);
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-role {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 2px;
}

/* ============================================
   TABLET ICON RAIL — 768–991.98px
   ──────────────────────────────────────────────────────────────
   Below md the bottom notch is the navigation; from md the sidebar is
   rendered again. A 240px column on a 768–991px tablet, however, left
   only ~510px of content and squeezed every table into a scroll area.
   In that band the sidebar becomes a 72px icon rail: same links, same
   order, same amber active rule — the label moves to the row's `title`
   (set in partials/nav-items.ejs) and the unread badge rides the icon.

   Deliberately CSS-only: no extra markup, no persisted state, and the
   rail can never drift from the desktop list. `main` only gives up
   72px, so tables get their width back.

   Note: this must stay after the base `.sidebar` / `main.with-sidebar`
   rules above — it overrides their width and margin in this band.
   ============================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
  :root {
    --sidebar-rail: 72px;
  }

  /* The wrapper's only child is the fixed sidebar, so it must not reserve a
     column of its own to the right of the rail. */
  .sidebar-container {
    width: 0;
    flex: 0 0 0;
  }

  .sidebar-container .sidebar {
    width: var(--sidebar-rail);
    padding: 12px 0 10px;
    overflow-x: hidden;
  }

  /* Wordmark → amber monogram: the rail still opens on the brand. */
  .sidebar-container .sidebar-logo {
    width: 40px;
    height: 40px;
    margin: 0 auto 14px;
    padding: 0;
    border-radius: 12px;
    background: rgba(249, 115, 22, 0.12);
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar-container .sidebar-logo::before {
    content: 'T';
    font-family: "Syne", sans-serif;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--amber);
  }

  /* Section names (10px / 3px tracking) cannot fit a 72px column. */
  .sidebar-container .sidebar-section-label {
    display: none;
  }

  .sidebar-container .nav-item {
    position: relative;
    justify-content: center;
    gap: 0;
    padding: 11px 0;
  }
  .sidebar-container .nav-label {
    display: none;
  }
  .sidebar-container .nav-icon {
    width: auto;
    font-size: 19px;
  }

  /* Unread counts ride the icon instead of the hidden label row. */
  .sidebar-container .nav-item .badge {
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: 6px !important;
    font-size: 9px;
    padding: 0.3em 0.45em;
  }

  .sidebar-container .sidebar-bottom {
    padding: 0 10px;
  }
  .sidebar-container .user-card {
    justify-content: center;
    padding: 6px;
    background: transparent;
  }
  .sidebar-container .user-card > div:nth-child(2) {
    display: none;
  }

  /* `main.container.with-sidebar` matches sales-index.css's
     `.container.with-sidebar { margin-left: var(--sidebar) }` (2 classes) —
     plain `main.with-sidebar` is 1 class + 1 element and loses to it. */
  main.container.with-sidebar,
  .container.with-sidebar,
  main.with-sidebar {
    margin-left: var(--sidebar-rail);
  }
}
