/**
 * Ravenore app shell — sidebar navigation.
 * Uses ravenore-tokens.css variables when present; includes fallbacks.
 * Safe to include on all pages that extend base.html.
 *
 * Visual target: rail matches app body (--rn-bg-app / body #0f1113), gold keyline,
 * workflow pillars as rounded pills (muted gold caps + chevron) — same on every page.
 */

.layout {
  min-height: 100vh;
}

.sidebar {
  /* Same as base.html body (tokens --rn-bg-app is darker; body wins for “app” feel) */
  --rn-sidebar-surface: #0f1113;
  --rn-sidebar-pillar-fill: #171a1f;
  --rn-sidebar-pillar-fill-active: #1a1f26;
  --rn-sidebar-gold: #c9a64a;
  --rn-sidebar-gold-bright: #e0c282;
  --rn-sidebar-pillar-border: rgba(212, 175, 55, 0.38);
  --rn-sidebar-pillar-border-active: rgba(212, 175, 55, 0.58);
  --rn-sidebar-rail-line: rgba(201, 166, 74, 0.32);

  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--rn-sidebar-width, 200px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  padding: 1rem 0.7rem 1.1rem;
  z-index: 20;
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: var(--rn-scrollbar-thumb) var(--rn-scrollbar-track);
  font-family: var(--rn-font-sans);
  -webkit-font-smoothing: antialiased;

  /* Left edge darkest; black overlay eases to none across full rail width */
  background: linear-gradient(
      to right,
      rgba(0, 0, 0, 0.88) 0%,
      rgba(0, 0, 0, 0.5) 35%,
      rgba(0, 0, 0, 0.2) 68%,
      rgba(0, 0, 0, 0) 100%
    ),
    var(--rn-sidebar-surface);
  border-right: 1px solid var(--rn-sidebar-rail-line);
  box-shadow: inset -1px 0 0 rgba(212, 175, 55, 0.08);
}

