/* /opt/cashback/public/css/app_shell.css */

:root {
  /* chrome heights */
  --topbar-h: 64px;
  /* ✅ increased for KPI */
  --menubar-h: 44px;
  --sidebar-gap: 8px;
  --sidebar-offset: calc(var(--topbar-h) + var(--menubar-h) + var(--sidebar-gap));

  /* ✅ iOS / safe-area */
  --safe-top: env(safe-area-inset-top, 0px);
  /* Content offset below fixed menubar (cross-browser stable, no runtime measuring). */
  --page-offset-with-filters: 132px;
  --page-offset-no-filters: 56px;
}

/* top bar */

.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;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: box-shadow 160ms ease;

  /* ⚠️ ВАЖНО: не держим постоянный композитный слой — на Windows это “мылит” попапы/текст */
  /* transform: translateZ(0); */
  /* will-change: transform; */

  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;
}

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

/* ✅ Кабинет: через ::before */
.topbar-cabinet-name {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.9;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.topbar-cabinet-sep {
  opacity: 0.82;
}

.topbar-cabinet-source-logo {
  width: 16px;
  height: 16px;
  display: inline-block;
  object-fit: contain;
  vertical-align: middle;
}

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

/* ✅ right side: KPI + user */
.topbar-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

/* ===== KPI in topbar (always visible; horizontal scroll if tight) ===== */

.topbar-kpis {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;

  max-width: min(760px, 58vw);

  padding: 4px 4px;
  border-radius: 8px;

  background: rgba(28, 28, 30, 0.92);
  border: none;

  -webkit-backdrop-filter: blur(10px) saturate(1.05);
  backdrop-filter: blur(10px) saturate(1.05);

  scrollbar-width: none;
}

.topbar-kpis::-webkit-scrollbar {
  display: none;
}

.topbar-kpi {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  height: 40px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: var(--bg-panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.12);
  backdrop-filter: blur(14px) saturate(1.12);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
  min-width: 112px;
  max-width: 170px;
}

.topbar-kpi-label {
  font-size: 10px;
  letter-spacing: 0.28px;
  text-transform: uppercase;
  color: rgba(161, 161, 170, 0.86);
  line-height: 1;
  white-space: nowrap;
}

.topbar-kpi-value {
  font-size: 13px;
  font-weight: 700;
  color: rgba(245, 245, 247, 0.95);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ✅ user area: anchor for popover */
.topbar-user-area {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

/* ✅ user container (name + avatar) */
.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;
  max-width: none;
}

.topbar-avatar {
  --auth-login-icon: 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");
  width: 24px;
  height: 24px;
  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-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.topbar-avatar-has-image {
  background-color: #0f172a;
  color: transparent;
}

.topbar-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 {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--auth-login-icon) center / contain no-repeat;
  mask: var(--auth-login-icon) center / contain no-repeat;
}

/* ===== user popover ===== */

.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-avatar {
  --auth-login-icon: 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");
  width: 34px;
  height: 34px;
  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-size: 16px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.user-popover-avatar-has-image {
  background-color: #0f172a;
  color: transparent;
}

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

.user-popover-avatar[data-auth-icon]::before {
  content: "";
  display: block;
  width: 21px;
  height: 21px;
  background: currentColor;
  -webkit-mask: var(--auth-login-icon) center / contain no-repeat;
  mask: var(--auth-login-icon) center / contain no-repeat;
}

.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;
}

/* ✅ close button (shared iconbtn) — layout only */
.user-popover-close {
  margin-left: auto;
}

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

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

.user-popover-actions-top {
  padding: 2px 0 0;
}

.user-popover-actions-bottom {
  padding: 0;
}

.user-popover-field {
  display: grid;
  gap: 8px;
  padding: 0;
}

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

.user-popover-panel[hidden] {
  display: none !important;
}

.user-auth-form {
  display: grid;
  gap: 10px;
}

.user-auth-step {
  display: grid;
  gap: 10px;
}

.user-auth-step[hidden] {
  display: none !important;
}

.user-auth-input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: 30px;
}

.user-auth-row {
  display: flex;
  gap: 8px;
}

.user-auth-code-actions {
  display: grid;
  gap: 8px;
}

.user-auth-btn {
  box-sizing: border-box;
  flex: 1 1 100%;
  min-width: 0;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-auth-btn:disabled {
  transform: none;
}

.user-auth-link {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  color: rgba(101, 183, 255, 0.96);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
}

.user-auth-link:hover {
  color: rgba(143, 204, 255, 1);
  text-decoration: underline;
}

.user-auth-link[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.55;
  text-decoration: none;
}

.user-auth-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.22);
  border-radius: 8px;
}

.user-auth-status {
  margin: 0;
  min-height: 32px;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(161, 161, 170, 0.92);
}

.user-auth-status:empty {
  display: none;
}

.user-auth-status[data-kind="error"] {
  color: rgba(255, 105, 97, 0.98);
}

.user-auth-status[data-kind="success"] {
  color: rgba(72, 199, 116, 0.98);
}

