/* ==========================================================================
   Tiered Sidebar Navigation — Tier 1 Rail Safety + Tier 2 Plugin Flyout
   ========================================================================== */

#left-rail nav {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  scrollbar-width: none;
}

#left-rail nav::-webkit-scrollbar {
  display: none;
}

/* Tier 1 Apps trigger button badge */
.nav-apps-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  background: var(--color-primary, #3d1b6c);
  color: #ffffff;
  pointer-events: none;
}

/* Tier 2 Flyout Popover */
#nav-apps-popover {
  padding: 0;
  border: 1px solid var(--color-outline, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  background: var(--color-surface-container, #151923);
  color: var(--color-on-surface, #e2e8f0);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
  width: 310px;
  max-width: calc(100vw - 88px);
  max-height: min(78vh, 620px);
  overflow: hidden;
  /* Fallback placement for browsers without CSS Anchor Positioning */
  position: fixed;
  top: 72px;
  left: 72px;
  right: auto;
  bottom: auto;
  margin: 0;
}

html.light #nav-apps-popover {
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
}

#nav-apps-popover:is(:popover-open, .\:popover-open) {
  display: flex;
  flex-direction: column;
}

/* Progressive enhancement with CSS Anchor Positioning */
@supports (position-area: inline-end span-block-end) {
  #nav-apps-popover {
    inset: auto;
    margin: 0 0 0 10px;
    position-area: inline-end span-block-end;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  }
}

.tiered-flyout-header {
  padding: 12px 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

html.light .tiered-flyout-header {
  border-bottom-color: rgba(15, 23, 42, 0.08);
}

.tiered-flyout-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tiered-flyout-title {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tiered-flyout-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  opacity: 0.65;
}

.tiered-flyout-search {
  width: 100%;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: inherit;
  outline: none;
}

html.light .tiered-flyout-search {
  background: rgba(15, 23, 42, 0.04);
  border-color: rgba(15, 23, 42, 0.12);
}

.tiered-flyout-search:focus {
  border-color: var(--color-neon-teal, #20ffda);
}

.tiered-flyout-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tiered-cat {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

html.light .tiered-cat {
  border-color: rgba(15, 23, 42, 0.08);
  background: rgba(15, 23, 42, 0.02);
}

.tiered-cat-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: background-color 140ms ease;
}

.tiered-cat-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

html.light .tiered-cat-header:hover {
  background: rgba(15, 23, 42, 0.04);
}

.tiered-cat-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
}

.tiered-cat-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  opacity: 0.8;
}

html.light .tiered-cat-count {
  background: rgba(15, 23, 42, 0.08);
}

.tiered-cat-chevron {
  font-size: 16px;
  opacity: 0.6;
  transition: transform 160ms ease;
}

.tiered-cat.open .tiered-cat-chevron {
  transform: rotate(180deg);
}

.tiered-cat-items {
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px 6px;
}

.tiered-cat.open .tiered-cat-items {
  display: flex;
}

.tiered-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-on-surface-variant, #94a3b8);
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.tiered-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-on-surface, #f8fafc);
}

html.light .tiered-item:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
}

.tiered-item.active {
  background: rgba(32, 255, 218, 0.12);
  border-color: rgba(32, 255, 218, 0.3);
  color: var(--color-neon-teal, #20ffda);
  font-weight: 600;
}

html.light .tiered-item.active {
  background: rgba(61, 27, 108, 0.1);
  border-color: rgba(61, 27, 108, 0.28);
  color: var(--color-primary, #3d1b6c);
}

.tiered-item.has-error {
  color: #f87171;
}

.tiered-item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tiered-item-title {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tiered-item-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tiered-flyout-footer {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

html.light .tiered-flyout-footer {
  border-top-color: rgba(15, 23, 42, 0.08);
}

.tiered-footer-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-on-surface-variant, #94a3b8);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

html.light .tiered-footer-btn {
  border-color: rgba(15, 23, 42, 0.1);
  background: rgba(15, 23, 42, 0.04);
}

.tiered-footer-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-on-surface, #ffffff);
}

html.light .tiered-footer-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: #0f172a;
}

.tiered-empty {
  padding: 16px 10px;
  text-align: center;
  font-size: 12px;
  opacity: 0.65;
}
