/**
 * Navigation - Rail + Sliding Panel (Desktop)
 * Fixed 56px icon rail on the left with a 220px panel that slides out on click.
 * Mobile: rail and panel are hidden; mobile uses topbar (navigation-mobile.css).
 */

/* ---------- Variables ---------- */
:root {
  --rail-width: 56px;
  --panel-width: 252px;
  /* Rail surface uses the same dark treatment as the HIG sidebar */
  --rail-bg: linear-gradient(180deg, rgba(29, 29, 31, 0.99) 0%, rgba(26, 26, 28, 0.995) 100%);
  --rail-border: rgba(255, 255, 255, 0.05);
  --rail-item-color: var(--hig-color-text-muted);
  --rail-item-color-active: #fff;
  --rail-item-bg-active: rgba(255, 255, 255, 0.09);
  --rail-item-bg-hover: rgba(255, 255, 255, 0.045);
  --panel-bg: rgba(25, 25, 28, 0.98);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-shadow: 14px 0 34px rgba(0, 0, 0, 0.28);
  --panel-z: 1050;
  --rail-z: 1060;
  --overlay-z: 1040;
}

.public-site-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  backdrop-filter: blur(18px);
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.public-site-header__inner {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 72px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
}

.public-site-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--hig-color-text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.public-site-header__logo {
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.public-site-header__brand-text {
  font-size: 1rem;
}

.public-site-header__nav {
  display: inline-flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.public-site-header__link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--hig-color-text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
}

.public-site-header__link:hover,
.public-site-header__link:focus-visible,
.public-site-header__link.is-active {
  color: var(--hig-color-text);
  background: rgba(0, 113, 227, 0.08);
  outline: none;
}

.public-site-header__actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.public-site-header__theme,
.public-site-header__login,
.public-site-header__cta {
  min-height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
}

.public-site-header__theme {
  width: 40px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.68);
  color: var(--hig-color-text);
}

.public-site-header__login {
  padding: 0 14px;
  color: var(--hig-color-text);
}

.public-site-header__cta {
  padding: 0 16px;
  background: var(--hig-color-primary);
  color: #fff !important;
  box-shadow: 0 10px 24px rgba(0, 113, 227, 0.22);
}

.public-site-header__theme:hover,
.public-site-header__theme:focus-visible,
.public-site-header__login:hover,
.public-site-header__login:focus-visible {
  background: rgba(0, 113, 227, 0.08);
  color: var(--hig-color-primary);
  outline: none;
}

.public-site-header__cta:hover,
.public-site-header__cta:focus-visible {
  background: var(--hig-color-primary-hover);
  color: #fff !important;
  outline: none;
}

body.dark-theme .public-site-header {
  background: rgba(10, 14, 20, 0.82);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.dark-theme .public-site-header__logo {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

body.dark-theme .public-site-header__theme {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--hig-color-text);
}

body.dark-theme .public-site-header__cta,
body.dark-theme .public-site-header__cta:hover,
body.dark-theme .public-site-header__cta:focus-visible {
  color: #fff !important;
}

body.dark-theme .public-site-header__link:hover,
body.dark-theme .public-site-header__link:focus-visible,
body.dark-theme .public-site-header__link.is-active,
body.dark-theme .public-site-header__theme:hover,
body.dark-theme .public-site-header__theme:focus-visible,
body.dark-theme .public-site-header__login:hover,
body.dark-theme .public-site-header__login:focus-visible {
  background: rgba(59, 130, 246, 0.14);
}

/* ---------- Hide on mobile, keep mobile topbar padding ---------- */
@media (max-width: 768px) {
  .desktop-nav {
    display: none !important;
  }

  .public-site-header {
    position: sticky;
  }

  .public-site-header__inner {
    width: min(100% - 16px, 100%);
    min-height: 64px;
    grid-template-columns: auto auto;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
  }

  .public-site-header__nav {
    display: none;
  }

  .public-site-header__brand-text,
  .public-site-header__login {
    display: none;
  }

  .public-site-header__actions {
    gap: 8px;
  }

  .public-site-header__cta {
    padding: 0 14px;
    min-width: 118px;
  }

  /* Mobile content padding when in rail mode (same as sidebar mobile rule) */
  body.nav-mode-rail .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding-top: calc(var(--mobile-topbar-height) + 16px);
    padding-left: 8px;
    padding-right: 8px;
    padding-bottom: 8px;
  }

  body.nav-mode-rail .main-content.main-content--no-nav {
    padding-top: 0;
  }
}