/* ✅ logout full width bottom — под размер селекта */
.user-logout-btn {
  box-sizing: border-box;
  width: 100%;
  height: var(--select-h, 34px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  border: 1px solid rgba(255, 69, 58, 0.35);
  background-color: rgba(255, 69, 58, 0.12);
  color: rgba(245, 245, 247, 0.94);
  border-radius: var(--select-r, 11px);
  font-size: var(--select-fs, 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-logout-btn:hover {
  border-color: rgba(255, 69, 58, 0.45);
  background-color: rgba(255, 69, 58, 0.16);
}

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

/* ===== ✅ page menubar (macOS-like) ===== */

.page-menubar {
  margin-top: 0;
  position: fixed;
  top: calc(var(--topbar-h) + var(--safe-top));
  left: 0;
  right: 0;
  width: 100%;
  z-index: 90;
  padding: 10px 12px 6px;
  background: linear-gradient(to bottom, #000, #1b1b1b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.layout {
  /* Keep content below fixed topbar + fixed menubar (filters visible). */
  padding-top: calc(var(--topbar-h) + var(--safe-top) + var(--page-offset-with-filters));
}

body.filters-hidden .layout {
  /* Compact header height when filters row is hidden. */
  padding-top: calc(var(--topbar-h) + var(--safe-top) + var(--page-offset-no-filters));
}

.page-menubar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 4px;
}

.page-menubar-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.page-menubar-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* ✅ user popover: cabinet dropdown full width */
.user-popover-field .menudrop { width: 100%; }
.user-popover-field .menudrop-btn { width: 100%; }

/* ==========================================================
   ✅ Filters row: allow truncation inside flex/grid
   ========================================================== */

.controls-field { min-width: 0; }
.filters-row { min-width: 0; }

.controls-field .menudrop { width: 100%; }
.controls-field .menudrop-btn { width: 100%; }

/* ===== cabinet dropdown label parts ===== */

.cabinet-label-sep {
  display: inline-block;
  margin: 0 4px;
  opacity: 0.82;
}

.cabinet-label-logo {
  width: 16px;
  height: 16px;
  display: inline-block;
  object-fit: contain;
  vertical-align: middle;
}

/* filters toggle button */

.menutoggle-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(28, 28, 30, 0.60);
  color: rgba(245, 245, 247, 0.94);
  border-radius: var(--select-r, 10px);
  padding: 8px 10px;
  font-size: 13px;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  transition: transform 140ms ease, background 160ms ease, border-color 160ms ease;
}

.menutoggle-btn:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(38, 38, 40, 0.66);
}

.menutoggle-btn:active { transform: translateY(1px); }

.menutoggle-ic { display: inline-flex; opacity: 0.9; }

.menutoggle-btn[aria-pressed="false"] {
  border-color: rgba(10, 132, 255, 0.35);
  background: rgba(10, 132, 255, 0.16);
}

.menutoggle-btn[data-active="true"] {
  border-color: color-mix(in srgb, var(--accent) 58%, transparent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ✅ settings icon button */
.menuicon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: rgba(245, 245, 247, 0.92);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1),
    color 140ms ease,
    opacity 140ms ease;
}

.menuicon-btn:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.menuicon-btn:active { transform: translateY(1px) scale(0.985); }

.menuicon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.35);
}

.menuicon-svg {
  display: block;
  shape-rendering: geometricPrecision;
}

.menuicon-btn:hover .menuicon-svg {
  animation: gearwiggle 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes gearwiggle {
  0% { transform: rotate(0deg) scale(1); }
  55% { transform: rotate(10deg) scale(1.02); }
  100% { transform: rotate(0deg) scale(1); }
}

/* hide/show filters */
body.filters-hidden .controls { display: none; }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  .userpop--open .user-popover { animation: none !important; }
  .user-popover {
    transition: opacity 120ms ease !important;
    transform: none !important;
  }

  .menuicon-btn:hover .menuicon-svg { animation: none !important; }
}

/* Chromium-safe low-motion profile */
html.is-chromium .userpop--open .user-popover {
  animation: none !important;
}

html.is-chromium .user-popover {
  transition: opacity 120ms ease !important;
  transform: none !important;
}

html.is-chromium .menutoggle-btn,
html.is-chromium .menuicon-btn,
html.is-chromium .topbar-userbox,
html.is-chromium .user-auth-link {
  transition: none !important;
}

html.is-chromium .menutoggle-btn:active,
html.is-chromium .menuicon-btn:hover,
html.is-chromium .menuicon-btn:active,
html.is-chromium .topbar-userbox:active {
  transform: none !important;
}

html.is-chromium .menuicon-btn:hover .menuicon-svg {
  animation: none !important;
}

/* responsive (shell only) */
@media (max-width: 900px) and (hover: none) and (pointer: coarse) {
  .page-menubar-inner {
    gap: 8px;
  }

  .page-menubar-left .menutoggle-btn,
  .page-menubar-left .menudrop-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .page-menubar-left {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .page-menubar-left::-webkit-scrollbar {
    display: none;
  }

  #menu-payment-orders {
    min-width: max-content;
    padding-left: 12px;
    padding-right: 14px;
  }

  .page-menubar-right {
    flex: 0 0 auto;
    margin-left: auto;
  }

  #settings-toggle-btn {
    flex: 0 0 auto;
  }

  .topbar-user-name { display: none; }
  .user-popover { width: min(360px, calc(100vw - 16px)); }
  .topbar-kpis { max-width: min(720px, 72vw); }
}

/* ==========================================================
   Windows/Chromium fixes (Yandex/Chrome on Windows + ClearType)
   ========================================================== */

html.is-win .user-popover {
  transform: none !important;
  animation: none !important;
  transition: opacity 120ms ease !important;
}

html.is-win .user-popover-card {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  background: #1c1c1e !important;
}

html.is-win .user-popover-card,
html.is-win .topbar-userbox,
html.is-win .topbar-kpi {
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

html.is-win #user-cabinet-select {
  color-scheme: dark;
}

.topbar-kpis,
.cashback-balance-kpis {
  max-width: min(760px, 58vw);
  flex: 0 1 auto;
}

@media (max-width: 980px) {
  .topbar-kpis,
  .cashback-balance-kpis {
    max-width: min(720px, 72vw);
  }
}
