/* ═══════════════════════════════════════════════════════════════════════
   Native iOS-style application header
   Safe-area spacer (non-interactive) + fixed-height toolbar row.
   Loaded last so it wins over legacy topbar rules in mobile.css / main.css.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --topbar-content-h: 52px;
  --app-header-total: calc(var(--topbar-content-h) + var(--sat));
  --topbar-side-slot: 44px;
}

/* ── Shell: column layout — nothing interactive in the safe band ───── */
#topbar.app-topbar {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  padding: 0 !important;
  gap: 0 !important;
  height: var(--app-header-total) !important;
  min-height: var(--app-header-total) !important;
  max-height: var(--app-header-total) !important;
  overflow: visible !important;
  box-sizing: border-box !important;
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  background: rgba(255, 255, 255, 0.82) !important;
  border-bottom: 0.5px solid rgba(60, 60, 67, 0.18);
  box-shadow: none;
}

.app-topbar__safe {
  flex: 0 0 auto;
  height: var(--sat);
  min-height: var(--sat);
  max-height: var(--sat);
  pointer-events: none;
  user-select: none;
  background: inherit;
}

.app-topbar__bar {
  flex: 0 0 var(--topbar-content-h);
  height: var(--topbar-content-h);
  min-height: var(--topbar-content-h);
  max-height: var(--topbar-content-h);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0 var(--page-pad-x-r) 0 var(--page-pad-x);
}

.app-topbar__leading,
.app-topbar__trailing {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--touch-gap, 12px);
  flex-shrink: 0;
  min-width: var(--topbar-side-slot);
}

.app-topbar__leading {
  justify-content: flex-start;
}

.app-topbar__trailing {
  justify-content: flex-end;
}

/* True optical center (Apple navigation bar pattern) */
.app-topbar__center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  max-width: min(72vw, calc(100% - (var(--topbar-side-slot) * 2) - 16px));
  pointer-events: none;
}

.app-topbar__center > * {
  pointer-events: auto;
}

.app-topbar__logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(26, 9, 56, 0.12);
}

.app-topbar__center-text {
  min-width: 0;
  max-width: 100%;
  text-align: center;
}

.app-topbar__clinic-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
}

.app-topbar__clinic-static {
  display: block;
  font-family: var(--head);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.15;
}

.app-topbar__clinic-select {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  font-family: var(--head);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-align: center;
  text-align-last: center;
  max-width: 100%;
  min-width: 0;
  padding: 2px 20px 2px 4px;
  margin: 0;
  line-height: 1.15;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: 10px 6px;
  -webkit-tap-highlight-color: transparent;
}

.app-topbar__clinic-select:focus-visible {
  outline: 2px solid rgba(99, 102, 241, 0.45);
  outline-offset: 2px;
  border-radius: 6px;
}

.app-topbar__page-title {
  flex: none !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  color: var(--ink3) !important;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.app-topbar__meta {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Icon buttons (44pt touch targets) ─────────────────────────────── */
.app-topbar__icon-btn,
#mob-menu-btn.app-topbar__menu-btn,
#ln-bell-btn.app-topbar__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--topbar-side-slot) !important;
  height: var(--topbar-side-slot) !important;
  min-width: var(--topbar-side-slot) !important;
  min-height: var(--topbar-side-slot) !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.12s ease;
}

.app-topbar__icon-btn:active,
#mob-menu-btn.app-topbar__menu-btn:active,
#ln-bell-btn.app-topbar__icon-btn:active {
  transform: scale(0.94);
  background: rgba(124, 110, 154, 0.1);
}

#ln-bell-wrap.app-topbar__bell-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: 0 !important;
}

#ln-bell-btn {
  border-radius: 10px !important;
}

/* Hamburger */
#mob-menu-btn.app-topbar__menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
}

.app-topbar__menu-line {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#mob-menu-btn.open .app-topbar__menu-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

#mob-menu-btn.open .app-topbar__menu-line:nth-child(2) {
  opacity: 0;
}

#mob-menu-btn.open .app-topbar__menu-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.app-topbar__logout-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 14px;
  min-height: var(--touch-min, 44px);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 2px;
  white-space: nowrap;
}

/* ── Phone: hamburger menu ─────────────────────────────────────────── */
@media (max-width: 640px) {
  #mob-menu-btn.app-topbar__menu-btn {
    display: inline-flex !important;
  }

  .app-topbar__page-title {
    max-width: min(46vw, 180px);
  }
}

/* ── Tablet: sidebar toggle lives in toolbar row (not under notch) ─── */
@media (min-width: 641px) and (max-width: 1180px) {
  #topbar.app-topbar {
    padding-left: 0 !important;
  }

  #sidebar-toggle {
    position: fixed !important;
    top: calc(var(--sat) + (var(--topbar-content-h) - var(--topbar-side-slot)) / 2) !important;
    left: calc(var(--page-pad-x) + 2px) !important;
    transform: none !important;
    width: var(--topbar-side-slot) !important;
    height: var(--topbar-side-slot) !important;
    min-width: var(--topbar-side-slot) !important;
    min-height: var(--topbar-side-slot) !important;
    border-radius: 10px !important;
    background: transparent !important;
    border: none !important;
    color: var(--ink) !important;
    box-shadow: none !important;
    z-index: 210 !important;
  }

  body.mob-sidebar-open #sidebar-toggle {
    top: calc(var(--sat) + 8px) !important;
    left: calc(min(var(--side-w), 80vw) - 22px) !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.12) !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    color: #fff !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28) !important;
  }

  .app-topbar__leading {
    min-width: calc(var(--topbar-side-slot) + 4px);
  }

  .app-topbar__center {
    max-width: min(62vw, calc(100% - 120px));
  }
}

/* ── Desktop: sidebar visible; clinic still shown in header ──────── */
@media (min-width: 1181px) {
  .app-topbar__leading {
    min-width: var(--topbar-side-slot);
  }

  .app-topbar__page-title {
    font-size: 12px !important;
  }
}

@media (display-mode: standalone) {
  #topbar.app-topbar {
    background: rgba(255, 255, 255, 0.88) !important;
  }
}