/* ---------- Rail ---------- */
@media (min-width: 769px) {
  .desktop-nav {
    display: block;
  }

  .public-site-header {
    display: block;
  }

  .nav-rail {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: var(--rail-width);
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--rail-bg);
    border-right: 1px solid var(--rail-border);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.12);
    z-index: var(--rail-z);
    overflow: hidden;
    box-sizing: border-box;
    padding: 8px 0;
  }

  /* Brand / logo button */
  .nav-rail__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    margin-bottom: 8px;
    flex-shrink: 0;
    position: relative;
    text-decoration: none;
    transition: background 0.18s ease;
  }

  .nav-rail__brand:hover,
  .nav-rail__brand:focus-visible {
    background: var(--rail-item-bg-hover);
    outline: none;
  }

  .nav-rail__brand img {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  }

  /* Badge on brand icon (notification count) */
  .nav-rail__brand-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    background: var(--hig-color-danger);
    color: #fff;
    font-weight: 700;
    font-size: 0.62rem;
    line-height: 1.1rem;
    padding: 0 3px;
    text-align: center;
  }

  /* Divider between brand and nav items */
  .nav-rail__divider {
    width: 28px;
    height: 1px;
    background: var(--rail-border);
    margin: 6px 0;
    flex-shrink: 0;
  }

  /* Primary nav list */
  .nav-rail__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    /* Hide scrollbar */
    scrollbar-width: none;
  }

  .nav-rail__list::-webkit-scrollbar {
    display: none;
  }

  .nav-rail__item {
    list-style: none;
    width: 100%;
    display: flex;
    justify-content: center;
  }

  /* Shared styles for rail buttons and links */
  .nav-rail__btn,
  .nav-rail__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 40px;
    min-height: 40px;
    padding: 6px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--rail-item-color);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.18s ease, color 0.18s ease;
    position: relative;
    box-sizing: border-box;
  }

  .nav-rail__btn:hover,
  .nav-rail__link:hover,
  .nav-rail__btn:focus-visible,
  .nav-rail__link:focus-visible {
    background: var(--rail-item-bg-hover);
    color: #fff;
    outline: none;
  }

  /* Active state: left indicator bar + background */
  .nav-rail__btn.active,
  .nav-rail__link.active {
    background: var(--rail-item-bg-active);
    color: var(--rail-item-color-active);
  }

  .nav-rail__btn.active::before,
  .nav-rail__link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 60%;
    border-radius: 0 2px 2px 0;
    background: var(--hig-color-primary, #0071e3);
  }

  /* Icon inside rail item */
  .nav-rail__btn i,
  .nav-rail__link i {
    font-size: 1.05rem;
    line-height: 1;
  }

  /* Badge on a rail item (e.g. notifications) */
  .nav-rail__badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 1rem;
    height: 1rem;
    border-radius: 999px;
    background: var(--hig-color-danger);
    color: #fff;
    font-weight: 700;
    font-size: 0.6rem;
    line-height: 1rem;
    padding: 0 3px;
    text-align: center;
    pointer-events: none;
  }

  /* Tooltip via CSS (using data-tooltip or title) */
  .nav-rail__btn[title],
  .nav-rail__link[title] {
    position: relative;
  }

  /* Footer area of rail (profile) */
  .nav-rail__footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    width: 100%;
    border-top: 1px solid var(--rail-border);
  }

  /* ---------- Sliding Panel ---------- */
  .nav-panel {
    position: fixed;
    left: var(--rail-width);
    top: 0;
    height: 100vh;
    width: var(--panel-width);
    background: var(--panel-bg);
    border-right: 1px solid var(--panel-border);
    box-shadow: var(--panel-shadow);
    z-index: var(--panel-z);
    transform: translateX(calc(-1 * var(--panel-width)));
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    pointer-events: none;
    visibility: hidden;
  }

  .nav-panel.is-open {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
  }

  .nav-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
  }

  .nav-panel__title {
    font-size: 0.72rem;
    font-weight: 640;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--hig-color-text-muted);
  }

  .nav-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--hig-color-text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .nav-panel__close:hover,
  .nav-panel__close:focus-visible {
    background: var(--rail-item-bg-hover);
    color: #fff;
    outline: none;
  }

  .nav-panel__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 6px;
  }

  /* Panel content block (one per nav group) */
  .nav-panel__content {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  /* Section heading inside panel */
  .nav-panel__section {
    padding: 0.45rem 0.5rem 0.2rem;
    font-size: 0.62rem;
    font-weight: 640;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    color: var(--hig-color-text-muted);
  }

  /* Link inside panel */
  .nav-panel__link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.46rem 0.5rem;
    border-radius: 9px;
    color: var(--hig-color-text-secondary);
    font-size: 0.82rem;
    font-weight: 470;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .nav-panel__link .nav-label {
    white-space: normal;
    line-height: 1.3;
  }

  .nav-panel__link i:first-child {
    font-size: 0.87rem;
    color: var(--hig-color-text-muted);
    flex-shrink: 0;
    width: 16px;
    text-align: center;
  }

  .nav-panel__link:hover,
  .nav-panel__link:focus-visible {
    background: var(--rail-item-bg-hover);
    color: #fff;
    outline: none;
  }

  .nav-panel__link:hover i:first-child,
  .nav-panel__link:focus-visible i:first-child {
    color: #fff;
  }

  .nav-panel__link.active {
    background: var(--rail-item-bg-active);
    color: #fff;
  }

  .nav-panel__link.active i:first-child {
    color: var(--hig-color-text);
  }

  /* Danger variant */
  .nav-panel__link.text-danger {
    color: var(--hig-color-danger) !important;
  }

  .nav-panel__link.text-danger i:first-child {
    color: var(--hig-color-danger) !important;
  }

  .nav-panel__link.text-danger:hover,
  .nav-panel__link.text-danger:focus-visible {
    background: rgba(255, 59, 48, 0.12);
    color: var(--hig-color-danger) !important;
  }

  /* Panel divider */
  .nav-panel__divider {
    height: 1px;
    margin: 6px 4px;
    background: var(--panel-border);
  }

  /* ---------- Company switcher inside panel ---------- */
  .nav-panel .company-switcher {
    position: relative;
    margin: 0 0 6px;
    padding: 6px;
  }

  .nav-panel .company-switcher__trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--rail-item-bg);
    color: var(--hig-color-text);
    cursor: pointer;
    text-align: left;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  }

  .nav-panel .company-switcher__trigger:hover,
  .nav-panel .company-switcher__trigger:focus-visible {
    background: var(--rail-item-bg-hover);
    border-color: rgba(255, 255, 255, 0.1);
    outline: none;
  }

  .nav-panel .company-switcher__icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--hig-color-primary), var(--hig-color-primary-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
  }

  .nav-panel .company-switcher__initial {
    font-size: 0.9rem;
    font-weight: 620;
    text-transform: uppercase;
  }

  .nav-panel .company-switcher__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .nav-panel .company-switcher__label {
    font-size: 0.62rem;
    font-weight: 620;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--hig-color-text-muted);
  }

  .nav-panel .company-switcher__name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--hig-color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-panel .company-switcher__chevron {
    font-size: 0.76rem;
    color: var(--hig-color-text-muted);
    transition: transform 0.2s ease;
  }

  .nav-panel .company-switcher__trigger[aria-expanded="true"] .company-switcher__chevron {
    transform: rotate(180deg);
  }

  .nav-panel .company-switcher__dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 6px;
    right: 6px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.26);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    z-index: calc(var(--panel-z) + 1);
    overflow: hidden;
  }

  .nav-panel .company-switcher__trigger[aria-expanded="true"] + .company-switcher__dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .nav-panel .company-switcher__header {
    padding: 8px 10px;
    font-size: 0.63rem;
    font-weight: 560;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--hig-color-text-muted);
    border-bottom: 1px solid var(--panel-border);
  }

  .nav-panel .company-switcher__list {
    padding: 4px;
    max-height: 280px;
    overflow-y: auto;
  }

  .nav-panel .company-switcher__list form {
    margin: 0;
  }

  .nav-panel .company-switcher__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 8px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--hig-color-text);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
  }

  .nav-panel .company-switcher__item:hover,
  .nav-panel .company-switcher__item:focus-visible {
    background: var(--rail-item-bg-hover);
    outline: none;
  }

  .nav-panel .company-switcher__item--active {
    background: var(--rail-item-bg-active);
  }

  .nav-panel .company-switcher__item-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, #2b2b2d, #494950);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
  }

  .nav-panel .company-switcher__item-icon--all {
    background: linear-gradient(135deg, #2f6dd8, #2657aa);
  }

  .nav-panel .company-switcher__item-name {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 470;
    color: var(--hig-color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-panel .company-switcher__check {
    font-size: 0.86rem;
    color: var(--hig-color-text);
    flex-shrink: 0;
  }

  /* ---------- Overlay ---------- */
  .nav-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    z-index: calc(var(--panel-z) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .nav-panel-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------- Main content offset when rail is active ---------- */
  body.nav-mode-rail .main-content {
    margin-left: var(--rail-width);
    width: calc(100% - var(--rail-width));
  }

  body.nav-mode-rail .main-content.main-content--no-nav {
    margin-left: 0;
    width: 100%;
  }
}

/* ---------- Dark mode overrides (data-theme="dark") ---------- */
[data-theme="dark"] .nav-rail,
body.dark-theme .nav-rail {
  background: var(--rail-bg);
  border-right-color: var(--rail-border);
}

[data-theme="dark"] .nav-panel,
body.dark-theme .nav-panel {
  background: var(--panel-bg);
  border-right-color: var(--panel-border);
}

[data-theme="dark"] .nav-panel__link {
  color: var(--hig-color-text-secondary);
}

[data-theme="dark"] .nav-panel__link:hover,
[data-theme="dark"] .nav-panel__link:focus-visible,
body.dark-theme .nav-panel__link:hover,
body.dark-theme .nav-panel__link:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

[data-theme="dark"] .nav-panel__link.active,
body.dark-theme .nav-panel__link.active {
  background: rgba(255, 255, 255, 0.075);
  color: #fff;
}

.nav-rail__profile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  padding: 0;
  transition: background 0.18s ease;
}

.nav-rail__profile-btn:hover,
.nav-rail__profile-btn:focus-visible {
  background: var(--rail-item-bg-hover);
  outline: none;
}