.sidebar__nav-block {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Isolate nav from global <a> / <button> rules in base.html */
.sidebar a {
  text-decoration: none;
}
.sidebar a:hover {
  text-decoration: none;
}

.sidebar-title {
  margin: 0 0 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(201, 166, 74, 0.14);
}

.sidebar-title a {
  display: block;
  text-decoration: none;
  border-radius: var(--rn-radius-sm, 6px);
  outline-offset: 2px;
}

.sidebar-title a:focus-visible {
  outline: 1px solid rgba(201, 166, 74, 0.45);
}

.sidebar-title img {
  max-width: 82%;
  height: auto;
  vertical-align: middle;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

/* Workflow pillars — rounded pill buttons, muted gold, chevron right (front page = reference) */
.nav-list--pillars {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(201, 166, 74, 0.1);
}
.sidebar .nav-group.nav-pillar {
  margin-bottom: 0.52rem;
}
.sidebar .nav-group.nav-pillar:last-child {
  margin-bottom: 0.15rem;
}
.nav-pillar__row {
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 2.55rem;
  border-radius: 10px;
  background: var(--rn-sidebar-pillar-fill);
  border: 1px solid var(--rn-sidebar-pillar-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.nav-pillar--contains-active .nav-pillar__row {
  border-color: var(--rn-sidebar-pillar-border-active);
  background: var(--rn-sidebar-pillar-fill-active);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(212, 175, 55, 0.12);
}
.nav-pillar__label {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.5rem 0.5rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--rn-sidebar-gold-bright);
  line-height: 1.15;
}
.nav-pillar--contains-active .nav-pillar__label {
  color: #f0e6c8;
}
.nav-pillar .nav-group__toggle {
  border-radius: 0 10px 10px 0;
  color: var(--rn-sidebar-gold);
}
.nav-pillar .nav-group__toggle:hover {
  color: var(--rn-sidebar-gold-bright);
  background: rgba(201, 166, 74, 0.1) !important;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin-bottom: 0.15rem;
}

.nav-group {
  margin-bottom: 0.35rem;
  position: relative;
}

/* Parent row: label link + right chevron */
.nav-group__row {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.sidebar .nav-link--row-fill {
  flex: 1;
  min-width: 0;
}

.sidebar .nav-group__toggle {
  flex: 0 0 1.65rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0 10px 10px 0;
  background: transparent !important;
  cursor: pointer;
  color: var(--rn-sidebar-gold, #c9a64a);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
  font-size: inherit;
  font-weight: 500;
  box-shadow: none;
}

.sidebar .nav-group__toggle:hover {
  color: rgba(240, 215, 138, 0.82);
  background: rgba(201, 166, 74, 0.07) !important;
}

.sidebar .nav-group__toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px rgba(201, 166, 74, 0.45);
}

/* Chevron: closed = points right; open = points down — weight matches gold keyline */
.nav-group__chev {
  display: block;
  width: 0.42rem;
  height: 0.42rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  margin-left: -0.1rem;
  opacity: 0.92;
  transition: transform 0.16s ease, opacity 0.12s ease;
}

.nav-group:hover .nav-group__chev,
.nav-group--expanded .nav-group__chev {
  transform: rotate(45deg);
  margin-top: -0.08rem;
  margin-left: 0;
}

/* Pillar chevrons: only look “open” when expanded (avoid false open cue on row hover) */
.nav-pillar:not(.nav-group--expanded):hover .nav-group__chev {
  transform: rotate(-45deg);
  margin-top: -0.08rem;
  margin-left: -0.12rem;
}
.nav-pillar.nav-group--expanded .nav-group__chev {
  transform: rotate(45deg);
  margin-top: -0.08rem;
  margin-left: 0;
}

/* Child list: hidden by default; subtle reveal */
.nav-group .nav-sub {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  margin: 0 0 0 0.35rem;
  padding: 0 0 0 0.55rem;
  border-left: 1px solid transparent;
  transition: max-height 0.22s ease, opacity 0.16s ease, padding 0.18s ease, border-color 0.18s ease,
    visibility 0.16s ease;
}

/* Click-to-open: stays open until toggled off (see sidebar-nav.js) */
.nav-group--expanded .nav-sub {
  max-height: 16rem;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  padding: 0.28rem 0 0.15rem 0.52rem;
  margin-top: 0.15rem;
  border-left-color: rgba(212, 175, 55, 0.28);
  border-radius: 0 0 8px 8px;
  background: rgba(0, 0, 0, 0.45);
}

/* Fine pointer + hover: expand non-pillar groups only (workflow pillars use click + accordion) */
@media (hover: hover) and (pointer: fine) {
  .nav-group:not(.nav-pillar):hover .nav-sub {
    max-height: 16rem;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    padding: 0.18rem 0 0.1rem 0.52rem;
    border-left-color: var(--rn-chrome-gold-muted, rgba(201, 166, 74, 0.22));
  }
}

.nav-child {
  margin-bottom: 0.08rem;
}

.sidebar .nav-sub .nav-link {
  padding: 0.34rem 0.42rem 0.34rem 0.48rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--rn-text-faint, #8e97a3);
}

.sidebar .nav-sub .nav-link:hover {
  color: var(--rn-text-secondary, #c5ccd4);
}

.sidebar .nav-sub .nav-link.active {
  color: rgba(240, 215, 138, 0.95);
}

.sidebar .nav-link--parent {
  font-weight: 600;
}

/* Parent row when a nested page is active (not the parent page itself) */
.sidebar .nav-link--ancestor {
  color: rgba(196, 184, 154, 0.88);
  background: rgba(201, 166, 74, 0.05);
  border-left-color: rgba(201, 166, 74, 0.42);
}

.sidebar .nav-link {
  display: block;
  padding: 0.4rem 0.52rem 0.4rem 0.55rem;
  border-radius: var(--rn-radius-sm, 6px);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.35;
  color: var(--rn-text-muted, #8b949e);
  text-decoration: none;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.sidebar .nav-link:hover {
  color: var(--rn-text-secondary, #c5ccd4);
  background: rgba(201, 166, 74, 0.06);
  border-color: rgba(255, 255, 255, 0.04);
  border-left-color: rgba(201, 166, 74, 0.22);
}

.sidebar .nav-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px rgba(201, 166, 74, 0.35);
}

.sidebar-account {
  flex: 0 0 auto;
  text-align: center;
  padding: 0.85rem 0.35rem 0.15rem;
}

.sidebar-account__form {
  margin: 0;
}

.sidebar .sidebar-account__action {
  display: inline-block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  border-radius: 0;
  cursor: pointer;
  font-family: inherit;
    font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
  color: rgba(142, 151, 163, 0.8);
  text-decoration: none;
}

.sidebar .sidebar-account__action:hover {
  background: none;
  border: 0;
  color: var(--rn-sidebar-gold-bright, #e0c282);
}

.sidebar .nav-link.active {
  color: rgba(240, 215, 138, 0.95);
  font-weight: 600;
  background: rgba(201, 166, 74, 0.09);
  border-color: rgba(201, 166, 74, 0.1);
  border-left-color: rgba(201, 166, 74, 0.72);
  box-shadow: none;
}

/* Scrollbar: token-aligned (same as digest rail / Hunter tables) */
.sidebar__nav-block::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
  width: var(--rn-scrollbar-size);
}
.sidebar__nav-block::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
  background: var(--rn-scrollbar-track);
  border-radius: 4px;
}
.sidebar__nav-block::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: var(--rn-scrollbar-thumb);
  border-radius: 4px;
}
.sidebar__nav-block::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--rn-scrollbar-thumb-hover);
}

.rn-mobile-bar,
.rn-mobile-backdrop {
  display: none;
}

@media (max-width: 800px) {
  .rn-mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 25;
    min-height: 3.25rem;
    padding: calc(0.4rem + env(safe-area-inset-top)) 0.85rem 0.4rem;
    background: #0f1113;
    border-bottom: 1px solid rgba(201, 166, 74, 0.32);
  }

  .rn-mobile-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #e8e4dc;
  }

  .rn-burger,
  .rn-burger::before,
  .rn-burger::after {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
  }

  .rn-burger {
    position: relative;
  }

  .rn-burger::before,
  .rn-burger::after {
    content: "";
    position: absolute;
    left: 0;
  }

  .rn-burger::before { top: -7px; }
  .rn-burger::after { top: 7px; }

  .rn-mobile-bar__logo img {
    display: block;
    height: 40px;
    width: auto;
  }

  .rn-mobile-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.55);
  }

  .sidebar {
    width: min(18rem, 86vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
  }

  body.rn-nav-open .sidebar {
    transform: none;
  }

  body.rn-nav-open {
    overflow: hidden;
  }

  .nav-pillar__label {
    font-size: 0.95rem;
    letter-spacing: 0.08em;
  }

  .sidebar .nav-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    font-size: 1.08rem;
  }

  .sidebar .sidebar-account__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0 0.75rem;
    font-size: 0.95rem;
  }
}

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

  .nav-group .nav-sub,
  .nav-group__chev,
  .sidebar .nav-group__toggle {
    transition: none;
  }
}
