:root {
  --topbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --bg-elevated: #1c1c1e;
  --bg-panel: #2c2c2e;
  --bg-sector: #3a3a3c;
  --text-main: rgba(245, 245, 247, 0.95);
  --text-muted: rgba(161, 161, 170, 0.85);
  --accent: #0a84ff;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body.app-body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Inter, sans-serif;
  background: var(--bg-elevated);
  color: var(--text-main);
  overflow-x: hidden;
}

.topbar {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  padding: 15px 16px 10px 16px;
  background: #1c1c1e;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  z-index: 100;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

.topbar-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.topbar-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.topbar-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-title {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.92;
  line-height: 1.15;
}

.topbar-cabinet-name {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.9;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1.15;
  max-width: 42vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-cabinet-name::before {
  content: "Кабинет:";
  color: rgba(161, 161, 170, 0.78);
  opacity: 0.95;
  flex: 0 0 auto;
}

.topbar-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.topbar-user-area {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.topbar-userbox {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.10);
  -webkit-backdrop-filter: blur(14px) saturate(1.12);
  backdrop-filter: blur(14px) saturate(1.12);
  cursor: pointer;
  user-select: none;
  transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 200ms ease;
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(520px, 72vw);
}

.topbar-userbox:hover {
  border-color: rgba(255, 255, 255, 0.16);
  background: var(--bg-sector);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

.topbar-userbox:active { transform: translateY(1px); }

.topbar-userbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.35), 0 10px 26px rgba(0, 0, 0, 0.28);
}

.topbar-user-name {
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  opacity: 0.92;
  line-height: 1.1;
  flex: 1 1 auto;
  min-width: 0;
}

.topbar-avatar,
.user-popover-avatar {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #3b82f6, #1d4ed8);
  border: 1px solid rgba(15, 23, 42, 0.9);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.98);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.topbar-avatar {
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.user-popover-avatar {
  width: 34px;
  height: 34px;
  font-size: 16px;
}

.topbar-avatar[data-auth-icon],
.user-popover-avatar[data-auth-icon] {
  background: transparent;
  border-color: transparent;
  color: rgba(161, 161, 170, 0.96);
  font-size: 0;
  text-transform: none;
}

.topbar-avatar[data-auth-icon]::before,
.user-popover-avatar[data-auth-icon]::before {
  content: "";
  display: block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M11 8l4 4-4 4' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M6 12h9' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14 5h2.25A2.75 2.75 0 0 1 19 7.75v8.5A2.75 2.75 0 0 1 16.25 19H14' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M11 8l4 4-4 4' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M6 12h9' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14 5h2.25A2.75 2.75 0 0 1 19 7.75v8.5A2.75 2.75 0 0 1 16.25 19H14' stroke='black' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.topbar-avatar[data-auth-icon]::before {
  width: 16px;
  height: 16px;
}

.user-popover-avatar[data-auth-icon]::before {
  width: 21px;
  height: 21px;
}

.user-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 280px;
  max-width: min(360px, calc(100vw - 24px));
  z-index: 210;
  opacity: 0;
  pointer-events: none;
  transform-origin: 90% 0%;
  transform: translateY(-8px) scale(0.965);
  transition: opacity 140ms ease, transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.userpop--open .user-popover {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  animation: userpop 340ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes userpop {
  0% { transform: translateY(-10px) scale(0.96); }
  70% { transform: translateY(0) scale(1.01); }
  100% { transform: translateY(0) scale(1); }
}

.user-popover-card {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(28, 28, 30, 0.94);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  backdrop-filter: blur(18px) saturate(1.15);
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.60),
    0 0 0 0.5px rgba(255, 255, 255, 0.06) inset;
  padding: 12px;
}

.user-popover-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-popover-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-popover-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(245, 245, 247, 0.96);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-popover-sub {
  font-size: 11px;
  color: rgba(161, 161, 170, 0.90);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-popover-close {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 0;
  color: rgba(245, 245, 247, 0.74);
  background: transparent;
  cursor: pointer;
}

.user-popover-close:hover { background: rgba(255, 255, 255, 0.08); }

.user-popover-sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 10px 0;
}

.user-popover-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-popover-label {
  font-size: 12px;
  opacity: 0.82;
  color: rgba(161, 161, 170, 0.92);
  letter-spacing: 0.2px;
  margin-bottom: 8px;
}

.cabinet-placeholder {
  width: 100%;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-radius: 11px;
  background-color: rgba(28, 28, 30, 0.72);
  color: rgba(245, 245, 247, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 13px;
}

.user-action-btn,
.user-logout-btn {
  box-sizing: border-box;
  width: 100%;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, background-color 160ms ease, border-color 160ms ease;
}

.user-action-btn {
  border: 1px solid rgba(10, 132, 255, 0.42);
  background-color: rgba(10, 132, 255, 0.18);
  color: rgba(245, 245, 247, 0.96);
}

.user-action-btn:hover { background-color: rgba(10, 132, 255, 0.24); }

.user-logout-btn {
  border: 1px solid rgba(255, 69, 58, 0.35);
  background-color: rgba(255, 69, 58, 0.12);
  color: rgba(245, 245, 247, 0.94);
}

.user-logout-btn:hover {
  border-color: rgba(255, 69, 58, 0.45);
  background-color: rgba(255, 69, 58, 0.16);
}

.user-action-btn:active,
.user-logout-btn:active { transform: translateY(1px); }

.cashback-empty {
  min-height: 100vh;
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  background: #1c1c1e;
}

@media (max-width: 900px) and (hover: none) and (pointer: coarse) {
  .topbar-user-name { display: none; }
  .user-popover { width: min(360px, calc(100vw - 16px)); }
}
