/* ═══════════════════════════════════════════════════════════
   TB CRM — Top Navigation Bar
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ── */
:root {
  --tnav-h: 60px;
  --tnav-h-mob: 54px;
  --tnav-bg: rgba(8, 15, 34, 0.82);
  --tnav-border: rgba(96, 130, 250, 0.14);
  --tnav-blur: blur(20px);
  --tnav-shadow: 0 1px 0 rgba(96,130,250,.1), 0 4px 24px rgba(2,6,23,.32);
  --tnav-text: #e2e8f0;
  --tnav-muted: rgba(148,163,184,.75);
  --tnav-accent: #3b82f6;
  --tnav-radius: 0px;
  --tnav-pill-r: 12px;
}

/* ── Shell ── */
.tb-global-header-shell {
  position: sticky;
  top: 0;
  z-index: 1200;
  padding: 0;
  background: var(--tnav-bg);
  border-bottom: 1px solid var(--tnav-border);
  backdrop-filter: var(--tnav-blur);
  -webkit-backdrop-filter: var(--tnav-blur);
  box-shadow: var(--tnav-shadow);
}

/* subtle top accent line */
.tb-global-header-shell::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(96,165,250,.35) 30%, rgba(139,92,246,.3) 70%, transparent);
  pointer-events: none;
}

/* ── Inner layout ── */
.tb-global-header {
  display: flex;
  align-items: center;
  width: 100%;
  height: var(--tnav-h);
  padding: 0 20px;
  box-sizing: border-box;
}

/* ── Center block: занимает всё пространство, контент по центру ── */
.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  overflow: visible;
}

.topbar-brand { flex-shrink: 0; margin-right: 0; }
.topbar-side  { flex-shrink: 0; }

/* ── Brand ── */
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
  margin-right: 24px;
}

.topbar-brand .brand-logo-wrap {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1d4ed8, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(59,130,246,.35);
}

.topbar-brand .brand-logo {
  width: 28px; height: 28px; object-fit: contain; border-radius: 4px;
}

.topbar-brand .brand-logo-fallback {
  font-size: 13px; font-weight: 900; color: #fff; letter-spacing: -.04em;
}

.topbar-brand .brand-logo-wrap.is-fallback .brand-logo-fallback { display: inline; }
.topbar-brand .brand-logo-wrap:not(.is-fallback) .brand-logo-fallback { display: none; }

.topbar-brand .brand-copy {
  display: grid; gap: 0;
}
.topbar-brand .brand-title {
  font-size: .88rem; font-weight: 800; color: var(--tnav-text);
  letter-spacing: -.02em; line-height: 1.15;
  display: flex; align-items: center; gap: 5px;
}
.topbar-brand .crm-v2-badge {
  font-size: .55rem; font-weight: 800; letter-spacing: .06em;
  padding: 1px 5px; border-radius: 5px;
  background: linear-gradient(135deg, rgba(59,130,246,.25), rgba(139,92,246,.25));
  border: 1px solid rgba(96,165,250,.2);
  color: #93c5fd; vertical-align: middle; text-transform: uppercase;
}
.topbar-brand .brand-subtitle {
  font-size: .62rem; font-weight: 500; color: rgba(148,163,184,.6);
  letter-spacing: .01em; line-height: 1; margin-top: 1px;
}

/* ── Nav ── */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 34px;
  border-radius: var(--tnav-pill-r);
  font-size: .8rem;
  font-weight: 600;
  color: var(--tnav-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s, background .15s;
  position: relative;
}
.topbar-nav-link:hover {
  color: var(--tnav-text);
  background: rgba(255,255,255,.06);
}
.topbar-nav-link.is-active,
.topbar-nav-link.active {
  color: #bfdbfe;
  background: rgba(59,130,246,.14);
  box-shadow: inset 0 0 0 1px rgba(96,165,250,.18);
}
.topbar-nav-icon {
  font-size: 13px;
  line-height: 1;
  opacity: .85;
}

