/* app/assets/stylesheets/components/nav.css
   ─────────────────────────────────────────────────────────────────────────────
   Masthead (top bar) and navigation for the admin, dashboard and agent
   layouts: hide-on-scroll, the mobile drawer and the theme toggle. Behaviour
   lives in masthead_controller.js and theme_controller.js.
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Masthead ─────────────────────────────────────────────────────────────── */

/* Slightly see-through (--glass-chrome, 88%) so the map drifts faintly under
   it — no blur, see the note on glass in tokens.css. The solid declaration
   first is the fallback for browsers without color-mix(). */
.masthead {
  position:         sticky;
  top:              0;
  z-index:          var(--z-masthead);
  background:       var(--bg-chrome);
  background:       var(--glass-chrome);
  border-bottom:    3px solid var(--color-blue-600);
  height:           var(--masthead-height);
  display:          flex;
  align-items:      center;
  /* While hidden the bar carries a transform, and a transformed element
     becomes the containing block for its position:fixed children — so the
     closed drawer, parked off the right edge, stops being fixed to the screen
     and turns into page content 320px wider than the phone. Mobile Chrome
     answers that by rescaling and jumping the page. Clipping keeps it inside
     the bar then; when the bar is not transformed the drawer is fixed to the
     viewport again and the clip does not touch it. hidden is the fallback for
     browsers without clip. */
  overflow:         hidden;
  overflow:         clip;
}

.masthead__inner {
  width:          100%;
  max-width:      var(--max-width-content);
  margin:         0 auto;
  padding:        0 var(--gutter);
  display:        flex;
  align-items:    center;
  gap:            var(--space-8);
}

/* Brand / wordmark */
.masthead__brand {
  display:     flex;
  align-items: baseline;
  gap:         var(--space-2);
  flex-shrink: 0;
}

.masthead__wordmark {
  font-family:    var(--font-serif);
  font-size:      var(--text-lg);
  font-weight:    700;
  color:          var(--color-white);
  text-decoration: none;
  letter-spacing: var(--tracking-tight);
  white-space:    nowrap;
}

.masthead__wordmark:hover {
  color: var(--color-blue-200);
}

.masthead__edition {
  font-family:    var(--font-sans);
  font-size:      var(--text-xs);
  font-weight:    600;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color:          var(--color-blue-500);
  padding:        2px 6px;
  border:         1px solid var(--color-blue-600);
  border-radius:  var(--radius-sm);
  line-height:    1;
}

/* Nav + actions. On wide screens this is just the rest of the bar; on narrow
   ones it becomes the drawer (see Responsive masthead below). */
.masthead__menu {
  display:     flex;
  align-items: center;
  gap:         var(--space-8);
  flex:        1;
  min-width:   0;
}

/* Nav links */
.masthead__nav {
  display:     flex;
  align-items: center;
  gap:         var(--space-1);
  flex:        1;
}

/* Section links that exist only in the mobile drawer (the dashboard shows its
   sections in a tab strip on desktop). */
.masthead__nav--drawer {
  display: none;
}

.masthead__nav-link {
  font-family:    var(--font-sans);
  font-size:      var(--text-sm);
  font-weight:    500;
  color:          var(--text-muted);
  text-decoration: none;
  padding:        var(--space-2) var(--space-3);
  border-radius:  var(--radius-md);
  transition:     color var(--transition-fast),
                  background var(--transition-fast);
  white-space:    nowrap;
}

.masthead__nav-link:hover {
  color:      var(--color-white);
  background: var(--tint-neutral-bg);
}

.masthead__nav-link.is-active {
  color:      var(--color-white);
  background: rgba(255,255,255,0.12);
  font-weight: 600;
}

/* Right-side admin actions */
.masthead__actions {
  display:     flex;
  align-items: center;
  gap:         var(--space-4);
  flex-shrink: 0;
}

/* A bar with no nav links (agent, dashboard, signed-out admin) keeps its
   actions on the right. */
.masthead__actions--end,
.masthead__menu > .masthead__actions:first-child {
  margin-left: auto;
}

/* Sign out and the theme switch, always side by side. */
.masthead__session {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
}

.masthead__admin-name {
  font-family: var(--font-sans);
  font-size:   var(--text-sm);
  color:       var(--text-muted);
  white-space: nowrap;
  max-width:   160px;
  overflow:    hidden;
  text-overflow: ellipsis;
}

/* ── Tab strip (dashboard section navigation) ────────────────────────────── */

