/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent; transition: border-color 0.25s, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: clamp(6px, 0.7vw, 12px); padding-block: 12px; flex-wrap: nowrap; }
.logo { display: flex; align-items: center; gap: 9px; border: 0; background: none; padding: 4px 4px 4px 0; font-weight: 600; font-size: var(--step-0); letter-spacing: -0.02em; white-space: nowrap; flex-shrink: 0; }
.logo svg { width: 26px; height: 26px; flex: none; }
.tabs { display: flex; gap: 2px; background: var(--hover); padding: 3px; border-radius: 999px; position: relative; flex-shrink: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; z-index: 1; border: 0; background: none; padding: 6px clamp(9px, 0.85vw, 13px); border-radius: 999px; font-size: var(--step--1); font-weight: 500; color: var(--ink-2); white-space: nowrap; flex-shrink: 0; transition: color 0.2s; }
.tab[aria-current="page"] { color: var(--ink); }
.tab-count { display: inline-block; padding: 1px 6px; margin-left: 4px; border-radius: 999px; font-size: var(--step--2); font-family: var(--font-num); font-weight: 600; background: var(--hover); color: var(--ink-2); line-height: 1.2; vertical-align: middle; transition: background 0.2s, color 0.2s; }
.tab[aria-current="page"] .tab-count { background: var(--ink); color: var(--on-ink); }
.tab-pill { position: absolute; z-index: 0; top: 3px; bottom: 3px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-1); }
.spacer { flex: 1 1 0; min-width: 0; transition: flex-grow 0.28s var(--ease); }

/* Search: icon button initially, expands smoothly on focus / click / query */
.search-slot { display: contents; }

.search {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; width: 36px; min-width: 36px; max-width: 36px;
  padding: 0; border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  box-shadow: var(--shadow-1);
  cursor: pointer; position: relative; overflow: hidden; flex: 0 0 36px;
  transition: width 0.28s var(--ease), max-width 0.28s var(--ease), flex-basis 0.28s var(--ease), flex-grow 0.28s var(--ease),
              padding 0.22s var(--ease), background 0.2s, color 0.2s, box-shadow 0.2s;
}
.search:hover {
  background: var(--raised); color: var(--ink);
  box-shadow: var(--shadow-1), 0 2px 8px -2px rgba(0,0,0,0.12);
}
.search-ico {
  width: 15px; height: 15px; color: currentColor; flex: none; pointer-events: none;
  transition: color 0.2s;
}
.search input {
  border: 0; outline: 0; background: none; font-size: var(--step--1); font-family: inherit; color: var(--ink);
  width: 0; opacity: 0; padding: 0; margin: 0; pointer-events: none; min-width: 0;
  transition: width 0.24s var(--ease), opacity 0.18s var(--ease);
}
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }

.search-clear {
  display: none; border: 0; background: none; padding: 0; color: var(--ink-3);
  cursor: pointer; border-radius: 999px; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: none; margin-left: 2px;
  transition: color 0.15s, background 0.15s;
}
.search-clear:hover { color: var(--ink); background: var(--hover); }
.search-clear svg { width: 12px; height: 12px; }

/* Expanded search states */
.search:focus-within,
.search.is-open,
.search.has-query {
  cursor: default;
  width: clamp(210px, 22vw, 300px); max-width: 320px; flex: 0 1 300px;
  padding: 0 10px 0 12px; justify-content: flex-start; gap: 8px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 0 0 2px var(--focus);
}
.search:focus-within .search-ico,
.search.is-open .search-ico,
.search.has-query .search-ico {
  color: var(--ink-3);
}
.search:focus-within input,
.search.is-open input,
.search.has-query input {
  width: 100%; opacity: 1; pointer-events: auto;
}
.search.has-query .search-clear {
  display: inline-flex;
}

/* User / Dashboard button */
.user-btn {
  width: 36px; height: 36px; padding: 0; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--ink-2);
  box-shadow: var(--shadow-1); border: 0; cursor: pointer; flex-shrink: 0;
  transition: transform 0.15s var(--ease), background 0.2s, color 0.2s, box-shadow 0.2s;
}
.user-btn:hover {
  background: var(--raised); color: var(--ink);
  box-shadow: var(--shadow-1), 0 2px 8px -2px rgba(0,0,0,0.12);
}
.user-btn:active { transform: scale(0.96); }
.user-btn.active, .user-btn[aria-current="page"] {
  background: var(--ink); color: var(--on-ink);
  box-shadow: none;
}
.user-btn svg { width: 16px; height: 16px; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px; border-radius: 999px; border: 0; flex-shrink: 0;
  font-size: var(--step--1); font-weight: 500; white-space: nowrap; text-decoration: none;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1);
  transition: transform 0.15s var(--ease), background 0.2s, box-shadow 0.2s;
}
.btn:hover { background: var(--raised); box-shadow: var(--shadow-1), 0 2px 8px -2px rgba(0,0,0,0.12); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--ink); color: var(--on-ink); box-shadow: none; }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--bg)); }
.btn.ghost { background: none; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.danger { color: var(--neg); }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
/* Top bar sheds elements as it narrows: wordmark first, then button labels, so everything stays on one row */
@media (max-width: 1180px) { .logo span { display: none; } .logo { padding-right: 0; } }
@media (max-width: 980px) { #addBtn .lbl { display: none; } #addBtn { padding: 0 11px; } }
@media (max-width: 760px) {
  .topbar .wrap { position: relative; flex-wrap: nowrap; gap: 6px; padding-block: 10px; }
  body.pdp-scrolled .topbar { transform: translateY(-100%); pointer-events: none; }
  body.mobile-menu-open .topbar { transform: none !important; pointer-events: auto !important; }
  .tabs { display: none !important; }
  .mobile-menu-btn { display: inline-flex !important; }
  .logo span { display: none; }
  .logo { padding-right: 0; }

  /* Fixed 36px slot in mobile flex row — guarantees ZERO layout shift for siblings */
  .search-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
  }

  .search {
    flex: 0 0 36px;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    height: 36px;
  }

  /* When search is focused or active on mobile: expands as an overlay without moving any sibling element */
  .search:focus-within,
  .search.is-open {
    position: absolute;
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    max-width: none;
    flex: none;
    height: 38px;
    padding: 0 10px 0 14px;
    z-index: 50;
    gap: 8px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 0 0 2px var(--focus), var(--shadow-2);
    border-radius: 999px;
    animation: searchOverlayIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes searchOverlayIn {
    from {
      opacity: 0;
      transform: translateY(-50%) scale(0.96);
    }
    to {
      opacity: 1;
      transform: translateY(-50%) scale(1);
    }
  }

  .search:focus-within input,
  .search.is-open input {
    font-size: 16px; /* Prevents iOS auto-zoom shift */
    width: 100%;
    opacity: 1;
    pointer-events: auto;
  }

  .search:focus-within .search-clear,
  .search.is-open .search-clear {
    display: inline-flex;
    width: 22px;
    height: 22px;
  }

  /* When blurred but has query on mobile: stays compact in search-slot with active indicator */
  .search.has-query:not(:focus-within):not(.is-open) {
    background: var(--ink);
    color: var(--on-ink);
    box-shadow: none;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    padding: 0;
    justify-content: center;
  }

  .search.has-query:not(:focus-within):not(.is-open) input {
    width: 0;
    opacity: 0;
    pointer-events: none;
  }

  .search.has-query:not(:focus-within):not(.is-open) .search-clear {
    display: none;
  }

  /* Spacer keeps its flexible width without collapsing */
  .spacer {
    flex: 1 1 0 !important;
    min-width: 0 !important;
  }
}

