/*
  topbar.css — Nium Portal Global Header
  ────────────────────────────────────────
  Link after tokens.css and typography.css.

  <link rel="stylesheet" href="tokens.css">
  <link rel="stylesheet" href="typography.css">
  <link rel="stylesheet" href="topbar.css">

  HTML STRUCTURE:
  ───────────────
  <header class="topbar">

    <!-- Optional: sidebar collapse toggle (mobile/narrow) -->
    <button class="topbar-collapse-toggle" id="collapseToggle">...</button>

    <!-- Account / workspace switcher -->
    <button class="account-switcher">
      <span class="account-dot"></span>
      Harlow University
      <svg>...</svg>  ← chevron
    </button>

    <!-- Global search -->
    <div class="search-wrap">
      <svg class="search-icon">...</svg>
      <input class="search-input" placeholder="Search for anything" />
      <div class="search-kbd">
        <kbd>⌘</kbd><kbd>K</kbd>
      </div>
    </div>

    <div class="spacer"></div>

    <!-- Environment switcher -->
    <div class="env-dropdown">
      <button class="env-current" data-tooltip="Switch environment">
        Production <svg>...</svg>
      </button>
      <div class="env-menu">
        <button class="env-menu-item active">Production <svg class="env-check">...</svg></button>
        <button class="env-menu-item">Sandbox</button>
      </div>
    </div>

    <!-- Icon buttons (settings, notifications, profile) -->
    <div class="topbar-icon-wrap">
      <button class="icon-btn">
        <svg>...</svg>
      </button>
      <div class="topbar-tooltip">Settings</div>
    </div>

    <!-- Notification bell (with badge) -->
    <div class="notif-anchor topbar-icon-wrap">
      <button class="icon-btn" id="notifBtn">
        <svg>...</svg>
        <span class="notification-dot"></span>
      </button>
      <div class="topbar-tooltip">Notifications</div>
    </div>

    <!-- Profile avatar -->
    <div class="topbar-icon-wrap">
      <button class="avatar-btn" id="profileBtn">EE</button>
      <div class="topbar-tooltip">Profile</div>
    </div>

  </header>

  TOKENS USED:
  ────────────
  --color-bg-primary          topbar background
  --color-bg-secondary        hover state
  --color-bg-tertiary         subtle backgrounds
  --color-bg-input            tooltip background
  --color-border-tertiary     topbar bottom border, search border
  --color-border-secondary    search focus border
  --color-border-divider      tooltip border
  --color-text-primary        main text
  --color-text-secondary      muted icons
  --color-text-tertiary       kbd hints, icon opacity
  --color-brand-navy          search focus ring
  --color-success-bg          Production badge background
  --color-success-border-light Production badge border
  --color-success-text        Production badge text
  --color-overlay             env switch modal backdrop
  --color-danger-dot          notification dot
*/

/* ── Topbar shell ──────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 32px;
  border-bottom: 0.5px solid var(--color-border-tertiary);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg-primary);
}

.spacer { flex: 1; }

/* Collapse toggle — hidden by default, shown on narrow viewports */
.topbar-collapse-toggle {
  display: none;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
.topbar-collapse-toggle:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

/* ── Account / workspace switcher ──────────────────────────────────────── */

.account-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--radius-md);
  background: var(--color-bg-primary);
  font-size: var(--text-small-size, 13px);
  font-weight: 500;
  color: var(--color-text-primary);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.account-switcher:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-border-secondary);
}

.account-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-neutral-dot);
  flex-shrink: 0;
}

/* ── Global search ─────────────────────────────────────────────────────── */

.search-wrap {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 8px 64px 8px 34px;
  border: 0.5px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  font-size: var(--text-small-size, 13px);
  font-family: inherit;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.1s;
}

.search-input::placeholder { color: var(--color-text-placeholder); }
.search-input:focus         { border-color: var(--color-brand-navy); }

.search-kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 3px;
  pointer-events: none;
}

.search-kbd kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: inherit;
  font-size: var(--text-micro-size, 11px);
  font-weight: 500;
  color: var(--color-text-tertiary);
  background: var(--color-bg-primary);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: 4px;
  line-height: 1;
}