.tab-strip {
  display:       flex;
  align-items:   flex-end;
  gap:           0;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: var(--space-6);
  overflow-x:    auto;
}

.tab-strip__tab {
  font-family:    var(--font-sans);
  font-size:      var(--text-sm);
  font-weight:    500;
  color:          var(--text-secondary);
  text-decoration: none;
  padding:        var(--space-3) var(--space-5);
  border-bottom:  2px solid transparent;
  margin-bottom:  -2px;
  white-space:    nowrap;
  transition:     color var(--transition-fast),
                  border-color var(--transition-fast);
}

.tab-strip__tab:hover {
  color:        var(--text-primary);
  border-color: var(--border-strong);
}

.tab-strip__tab.is-active {
  color:        var(--color-blue-600);
  border-color: var(--color-blue-600);
  font-weight:  600;
}

/* Dashboard nav: Overview plus one dropdown per group (Sentiment, Campaign,
   Finance). Visible overflow so the menus can hang below the strip. */
.tab-strip--grouped {
  overflow:   visible;
  position:   relative;
  z-index:    var(--z-dropdown);
}

.tab-strip__group {
  position: relative;
}

.tab-strip__group > summary {
  display:     flex;
  align-items: center;
  gap:         var(--space-2);
  cursor:      pointer;
  list-style:  none;
  user-select: none;
}

.tab-strip__group > summary::-webkit-details-marker {
  display: none;
}

.tab-strip__group[open] > summary {
  color:        var(--text-primary);
  border-color: var(--border-strong);
}

/* Names the page you're on within the group, e.g. "Sentiment · Narratives". */
.tab-strip__current {
  font-weight: 500;
  color:       var(--text-muted);
}

.tab-strip__current::before {
  content: "·";
  margin:  0 var(--space-2) 0 0;
}

.tab-strip__caret {
  width:        6px;
  height:       6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform:    translateY(-2px) rotate(45deg);
  opacity:      0.6;
  transition:   transform var(--transition-fast);
}

.tab-strip__group[open] .tab-strip__caret {
  transform: translateY(1px) rotate(-135deg);
}

.tab-strip__menu {
  position:      absolute;
  top:           calc(100% + 2px);
  left:          0;
  min-width:     260px;
  display:       flex;
  flex-direction: column;
  padding:       var(--space-2);
  background:    var(--bg-surface);
  border:        1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-lg);
}

/* The last group opens leftward so its menu stays on screen on narrow widths. */
.tab-strip__group:last-of-type .tab-strip__menu {
  left:  auto;
  right: 0;
}

.tab-strip__item {
  display:        flex;
  flex-direction: column;
  gap:            2px;
  padding:        var(--space-2) var(--space-3);
  border-radius:  var(--radius-md);
  text-decoration: none;
  transition:     background var(--transition-fast);
}

.tab-strip__item:hover,
.tab-strip__item:focus-visible {
  background: var(--bg-raised);
}

.tab-strip__item-label {
  font-family: var(--font-sans);
  font-size:   var(--text-sm);
  font-weight: 500;
  color:       var(--text-primary);
}

.tab-strip__item-hint {
  font-family: var(--font-sans);
  font-size:   var(--text-xs);
  color:       var(--text-muted);
}

.tab-strip__item.is-active {
  box-shadow: inset 2px 0 0 var(--color-blue-600);
}

.tab-strip__item.is-active .tab-strip__item-label {
  color:       var(--color-blue-600);
  font-weight: 600;
}

/* ── Admin body layout ───────────────────────────────────────────────────── */

.admin-body {
  background: var(--bg-page);
  min-height: 100dvh;
  display:    flex;
  flex-direction: column;
}

.admin-main {
  flex:       1;
  width:      100%;
  max-width:  var(--max-width-content);
  margin:     0 auto;
  padding:    var(--space-8) var(--gutter);
}

/* ── Admin footer ────────────────────────────────────────────────────────── */

.admin-footer {
  border-top:  1px solid var(--border-color);
  background:  var(--bg-surface);
  padding:     var(--space-4) var(--space-6);
  margin-top:  auto;
}

.admin-footer__inner {
  max-width:   var(--max-width-content);
  margin:      0 auto;
  display:     flex;
  align-items: center;
  justify-content: space-between;
  font-size:   var(--text-xs);
  color:       var(--text-muted);
}

/* ── Hide on scroll ──────────────────────────────────────────────────────── */
/* masthead_controller.js adds .is-hidden on a scroll down and drops it on a
   scroll up. The two directions move differently on purpose: the bar ducks
   out quickly and gets out of the way, then comes back with a longer
   overshooting ease so the reveal reads as a deliberate slide-in. */

