/**
 * SunMonitor — Scope selector (Sprint 2)
 *
 * Topbar dropdown voor multi-site klant: "Alle 5 installaties ▾" of
 * "Site naam ▾". Vervangt de oude statische .tb-site-label tekst voor
 * klanten met >1 site. Voor klant met 1 site = read-only label.
 *
 * Mount: <div id="custScopeSelector"> in topbar-customer.html
 * JS: js/customer/scope.js
 */

#custScopeSelector {
  position: relative;
  flex: 1;
  margin: 0 var(--space-7);
  min-width: 0;
}

/* Static label voor klant met 1 site */
.scope-static {
  font-size: var(--fs-14);
  font-weight: var(--fw-semibold);
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 10px;
}

/* Dropdown trigger */
.scope-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  max-width: 100%;
}
.scope-trigger:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.20);
}
.scope-trigger:focus-visible {
  outline: 2px solid rgba(245, 158, 11, 0.55);
  outline-offset: 2px;
}
.scope-trigger-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.scope-trigger-caret {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  flex-shrink: 0;
}

/* Dropdown menu */
.scope-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1200;
  min-width: 280px;
  max-width: 380px;
  background: var(--surface-card, #fff);
  border: 1px solid var(--color-gray-200, #e2e8f0);
  border-radius: 12px;
  box-shadow:
    0 12px 32px rgba(15, 23, 42, 0.18),
    0 4px 12px rgba(15, 23, 42, 0.10);
  padding: 6px;
  max-height: 70vh;
  overflow-y: auto;
}
.scope-menu.is-open { display: block; }

/* Menu item */
.scope-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: var(--fs-12);
  color: var(--text-primary, #1f2632);
  transition: background 0.12s ease;
}
.scope-item:hover {
  background: var(--color-gray-100, #f3f6fa);
}
.scope-item.is-active {
  background: var(--color-brand-soft, rgba(217, 119, 6, 0.08));
  border-color: rgba(217, 119, 6, 0.18);
  color: var(--color-brand-active, #b45309);
}
.scope-item-icon {
  font-size: 14px;
  text-align: center;
  color: var(--text-secondary, #64748b);
}
.scope-item.is-active .scope-item-icon {
  color: var(--color-brand-active, #b45309);
}
.scope-item-name {
  font-weight: var(--fw-semibold, 600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scope-item-loc {
  font-size: var(--fs-10);
  color: var(--text-muted, #94a3b8);
  font-weight: var(--fw-medium, 500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.scope-menu-sep {
  height: 1px;
  background: var(--color-gray-200, #e2e8f0);
  margin: 4px 8px;
}

/* Mobile: trigger compacter */
@media (max-width: 768px) {
  #custScopeSelector {
    margin: 0 var(--space-3);
  }
  .scope-trigger {
    padding: 6px 9px;
    font-size: var(--fs-12);
  }
  .scope-trigger-label {
    max-width: 180px;
  }
  .scope-menu {
    min-width: 240px;
    max-width: 90vw;
  }
}
