/* ============================================================================
   overlays.css — всё, что появляется поверх страницы, и промежуточные состояния:
   cookie-баннер и его настройки, тосты, лайтбокс, скелетон, пустое состояние.

   Подключается на всех страницах: cookie-баннер обязан быть везде.
   ========================================================================== */

@layer components {
  /* ------------------------------------------------------------------------
     Блокировка фона, пока открыто модальное окно.
     :has вместо класса на <body> — не нужно ничего ставить и снимать из JS,
     а значит нечему и рассинхронизироваться.
     ---------------------------------------------------------------------- */
  body:has(dialog[open]:modal) {
    overflow: hidden;
  }

  /* --- переключатель ------------------------------------------------------ */
  /* Настоящий <input type="checkbox">: клавиатура, screen reader и форма
     работают сами, CSS только рисует */
  .switch {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: #f7f7f7;
    cursor: pointer;
  }

  .switch__text {
    flex: 1;
  }

  .switch__title {
    font: 400 var(--fs-body) / 1.3 var(--font-sans);
  }

  .switch__note {
    margin-top: 5px;
    font: 400 var(--fs-caption) / 1.45 var(--font-sans);
    color: var(--ink-muted);
  }

  .switch__input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .switch__track {
    position: relative;
    flex: none;
    width: 46px;
    height: 27px;
    border-radius: var(--r-pill);
    background: rgb(0 0 0 / 0.12);
    transition: background var(--dur-fast) ease;
  }

  .switch__track::after {
    content: "";
    position: absolute;
    inset-block-start: 3px;
    inset-inline-start: 3px;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background: #fff;
    transition:
      translate var(--dur-fast) ease,
      background var(--dur-fast) ease;
  }

  .switch__input:checked + .switch__track {
    background: var(--ink);
  }

  .switch__input:checked + .switch__track::after {
    translate: 19px 0;
    background: var(--accent);
  }

  .switch__input:focus-visible + .switch__track {
    outline: 2px solid var(--accent-deep);
    outline-offset: 3px;
  }

  /* Обязательные cookie: включены и заблокированы — видно, что выбора нет */
  .switch--locked {
    border-color: rgb(95 130 38 / 0.25);
    background: var(--accent-softer);
    cursor: default;
  }

  .switch--locked .switch__note {
    color: #4a5a30;
  }

  .switch--locked .switch__track {
    background: var(--accent-deep);
    opacity: 0.55;
  }

  .switch--locked .switch__track::after {
    translate: 19px 0;
  }
}