/* ── Environment switcher ──────────────────────────────────────────────── */

.env-dropdown { position: relative; flex-shrink: 0; }

.env-current {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-success-bg);
  border: 0.5px solid var(--color-success-border-light);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-small-size, 13px);
  font-weight: 500;
  color: var(--color-success-text);
  transition: opacity 0.15s, transform 0.1s;
  min-width: 94px;
  justify-content: center;
  position: relative;
}

.env-current:hover         { opacity: 0.9; }
.env-current:active        { transform: scale(0.97); }
.env-current svg           { opacity: 0.7; flex-shrink: 0; }

/* Tooltip on hover */
.env-current::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--color-bg-input);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-divider);
  font-size: var(--text-micro-size, 11px);
  font-weight: 400;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 9999;
}
.env-current:hover::after               { opacity: 1; }
.env-current.no-tooltip::after,
.env-dropdown.open .env-current::after  { opacity: 0 !important; pointer-events: none; }

/* Dropdown menu */
.env-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--color-bg-primary);
  border: 0.5px solid var(--color-border-primary);
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  overflow: hidden;
  z-index: 1000;
  min-width: 140px;
}
.env-menu.open { display: block; }

.env-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: var(--text-small-size, 13px);
  font-weight: 500;
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.env-menu-item:hover  { background: var(--color-bg-secondary); }
.env-menu-item.active { font-weight: 700; }
.env-check            { color: var(--color-text-primary); }

/* Environment switch confirmation modal */
.env-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
.env-modal-backdrop.open { display: flex; }

.env-modal {
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  padding: 28px 28px 22px;
  width: 360px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.18);
}

.env-modal-title {
  font-size: var(--text-section-title-size, 16px);
  font-weight: var(--text-section-title-weight, 500);
  color: var(--color-text-primary);
  margin-bottom: 8px;
}

.env-modal-body {
  font-size: var(--text-ui-size, 13.5px);
  color: var(--color-text-label);
  line-height: var(--text-line-height-base, 1.5);
  margin-bottom: 22px;
}

.env-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.env-modal-cancel {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-secondary);
  background: var(--color-bg-primary);
  font-size: var(--text-small-size, 13px);
  font-weight: 400;
  color: var(--color-text-label);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s;
}
.env-modal-cancel:hover  { background: var(--color-bg-tertiary); }

.env-modal-confirm {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--color-brand-navy-muted);
  color: var(--color-bg-primary);
  font-size: var(--text-small-size, 13px);
  font-weight: 400;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s;
}
.env-modal-confirm:hover { background: var(--color-bg-nav-dark); }

/* ── Icon buttons (settings, notifications) ────────────────────────────── */

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: background 0.1s, color 0.1s;
}
.icon-btn:hover { background: var(--color-bg-secondary); color: var(--color-text-primary); }

/* Notification dot */
.notification-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-danger-dot);
  border: 1.5px solid var(--color-bg-primary);
}

/* ── Tooltips ──────────────────────────────────────────────────────────── */

.topbar-icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.topbar-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg-input);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-divider);
  font-size: var(--text-tag-size, 11.5px);
  font-weight: 500;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
}

.topbar-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-bottom-color: var(--color-border-divider);
}

.topbar-icon-wrap:hover .topbar-tooltip { display: block; }

/* ── Profile avatar button ─────────────────────────────────────────────── */

.avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border-primary);
  background: var(--color-bg-secondary);
  color: var(--color-avatar-text);
  font-size: var(--text-micro-size, 11px);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
  transition: border-color 0.1s;
}
.avatar-btn:hover { border-color: var(--color-border-secondary); }

/* ── Settings dropdown ─────────────────────────────────────────────────── */

.settings-dropdown { position: relative; }

.settings-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--color-bg-primary);
  border: 0.5px solid var(--color-border-primary);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 6px;
  z-index: 200;
}

.settings-menu.open { display: block; }

.settings-menu-item {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--color-text-primary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.settings-menu-item:hover { background: var(--color-bg-secondary); }
.settings-menu-item.active { background: var(--color-bg-secondary); }
