/* TOUR-OPS — Compact Topbar utilities (2026-08-30)
   Visible: Menu + Title | Location | Company | User | UAT | Lang | Theme | Settings
   Secondary controls live in Settings popover / mobile sheet.
*/

.topbar {
  gap: 8px;
  overflow: visible;
}

.topbar-left {
  flex: 0 1 auto;
  max-width: min(42vw, 22rem);
}

.topbar-identity {
  min-width: 0;
}

.topbar-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-crumb {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Operational context — Location | Company */
.topbar-ops-ctx.desktop-only {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 1 auto;
  max-width: min(36vw, 22rem);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface, #fff);
  font-size: var(--fs-meta);
  line-height: 1.2;
}

@media (max-width: 768px) {
  .topbar-ops-ctx.desktop-only {
    display: none !important;
  }
}

html.force-mobile .topbar-ops-ctx.desktop-only {
  display: none !important;
}

.topbar-ctx-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  max-width: 11rem;
}

.topbar-ctx-k {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.topbar-ctx-v {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-weight: 600;
  font-size: var(--fs-label);
}

.topbar-ctx-sep {
  color: var(--text-muted);
  flex: 0 0 auto;
  opacity: 0.7;
}

/* Right utilities */
.topbar-utils {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
}

.topbar-user {
  max-width: 7.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-meta);
  font-weight: 600;
  color: var(--text-primary);
  padding: 2px 4px;
}

.topbar-util-wrap {
  position: relative;
  flex: 0 0 auto;
}

.topbar-util-btn {
  min-width: 32px;
  min-height: 32px;
  padding: 4px 6px;
  gap: 4px;
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.topbar-util-btn:hover,
.topbar-util-btn:focus-visible {
  background: var(--surface-hover, #f3f5f8);
  border-color: var(--border);
  color: var(--text-primary);
}

.topbar-util-btn .ui-icon,
.topbar-util-btn svg {
  width: 16px;
  height: 16px;
}

/* Language = compact text control (no globe) */
.topbar-lang-btn {
  min-width: 36px;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
}
.topbar-lang-btn:hover,
.topbar-lang-btn:focus-visible {
  background: var(--surface-hover, #f3f5f8);
  border-color: var(--border);
}
.topbar-lang-code {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--text-primary);
}

/* Theme vs More: same size, different weight via hover only; More slightly quieter */
.topbar-theme-btn {
  color: var(--text-secondary);
}
.topbar-more-btn {
  color: var(--text-muted);
}
.topbar-more-btn:hover,
.topbar-more-btn:focus-visible {
  color: var(--text-primary);
}

.topbar-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: calc(var(--z-topbar) + 20);
  min-width: 9rem;
  padding: 6px;
  background: var(--surface-popover, var(--surface, #fff));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md, 0 8px 24px rgba(15, 27, 45, 0.12));
}

.topbar-popover--settings {
  min-width: 15.5rem;
  width: min(17.5rem, 92vw);
  padding: 0;
  overflow: hidden;
}

.topbar-popover-hd {
  padding: 10px 12px 8px;
  font-weight: 600;
  font-size: var(--fs-label);
  border-bottom: 1px solid var(--border);
  background: var(--surface-table-header, #f7f9fb);
  color: var(--text-primary);
}

.topbar-popover-bd {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar-popover-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.topbar-popover-item:hover,
.topbar-popover-item:focus-visible {
  background: #eef3f8;
  outline: none;
}

.topbar-popover-item.is-active {
  background: var(--primary-soft, #e8f2fb);
  color: var(--primary, #0b6bcb);
}

.topbar-settings-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar-settings-group[hidden],
.topbar-settings-hidden-lang[hidden] {
  display: none !important;
}

.topbar-settings-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.topbar-settings-group select {
  width: 100%;
  min-height: 32px;
  height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
}

.topbar-settings-group .viewport-switch {
  display: flex;
  width: 100%;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
}

.topbar-settings-group .viewport-switch button {
  flex: 1;
  min-height: 30px;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.topbar-settings-group .viewport-switch button.active {
  background: var(--primary-soft, #e8f2fb);
  color: var(--primary, #0b6bcb);
}

.topbar-settings-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
}

/* Avoid duplicate Location/Company on desktop (shown in topbar) */
@media (min-width: 769px) {
  html:not(.force-mobile) .context-pill--locco.desktop-hide-dup {
    display: none;
  }
}

html.force-mobile .context-pill--locco.desktop-hide-dup {
  display: inline-flex;
}

/* Compact desktop 1024–1279 — tighten before collision */
@media (min-width: 1024px) and (max-width: 1279px) {
  .topbar-ops-ctx.desktop-only {
    max-width: min(30vw, 16rem);
  }
  .topbar-ctx-chip {
    max-width: 7.5rem;
  }
  .topbar-ctx-k {
    display: none;
  }
  .topbar-user {
    max-width: 5.5rem;
  }
  .topbar-left {
    max-width: min(34vw, 16rem);
  }
  .topbar-crumb {
    display: none;
  }
}

/* Tablet drawer band */
@media (min-width: 769px) and (max-width: 1023px) {
  .topbar-ops-ctx.desktop-only {
    max-width: min(28vw, 12rem);
  }
  .topbar-ctx-k {
    display: none;
  }
  .topbar-ctx-chip {
    max-width: 6.5rem;
  }
  .topbar-user {
    max-width: 4.5rem;
  }
  .topbar-lang-code {
    display: none;
  }
  .topbar-crumb {
    display: none;
  }
}

/* Mobile — overflow sheet holds secondary settings; keep lang/theme icons if space */
@media (max-width: 768px) {
  .topbar-user {
    max-width: 4.25rem;
  }
  #btnSettings {
    display: none !important;
  }
}

html.force-mobile #btnSettings {
  display: none !important;
}
html.force-mobile .topbar-user {
  max-width: 4.25rem;
}

/* Sheet-mounted settings stack */
.proto-group #protoDesktopControls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.proto-group .topbar-settings-group .viewport-switch {
  width: 100%;
}

/* Dark appearance stub — keep utilities readable */
html[data-appearance="dark"] .topbar-ops-ctx.desktop-only,
html[data-appearance="dark"] .topbar-popover {
  background: #1a2332;
  border-color: #2c3a4f;
}
html[data-appearance="dark"] .topbar-popover-hd {
  background: #141c28;
}
html[data-appearance="dark"] .topbar-popover-item:hover,
html[data-appearance="dark"] .topbar-popover-item:focus-visible {
  background: #243044;
}
html[data-appearance="dark"] .topbar-settings-group select {
  background: #141c28;
  color: inherit;
  border-color: #2c3a4f;
}
