/* ==============================
   1) СБРОС И ПЕРЕМЕННЫЕ
============================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
}

:root {
    --width-img: 336px;
    --height-img: 336px;
    --max-width-main: 768px;
    --side-gap: calc((100vw - min(100vw, var(--max-width-main))) / 2);

    color-scheme: light dark;
}

/* Ретина-сглаживание */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    html {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ==============================
   2) БАЗОВЫЕ ТЕГИ
============================== */
html {
    height: 100%;
    font-size: 16px;
    scroll-padding-top: 72px;
}

body {
    min-height: 100vh;
    font-family:
        ui-sans-serif,
        -apple-system,
        BlinkMacSystemFont,
        Segoe UI,
        Roboto,
        Helvetica,
        Arial,
        sans-serif,
        Apple Color Emoji,
        Segoe UI Emoji;
    background: #fff;
    color: #222;
    line-height: 1.5;
    font-size: 1rem;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.15;
}

p {
    margin: 1em 0;
}

ul,
ol {
    list-style: none;
}

::selection {
    background: #0075ff22;
}

/* Формы */
input,
textarea,
select {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
    box-sizing: border-box;
    /* box-shadow: 0 0 0 1px red; */
}

/* Ссылки и фокус */
a {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s;
}
a:hover {
    text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid
        color-mix(in srgb, var(--color-primary, #4c8dff), #000 20%);
    outline-offset: 2px;
}

:disabled {
    pointer-events: none;
}

/* ==============================
   3) КНОПКИ / ПСЕВДОКНОПКИ
============================== */
button,
.file-upload-label,
body.edit-mode button.link-label.smart-checkbox + div {
    font: inherit;
    font-size: 17px;
    letter-spacing: -0.41px;
    font-weight: 500;
    cursor: pointer;
    background: rgb(0 0 0 / 4%);
    color: inherit;
    border: none;
    outline: none;
    padding: 14px 27px;
    border-radius: 100px;
    white-space: nowrap;
    transition:
        background 0.2s,
        transform 0.1s;
    box-shadow: 0 0 0 transparent;
    text-decoration: none;
}

button:hover,
.file-upload-label:hover,
body.edit-mode button.link-label.smart-checkbox + div:hover {
    background: rgb(0 0 0 / 7%);
}

button:active,
.file-upload-label:active {
    transform: translateY(1px);
}

/* ==============================
   4) SWITCH / TOGGLE
============================== */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 30px;
}
.switch input {
    position: absolute;
    opacity: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
}
.switch .slider-bg {
    position: absolute;
    inset: 0;
    background: #e3e3e3;
    border-radius: 999px;
    transition: background 0.35s;
}
.slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    cursor: pointer;
}
.slider::before {
    content: "";
    position: absolute;
    left: 2px;
    bottom: 2px;
    width: 26px;
    height: 26px;
    background: #fff;
    border-radius: 50%;
    border: 1px solid rgb(0 0 0 / 15%);
    box-shadow: 0 1px 2px rgb(0 0 0 / 12%);
    transition: transform 0.35s;
}
.switch input:checked + .slider-bg {
    background: #000;
}
.switch input:checked + .slider-bg + .slider::before {
    transform: translateX(20px);
}

/* ==============================
   5) ОСНОВНАЯ СЕТКА
============================== */
.mainBody {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
    max-width: var(--max-width-main);
    width: 100%;
    margin: 0 auto;
    padding: 0 8px;
    transition: all 0.35s;
}

/* Site title */
.site-title div {
    display: flex;
    text-transform: lowercase;
    font-size: 26px;
    font-weight: 650;
}
.site-title span {
    width: 0;
    overflow: hidden;
}
.site-title span:last-child {
    opacity: 1;
    width: auto;
}
body.edit-mode .site-title span:last-child {
    opacity: 0;
}
body.edit-mode .site-title > div:last-child {
    display: inline-block;
}

/* ==============================
   6) КАРТОЧКИ
============================== */
.cardsAll {
    display: flex;
    gap: 8px;
    max-width: 100vw;
    padding: 0 8px 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: var(--height-img);
}

