/* Topbar layout and controls; responsive rules live in topbar-responsive.css. */
.topbar .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.topbar {
  --topbar-bg: #0B1118;
  --topbar-control: #111A24;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(0, 520px) auto;
  align-items: center;
  height: 68px;
  padding-inline: var(--space-6);
  gap: var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 20;
  isolation: isolate;
}
:root[data-theme="light"] .topbar {
  --topbar-bg: var(--bg);
  --topbar-control: var(--panel);
}
.topbar-heading,
.topbar-actions,
.topbar-profile-trigger,
.topbar-search-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.topbar-heading { gap: var(--space-3); }
.topbar-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}
.topbar-actions { direction: ltr; }
.topbar .icon-button,
.topbar-profile-trigger {
  min-height: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.topbar .icon-button,
.topbar #theme-toggle { width: 40px; }
.topbar .mobile-menu { display: inline-flex; }
.topbar .icon-button:hover,
.topbar-profile-trigger:hover,
.topbar-dropdown[open] > summary {
  background: var(--topbar-control);
  color: var(--text);
}
.topbar :is(button, summary, a, input):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.topbar .topbar-search-toggle { display: none; }
.topbar .search-area { position: relative; min-width: 0; width: 100%; }
.topbar-search-field {
  position: relative;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding-inline: var(--space-3);
  background: var(--topbar-control);
  color: var(--muted);
  transition: border-color .18s ease;
}
.topbar-search-field:focus-within { border-color: var(--focus); }
.topbar .search {
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12px;
}
.topbar .search::placeholder { color: var(--muted); opacity: 1; }
.topbar-search-shortcut {
  flex: none;
  font: 11px 'Segoe UI', sans-serif;
  color: var(--muted);
  white-space: nowrap;
}
.search-results,
.topbar-dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  background: var(--topbar-control);
  box-shadow: 0 8px 24px var(--shadow);
  border-radius: 10px;
  padding: var(--space-2);
  max-height: min(65vh, 480px);
  overflow: auto;
  overflow-wrap: anywhere;
  z-index: 20;
  direction: rtl;
}
.search-results { inset-inline: 0; }
.topbar-dropdown-panel { left: 0; width: 224px; max-width: calc(100vw - 32px); }
.topbar-dropdown {
  position: relative;
  margin: 0;
  border: 0;
  border-radius: 0;
  flex: none;
}
.topbar-dropdown > summary { list-style: none; position: relative; }
.topbar-dropdown > summary::-webkit-details-marker { display: none; }
.topbar-dropdown > .topbar-dropdown-panel { padding: var(--space-2); }
.topbar-dropdown-panel h2 { margin: var(--space-2); font-size: 13px; }
.topbar-notification-dot {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--topbar-bg);
}
#topbar-notification-panel {
  display: flex;
  flex-direction: column;
  width: 400px;
  max-height: min(680px, calc(100dvh - 100px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 18px 48px var(--shadow), 0 3px 10px var(--shadow);
  text-align: start;
}
.topbar-notification-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
}
.topbar-notification-emblem,
.topbar-empty-icon { display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
.topbar-notification-emblem { width: 40px; height: 40px; border: 1px solid var(--warning-border); border-radius: 12px; }
.topbar-notification-heading { flex: 1; min-width: 0; }
.topbar-notification-heading h2 { margin: 0 0 3px; color: var(--text); font-size: 15px; font-weight: 800; }
.topbar-notification-heading p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.8; }
.topbar-notification-total { flex: none; padding: 3px 9px; border-radius: 999px; background: var(--badge-warning-bg); color: var(--text); font-size: 11px; font-weight: 700; white-space: nowrap; }
.topbar-notification-body { min-height: 0; padding: 14px 12px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--phase-border) transparent; }
.topbar-notification-body:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; border-radius: 4px; }
.topbar-notification-body > section + section { margin-top: 18px; }
.topbar-notification-section { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 4px 10px; color: var(--text-soft); font-size: 11px; font-weight: 600; }
.topbar-notification-section > span { color: var(--muted); font-size: 10px; font-weight: 400; }
.topbar-alert-count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #B42318;
  box-shadow: 0 0 0 2px var(--topbar-bg);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.topbar-alert {
  --alert-color: var(--warning-text);
  --alert-bg: var(--badge-warning-bg);
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-inline-start: 2px solid var(--alert-color);
  border-radius: 12px;
  background: var(--panel2);
}
.topbar-alert + .topbar-alert { margin-top: 10px; }
.topbar-alert--critical { --alert-color: var(--error-text); --alert-bg: var(--error-bg); }
.topbar-alert-link { display: flex; align-items: flex-start; gap: 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.topbar-alert-icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 9px; background: var(--alert-bg); color: var(--alert-color); }
.topbar-alert-content { flex: 1; min-width: 0; }
.topbar-alert-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 5px; font-size: 10px; line-height: 1.6; }
.topbar-alert-severity { color: var(--alert-color); font-weight: 700; }
.topbar-alert-state { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.topbar-alert-content strong { display: block; font-size: 12px; font-weight: 700; line-height: 1.9; }
.topbar-alert-content p { margin: 4px 0 8px; color: var(--text-soft); font-size: 11px; line-height: 1.9; }
.topbar-alert-content time { display: block; width: fit-content; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.topbar-alert-chevron { display: flex; flex: none; margin-top: 4px; color: var(--muted); }
.topbar-alert-link:hover strong,
.topbar-alert-link:hover .topbar-alert-chevron { color: var(--accent); }
.topbar-alert-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.topbar-alert-actions form { margin: 0; }
.topbar-alert-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 34px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--text-soft); font: inherit; font-size: 10px; cursor: pointer; transition: background .18s ease, border-color .18s ease; }
.topbar-alert-actions .topbar-alert-acknowledge { border-color: var(--phase-border); color: var(--text); }
.topbar-alert-actions button:hover { border-color: var(--muted); background: var(--topbar-control); color: var(--text); }
.topbar-alert-all { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: none; min-height: 52px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel2); color: var(--text-soft); font-size: 12px; font-weight: 600; text-decoration: none; }
.topbar-alert-all > span { display: inline-flex; align-items: center; gap: 8px; }
.topbar-alert-all:hover { background: var(--accent-soft); color: var(--text); }
.topbar-notification { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.topbar-notification + .topbar-notification { margin-top: 8px; }
.topbar-notification p { margin: 0; color: var(--text); font-size: 12px; line-height: 1.9; }
.topbar-message-icon { display: flex; flex: none; margin-top: 3px; color: var(--badge-info-text); }
.topbar-notification--success .topbar-message-icon { color: var(--success-text); }
.topbar-notification--error .topbar-message-icon { color: var(--error-text); }
.topbar-notification--warning .topbar-message-icon { color: var(--warning-text); }
.topbar-notification-empty { display: flex; flex-direction: column; align-items: center; padding: 30px 12px 36px; text-align: center; }
.topbar-empty-icon { width: 64px; height: 64px; margin-bottom: 18px; border: 1px solid var(--warning-border); border-radius: 20px; }
.topbar-empty { margin: 0 0 8px; color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.9; }
.topbar-empty-description { max-width: 240px; margin: 0; color: var(--muted); font-size: 11px; line-height: 2; }
.topbar-divider { width: 1px; height: 24px; background: var(--line); margin-inline: var(--space-2); }
.topbar-profile-trigger { padding-inline: var(--space-2); color: var(--text); }
.topbar-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: var(--panel2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}
.topbar-account-name {
  display: block;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.topbar-chevron { color: var(--muted); transition: transform .18s ease; }
.topbar-account[open] .topbar-chevron { transform: rotate(180deg); }
.topbar-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 13px;
  text-align: start;
  text-decoration: none;
  transition: background .18s ease, color .18s ease;
}
.topbar-menu-item:hover { background: var(--panel2); color: var(--text); }
.topbar-menu-divider { border: 0; border-top: 1px solid var(--line); margin: var(--space-2); }
.topbar-logout { margin: 0; }
.topbar-logout-button:hover { color: var(--red); }
.topbar-dialog {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--topbar-control);
  color: var(--text);
  box-shadow: 0 8px 24px var(--shadow);
  direction: rtl;
}
.topbar-dialog::backdrop { background: var(--overlay); }
.topbar-dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.topbar-dialog-heading h2 { margin: 0; }
.topbar-dialog dt { color: var(--muted); font-size: 12px; }
.topbar-dialog dd { margin: 0 0 var(--space-4); overflow-wrap: anywhere; }

