/**
 * assets/css/subnav.css
 * Interactive Sub-Navigation Bar Below Topbar
 * Contract: FLOAT-CRUD-v1 (Section 6.1, 9.3)
 *
 * Provides a responsive, accessible navigation bar below .topbar
 * featuring category dropdowns, quick-action CRUD CTAs, and real-time active window indicator.
 */

:root {
  --subnav-height: 42px;
  --subnav-bg: var(--surface, #16202e);
  --subnav-border: var(--border, #2a3648);
  --subnav-text: var(--text, #e7ebf2);
  --subnav-muted: var(--muted, #8a99ad);
  --subnav-accent: var(--accent, #5b90d6);
  --subnav-dropdown-bg: var(--surface, #16202e);
  --subnav-hover-bg: rgba(255, 255, 255, 0.06);
  --subnav-active-bg: rgba(91, 144, 214, 0.16);
}

[data-theme="light"] {
  --subnav-bg: #ffffff;
  --subnav-border: var(--border, #d7dee8);
  --subnav-text: var(--text, #16233d);
  --subnav-muted: var(--muted, #64748b);
  --subnav-accent: var(--accent, #2b5ea3);
  --subnav-dropdown-bg: #ffffff;
  --subnav-hover-bg: rgba(0, 0, 0, 0.04);
  --subnav-active-bg: rgba(43, 94, 163, 0.1);
}

/* Subnav Bar Container: Pinned in-flow flex-column container between .topbar and .content */
.erp-subnav-bar {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: auto;
  min-height: var(--subnav-height);
  background: var(--subnav-bg);
  border-bottom: 1px solid var(--subnav-border);
  box-sizing: border-box;
  flex-shrink: 0;
  z-index: 100;
  user-select: none;
  -webkit-user-select: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--subnav-text);
  position: relative;
}

/* Row 1: Primary Category Toolbar & Quick Action CTAs */
.erp-subnav-primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--subnav-height);
  min-height: var(--subnav-height);
  flex-shrink: 0;
  padding: 0 16px;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.erp-subnav-primary::-webkit-scrollbar {
  display: none;
}

/* Left: Category Navigation Group */
.erp-subnav-categories {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.erp-subnav-dropdown-wrap {
  position: static;
}

/* Category Trigger Buttons */
.erp-subnav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: transparent;
  color: var(--subnav-text);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  outline: none;
}

.erp-subnav-btn:hover {
  background: var(--subnav-hover-bg);
  color: var(--subnav-accent);
}

.erp-subnav-btn:focus-visible {
  border-color: var(--subnav-accent);
  box-shadow: 0 0 0 2px rgba(91, 144, 214, 0.25);
}

.erp-subnav-btn.is-open {
  background: var(--subnav-active-bg);
  color: var(--subnav-accent);
  border-color: var(--subnav-accent);
}

.erp-subnav-btn.is-active-parent {
  color: var(--subnav-accent);
  font-weight: 700;
}

.erp-subnav-arrow {
  display: inline-block;
  font-size: 10px;
  transition: transform 0.2s ease;
}

.erp-subnav-btn.is-open .erp-subnav-arrow {
  transform: rotate(180deg);
}

/* Row 2: In-Flow Submenu Strip (Pushes .content naturally to y132) */
.erp-subnav-subrow {
  display: none;
  width: 100%;
  height: 44px;
  min-height: 44px;
  flex-shrink: 0;
  background: var(--subnav-dropdown-bg);
  border-top: 1px solid var(--subnav-border);
  box-sizing: border-box;
  position: static;
}

.erp-subnav-bar.has-open-menu .erp-subnav-subrow {
  display: flex;
}

/* Sub-Menu Bar: in-flow single horizontal line with horizontal scroll (44px height prevents scrollbar clipping) */
.erp-subnav-menu {
  position: static;
  width: 100%;
  height: 44px;
  min-height: 44px;
  flex-shrink: 0;
  background: var(--subnav-dropdown-bg);
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--subnav-border) transparent;
  -webkit-overflow-scrolling: touch;
}

[data-theme="light"] .erp-subnav-subrow,
[data-theme="light"] .erp-subnav-menu {
  background: #f8fafc;
}

.erp-subnav-menu.is-open {
  display: flex;
}

.erp-subnav-menu::-webkit-scrollbar {
  height: 4px;
}
.erp-subnav-menu::-webkit-scrollbar-track {
  background: transparent;
}
.erp-subnav-menu::-webkit-scrollbar-thumb {
  background: var(--subnav-border);
  border-radius: 4px;
}
.erp-subnav-menu::-webkit-scrollbar-thumb:hover {
  background: var(--subnav-muted);
}

/* Horizontal Sub-Menu Item (Chip/Button) */
.erp-subnav-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  height: 28px;
  color: var(--subnav-text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  outline: none;
  box-sizing: border-box;
}

.erp-subnav-item:hover,
.erp-subnav-item:focus-visible {
  background: var(--subnav-hover-bg);
  color: var(--subnav-accent);
  border-color: rgba(91, 144, 214, 0.3);
}

.erp-subnav-item.active {
  background: var(--subnav-active-bg);
  color: var(--subnav-accent);
  border-color: var(--subnav-accent);
  font-weight: 700;
}

.erp-subnav-item-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(128, 128, 128, 0.15);
  color: var(--subnav-muted);
  font-family: inherit;
}

/* Middle: Quick Action CRUD CTAs */
.erp-subnav-ctas {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.erp-subnav-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  background: rgba(91, 144, 214, 0.12);
  color: var(--subnav-accent);
  border: 1px solid rgba(91, 144, 214, 0.3);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  outline: none;
}

[data-theme="light"] .erp-subnav-cta-btn {
  background: rgba(43, 94, 163, 0.08);
  border-color: rgba(43, 94, 163, 0.25);
  color: var(--subnav-accent);
}

.erp-subnav-cta-btn:hover {
  background: var(--subnav-accent);
  color: #ffffff;
  border-color: var(--subnav-accent);
}

.erp-subnav-cta-btn:active {
  transform: scale(0.97);
}

/* Right: Active Window Indicator */
.erp-subnav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.erp-subnav-active-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--subnav-border);
  border-radius: 14px;
  font-size: 11.5px;
  color: var(--subnav-muted);
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="light"] .erp-subnav-active-pill {
  background: rgba(0, 0, 0, 0.04);
}

.erp-subnav-active-pill .pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--subnav-accent);
  flex-shrink: 0;
}

.erp-subnav-active-pill .pill-tenant {
  font-weight: 700;
  font-size: 10.5px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(91, 144, 214, 0.2);
  color: var(--subnav-accent);
}

.erp-subnav-active-pill .pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile & Small Screen Adaptation */
@media (max-width: 768px) {
  .erp-subnav-bar {
    position: relative;
  }
  .erp-subnav-primary {
    height: 38px;
    min-height: 38px;
    flex-shrink: 0;
    padding: 0 10px;
    gap: 6px;
  }
  .erp-subnav-btn {
    padding: 5px 8px;
    font-size: 12px;
  }
  .erp-subnav-ctas {
    display: none; /* Hide CTAs on mobile to prioritize category navigation and preserve touch width */
  }
  .erp-subnav-status {
    display: none;
  }
  .erp-subnav-subrow {
    height: 42px;
    min-height: 42px;
    flex-shrink: 0;
  }
  .erp-subnav-menu {
    position: static;
    height: 42px;
    min-height: 42px;
    flex-shrink: 0;
    padding: 0 10px;
    gap: 4px;
  }
  .erp-subnav-item {
    height: 26px;
    padding: 2px 8px;
    font-size: 11.5px;
  }
}