/* ── Right cluster ── */
.topbar-side {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

/* ── Search button ── */
.tnav-search-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 16px;
  min-width: 160px;
  border-radius: var(--tnav-pill-r);
  border: 1px solid rgba(96,165,250,.14);
  background: rgba(255,255,255,.04);
  color: var(--tnav-muted);
  font-size: .78rem;
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s;
  white-space: nowrap;
}
.tnav-search-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(96,165,250,.25);
  color: var(--tnav-text);
}
.tnav-search-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.tnav-search-btn kbd {
  font-size: .62rem; padding: 1px 5px; border-radius: 4px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(96,165,250,.15);
  color: rgba(148,163,184,.6);
}

/* ── CTA ── */
.tnav-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--tnav-pill-r);
  border: none;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: filter .14s, transform .12s, box-shadow .14s;
  box-shadow: 0 4px 14px rgba(59,130,246,.3);
  white-space: nowrap;
  flex-shrink: 0;
}
.tnav-cta:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59,130,246,.38);
  color: #fff;
  text-decoration: none;
}

/* ── Divider ── */
.tnav-sep {
  width: 1px; height: 20px;
  background: rgba(96,165,250,.12);
  flex-shrink: 0;
  margin: 0 2px;
}

/* ── Icon buttons (theme, bell, back) ── */
.tnav-icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--tnav-pill-r);
  border: 1px solid rgba(96,165,250,.1);
  background: rgba(255,255,255,.03);
  color: var(--tnav-muted);
  font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .13s, border-color .13s, color .13s;
  flex-shrink: 0;
  text-decoration: none;
}
.tnav-icon-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(96,165,250,.22);
  color: var(--tnav-text);
}

/* ── System toggle buttons ── */
.system-toggle-form { display: inline-flex; }
.system-toggle-btn {
  width: 34px; height: 34px;
  border-radius: var(--tnav-pill-r);
  border: 1px solid rgba(96,165,250,.1);
  background: rgba(255,255,255,.03);
  color: var(--tnav-muted);
  font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .13s, border-color .13s;
}
.system-toggle-btn.is-on {
  background: rgba(34,197,94,.12);
  border-color: rgba(34,197,94,.25);
}
.system-toggle-btn.is-off {
  background: rgba(239,68,68,.08);
  border-color: rgba(239,68,68,.2);
}
.system-toggle-btn:hover { filter: brightness(1.15); }

/* ── Telephony toggle ── */
.telephony-line-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--tnav-pill-r);
  border: 1px solid rgba(96,165,250,.1);
  background: rgba(255,255,255,.03);
  color: var(--tnav-muted);
  font-size: .73rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .13s, border-color .13s, color .13s;
  white-space: nowrap;
}
.telephony-line-toggle.is-active {
  background: rgba(34,197,94,.12);
  border-color: rgba(34,197,94,.28);
  color: #86efac;
}
.telephony-line-toggle:hover { filter: brightness(1.1); }
.telephony-line-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  flex-shrink: 0;
}

/* ── Notification bell ── */
.notification-panel-wrap { position: relative; }
.notification-bell {
  position: relative;
}
.notification-badge {
  position: absolute;
  top: -3px; right: -3px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 9px; font-weight: 800;
  line-height: 16px; text-align: center;
  padding: 0 3px;
  display: none;
  border: 2px solid rgba(8,15,34,.9);
}
.notification-badge.has-count { display: block; }