@layer sections {
  /* ========================================================= cookie-баннер */
  /* Полоса по нижней грани экрана — привычный для сайтов формат.
     Внутри тот же контейнер, что и у страницы, чтобы текст не разъезжался
     до краёв на широких мониторах */
  .cookie {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: var(--z-menu);
    overflow: clip;
    border-top: 1px solid var(--line-on-dark);
    background: var(--ink);
    color: #fff;
    box-shadow: 0 -18px 54px rgb(0 0 0 / 0.28);
    animation: cookie-in 0.4s var(--ease) both;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .cookie__inner {
    position: relative;
    display: flex;
    align-items: center;
    gap: clamp(16px, 2vw, 28px);
    width: min(var(--container), 100%);
    margin-inline: auto;
    padding: 16px var(--gutter);
  }

  .cookie__copy {
    flex: 1 1 auto;
    min-width: 0;
  }

  .cookie[hidden] {
    display: none;
  }

  @keyframes cookie-in {
    from {
      opacity: 0;
      translate: 0 100%;
    }
  }

  .cookie__glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(
      680px 200px at 12% 120%,
      rgb(203 251 85 / 0.22),
      rgb(203 251 85 / 0) 70%
    );
    pointer-events: none;
  }

  .cookie__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--ink);
  }

  .cookie__icon svg {
    width: 19px;
    height: 19px;
  }

  .cookie__title {
    font: 400 clamp(17px, 1.5vw, 21px) / 1.25 var(--font-display);
    letter-spacing: -0.02em;
  }

  .cookie__title em {
    color: var(--accent);
  }

  .cookie__text {
    max-width: 76ch;
    margin-top: 4px;
    font: 400 13px / 1.5 var(--font-sans);
    color: rgb(255 255 255 / 0.62);
  }

  .cookie__actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
  }

  /* Узкий экран: полоса становится столбиком. Держим её невысокой —
     баннер согласия не должен занимать треть экрана */
  @media (width < 860px) {
    .cookie__inner {
      flex-direction: column;
      align-items: stretch;
      gap: 12px;
      padding-block: 14px;
    }

    .cookie__icon {
      display: none;
    }

    .cookie__actions {
      flex-wrap: wrap;
    }

    .cookie__accept,
    .cookie__secondary {
      flex: 1 1 auto;
      justify-content: center;
    }
  }

  @media (width < 560px) {
    .cookie__inner {
      gap: 10px;
      padding-block: 12px;
    }

    .cookie__title {
      font-size: 16px;
    }

    .cookie__text {
      font-size: 12px;
      line-height: 1.4;
    }

    .cookie__accept,
    .cookie__secondary {
      height: 38px;
      font-size: 13px;
    }

    /* «Настроить» — строкой под кнопками: в один ряд с ними на 375 px
       не помещается, а перенос по flex-wrap даёт непредсказуемый разрыв */
    .cookie__link {
      order: 3;
      width: 100%;
      text-align: center;
      padding: 0;
      font-size: 12px;
    }
  }

  /* Пока внизу висит полоса согласия, плавающие кнопки прячем: два
     всплывающих элемента на одной грани спорят друг с другом, а поднятая
     над полосой кнопка ложится поверх текста. Вернутся сразу после выбора */
  body:has(.cookie:not([hidden])) .float-cta,
  body:has(.cookie:not([hidden])) .to-top {
    opacity: 0;
    translate: 0 12px;
    pointer-events: none;
  }

  .cookie__accept {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 6px 0 18px;
    border-radius: var(--r-pill);
    background: var(--accent);
    color: var(--ink);
    font: 400 var(--fs-body) / 1 var(--font-sans);
    cursor: pointer;
  }

  .cookie__accept span {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--accent);
  }

  .cookie__accept svg {
    width: 16px;
    height: 16px;
  }

  .cookie__secondary {
    height: 44px;
    padding-inline: 18px;
    border: 1px solid rgb(255 255 255 / 0.2);
    border-radius: var(--r-pill);
    color: #fff;
    font: 400 var(--fs-body) / 1 var(--font-sans);
    cursor: pointer;
    transition: border-color var(--dur-fast) ease;
  }

  .cookie__secondary:hover {
    border-color: var(--accent);
  }

  .cookie__link {
    height: 44px;
    padding-inline: 12px;
    color: rgb(255 255 255 / 0.55);
    font: 400 var(--fs-body) / 1 var(--font-sans);
    cursor: pointer;
    transition: color var(--dur-fast) ease;
  }

  .cookie__link:hover {
    color: #fff;
  }


  /* --- окно настроек ------------------------------------------------------ */
  .cookie-prefs {
    width: min(480px, 100% - 2 * var(--gutter));
    max-height: min(760px, 92svh);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--card);
    color: var(--ink);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .cookie-prefs::backdrop {
    background: rgb(10 10 10 / 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .cookie-prefs__inner {
    padding: clamp(20px, 2.4vw, 28px);
  }

  .cookie-prefs__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .cookie-prefs__list {
    display: grid;
    gap: 10px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
  }

  .cookie-prefs__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
  }

  .cookie-prefs__save {
    flex: 1 1 180px;
  }

  /* ================================================================= тосты */
  /* Снизу по центру, один одновременно — живую очередь ведёт toast.js */
  .toasts {
    position: fixed;
    inset-block-end: 24px;
    inset-inline: 0;
    z-index: var(--z-modal);
    display: grid;
    justify-items: center;
    gap: 10px;
    padding-inline: 16px;
    pointer-events: none;
  }

  .toast {
    display: flex;
    align-items: center;
    gap: 14px;
    width: min(460px, 100%);
    padding: 16px 20px;
    border-radius: var(--r-md);
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow-float);
    pointer-events: auto;
    animation: toast-in 0.32s var(--ease) both;
  }

  .toast.is-leaving {
    animation: toast-out 0.28s var(--ease) both;
  }

  @keyframes toast-in {
    from {
      opacity: 0;
      translate: 0 16px;
    }
  }

  @keyframes toast-out {
    to {
      opacity: 0;
      translate: 0 10px;
    }
  }

  .toast__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgb(255 255 255 / 0.12);
    color: #fff;
  }

  .toast__icon svg {
    width: 16px;
    height: 16px;
  }

  .toast--success .toast__icon {
    background: var(--accent);
    color: var(--ink);
  }

  .toast--error .toast__icon {
    background: rgb(194 65 12 / 0.3);
    color: #ffb89a;
  }

  .toast__text {
    flex: 1;
    font: 400 var(--fs-body) / 1.4 var(--font-sans);
  }

  .toast__action {
    flex: none;
    font: 400 var(--fs-caption) / 1 var(--font-sans);
    color: var(--accent);
    white-space: nowrap;
    cursor: pointer;
  }

  .toast__close {
    flex: none;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    color: #fff;
    opacity: 0.5;
    cursor: pointer;
    transition: opacity var(--dur-fast) ease;
  }

  .toast__close:hover {
    opacity: 1;
  }

  .toast__close svg {
    width: 16px;
    height: 16px;
  }

  /* ============================================================= лайтбокс */
  .lightbox {
    width: min(1180px, 100% - 2 * var(--gutter));
    max-height: 92svh;
    padding: 0;
    border: 0;
    border-radius: var(--r-lg);
    background: var(--ink-2);
    color: #fff;
    overflow: hidden;
  }

  .lightbox::backdrop {
    background: rgb(6 6 6 / 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .lightbox__inner {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    height: 100%;
    padding: clamp(16px, 2vw, 26px);
  }

  .lightbox__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .lightbox__counter {
    font: 400 var(--fs-label) / 1 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgb(255 255 255 / 0.6);
  }

  .lightbox__stage {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(10px, 1.6vw, 22px);
  }

  .lightbox__frame {
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border-radius: var(--r-md);
    background-color: #f0f0f0;
    background-image: repeating-linear-gradient(
      135deg,
      rgb(0 0 0 / 0.035) 0 10px,
      transparent 10px 20px
    );
  }

  .lightbox__frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .lightbox__label {
    font: 400 var(--fs-label) / 1.5 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
    color: var(--ink-muted);
  }

  .lightbox__nav,
  .lightbox__close {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    border: 1px solid rgb(255 255 255 / 0.16);
    border-radius: 50%;
    background: rgb(255 255 255 / 0.06);
    color: #fff;
    cursor: pointer;
    transition:
      background var(--dur-fast) ease,
      border-color var(--dur-fast) ease;
  }

  .lightbox__nav:hover,
  .lightbox__close:hover {
    border-color: var(--accent);
    background: rgb(203 251 85 / 0.14);
  }

  .lightbox__nav[disabled] {
    opacity: 0.3;
    cursor: default;
  }

  .lightbox__nav svg,
  .lightbox__close svg {
    width: 20px;
    height: 20px;
  }

  .lightbox__caption {
    font: 400 var(--fs-body) / 1.5 var(--font-sans);
    color: rgb(255 255 255 / 0.68);
  }

  @media (width < 620px) {
    .lightbox__stage {
      grid-template-columns: minmax(0, 1fr);
    }

    .lightbox__nav {
      display: none;
    }
  }

  /* ====================================================== скелетон и пусто */
  .skeleton {
    display: grid;
    gap: 14px;
    padding: clamp(20px, 2.2vw, 28px);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--card);
  }

  .skeleton__bar {
    height: 14px;
    border-radius: var(--r-pill);
    background: linear-gradient(90deg, #efefef 0%, #f7f7f7 40%, #efefef 80%);
    background-size: 420px 100%;
    animation: shimmer 1.3s linear infinite;
  }

  .skeleton__bar--block {
    height: 120px;
    border-radius: var(--r-md);
  }

  .skeleton__bar--title {
    height: 22px;
    width: 80%;
  }

  .skeleton__bar--short {
    width: 55%;
  }

  @keyframes shimmer {
    from {
      background-position: -420px 0;
    }
    to {
      background-position: 420px 0;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .skeleton__bar {
      animation: none;
    }
  }

  .empty-state {
    display: grid;
    justify-items: center;
    gap: 14px;
    padding: clamp(36px, 5vw, 64px) clamp(20px, 3vw, 40px);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--card);
    text-align: center;
  }

  .empty-state__icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border: 1px solid rgb(111 147 40 / 0.25);
    border-radius: 50%;
    background: var(--accent-softer);
    color: var(--accent-deep);
  }

  .empty-state__icon svg {
    width: 28px;
    height: 28px;
  }

  .empty-state__title {
    font: 400 var(--fs-h3) / 1.24 var(--font-sans);
    letter-spacing: -0.015em;
  }

  .empty-state__text {
    max-width: 46ch;
    font: 400 var(--fs-body) / 1.6 var(--font-sans);
    color: var(--ink-muted);
  }

  /* ============================== состояния формы: отправка и успех ======= */
  .modal__sending {
    display: grid;
    justify-items: center;
    gap: 18px;
    padding-block: 48px;
  }

  .spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgb(0 0 0 / 0.1);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
  }

  @keyframes spin {
    to {
      rotate: 360deg;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .spinner {
      animation-duration: 2.4s;
    }
  }

  .modal__sending-text {
    font: 400 var(--fs-body) / 1.4 var(--font-sans);
    color: var(--ink-muted);
  }

  /* Лаймовый круг с галочкой — общий для «Спасибо» и успеха формы */
  .done-mark {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--ink);
  }

  .done-mark svg {
    width: 32px;
    height: 32px;
  }

  .done-mark--sm {
    width: 56px;
    height: 56px;
  }

  .done-mark--sm svg {
    width: 26px;
    height: 26px;
  }

  /* Подпись ошибки под полем — с иконкой, а не просто красным текстом */
  .field__error {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .field__error svg {
    flex: none;
    width: 15px;
    height: 15px;
  }
}
