/*
 * Portal icon rail — the app's left-hand portal navigation (ISH-253).
 *
 * This is the single source of truth for the rail's appearance. It replaced the
 * per-page copies of the old top-right portal dropdown's CSS, which had drifted
 * across the 18 pages that carried it (see .docs/AGENT_GUIDE.md §N). The markup
 * this styles is rendered by renderPortalRail() in js/shared.js — don't hand-write
 * rail markup in a page, and don't re-declare these rules in a page's inline
 * <style>.
 *
 * Colors resolve against each page's own :root tokens where those exist, with
 * literal fallbacks so the rail still renders correctly on a page whose :root is
 * incomplete. Rail-specific tokens are declared on .portal-rail itself rather
 * than :root, so a page's inline <style> can't clobber them by redefining :root
 * after this file loads.
 *
 * Requires <body class="has-portal-rail"> for the 60px content offset. That class
 * is set statically in each page's HTML rather than by JS, so the layout doesn't
 * shift once scripts run.
 */

/* Content offset. Applied to body rather than each page's own content container
 * because those container classes differ per page (.page, .container, etc.);
 * padding on body shifts every in-flow child uniformly, including the sticky
 * .top-nav. The class selector also outranks the `* { padding: 0 }` reset that
 * most pages declare inline. */
body.has-portal-rail {
  padding-left: 60px;
}

.portal-rail {
  --rail-bg: #ffffff;
  --rail-icon: var(--text-secondary, #4b5563);
  --rail-icon-active: #ffffff;
  --rail-hover-bg: rgba(15, 23, 42, 0.06);
  --rail-active-bg: var(--red, #a62626);
  --rail-active-bg-hover: var(--red-hover, #8f2121);

  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 60px;
  background: var(--rail-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 0 0.6rem;
  z-index: 110;
  /* Neutral grey, deliberately not red-tinted — a red separation shadow was
   * tried during design review and rejected. */
  box-shadow:
    3px 0 16px rgba(15, 23, 42, 0.08),
    1px 0 0 rgba(15, 23, 42, 0.12);
}

.rail-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 0.9rem;
}

.rail-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.rail-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.rail-item {
  position: relative;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--rail-icon);
  text-decoration: none;
  cursor: pointer;
  margin-bottom: 0.3rem;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  border: none;
  background: none;
  font: inherit;
}

.rail-item svg {
  width: 19px;
  height: 19px;
  display: block;
}

/* Neutral grey hover, deliberately not red-tinted — same design-review call as
 * the box-shadow above. */
.rail-item:hover {
  background: var(--rail-hover-bg);
  color: var(--text, #0f172a);
}

.rail-item.is-current {
  background: var(--rail-active-bg);
  color: var(--rail-icon-active);
}

.rail-item.is-current:hover {
  background: var(--rail-active-bg-hover);
  color: var(--rail-icon-active);
}

.rail-item:focus-visible {
  outline: 2px solid var(--red, #a62626);
  outline-offset: 2px;
}

.rail-spacer {
  flex: 1;
}

.rail-divider {
  width: 26px;
  height: 1px;
  background: var(--border-light, #f1f5f9);
  margin: 0.5rem 0;
}

.rail-account-btn {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0;
  border-radius: inherit;
}

.rail-tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: #101012;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
  z-index: 115;
}

.rail-item:hover .rail-tooltip,
.rail-item:focus-visible .rail-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Suppress the account tooltip while its popover is open — otherwise the
 * tooltip and the menu render on top of each other. */
.rail-account.is-open .rail-tooltip {
  opacity: 0 !important;
}

/*
 * Account popover.
 *
 * These .nav-portal-menu / .portal-menu-* / .portal-user-* rules were previously
 * duplicated in all 18 pages' inline <style> blocks; they live here now so the
 * popover has one definition. .rail-account-menu repositions the panel to fly out
 * from the rail's bottom-left instead of hanging below a top-right button.
 */
.nav-portal-menu {
  position: absolute;
  min-width: 260px;
  background: var(--card-bg, #ffffff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 0.35rem 0 0.5rem;
  z-index: 200;
}

.nav-portal-menu[hidden] {
  display: none;
}

.rail-account-menu {
  top: auto;
  right: auto;
  bottom: 0;
  left: calc(100% + 10px);
}

.portal-menu-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}

.portal-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--red, #a62626);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.portal-user-meta {
  min-width: 0;
}

.portal-user-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text, #0f172a);
  line-height: 1.3;
}

.portal-user-title {
  font-size: 0.8125rem;
  color: var(--text-secondary, #4b5563);
  margin-top: 0.15rem;
  line-height: 1.3;
}

.portal-menu-section-title {
  padding: 0.65rem 1rem 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-label, #94a3b8);
}

.portal-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text, #0f172a);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.portal-menu-item:hover {
  background: var(--page-bg, #f8f9fa);
}

.portal-menu-item.is-danger {
  color: var(--red, #a62626);
}

.portal-menu-divider {
  height: 1px;
  background: var(--border-light, #f1f5f9);
  margin: 0.35rem 0;
}

@media (prefers-reduced-motion: reduce) {
  .rail-item,
  .rail-tooltip {
    transition: none;
  }
}
