.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  background: rgba(255,255,255,0.8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: 4rem;
  padding: .65rem 1.5rem 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
}

.topbar__text {
  flex: 0 0 auto;
  min-width: 0;
}

.topbar__eyebrow {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .2rem;
}

.topbar__title {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hamburger button — hidden on desktop */
.topbar__hamburger {
  display: none;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: .5rem;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: background .15s;
}
.topbar__hamburger:hover {
  background: var(--bg-hover);
}
.topbar__hamburger svg {
  width: 1.375rem;
  height: 1.375rem;
}

/* ── Clock-in badge ── */
.topbar__clock-badge {
  display: flex; align-items: center; gap: .375rem;
  padding: .25rem .625rem; border-radius: 2rem;
  background: #ecfdf5; border: 1px solid #a7f3d0;
  font-size: .7rem; font-weight: 600; color: #065f46;
  white-space: nowrap; flex-shrink: 0;
}
.topbar__clock-dot {
  width: .5rem; height: .5rem; border-radius: 50%;
  background: #10b981; flex-shrink: 0;
  animation: topbar-pulse 2s ease-in-out infinite;
}
@keyframes topbar-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.topbar__clock-label { display: inline; }
.topbar__clock-time { font-variant-numeric: tabular-nums; }
[data-theme="dark"] .topbar__clock-badge { background: #052e16; border-color: #166534; color: #6ee7b7; }

/* ── Profile dropdown ── */
.topbar__profile { position: relative; flex-shrink: 0; }
.topbar__avatar {
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: 2px solid transparent; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: box-shadow .15s, transform .15s;
}
.topbar__avatar--clocked { border-color: #10b981; box-shadow: 0 0 0 2px rgba(16,185,129,.3); }
.topbar__avatar:hover { box-shadow: 0 0 0 3px rgba(99,102,241,.25); transform: scale(1.05); }
.topbar__avatar--clocked:hover { box-shadow: 0 0 0 3px rgba(16,185,129,.3); transform: scale(1.05); }
.topbar__avatar-initials { color: #fff; font-size: .75rem; font-weight: 700; letter-spacing: .03em; line-height: 1; }
.topbar__dropdown {
  position: absolute; right: 0; top: calc(100% + .5rem);
  width: 17rem; background: var(--bg-surface, #fff); border: 1px solid var(--border);
  border-radius: .75rem; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s, visibility .15s, transform .15s;
  z-index: var(--z-dropdown);
}
.topbar__dropdown--open { opacity: 1; visibility: visible; transform: translateY(0); }
.topbar__dropdown-header { padding: .75rem 1rem; }
.topbar__dropdown-name { font-size: .875rem; font-weight: 600; color: var(--text-primary); }
.topbar__dropdown-email { font-size: .75rem; color: var(--text-muted); margin-top: .125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__dropdown-role { font-size: .675rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #6366f1; margin-top: .375rem; }
.topbar__dropdown-divider { height: 1px; background: var(--border); margin: 0; }
.topbar__dropdown-item {
  display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem;
  font-size: .8125rem; color: var(--text-primary); text-decoration: none;
  transition: background .12s;
}
.topbar__dropdown-item:hover { background: var(--bg-hover, #f4f4f5); }
.topbar__dropdown-item:first-of-type { border-radius: 0; }
.topbar__dropdown-item:last-child { border-radius: 0 0 .75rem .75rem; }
.topbar__dropdown-item svg { width: 1rem; height: 1rem; flex-shrink: 0; }
.topbar__dropdown-item--danger { color: #ef4444; }
.topbar__dropdown-item--danger:hover { background: #fef2f2; }

/* Status rows inside dropdown */
.topbar__dropdown-status { padding: .375rem .5rem; }
.topbar__status-row {
  display: flex; align-items: flex-start; gap: .5rem; padding: .375rem .5rem;
  border-radius: .5rem; text-decoration: none; color: inherit;
  transition: background .12s;
}
.topbar__status-row--task:hover { background: var(--bg-hover, #f4f4f5); }
.topbar__status-icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; margin-top: .05rem; }
.topbar__status-icon svg { width: 100%; height: 100%; }
.topbar__status-icon--green { color: #10b981; }
.topbar__status-icon--amber { color: #f59e0b; }
.topbar__status-icon--blue { color: #3b82f6; }
.topbar__status-info { min-width: 0; flex: 1; }
.topbar__status-label { font-size: .675rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.topbar__status-detail { font-size: .8rem; color: var(--text-primary); margin-top: .05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Notification bell ── */
.topbar__notifications { position: relative; flex-shrink: 0; }
.topbar__notif-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background .15s, color .15s;
  position: relative;
}
.topbar__notif-btn:hover { background: var(--bg-hover, #f4f4f5); color: var(--text-primary); }
.topbar__notif-btn svg { width: 1.25rem; height: 1.25rem; }
.topbar__notif-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 1rem; height: 1rem; padding: 0 .3rem;
  border-radius: 999px; background: #ef4444; color: #fff;
  font-size: .625rem; font-weight: 700; line-height: 1rem;
  text-align: center; pointer-events: none;
}
.topbar__notif-badge:empty, .topbar__notif-badge[data-count="0"] { display: none; }
.topbar__notif-dropdown {
  position: absolute; right: 0; top: calc(100% + .5rem);
  width: 22rem; max-height: 28rem; overflow-y: auto;
  background: var(--bg-surface, #fff); border: 1px solid var(--border);
  border-radius: .75rem; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .15s, visibility .15s, transform .15s;
  z-index: var(--z-dropdown);
}
.topbar__notif-dropdown--open { opacity: 1; visibility: visible; transform: translateY(0); }
.topbar__notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-surface, #fff); z-index: 1;
}
.topbar__notif-title { font-size: .875rem; font-weight: 600; color: var(--text-primary); }
.topbar__notif-clear {
  font-size: .75rem; color: #6366f1; cursor: pointer;
  border: none; background: none; padding: 0;
}
.topbar__notif-clear:hover { text-decoration: underline; }
.topbar__notif-list { padding: .25rem 0; }
.topbar__notif-item {
  display: flex; align-items: flex-start; gap: .625rem; padding: .625rem 1rem;
  cursor: pointer; transition: background .12s; text-decoration: none; color: inherit;
}
.topbar__notif-item:hover { background: var(--bg-hover, #f4f4f5); }
.topbar__notif-item--unread { background: #eff6ff; }
[data-theme="dark"] .topbar__notif-item--unread { background: #172554; }
.topbar__notif-icon {
  width: 2rem; height: 2rem; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .875rem;
}
.topbar__notif-icon--chat { background: #dbeafe; color: #2563eb; }
.topbar__notif-icon--task { background: #fef3c7; color: #d97706; }
.topbar__notif-icon--bug { background: #fce7f3; color: #db2777; }
[data-theme="dark"] .topbar__notif-icon--chat { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .topbar__notif-icon--task { background: #422006; color: #fbbf24; }
[data-theme="dark"] .topbar__notif-icon--bug { background: #500724; color: #f472b6; }
.topbar__notif-content { flex: 1; min-width: 0; }
.topbar__notif-text {
  font-size: .8125rem; color: var(--text-primary); line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar__notif-body {
  font-size: .75rem; color: var(--text-muted); margin-top: .125rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar__notif-time { font-size: .675rem; color: var(--text-muted); margin-top: .125rem; }
.topbar__notif-empty {
  padding: 2rem 1rem; text-align: center;
  font-size: .8125rem; color: var(--text-muted);
}

/* ── Chat toggle button in topbar ── */
.topbar__chat-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background .15s, color .15s;
  position: relative; flex-shrink: 0;
}
.topbar__chat-btn:hover { background: var(--bg-hover, #f4f4f5); color: var(--text-primary); }
.topbar__chat-btn svg { width: 1.25rem; height: 1.25rem; }
.topbar__chat-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 1rem; height: 1rem; padding: 0 .3rem;
  border-radius: 999px; background: #6366f1; color: #fff;
  font-size: .625rem; font-weight: 700; line-height: 1rem;
  text-align: center; pointer-events: none;
}
.topbar__chat-badge:empty, .topbar__chat-badge[data-count="0"] { display: none; }

/* ── Spacer pushes right items to far right ── */
.topbar__spacer { flex: 1 1 0; min-width: 0; }

/* ── Global Search ── */
.topbar__search { position: relative; flex: 0 1 480px; min-width: 0; }
.topbar__search-back { display: none; }
.topbar__search-input-wrap {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card, #fff); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 10px; height: 2.15rem;
  transition: border-color .15s, box-shadow .15s;
}
.topbar__search-input-wrap:focus-within {
  border-color: rgba(99,102,241,0.5);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.topbar__search-icon { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.topbar__search-input {
  border: none; background: none; outline: none; flex: 1; min-width: 0;
  font-size: .8125rem; color: var(--text-primary);
  font-family: inherit;
}
.topbar__search-input::placeholder { color: var(--text-muted); }
.topbar__search-clear {
  display: none; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; border: none; background: none;
  color: var(--text-muted); cursor: pointer; flex-shrink: 0; border-radius: 50%;
}
.topbar__search-clear:hover { color: var(--text-primary); background: var(--bg-page, #f4f4f5); }
.topbar__search-clear svg { width: 14px; height: 14px; }
.topbar__search-kbd {
  font-size: .625rem; font-family: 'IBM Plex Mono', monospace;
  padding: 1px 5px; border-radius: 4px;
  background: var(--bg-page, #f4f4f5); border: 1px solid var(--border);
  color: var(--text-muted); line-height: 1.4; flex-shrink: 0;
}

.topbar__search-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-surface, #fff); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 36px rgba(0,0,0,.15);
  max-height: 420px; overflow-y: auto; z-index: 60;
  display: none;
}
.topbar__search-dropdown--open { display: block; }

.topbar__search-group { padding: 6px 0; }
.topbar__search-group + .topbar__search-group { border-top: 1px solid var(--border); }
.topbar__search-group-label {
  padding: 4px 14px 2px; font-size: .625rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
}
.topbar__search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; cursor: pointer; text-decoration: none; color: inherit;
  transition: background .1s;
}
.topbar__search-item:hover, .topbar__search-item--active {
  background: var(--bg-hover, #f4f4f5);
}
.topbar__search-item-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
}
.topbar__search-item-icon--vehicle { background: #dbeafe; color: #2563eb; }
.topbar__search-item-icon--part { background: #fef3c7; color: #d97706; }
.topbar__search-item-icon--task { background: #dcfce7; color: #16a34a; }
.topbar__search-item-icon--team { background: #ede9fe; color: #7c3aed; }
.topbar__search-item-icon--expense { background: #fce7f3; color: #db2777; }
[data-theme="dark"] .topbar__search-item-icon--vehicle { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .topbar__search-item-icon--part { background: #422006; color: #fbbf24; }
[data-theme="dark"] .topbar__search-item-icon--task { background: #052e16; color: #4ade80; }
[data-theme="dark"] .topbar__search-item-icon--team { background: #2e1065; color: #a78bfa; }
[data-theme="dark"] .topbar__search-item-icon--expense { background: #500724; color: #f472b6; }
.topbar__search-item-icon svg { width: 14px; height: 14px; }
.topbar__search-item-text { flex: 1; min-width: 0; }
.topbar__search-item-title {
  font-size: .8125rem; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__search-item-sub {
  font-size: .7rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__search-item-badge {
  font-size: .6rem; font-weight: 600; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px;
  background: var(--bg-page); color: var(--text-muted); border: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar__search-empty {
  padding: 20px 14px; text-align: center;
  font-size: .8125rem; color: var(--text-muted);
}
.topbar__search-loading {
  padding: 16px 14px; text-align: center;
  font-size: .75rem; color: var(--text-muted);
}

[data-theme="dark"] .topbar { background: rgba(9,9,11,0.8); }
[data-theme="dark"] .topbar__search-dropdown { background: #18181b; box-shadow: 0 12px 36px rgba(0,0,0,.4); }
[data-theme="dark"] .topbar__notif-dropdown { background: #18181b; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
[data-theme="dark"] .topbar__notif-header { background: #18181b; }
[data-theme="dark"] .topbar__notif-item:hover { background: #27272a; }
[data-theme="dark"] .topbar__notif-clear { color: #818cf8; }
[data-theme="dark"] .topbar__dropdown { background: #18181b; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
[data-theme="dark"] .topbar__dropdown-item:hover { background: #27272a; }
[data-theme="dark"] .topbar__dropdown-item--danger:hover { background: #2d1215; }
[data-theme="dark"] .topbar__dropdown-role { color: #818cf8; }

@media (max-width: 920px) {
  .topbar {
    padding: .5rem 1rem 0;
    height: 3.5rem;
  }

  .topbar__hamburger {
    display: flex;
  }

  .topbar__title {
    font-size: 1.15rem;
  }

  .topbar__eyebrow {
    font-size: .625rem;
    margin-bottom: .1rem;
  }

  /* Hide closed dropdowns completely on mobile to prevent overflow */
  .topbar__notif-dropdown {
    display: none;
  }
  .topbar__notif-dropdown--open {
    display: block;
  }

  .topbar__dropdown {
    display: none;
  }
  .topbar__dropdown--open {
    display: block;
  }
}

@media (max-width: 640px) {
  .topbar__clock-badge { display: none !important; }
  .topbar__search-kbd { display: none; }

  /* Default: show as icon-only button */
  .topbar__search { flex: 0 0 auto; position: static; }
  .topbar__search-input-wrap {
    width: 40px; height: 40px; border-radius: 50%;
    padding: 0; justify-content: center; border-color: transparent;
    background: transparent;
  }
  .topbar__search-input-wrap:focus-within {
    border-color: transparent; box-shadow: none;
  }
  .topbar__search-icon { width: 20px; height: 20px; color: var(--text-muted); }
  .topbar__search-input { display: none; }

  /* Expanded: full-screen overlay */
  .topbar__search--expanded {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200; background: var(--bg-surface, #fff);
    flex: none; display: flex; flex-direction: column;
  }
  .topbar__search--expanded .topbar__search-input-wrap {
    width: 100%; height: 52px; border-radius: 0;
    padding: 0 12px; gap: 10px;
    border-color: transparent; border-bottom: 1px solid var(--border);
    background: var(--bg-surface, #fff);
  }
  .topbar__search--expanded .topbar__search-input-wrap:focus-within {
    border-color: transparent; border-bottom-color: rgba(99,102,241,0.5);
    box-shadow: none;
  }
  .topbar__search--expanded .topbar__search-icon { display: none; }
  .topbar__search--expanded .topbar__search-input {
    display: block; flex: 1; font-size: 1rem; height: 100%;
  }
  .topbar__search--expanded .topbar__search-back {
    display: flex;
  }
  .topbar__search--expanded .topbar__search-dropdown {
    display: block;
    flex: 1; max-height: none; border: none; border-radius: 0;
    box-shadow: none; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Back button — hidden by default */
  .topbar__search-back {
    display: none; width: 40px; height: 40px;
    border: none; background: none; color: var(--text-primary);
    cursor: pointer; align-items: center; justify-content: center;
    flex-shrink: 0; padding: 0;
  }
  .topbar__search-back svg { width: 20px; height: 20px; }

  /* Larger tap targets for results */
  .topbar__search-item { padding: 12px 16px; gap: 12px; min-height: 48px; }
  .topbar__search-item-icon { width: 36px; height: 36px; border-radius: 10px; }
  .topbar__search-item-icon svg { width: 18px; height: 18px; }
  .topbar__search-item-title { font-size: .875rem; }
  .topbar__search-item-sub { font-size: .75rem; }
  .topbar__search-group-label { padding: 8px 16px 4px; font-size: .7rem; }
  .topbar__search-empty, .topbar__search-loading { padding: 32px 16px; font-size: .875rem; }

  [data-theme="dark"] .topbar__search--expanded {
    background: #09090b;
  }
  [data-theme="dark"] .topbar__search--expanded .topbar__search-input-wrap {
    background: #09090b;
  }
  [data-theme="dark"] .topbar__search--expanded .topbar__search-dropdown {
    background: #09090b;
  }

  /* ── Notifications: full-page overlay on mobile ── */
  .topbar__notif-back { display: none; }
  .topbar__notif--expanded {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200; background: var(--bg-surface, #fff);
    display: flex; flex-direction: column;
  }
  .topbar__notif--expanded .topbar__notif-btn { display: none; }
  .topbar__notif--expanded .topbar__notif-dropdown {
    display: flex; flex-direction: column; flex: 1;
    width: 100%; max-height: none; height: auto; border: none; border-radius: 0;
    box-shadow: none; opacity: 1; visibility: visible; transform: none;
    position: static; overflow: visible;
  }
  .topbar__notif--expanded .topbar__notif-header {
    border-radius: 0; flex-shrink: 0;
  }
  .topbar__notif--expanded .topbar__notif-back {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0; border: none; background: none;
    color: var(--text-primary); cursor: pointer; flex-shrink: 0;
  }
  .topbar__notif--expanded .topbar__notif-back svg { width: 20px; height: 20px; }
  .topbar__notif--expanded .topbar__notif-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .topbar__notif--expanded .topbar__notif-item { padding: 12px 16px; gap: 12px; min-height: 48px; }

  [data-theme="dark"] .topbar__notif--expanded { background: #09090b; }
  [data-theme="dark"] .topbar__notif--expanded .topbar__notif-dropdown { background: #09090b; }
  [data-theme="dark"] .topbar__notif--expanded .topbar__notif-header { background: #09090b; }

  /* ── Profile: full-page overlay on mobile ── */
  .topbar__dropdown-back { display: none; }
  .topbar__dropdown--expanded {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200; background: var(--bg-surface, #fff);
    display: flex; flex-direction: column;
  }
  .topbar__dropdown--expanded .topbar__avatar { display: none; }
  .topbar__dropdown--expanded .topbar__dropdown {
    display: flex; flex-direction: column; flex: 1;
    width: 100%; border: none; border-radius: 0;
    box-shadow: none; opacity: 1; visibility: visible; transform: none;
    overflow: visible; position: static;
  }
  .topbar__dropdown--expanded .topbar__dropdown-back {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0; border: none; background: none;
    color: var(--text-primary); cursor: pointer; flex-shrink: 0;
    float: left; margin-right: .25rem;
  }
  .topbar__dropdown--expanded .topbar__dropdown-back svg { width: 20px; height: 20px; }
  .topbar__dropdown--expanded .topbar__dropdown-item { padding: 12px 16px; gap: 12px; min-height: 48px; font-size: .875rem; }
  .topbar__dropdown--expanded .topbar__dropdown-item:last-child { border-radius: 0; }

  [data-theme="dark"] .topbar__dropdown--expanded { background: #09090b; }
  [data-theme="dark"] .topbar__dropdown--expanded .topbar__dropdown { background: #09090b; }
}

@media (max-width: 480px) {
  .topbar {
    padding: .5rem .75rem 0;
  }

  .topbar__eyebrow {
    display: none;
  }

  .topbar__title {
    font-size: 1.05rem;
  }
}