.masthead,
.home-nav {
  transition: transform 420ms cubic-bezier(0.34, 1.32, 0.64, 1),
              box-shadow var(--transition-slow);
}

.masthead.is-hidden,
.home-nav.is-hidden {
  transform:  translateY(calc(-100% - 4px));
  transition: transform 220ms cubic-bezier(0.4, 0, 1, 1),
              box-shadow var(--transition-slow);
}

.masthead.is-scrolled,
.home-nav.is-scrolled {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.masthead.is-hidden,
.home-nav.is-hidden {
  box-shadow: none;
}

/* Above the flash region while the drawer is open, so it covers everything. */
.masthead.is-open {
  z-index: var(--z-modal);
}

@media (prefers-reduced-motion: reduce) {
  .masthead,
  .home-nav,
  .masthead.is-hidden,
  .home-nav.is-hidden {
    transition: none;
  }
}

/* ── Theme toggle ────────────────────────────────────────────────────────── */
/* Moon on the light theme, sun on the dark — the icon is where a click goes. */

.theme-toggle {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  width:           32px;
  height:          32px;
  flex-shrink:     0;
  padding:         0;
  color:           var(--text-secondary);
  background:      transparent;
  border:          1px solid var(--border-strong);
  border-radius:   var(--radius-md);
  cursor:          pointer;
  transition:      color var(--transition-fast),
                   background var(--transition-fast);
}

.theme-toggle:hover {
  color:      var(--text-primary);
  background: var(--tint-neutral-bg);
}

.theme-toggle:focus-visible {
  outline:        2px solid var(--color-blue-500);
  outline-offset: 2px;
}

.theme-toggle__icon {
  width:           18px;
  height:          18px;
  fill:            none;
  stroke:          currentColor;
  stroke-width:    1.8;
  stroke-linecap:  round;
  stroke-linejoin: round;
  animation:       theme-icon-in var(--transition-slow);
}

.theme-toggle__sun { display: none; }

:root[data-theme="dark"] .theme-toggle__moon { display: none; }
:root[data-theme="dark"] .theme-toggle__sun  { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle__sun  { display: block; }
}

@keyframes theme-icon-in {
  from { transform: rotate(-60deg) scale(0.6); opacity: 0; }
  to   { transform: none;                      opacity: 1; }
}

/* ── Hamburger ───────────────────────────────────────────────────────────── */

.masthead__burger {
  display:         none;
  margin-left:     auto;
  width:           40px;
  height:          40px;
  padding:         0;
  align-items:     center;
  justify-content: center;
  background:      transparent;
  border:          none;
  color:           var(--text-primary);
  cursor:          pointer;
}

.masthead__burger:focus-visible {
  outline:        2px solid var(--color-blue-500);
  outline-offset: 2px;
  border-radius:  var(--radius-md);
}

/* Three bars that fold into an X when open. */
.masthead__burger-bars,
.masthead__burger-bars::before,
.masthead__burger-bars::after {
  display:       block;
  width:         22px;
  height:        2px;
  background:    currentColor;
  border-radius: 1px;
  transition:    transform 260ms cubic-bezier(0.4, 0, 0.2, 1),
                 background 120ms;
}

.masthead__burger-bars {
  position: relative;
}

.masthead__burger-bars::before,
.masthead__burger-bars::after {
  content:  "";
  position: absolute;
  left:     0;
}

.masthead__burger-bars::before { transform: translateY(-7px); }
.masthead__burger-bars::after  { transform: translateY(7px); }

.masthead.is-open .masthead__burger-bars         { background: transparent; }
.masthead.is-open .masthead__burger-bars::before { transform: rotate(45deg); }
.masthead.is-open .masthead__burger-bars::after  { transform: rotate(-45deg); }

.masthead__scrim {
  display: none;
}

/* ── Responsive masthead ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .masthead__inner {
    gap: var(--space-4);
  }

  .masthead__burger {
    display: inline-flex;
  }

  /* The drawer: full height, from the right, under the bar's own button. */
  .masthead__menu {
    position:       fixed;
    top:            0;
    right:          0;
    bottom:         0;
    width:          min(320px, 86vw);
    flex-direction: column;
    align-items:    stretch;
    gap:            var(--space-6);
    padding:        calc(var(--masthead-height) + var(--space-4)) var(--space-5) var(--space-6);
    background:     var(--bg-chrome);
    border-left:    1px solid var(--border-color);
    box-shadow:     -12px 0 32px rgba(0, 0, 0, 0.45);
    overflow-y:     auto;
    transform:      translateX(100%);
    visibility:     hidden;
    transition:     transform 300ms cubic-bezier(0.4, 0, 0.2, 1),
                    visibility 0s linear 300ms;
  }

  .masthead.is-open .masthead__menu {
    transform:  none;
    visibility: visible;
    transition: transform 380ms cubic-bezier(0.22, 1, 0.36, 1),
                visibility 0s;
  }

  /* The burger sits above the drawer so it doubles as the close button. */
  .masthead__brand,
  .masthead__burger {
    position: relative;
    z-index:  2;
  }

  .masthead__menu { z-index: 1; }

  .masthead__nav {
    flex-direction: column;
    align-items:    stretch;
    flex:           0 0 auto;
    gap:            var(--space-1);
  }

  .masthead__nav-link {
    font-size: var(--text-base);
    padding:   var(--space-3) var(--space-3);
  }

  .masthead__nav--drawer {
    display: flex;
  }

  /* The drawer carries the dashboard nav on phones. The grouped strip can't
     scroll (its menus need visible overflow), so at this width it would push
     the page wider than the screen and drag the drawer off the right edge. */
  .tab-strip--grouped {
    display: none;
  }

  /* Drawer groups: one accordion per group (Sentiment, Campaign, Finance). */
  .masthead__nav-group {
    border-top: 1px solid var(--border-color);
  }

  .masthead__nav-group:last-of-type {
    border-bottom: 1px solid var(--border-color);
  }

  .masthead__nav-heading {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    min-height:      44px;
    padding:         var(--space-3);
    font-family:     var(--font-sans);
    font-size:       var(--text-xs);
    font-weight:     600;
    letter-spacing:  0.08em;
    text-transform:  uppercase;
    color:           var(--text-muted);
    cursor:          pointer;
    list-style:      none;
    user-select:     none;
  }

  .masthead__nav-heading::-webkit-details-marker {
    display: none;
  }

  .masthead__nav-group[open] > .masthead__nav-heading {
    color: var(--color-white);
  }

  .masthead__nav-caret {
    width:         7px;
    height:        7px;
    border-right:  1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform:     translateY(-2px) rotate(45deg);
    transition:    transform var(--transition-fast);
  }

  .masthead__nav-group[open] .masthead__nav-caret {
    transform: translateY(2px) rotate(-135deg);
  }

  .masthead__nav-items {
    display:        flex;
    flex-direction: column;
    gap:            var(--space-1);
    padding-bottom: var(--space-3);
  }

  .masthead__nav-items .masthead__nav-link {
    display:        flex;
    flex-direction: column;
    gap:            2px;
  }

  .masthead__nav-items .masthead__nav-link.is-active {
    box-shadow: inset 2px 0 0 var(--color-blue-600);
  }

  .masthead__nav-hint {
    font-size:   var(--text-xs);
    font-weight: 400;
    color:       var(--text-muted);
  }

  /* Actions stack, with sign out + theme pinned to the bottom of the drawer. */
  .masthead__actions {
    flex:           1;
    flex-direction: column;
    align-items:    flex-start;
    gap:            var(--space-3);
  }

  .masthead__admin-name {
    max-width: 100%;
  }

  .masthead__session {
    margin-top:  auto;
    width:       100%;
    padding-top: var(--space-4);
    border-top:  1px solid var(--border-color);
  }

  .masthead__session form,
  .masthead__session .btn {
    flex: 1;
  }

  .masthead__session .btn {
    width: 100%;
  }

  .masthead__session .theme-toggle {
    width:  40px;
    height: 40px;
  }

  .masthead__scrim {
    display:    block;
    position:   fixed;
    inset:      0;
    z-index:    0;
    background: rgba(0, 0, 0, 0.5);
    opacity:    0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 0s linear 300ms;
  }

  .masthead.is-open .masthead__scrim {
    opacity:    1;
    visibility: visible;
    transition: opacity 300ms ease, visibility 0s;
  }

  .admin-main {
    padding: var(--space-4);
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .masthead__menu,
  .masthead.is-open .masthead__menu,
  .masthead__scrim,
  .masthead.is-open .masthead__scrim {
    transition: none;
  }
}

/* No page scroll behind an open drawer. */
:root.masthead-menu-open {
  overflow: hidden;
}

/* Placeholder nav items for routes not yet built (Phase 3+) */
.masthead__nav-link--soon {
  opacity: 0.35;
  cursor:  default;
  pointer-events: none;
}