.card:first-child {
    margin-left: var(--side-gap);
}
.card:nth-last-child(2) {
    margin-right: var(--side-gap);
}

.card.editable-card.add-card {
    margin-right: auto;
}

.edit-mode .card:nth-last-child(2) {
    margin-right: 0;
}
.edit-mode .card.editable-card.add-card,
.edit-mode .card.card-header.gallery-images {
    margin-right: var(--side-gap);
}

/* Header внутри карточки */
.card-header {
    display: flex;
    justify-content: center;
    align-items: center;
    width: var(--width-img);
    min-width: var(--width-img);
    height: var(--height-img);
    overflow: hidden;
    background: #fbfbfd;
    border-radius: 12px;
}
.card-header img {
    width: var(--width-img);
    height: var(--height-img);
    object-fit: cover;
}
.card-header label.file-upload-label {
    position: absolute;
}

/* Footer карточки */
.card-footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    padding: 16px;
}

.card-modal-footer {
    max-width: var(--max-width-main);
    width: 100%;
    margin: 0 auto;
}

/* Скрытые элементы в обычном режиме */
.add-card,
.form-footer,
section.footer,
.password-modal,
body.edit-mode button.link-label.smart-checkbox,
body.edit-mode .link-label,
.file-upload-label input,
.card.card-header.gallery-images {
    display: none;
}

/* В edit-mode показываем */
body.edit-mode .add-card,
body.edit-mode .form-footer {
    display: flex;
    flex-direction: column;
}

body.edit-mode .card-link-wrapper.enable button.link-label.smart-checkbox,
.edit-mode .card.card-header.gallery-images {
    display: flex;
}

/* Цвета кнопок в enable */
.card-link-wrapper.enable button {
    color: #fff;
}
button.link-label.smart-checkbox {
    color: #000;
}

/* Перекрывающая панель поверх изображения */
.advanced-toggle-wrapper {
    position: absolute;
    left: 0;
    top: calc(var(--height-img) - 54px);
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 16px 16px 8px;
    color: #fff;
    background: linear-gradient(0deg, rgb(0 0 0 / 50%), transparent);
    border-radius: 0 0 12px 12px;
}

/* Заглушка для add-card */
.add-card .card-footer {
    color: rgb(0 0 0 / 44%);
    opacity: 0.5;
    pointer-events: none;
}
.add-card .card-footer .card-link-wrapper button {
    color: rgb(0 0 0 / 44%);
}

/* ==============================
   7) МОДАЛКА
============================== */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-end;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}
.modal.modal-open {
    transform: translateY(0);
    z-index: 1001;
}
.modal.modal-open > button.close {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: transparent;
}

.card-modal-content {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 64px);
}
.card-modal {
    z-index: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    background: #fff;
}

/* ==============================
   8) OVERLAY ПОД МОДАЛКУ
============================== */
#modalOverlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgb(0 0 0 / 30%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s;
    z-index: 1000;
}
body.body-modal-open #modalOverlay {
    opacity: 1;
    pointer-events: auto;
}
body.body-modal-open {
    overflow: hidden;
}

/* ==============================
   9) REDUCE MOTION
============================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==============================
   10) DARK MODE
============================== */
@media (prefers-color-scheme: dark) {
    body {
        background: #0b0b0c;
        color: #e7e7ea;
    }
    header {
        background: #0f1620;
    }
    .card-header {
        background: #121418;
    }
    .switch .slider-bg {
        background: #26292e;
    }
    .card-link-wrapper.enable button {
        color: #111;
        background: #fff;
    }
    ::selection {
        background: #4c8dff33;
    }
}

/* ==============================
   11) ИКОН-КНОПКИ (upload/remove/add)
============================== */
.file-upload-label,
button.remove-card,
button.delete-button-img,
.add-card button {
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 99px;
    overflow: hidden;
    padding: 0;
    text-indent: -9999px;
    background: rgb(0 0 0 / 4%);
    cursor: pointer;
}

.file-upload-label::before,
.file-upload-label::after,
button.remove-card::before,
button.remove-card::after,
.add-card button::before,
.add-card button::after {
    content: "";
    position: absolute;
    width: 12px;
    height: 2px;
    background: rgb(60 60 67 / 60%);
    border-radius: 2px;
}
.file-upload-label::after,
.add-card button::after,
button.remove-card::after {
    transform: rotate(-90deg);
}
button.remove-card {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 32px;
    height: 32px;
    transform: rotate(45deg);
}

