/* Состояния «жидкого стекла»: ошибки и меню профиля.
   Все новые поверхности создаются только на время показа — скрытый blur не висит. */

/* ---- InlineError: плашка под полем ---- */
.inline-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 44px;      /* место зарезервировано: появление не сдвигает кнопку */
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  pointer-events: none;
}

.inline-error.on {
  opacity: 1;
  transform: translateY(0);
}

.inline-error__icon {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 1px;
  color: var(--danger);
}

.inline-error__text { flex: 1; word-break: break-word; }

/* Only the frame changes; the glass field itself stays the same. */
input.f[aria-invalid="true"] { border-color: var(--danger); }
input.f[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 0 0 2px var(--danger);
}

/* Плашка визуально под полем, кнопка «Войти» остаётся активной и на месте. */
.login { display: flex; flex-direction: column; }
.login .inline-error { order: 1; margin-top: 10px; }
.login .btn { order: 2; }

/* ---- ErrorDialog ---- */
.dialog-scrim {
  position: fixed;
  inset: 0;
  z-index: 10000;   /* выше полноэкранного сканера (9999) */
  display: grid;
  place-items: center;
  padding:
    calc(20px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: dlgFade 200ms var(--ease) both;
}

.dialog {
  width: 100%;
  max-width: 400px;
  max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--dialog-border);
  border-radius: 24px;
  background-color: var(--dialog-bg);
  box-shadow: inset 0 1px 0 var(--glass-shine), var(--dialog-shadow);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
  text-align: center;
  animation: dlgIn 240ms var(--ease) both;
}

.dialog-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--danger);
  border-radius: 50%;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.dialog-title {
  margin: 0;
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
}

.dialog-desc {
  margin: 0;
  color: var(--dialog-text-muted);
  font-size: 14px;
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

.dialog-actions .btn {
  flex: 1;
  width: auto;
  min-height: 48px;
  margin: 0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
}

.dialog-actions .btn.o {
  border: 1px solid var(--dialog-btn-line);
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.dialog-actions .btn.o:active { background: var(--glass-strong); }

@keyframes dlgFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dlgIn {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}

body.dialog-lock { overflow: hidden; }
body.profile-lock { overflow: hidden; }

/* ---- ProfileMenu: подложка под шапкой + стеклянная панель ---- */
.menu-scrim {
  position: fixed;
  left: 0;
  right: 0;
  top: 68px;              /* точное значение ставит JS по нижней границе шапки */
  bottom: 0;
  z-index: 40;
  background: var(--menu-scrim);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: menuFade 180ms var(--ease) both;
}

.menu-panel {
  position: absolute;
  top: 8px;
  right: max(calc(12px + env(safe-area-inset-right, 0px)), calc(50vw - 215px + env(safe-area-inset-right, 0px)));
  width: min(310px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-height: calc(100vh - 90px - env(safe-area-inset-top));
  max-height: calc(100dvh - 90px - env(safe-area-inset-top) - env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--menu-border);
  border-radius: 22px;
  background-color: var(--menu-bg);
  box-shadow: inset 0 1px 0 var(--glass-shine), var(--dialog-shadow);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
  transform-origin: top right;
  animation: menuIn 180ms var(--ease) both;
}

.menu-user {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.menu-avatar {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--menu-avatar-a), var(--menu-avatar-b));
  color: var(--menu-avatar-ink);
  font-size: 16px;
  font-weight: 700;
}

.menu-user-text { min-width: 0; }
.menu-name { font-size: 17px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.menu-role { margin-top: 2px; color: var(--menu-role); font-size: 13px; }
.menu-sep { width: 100%; height: 1px; flex: none; background: var(--menu-line); }

.menu-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* скроллбар скрыт и не занимает место: иначе на десктопе к отступу
     справа добавлялась бы ширина полосы прокрутки */
  scrollbar-width: none;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.menu-list::-webkit-scrollbar { display: none; }

/* правый отступ живёт здесь: переключатель добавляется рядом с кнопкой,
   а не внутрь неё (js/ui/profile-menu.js) */
.menu-row {
  display: flex;
  align-items: center;
  padding-right: 20px;
}

.menu-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 0 0 20px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--menu-text);
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.menu-item:hover,
.menu-item:focus-visible { background: var(--glass-strong); }
.menu-item svg { width: 20px; height: 20px; flex: none; color: var(--accent); }
.menu-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.menu-chevron { width: 18px; height: 18px; color: var(--menu-role); }
.menu-value { color: var(--menu-value); font-size: 13px; white-space: nowrap; }
.menu-item.danger { color: var(--danger); font-weight: 600; }
.menu-item.danger svg { color: var(--danger); }

/* ---- Switch ---- */
.ui-switch {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.ui-switch__track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--switch-off);
  transition: background 140ms var(--ease);
}

.ui-switch[aria-checked="true"] .ui-switch__track { background: var(--switch-on); }

.ui-switch__knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  transition: transform 140ms var(--ease);
}