/* Profile dialog */
.topbar-profile-dialog { width: min(400px, calc(100vw - 24px)); padding: var(--space-5) var(--space-6) var(--space-6); border-radius: 14px; background: var(--panel); }
.topbar-profile-dialog[open] { animation: profile-in .16s ease-out; }
@keyframes profile-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.topbar-profile-dialog .topbar-dialog-heading h2 { font-size: 15px; color: var(--muted); font-weight: 600; }
.topbar-profile-dialog .icon-button:focus-visible, .profile-actions .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.profile-identity { display: flex; align-items: center; gap: var(--space-4); margin: var(--space-4) 0 var(--space-5); }
.profile-avatar { flex: none; display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; background: var(--accent-soft); border: 1px solid var(--gold); color: var(--accent); font-size: 24px; font-weight: 800; }
.profile-identity-text { min-width: 0; }
.profile-identity-text p { margin: 0; }
.profile-name { font-size: 17px; font-weight: 800; color: var(--text); overflow-wrap: anywhere; }
.profile-username { color: var(--muted); font-size: 12.5px; text-align: right; }
.profile-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px !important; }
.profile-badge { padding: 1px 9px; border-radius: 999px; border: 1px solid var(--phase-border); background: var(--phase-bg); color: var(--phase-text); font-size: 11.5px; line-height: 1.9; }
.profile-badge.is-gold { color: var(--badge-warning-text); background: var(--badge-warning-bg); border-color: var(--warning-border); }
.profile-badge.is-green { color: var(--badge-success-text); background: var(--badge-success-bg); border-color: var(--success-border); }
.profile-facts { margin: 0 0 var(--space-5); border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.profile-facts > div { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: 10px var(--space-4); }
.profile-facts > div + div { border-top: 1px solid var(--line); }
.topbar-profile-dialog .profile-facts dt { font-size: 12.5px; }
.topbar-profile-dialog .profile-facts dd { margin: 0; font-size: 13px; color: var(--text); text-align: left; }
.profile-empty { color: var(--muted); font-style: normal; font-size: 12px; padding: 1px 8px; border: 1px dashed var(--phase-border); border-radius: 999px; }
.profile-actions { display: flex; gap: var(--space-2); }
.profile-actions > * { flex: 1; }
.profile-actions .btn { width: 100%; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; font-weight: 600; }

.profile-logout-button:hover { color: var(--red); border-color: var(--red); }
@media (max-width: 520px) {
  .topbar-profile-dialog { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
  .profile-actions { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { .topbar-profile-dialog[open] { animation: none; } }

/* User menu (consistent with profile dialog) */
.topbar-profile-trigger { gap: 8px; padding-block: 3px; padding-inline: 4px 10px; border-radius: 999px; }
.topbar-profile-trigger .topbar-avatar { background: var(--accent-soft); border: 1.5px solid var(--gold); color: var(--accent); font-weight: 800; }
.topbar-account-text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; min-width: 0; direction: rtl; }
.topbar-account-role { color: var(--muted); font-size: 10.5px; font-weight: 500; }
.topbar .icon-button:focus-visible, .topbar-profile-trigger:focus-visible, .topbar-menu-item:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.topbar-account-panel { width: 272px; padding: 6px !important; border: 1px solid var(--line); border-radius: 12px; }
.topbar-account-head { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 10px; border-radius: 10px; background: var(--panel2); }
.topbar-account-head-avatar { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); border: 1.5px solid var(--gold); color: var(--accent); font-size: 17px; font-weight: 800; }
.topbar-account-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.topbar-account-head-name { text-align: right; font-weight: 800; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-account-head-user { color: var(--muted); font-size: 11.5px; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.topbar-account-head .profile-badge { flex: none; }
.topbar-menu-group-label { margin: 8px 10px 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.topbar-account-panel .topbar-menu-item { gap: 10px; min-height: 38px; border-radius: 8px; }
.topbar-account-panel .topbar-menu-item .icon { color: var(--muted); flex: none; }
.topbar-account-panel .topbar-menu-item:hover .icon, .topbar-account-panel .topbar-menu-item:focus-visible .icon { color: var(--text); }
.topbar-menu-item[aria-current="page"] { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 700; }
.topbar-menu-item[aria-current="page"] .icon { color: var(--nav-active-text) !important; }
.topbar-account-panel .topbar-menu-divider { margin: 6px 4px; }
.topbar-logout-button { color: var(--error-text); }
.topbar-logout-button .icon { color: var(--error-text) !important; }
.topbar-logout-button:hover, .topbar-logout-button:focus-visible { background: var(--error-bg); color: var(--error-text); }
@media (max-width: 760px) {
  .topbar-account-text { display: none; }
  .topbar-profile-trigger { padding-inline: 3px 6px; }
}
@media (max-width: 520px) {
  .topbar-account-panel { position: fixed; top: 60px; left: 8px; right: 8px; width: auto; max-width: none; }
}
