/* The module rail and the module sidebar header (templates/partials/nav/).
   Hand-written: Tailwind is JIT-built, so new utility classes do not exist. Colours
   come from the ReachClub theme tokens (apps/landing/static/codyn/reach-theme.css)
   and the module brand colours (templates/partials/icons/modules.html), set per entry
   as --rail-color. */

/* ── The rail: 72px, desktop only, a glass card like the sidebar ──────── */
.app-rail { display: none; }
@media (min-width: 1024px) {
  .app-rail {
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    flex-shrink: 0; width: 72px; position: sticky; top: 14px; height: calc(100vh - 28px);
    margin: 14px 0 14px 14px; padding: 10px 0 12px; border-radius: 22px; z-index: 5;
    background: var(--glass-sheet, rgba(255,255,255,.6)); border: 1px solid var(--glass-edge, rgba(255,255,255,.78));
    -webkit-backdrop-filter: var(--glass-blur, blur(28px)); backdrop-filter: var(--glass-blur, blur(28px));
    box-shadow: var(--glass-spec, none), var(--glass-drop, none);
  }
  /* The sidebar sits right next to the rail, with a narrower gap than the page margin */
  div.flex.h-screen.overflow-hidden:has(> aside) > aside { margin-left: 10px !important; }
}
.app-rail .rail-top, .app-rail .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.app-rail .rail-top { gap: 2px; }

.app-rail .rail-ws-wrap { position: relative; margin-bottom: 10px; }
.app-rail .rail-ws {
  display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 14px;
  border: none; background: transparent; cursor: pointer; transition: background .2s var(--reach-ease, ease), transform .2s;
}
.app-rail .rail-ws:hover { background: rgba(255,255,255,.55); transform: translateY(-1px); }
.app-rail .rail-ws .sidebar-logo-mark { width: 34px; height: 34px; border-radius: 11px; font-size: 14px; }
/* The workspace unread count sits on the avatar's corner, like it did on the old toggle */
.app-rail .rail-ws-wrap .sidebar-ws-badge { top: -2px; right: -4px; }

/* Module entries are .sidebar-nav-item (so page tests and the theme know them) laid out
   as a column: icon in a pill, label under it. The theme's row styles are undone here. */