/* ==============================
   12) ЛЕЙАУТ ГЛАВНОГО БЛОКА
============================== */
.main-div {
    min-height: calc(100dvh - 64px);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.main-div .title {
    min-height: calc(100dvh - 542px);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    max-width: var(--max-width-main);
    width: 100%;
    margin: 0 auto;
    padding: 0 8px;
}

.form-footer {
    max-width: var(--max-width-main);
    margin: 0 auto;
}

/* ==============================
   13) ВИДИМОСТЬ В EDIT-MODE
============================== */
/* (исправлено: bbody -> body) */
body.edit-mode button.link-label.smart-checkbox,
button.link-label.smart-checkbox + div,
button.link-label.smart-checkbox + div + div,
button.link-label.smart-checkbox + div + div + a,
.card-link-wrapper.enable button.link-label.smart-checkbox + div,
.card-link-wrapper.enable button.link-label.smart-checkbox + div + div,
.advanced-toggle-wrapper,
button.remove-card {
    display: none;
}

body.edit-mode button.link-label.smart-checkbox + div,
body.edit-mode button.link-label.smart-checkbox + div + div,
body.edit-mode .advanced-toggle-wrapper,
body.edit-mode button.remove-card {
    display: flex;
}

/* Текстовые поля рядом с кнопкой-ссылкой */
body.edit-mode button.link-label.smart-checkbox + div,
body.edit-mode button.link-label.smart-checkbox + div + div {
    display: block;
    max-width: 12ch;
    min-width: 0;
    padding: 14px 27px;
    font-size: 17px;
    font-weight: 500;
    color: rgb(0 0 0 / 44%);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Раскрытие второго поля по фокусу */
body.edit-mode button.link-label.smart-checkbox + div + div {
    position: absolute;
    left: 0;
    width: 100%;
    max-width: 26ch;
    padding: 4px 24px;
    opacity: 0;
    z-index: -1;
}
body.edit-mode button.link-label.smart-checkbox + div:focus + div,
body.edit-mode button.link-label.smart-checkbox + div + div:focus {
    position: relative;
    opacity: 1;
    z-index: 9;
}

/* Расширение при фокусе контейнера */
body.edit-mode .card-footer.focus-link button.link-label.smart-checkbox + div {
    width: 26ch;
    max-width: 26ch;
}

/* Прятание контента футера при фокусе ссылки */
.card-footer.focus-link .footer-content-wrapper {
    opacity: 0;
}
.card-footer.focus-link .card-link-wrapper {
    position: absolute;
}

/* Заголовок в футере карточки */
.footer-content-wrapper h2 {
    max-width: 140px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Если нужна одна строка — оставляем nowrap; если clamp — снимите nowrap */
    white-space: nowrap;
}

/* Подчеркивание editable в edit-mode */
body.edit-mode .editable {
    border-bottom: 1px solid rgb(0 0 0 / 12%);
}

.password-modal {
    position: fixed;
    bottom: 0;
    background: white;
    flex-direction: column;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.password-modal .password-content.modal-window {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: var(--width-img);
}

input,
textarea {
    padding: 10px 16px;
    border: 1px solid;
    border-color: #dbdbdb;
    line-height: 20px;
    border-radius: 12px;
}

input:focus,
textarea:focus {
    border-color: black;
}

textarea {
    min-height: 40px;
    padding-right: 80px;
}

.card-footer .footer-content-wrapper {
    max-width: 210px;
    /* width: 100%; */
}

.card-footer .card-link-wrapper {
    max-width: 130px;
}

.titel-div {
    position: relative;
}
.char-counter {
    display: block;
    font-size: 12px;
    line-height: 1;
    opacity: 0.6;
    text-align: right;
    user-select: none;
    top: -20px;
    margin-right: 8px;
    position: relative;
}
textarea + .char-counter {
    top: -26px;
}
.char-counter.at-limit {
    opacity: 1;
    color: #d12;
}