/* keep existing notification panel styles working */
.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 480px;
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid rgba(96,165,250,.14);
  background: rgba(8,15,34,.97);
  backdrop-filter: blur(20px);
  box-shadow: 0 16px 48px rgba(2,6,23,.5);
  z-index: 1300;
}
.notification-panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: .5rem; padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(96,165,250,.08);
}
.notification-panel-title { font-size: .9rem; font-weight: 800; color: #e2e8f0; margin: 0; }
.notification-panel-note  { font-size: .72rem; color: rgba(148,163,184,.65); margin: 2px 0 0; }
.notification-panel-list  { padding: 8px; }

/* ── User button ── */
.tnav-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px 0 4px;
  border-radius: 14px;
  border: 1px solid rgba(96,165,250,.12);
  background: rgba(255,255,255,.04);
  color: var(--tnav-text);
  cursor: pointer;
  transition: background .13s, border-color .13s;
}
.tnav-user-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(96,165,250,.22);
}
.tnav-user-btn::after { display: none; } /* remove bootstrap caret */

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1d4ed8, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-avatar .js-user-avatar-image { display: block; }

.tnav-user-copy { display: none; }
@media (min-width: 900px) {
  .tnav-user-copy {
    display: grid; gap: 1px; text-align: left;
  }
  .tnav-user-copy .user-name {
    font-size: .76rem; font-weight: 700; color: var(--tnav-text);
    line-height: 1.1; max-width: 120px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .tnav-user-copy .user-role {
    font-size: .63rem; color: var(--tnav-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
}

.user-caret {
  font-size: 10px; color: var(--tnav-muted); flex-shrink: 0;
}

/* ── Dropdown ── */
.crm-dropdown {
  border-radius: 14px !important;
  border: 1px solid rgba(96,165,250,.14) !important;
  background: rgba(8,15,34,.97) !important;
  backdrop-filter: blur(20px);
  box-shadow: 0 16px 40px rgba(2,6,23,.5) !important;
  padding: 6px !important;
  min-width: 210px !important;
}
.crm-dropdown .dropdown-item {
  border-radius: 9px !important;
  font-size: .83rem !important;
  color: rgba(203,213,225,.85) !important;
  padding: 7px 10px !important;
  transition: background .12s !important;
}
.crm-dropdown .dropdown-item:hover,
.crm-dropdown .dropdown-item:focus {
  background: rgba(37,99,235,.14) !important;
  color: #e2e8f0 !important;
}
.crm-dropdown .dropdown-item.active {
  background: rgba(37,99,235,.2) !important;
  color: #bfdbfe !important;
}
.crm-dropdown .dropdown-item.text-danger { color: #fca5a5 !important; }
.crm-dropdown .dropdown-item.text-danger:hover { background: rgba(239,68,68,.12) !important; }
.crm-dropdown .dropdown-divider { border-color: rgba(96,165,250,.1) !important; margin: 4px 0 !important; }
.crm-dropdown-workspace {
  padding: 8px 10px 6px !important;
  display: grid; gap: 1px;
}
.crm-dropdown-workspace strong { font-size: .82rem; color: #e2e8f0; }
.crm-dropdown-workspace span   { font-size: .7rem;  color: rgba(148,163,184,.65); }

/* ── Back button (hidden by default, in dropdown) ── */
.crm-back-btn { display: none; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .tnav-search-btn .tnav-search-label,
  .tnav-search-btn kbd { display: none; }
  .tnav-search-btn { width: 34px; padding: 0; justify-content: center; }
}

@media (max-width: 780px) {
  .tb-global-header { padding: 0 12px; }
  .topbar-brand { margin-right: 12px; }
  .topbar-nav { display: none; }
  .tnav-cta .tnav-cta-label { display: none; }
  .tnav-cta { width: 34px; padding: 0; justify-content: center; }
}

/* Keep existing class aliases working */
.tbm-home-header-shell,
.site-header,
.app-nav.tb-global-header-shell {
  position: sticky;
  top: 0;
  z-index: 1200;
}
.market-body--home-bright .tbm-home-header-shell { display: none !important; }

.tbm-home-header,
.market-header.tb-global-header,
.header-bar.tb-global-header,
.topbar-layout.tb-global-header,
.ref-portal-nav {
  min-height: var(--tnav-h);
  border-radius: 0;
}

.tbm-brand,
.site-header .brand,
.brand.tb-global-brand,
.topbar-brand.tb-global-brand { color: var(--tnav-text); }