.app-rail .sidebar-nav-item {
  flex-direction: column; justify-content: center; align-items: center;
  width: 60px; gap: 3px !important; padding: 6px 2px 7px !important; margin: 0 !important;
  border-radius: 16px !important; font-size: 10.5px !important; font-weight: 600; letter-spacing: .01em;
  color: var(--reach-ink-2, var(--text-secondary)); background: transparent !important; box-shadow: none !important;
  text-decoration: none; transition: color .2s;
}
.app-rail .sidebar-nav-item:hover { background: rgba(255,255,255,.5) !important; color: var(--reach-ink, var(--text-primary)); transform: none !important; }
.app-rail .sidebar-nav-item.active { color: var(--reach-ink, var(--text-primary)) !important; font-weight: 700; }
.app-rail .sidebar-nav-item svg { width: 22px; height: 22px; }
.app-rail .rail-icon {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 44px; height: 32px; border-radius: 12px; transition: background .25s var(--reach-ease, ease), color .25s, box-shadow .25s;
}
.app-rail .sidebar-nav-item.active .rail-icon {
  background: var(--rail-color); color: #fff;
  box-shadow: 0 10px 20px -10px var(--rail-color), inset 0 1px 0 rgba(255,255,255,.35);
}
.app-rail .rail-label { display: block; line-height: 1.1; }
.app-rail .sidebar-badge {
  position: absolute; top: -5px; right: -2px; margin: 0; min-width: 16px; height: 16px; line-height: 14px;
  padding: 1px 4px; text-align: center; font-size: 9.5px; border: 1.5px solid var(--glass-sheet, #fff);
}

/* The bottom group: the sidebar toggle, notifications, settings, theme, account */
.rail-icon-btn {
  position: relative; display: flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border-radius: 12px; border: none; background: transparent; cursor: pointer; color: var(--reach-ink-2, var(--text-secondary));
  transition: background .2s, color .2s;
}
.rail-icon-btn:hover { background: rgba(255,255,255,.55); color: var(--reach-ink, var(--text-primary)); }
.rail-icon-btn.active { color: var(--reach-ink, var(--text-primary)); background: var(--glass-card, rgba(255,255,255,.75)); box-shadow: var(--glass-spec, none); }
.rail-icon-btn .rail-count { position: absolute; top: 2px; right: 1px; margin: 0; min-width: 16px; height: 16px; line-height: 14px; padding: 1px 4px; font-size: 9.5px; text-align: center; }
.rail-avatar {
  display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 999px;
  border: 2px solid var(--glass-edge, rgba(255,255,255,.78)); background: rgba(120, 113, 108, .18); color: var(--reach-ink-2, var(--text-secondary));
  cursor: pointer; overflow: hidden; transition: transform .2s var(--reach-spring, ease), box-shadow .2s; margin-top: 4px;
}
.rail-avatar:hover { transform: scale(1.06); box-shadow: 0 8px 18px -10px rgba(60,30,110,.6); }
.rail-avatar img { width: 100%; height: 100%; object-fit: cover; }
/* The sidebar toggle: a smaller button above the bell, the same tokens as the other rail
   buttons. Its two icons (panel-left-close open, panel-left-open collapsed) are picked by
   x-show once Alpine runs; before that, rail-toggle-initial reads html.sidebar-is-collapsed,
   which base.html sets from localStorage before first paint. */
.rail-toggle { width: 32px; height: 32px; border-radius: 10px; margin-bottom: 4px; color: var(--reach-ink-3, var(--text-tertiary, var(--text-secondary))); }
.rail-toggle svg { width: 16px; height: 16px; }
.rail-toggle:focus-visible { outline: 2px solid var(--reach-pink, var(--primary)); outline-offset: 2px; }
.rail-toggle-initial .rail-toggle-open { display: none; }
html.sidebar-is-collapsed .rail-toggle-initial .rail-toggle-close { display: none; }
html.sidebar-is-collapsed .rail-toggle-initial .rail-toggle-open { display: block; }

/* ── The module header at the top of every sidebar ────────────────────── */
.sidebar-module-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 12px; min-height: 64px; }
.sidebar-module-icon {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 12px;
  color: #fff; background: var(--module-color, var(--primary)); box-shadow: 0 10px 20px -12px var(--module-color, var(--primary)), inset 0 1px 0 rgba(255,255,255,.35);
}
.sidebar-module-icon svg { width: 20px; height: 20px; }
.sidebar-module-text { min-width: 0; }
.sidebar-module-title { font-weight: 750; font-size: 1rem; letter-spacing: -.02em; color: var(--reach-ink, var(--text-primary)); line-height: 1.15; white-space: nowrap; }
.sidebar-module-sub { font-size: .72rem; color: var(--reach-ink-2, var(--text-secondary)); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-note { font-size: .78rem; color: var(--reach-ink-2, var(--text-secondary)); padding: 6px 14px 10px; line-height: 1.4; }

/* ── Collapsed: the sidebar is gone; hovering the rail peeks it ──────────── */
/* Desktop only (below 1024px the sidebar is a drawer). Collapsed, the aside is 0px wide
   and the page takes the space (push, not overlay). Hovering the rail (or its toggle) peeks
   it: the aside is back at its full width, in 200ms with the aside's own transition
   (Tailwind transition-all duration-200, set after Alpine boots). The pre-Alpine selector
   (html.sidebar-is-collapsed .sidebar-initial) is what base.html sets from localStorage
   before first paint, so nothing flashes at full width. */
@media (min-width: 1024px) {
  /* The children keep the open width, so the labels do not wrap while the width animates */
  div.flex.h-screen.overflow-hidden:has(> aside) > aside[data-module] > * { min-width: 238px; }
  div.flex.h-screen.overflow-hidden:has(> aside) > aside.sidebar-hidden,
  html.sidebar-is-collapsed div.flex.h-screen.overflow-hidden:has(> aside) > aside.sidebar-initial {
    width: 0 !important; margin-left: 0 !important; border-width: 0 !important;
    box-shadow: none !important; opacity: 0; overflow: hidden; pointer-events: none;
  }
  div.flex.h-screen.overflow-hidden:has(> aside) > aside.sidebar-peeking {
    box-shadow: var(--glass-spec, none), 0 24px 56px -24px rgba(60, 30, 110, .45);
  }
}
@media (prefers-reduced-motion: reduce) {
  div.flex.h-screen.overflow-hidden:has(> aside) > aside[data-module] { transition: none !important; }
}

/* The active item's edge takes the module's colour instead of the global pink */
aside[data-module] .sidebar-nav .sidebar-nav-item.active {
  box-shadow: var(--glass-spec, none), 0 12px 24px -16px rgba(60,30,110,.45), inset 3px 0 0 var(--module-color, var(--reach-pink, #FF3D9A)) !important;
}
/* LinkedIn blue badges for the Link module's live counts (ids other pages swap out of band) */
.rl-sb-badge, .eg-sb-badge, .ld-sb-badge { background: linear-gradient(135deg, #0A66C2, #38BDF8) !important; color: #fff !important; }

/* ── Mobile: the module row at the top of the drawer, and the footer row ── */
.sidebar-mobile-modules { padding: 10px 10px 6px; border-bottom: 1px solid var(--hairline, rgba(11,15,20,.07)); }
.sidebar-mobile-ws {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border-radius: 12px; border: none; background: transparent;
  font-weight: 700; font-size: .9375rem; color: var(--reach-ink, var(--text-primary)); text-align: left; cursor: pointer;
}
.sidebar-mobile-ws:hover { background: rgba(0,0,0,.04); }
.sidebar-mobile-rail { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 8px; }
.sidebar-mobile-module {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px 7px; border-radius: 14px;
  font-size: 10.5px; font-weight: 600; color: var(--reach-ink-2, var(--text-secondary)); text-decoration: none; transition: background .2s;
}
.sidebar-mobile-module:hover { background: rgba(0,0,0,.04); }
.sidebar-mobile-module .rail-icon { position: relative; display: flex; align-items: center; justify-content: center; width: 40px; height: 30px; border-radius: 11px; }
.sidebar-mobile-module.active { color: var(--reach-ink, var(--text-primary)); font-weight: 700; }
.sidebar-mobile-module.active .rail-icon { background: var(--rail-color); color: #fff; box-shadow: 0 8px 16px -10px var(--rail-color); }
.sidebar-mobile-module .sidebar-badge { position: absolute; top: -5px; right: -4px; margin: 0; font-size: 9.5px; padding: 1px 4px; }
/* The open drawer sits above the onboarding checklist (z 55), which otherwise covers its footer */
@media (max-width: 1023.98px) { aside[data-module] { z-index: 60; } }
/* The account menu opens over the drawer on mobile and beside the rail on desktop */
.app-user-menu { z-index: 70 !important; }
.sidebar-footer-mobile { display: flex; align-items: center; gap: 2px; }
.sidebar-footer-mobile .rail-avatar { margin-top: 0; }
@media (min-width: 1024px) { .sidebar-footer-mobile { display: none; } }

/* ── Dark theme ───────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  html[data-theme="dark"] .app-rail {
    background: linear-gradient(160deg, rgba(255,255,255,.08), rgba(255,255,255,.03)), rgba(10, 10, 13, .55);
    border-color: rgba(255,255,255,.1);
  }
}
html[data-theme="dark"] .app-rail .rail-ws:hover,
html[data-theme="dark"] .app-rail .sidebar-nav-item:hover,
html[data-theme="dark"] .rail-icon-btn:hover,
html[data-theme="dark"] .sidebar-mobile-ws:hover,
html[data-theme="dark"] .sidebar-mobile-module:hover { background: rgba(255,255,255,.08) !important; }
html[data-theme="dark"] .rail-icon-btn.active { background: rgba(255,255,255,.1); box-shadow: none; }
html[data-theme="dark"] .app-rail .sidebar-badge { border-color: rgba(20, 20, 24, .9); }
html[data-theme="dark"] .rail-avatar { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.14); }
html[data-theme="dark"] .sidebar-mobile-modules { border-bottom-color: rgba(255,255,255,.1); }
@media (min-width: 1024px) {
  html[data-theme="dark"] div.flex.h-screen.overflow-hidden:has(> aside) > aside.sidebar-peeking { box-shadow: 0 26px 56px -20px rgba(0, 0, 0, .9); }
}
html[data-theme="dark"] aside[data-module] .sidebar-nav .sidebar-nav-item.active { box-shadow: inset 3px 0 0 var(--module-color, #FF7AB8) !important; }
/* The Agent module wears the ReachClub mark in its own orange, so its active state is a
   soft orange pill behind the mark instead of the solid module colour. */
.app-rail .sidebar-nav-item.ra-sb svg { width: 26px; height: 26px; }
.app-rail .sidebar-nav-item.ra-sb.active .rail-icon,
.sidebar-mobile-module.active .rail-icon:has(.rail-agent-mark) {
  background: rgba(255, 91, 31, .16); box-shadow: inset 0 0 0 1px rgba(255, 91, 31, .45);
}

/* ── Content fits its container ───────────────────────────────────────────
   A long name, handle or link must never make a card, a button or the page wider.
   Zero specificity (:where), so any class still wins:
   1. a word longer than its line breaks instead of sticking out;
   2. running text (paragraphs, list items, table cells) may also shrink with its box,
      so a long word in it cannot hold a flex or grid row open;
   3. one-line labels that carry names, handles and titles trim with an ellipsis.
   Titles, buttons and tabs keep whole words. static/js/fit.js shows trimmed text in
   full on hover. */
:where(main, .ra-root, .im-public) { overflow-wrap: break-word; }
:where(main, .ra-root) :where(p, li, dd, dt, blockquote, figcaption, td) { overflow-wrap: anywhere; min-width: 0; }
:where(main, .ra-root) :where(img, video, canvas, iframe, pre) { max-width: 100%; }
:where(main, .ra-root) :where(pre) { overflow-x: auto; }
/* Small interface labels (weekday names, column heads) stay whole. */
:where(main) :where(.uppercase, .tracking-wide, .tracking-wider, .tracking-widest, .truncate, .whitespace-nowrap) { overflow-wrap: normal; }

/* One-line pieces: trim, never stretch. */
.im-plat, .rl-pill, .rl-chip, .rl-tag, .a-calc-tag, .rp-badge, .ra-link, .ra-made-open { max-width: 100%; }
.im-plat > a, .im-name, .rl-pill, .rl-chip, .rl-tag, .rp-badge, .ra-link > span, .ra-feed-who strong, .ra-creator-main strong {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.im-plat > a { display: block; }
.im-headline { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
/* A deal card: the status drops under the name when the two do not fit side by side. */
.im-deal-top { flex-wrap: wrap; }
.im-deal-top > div { flex: 1 1 130px !important; }  /* over the inline flex: 1 */

/* ReachLink, Studio, Engage and Leads cards (the .rl family): text wraps inside the card. */
.rl-card, .rl-note, .rl-row, .rl-item, .rl-stat, .rl-tile { min-width: 0; overflow-wrap: anywhere; }
.rl-card > *, .rl-note > *, .rl-row > *, .rl-item > * { min-width: 0; }
.rl-section-head, .rl-page-head { flex-wrap: wrap; }
.rl-section-head > *, .rl-page-head > * { min-width: 0; max-width: 100%; }
.rl-card :where(h2, h3, h4, strong, span, a, div), .rl-note :where(span, a, div) { overflow-wrap: anywhere; }
.rl-card :where(button, .rl-btn, .rl-btn-ghost, .rl-pill, label), .rl-subnav a { overflow-wrap: normal; }

/* Reach's answers: nothing in a message is wider than the conversation. */
.ra-row > * { max-width: 100%; min-width: 0; }
.ra-msg, .ra-post-text, .ra-feed-text, .ra-made-text, .ra-creator-main, .ra-kpi, .ra-visual-title, .ra-visual-hint { overflow-wrap: anywhere; min-width: 0; }
.ra-chip, .ra-starter { white-space: normal; text-align: left; max-width: 100%; overflow-wrap: anywhere; }
.ra-links, .ra-made, .ra-creators, .ra-report, .ra-media { max-width: 100%; min-width: 0; }
.ra-made-card, .ra-creator, .ra-report-head, .ra-report-channel h4 { min-width: 0; }
.ra-creator-side { max-width: 42%; }
.ra-creator-side small, .ra-report-head small, .ra-report-channel h4 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.ra-report-head .ra-btn { flex: none; }

/* ── The loading bar (static/js/loadbar.js) ────────────────────────────────
   A thin orange line at the top of the window, running right to left while a page,
   an HTMX request or Reach is on its way. Flat colour in dark mode: no glow, no blur. */
.reach-loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 2147483000;
  overflow: hidden; pointer-events: none; opacity: 0; transition: opacity .25s ease;
}
.reach-loadbar.is-on { opacity: 1; }
.reach-loadbar i {
  position: absolute; top: 0; bottom: 0; right: 0; width: 38%; border-radius: 3px;
  background: linear-gradient(270deg, rgba(255, 91, 31, 0), #FF5B1F 35%, #FF8A3D 65%, rgba(255, 91, 31, 0));
  box-shadow: 0 0 10px rgba(255, 91, 31, .55);
  transform: translateX(110%);
}
.reach-loadbar.is-on i { animation: reach-loadbar 1.15s cubic-bezier(.45, .05, .35, 1) infinite; }
html[data-theme="dark"] .reach-loadbar i { background: #FF5B1F; box-shadow: none; }
@keyframes reach-loadbar {
  from { transform: translateX(110%); }
  to { transform: translateX(-280%); }
}
@media (prefers-reduced-motion: reduce) {
  .reach-loadbar i { width: 100%; transform: none; }
  .reach-loadbar.is-on i { animation: reach-loadbar-pulse 1.6s ease-in-out infinite; }
}
@keyframes reach-loadbar-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ── Motion: nothing pops, things move ─────────────────────────────────────
   One curve for the whole app, the soft deceleration Apple uses for sheets and
   sidebars: quick to start, long to settle, no bounce. Motion is short (under
   0.4s), it never blurs (so it is the same in dark mode), and it is switched off
   for people who ask their system for reduced motion. */
:root { --reach-glide: cubic-bezier(.32, .72, 0, 1); }

/* Going from one page to the next: the rail and the sidebar stay where they are,
   the page itself fades over and settles. (Cross-document view transitions; a
   browser without them changes page as before.) */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  .app-rail { view-transition-name: app-rail; }
  @media (min-width: 1024px) { aside[data-module] { view-transition-name: app-sidebar; } }
  main { view-transition-name: app-main; }
  #calendar-content { view-transition-name: cal-grid; }
  .reach-loadbar { view-transition-name: reach-loadbar; }

  ::view-transition-group(*) { animation-duration: .34s; animation-timing-function: var(--reach-glide); }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
  ::view-transition-old(app-rail), ::view-transition-old(reach-loadbar) { display: none; }
  ::view-transition-new(app-rail), ::view-transition-new(reach-loadbar) { animation: none; }
  ::view-transition-old(app-sidebar) { animation: reach-vt-out .16s ease both; }
  ::view-transition-new(app-sidebar) { animation: reach-vt-fade .3s ease both; }
  ::view-transition-old(app-main) { animation: reach-vt-out .16s ease both; }
  ::view-transition-new(app-main) { animation: reach-vt-in .36s var(--reach-glide) both; }

  /* The calendar: the next month comes in from the right while this one leaves to the
     left, and the other way round for the month before. base.html sets data-cal-dir. */
  ::view-transition-old(cal-grid) { animation: reach-vt-out .16s ease both; }
  ::view-transition-new(cal-grid) { animation: reach-vt-in .36s var(--reach-glide) both; }
  html[data-cal-dir="next"]::view-transition-old(cal-grid) { animation: reach-cal-out-left .3s var(--reach-glide) both; }
  html[data-cal-dir="next"]::view-transition-new(cal-grid) { animation: reach-cal-in-right .42s var(--reach-glide) both; }
  html[data-cal-dir="prev"]::view-transition-old(cal-grid) { animation: reach-cal-out-right .3s var(--reach-glide) both; }
  html[data-cal-dir="prev"]::view-transition-new(cal-grid) { animation: reach-cal-in-left .42s var(--reach-glide) both; }
  html[data-cal-dir]::view-transition-old(app-main), html[data-cal-dir]::view-transition-new(app-main) { animation: none; }
  html[data-cal-dir]::view-transition-old(app-main) { display: none; }

  /* Posts on the calendar settle in a moment after their month does. */
  #calendar-content .cal-day > *:not(:first-child):not(.cal-add-btn) { animation: reach-settle .4s var(--reach-glide) both; animation-delay: .08s; }

  /* The sidebar opens and closes as one piece: the width glides, and its content
     slides and fades with it instead of being cut off. */
  @media (min-width: 1024px) {
    div.flex.h-screen.overflow-hidden:has(> aside) > aside[data-module].transition-all {
      transition: width .38s var(--reach-glide), margin .38s var(--reach-glide), border-width .38s var(--reach-glide),
                  opacity .26s ease, box-shadow .3s ease !important;
    }
    div.flex.h-screen.overflow-hidden:has(> aside) > aside[data-module].transition-all > * {
      transition: transform .38s var(--reach-glide), opacity .24s ease;
    }
    div.flex.h-screen.overflow-hidden:has(> aside) > aside[data-module].sidebar-hidden > * { transform: translateX(-18px); opacity: 0; }
  }
  /* The drawer on a phone uses the same curve. */
  @media (max-width: 1023px) { aside[data-module] { transition: transform .36s var(--reach-glide) !important; } }
}
@keyframes reach-vt-out { to { opacity: 0; } }
@keyframes reach-vt-fade { from { opacity: 0; } }
@keyframes reach-vt-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes reach-settle { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes reach-cal-out-left { to { opacity: 0; transform: translateX(-36px); } }
@keyframes reach-cal-in-right { from { opacity: 0; transform: translateX(48px); } }
@keyframes reach-cal-out-right { to { opacity: 0; transform: translateX(36px); } }
@keyframes reach-cal-in-left { from { opacity: 0; transform: translateX(-48px); } }