.ui-switch[aria-checked="true"] .ui-switch__knob { transform: translateX(18px); }

@keyframes menuFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes menuIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}

/* ---- ProfileDialog: полнэкранная подложка над открытым меню ---- */
.profile-scrim {
  position: fixed;
  inset: 0;
  z-index: 10001;   /* меню — 40, ErrorDialog — 10000 */
  display: grid;
  place-items: center;
  padding:
    calc(20px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--profile-scrim);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: dlgFade 200ms var(--ease) both;
}

.profile-dialog {
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--profile-border);
  border-radius: 26px;
  background-color: var(--profile-bg);
  box-shadow: inset 0 1px 0 var(--profile-shine), var(--profile-shadow);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  backdrop-filter: blur(26px) saturate(160%);
  color: var(--profile-text);
  text-align: center;
  animation: dlgIn 240ms var(--ease) both;
}

.profile-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.profile-head-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background-color: var(--profile-icon-bg);
  color: var(--profile-text);
}

.profile-head-icon svg { width: 30px; height: 30px; stroke-width: 1.8; }

.profile-title {
  margin: 0;
  color: var(--profile-text);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
}

.profile-desc {
  margin: 0;
  color: var(--profile-subtitle);
  font-size: 14px;
  line-height: 1.4;
}

.profile-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--profile-card-border);
  border-radius: 16px;
  background-color: var(--profile-card-bg);
  text-align: left;
}

.profile-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.profile-avatar {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--profile-avatar-a), var(--profile-avatar-b));
  color: var(--profile-avatar-ink);
  font-size: 14px;
  font-weight: 700;
}

.profile-user-text { min-width: 0; }

.profile-name {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.profile-role {
  margin-top: 2px;
  color: var(--profile-subtitle);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.profile-divider {
  height: 1px;
  flex: none;
  background-color: var(--profile-divider);
}

.profile-modes-label {
  margin-bottom: 8px;
  color: var(--profile-text);
  font-size: 14px;
  font-weight: 600;
}

.profile-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}

.profile-chip {
  padding: 5px 12px;
  border-radius: 8px;
  background-color: var(--chip-bg);
  color: var(--chip-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.profile-close {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--profile-btn-border);
  border-radius: 14px;
  background-color: var(--profile-btn-bg);
  color: var(--profile-btn-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 140ms var(--ease), transform 140ms var(--ease);
}

.profile-close:hover { filter: brightness(1.08); }
.profile-close:active { filter: brightness(.96); transform: translateY(1px); }

.profile-close:focus-visible {
  outline: 2px solid var(--profile-btn-text);
  outline-offset: 3px;
}

/* ---- ConfirmDialog: опасные действия ---- */
.dialog-confirm .dialog-icon {
  border-color: var(--wait-ink);
  background-color: var(--tint-wait);
  color: var(--wait-ink);
}

.dialog-confirm .dialog-actions .btn.r { background-color: var(--btn-red); color: #fff; }

/* ---- Toast: короткое уведомление после успешной операции ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 9000;   /* ниже диалогов (10000), выше нижних панелей */
  width: max-content;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid var(--btn-green);
  border-radius: 14px;
  background-color: var(--dialog-bg);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--glass-shine), var(--dialog-shadow);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.toast.on { opacity: 1; transform: translate(-50%, 0); }

