/* ================================================================
   Pola Marshall Portfolio — стили
   Скандинавский минимализм: неброский градиент (тёмный по умолчанию,
   светлая альтернатива), типографика (Cormorant Garamond + Inter),
   никаких толстых рамок, glassmorphism, glow-теней и ярких акцентов.

   Темы: все цвета — в CSS-переменных. Тёмная задаётся в :root,
   светлая — в :root[data-theme="light"] (атрибут выставляет PHP
   из cookie pm_theme; переключение без перезагрузки делает JS).
   ================================================================ */

/* ----------------------------------------------------------------
   1. Шрифты (Google Fonts) — директива должна быть ПЕРВОЙ.
   Разрешены CSP: style-src fonts.googleapis.com, font-src fonts.gstatic.com
   ---------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600&family=Inter:wght@300;400;500&display=swap');

/* ----------------------------------------------------------------
   2. Дизайн-токены — ТЁМНАЯ тема (по умолчанию)
   ---------------------------------------------------------------- */
:root {
    /* Шрифты */
    --font-serif: 'Onest', Helvetica, Arial, sans-serif;
    --font-sans:  'Inter', system-ui, -apple-system, sans-serif;

    /* Фон: тёплый чёрный градиент (неброский) */
    --bg-0: #0b0b0d;
    --bg-1: #151518;

    /* Едва заметные радиальные блики поверх градиента */
    --glow-a: rgba(255, 255, 255, 0.035);
    --glow-b: rgba(255, 255, 255, 0.03);

    /* Текст */
    --text:        #e9e9e7;
    --text-muted:  rgba(233, 233, 231, 0.55);
    --text-faint:  rgba(233, 233, 231, 0.3);

    /* Разделители и линии — только тонкие hairline */
    --hairline:        rgba(255, 255, 255, 0.09);
    --hairline-strong: rgba(255, 255, 255, 0.18);

    /* Поверхности */
    --sidebar-bg:       rgba(13, 13, 15, 0.88);
    --sidebar-bg-solid: rgba(9, 9, 11, 0.97);
    --overlay-bg:       rgba(0, 0, 0, 0.94);

    /* Выделение и скроллбар */
    --selection-bg:  rgba(255, 255, 255, 0.2);
    --scrollbar-thumb: rgba(255, 255, 255, 0.14);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.25);

    /* Ошибки формы — мягкий тёплый песочный, без красного */
    --error: #e2b8a2;

    /* Размеры */
    --sidebar-width: 264px;
    --touch-size: 44px;            /* минимальная тач-зона по WCAG */
    --grid-gap: clamp(10px, 1.4vw, 18px);

    /* Эффекты */
    --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
    --fade: 0.3s ease;
}

/* ----------------------------------------------------------------
   2.1 Дизайн-токены — СВЕТЛАЯ тема (тёплая бумага)
   ---------------------------------------------------------------- */
:root[data-theme="light"] {
    /* Фон: тёплый кремовый градиент */
    --bg-0: #f3f0ea;
    --bg-1: #e8e4dc;

    --glow-a: rgba(0, 0, 0, 0.04);
    --glow-b: rgba(0, 0, 0, 0.03);

    /* Текст — глубокий тёплый графит */
    --text:        #23211d;
    --text-muted:  rgba(35, 33, 29, 0.6);
    --text-faint:  rgba(35, 33, 29, 0.34);

    /* Разделители */
    --hairline:        rgba(0, 0, 0, 0.1);
    --hairline-strong: rgba(0, 0, 0, 0.24);

    /* Поверхности */
    --sidebar-bg:       rgba(243, 240, 234, 0.92);
    --sidebar-bg-solid: rgba(247, 244, 239, 0.98);
    --overlay-bg:       rgba(246, 243, 237, 0.95);

    /* Выделение и скроллбар */
    --selection-bg:  rgba(0, 0, 0, 0.14);
    --scrollbar-thumb: rgba(0, 0, 0, 0.18);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.3);

    /* Ошибки — мягкая терракота */
    --error: #9c6a53;
}

/* ----------------------------------------------------------------
   3. Сброс и база
   ---------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    color-scheme: dark; /* тёмные контролы браузера в тон интерфейсу */
    scroll-behavior: smooth;
}

:root[data-theme="light"] {
    color-scheme: light;
}

body {
    font-family: var(--font-sans);
    font-weight: 400;
    color: var(--text);
    background-color: var(--bg-0);
    background-image:
        radial-gradient(1200px 800px at 78% -10%, var(--glow-a), transparent 60%),
        radial-gradient(1000px 700px at 8% 110%, var(--glow-b), transparent 55%),
        linear-gradient(165deg, var(--bg-0) 0%, var(--bg-1) 100%);
    background-attachment: fixed;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

/* Плавный переход цветов при переключении темы */
body,
.sidebar,
.lightbox {
    transition: background-color 0.35s ease, color 0.35s ease;
}

/* Выделение текста — деликатное */
::selection {
    background: var(--selection-bg);
    color: var(--text);
}

/* Тонкий скроллбар в тон интерфейсу */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Видимый фокус для доступности с клавиатуры */
:focus-visible {
    outline: 1px solid var(--text);
    outline-offset: 3px;
    border-radius: 2px;
}

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

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    color: inherit;
    background: none;
    border: none;
}

ul { list-style: none; }

/* ================================================================
   4. ЭКРАН ВХОДА
   ================================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-wrap {
    width: min(400px, 100%);
    animation: rise-in 0.6s var(--ease-out) both;
}

@keyframes rise-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Логотип слева от «БМ 19» — одна горизонтальная композиция */
.login-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.login-logo {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 4px;
}

.login-title {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: clamp(2rem, 7vw, 2.7rem);
    letter-spacing: 0.06em;
    color: var(--text);
    line-height: 1;
}

.login-subtitle {
    margin-top: 14px;
    text-align: center;
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.36em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Тонкий разделитель между заголовком и формой */
.login-divider {
    width: 100%;
    height: 1px;
    margin: 36px 0 32px;
    background: var(--hairline);
}

.form-field {
    display: block;
    margin-bottom: 26px;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.64rem;
    font-weight: 500;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Поля только с нижней линией — без карточек и рамок */
.field-input {
    width: 100%;
    padding: 10px 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--text);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--hairline-strong);
    border-radius: 0;
    transition: border-color var(--fade);
}

.field-input::placeholder { color: var(--text-faint); }

.field-input:focus {
    outline: none;
    border-bottom-color: var(--text);
}

.form-error {
    margin-bottom: 20px;
    padding: 10px 0;
    font-size: 0.84rem;
    line-height: 1.5;
    color: var(--error);
    border-bottom: 1px solid var(--hairline);
}

/* Кнопка входа: инвертирование при наведении (работает в обеих темах) */
.login-btn {
    width: 100%;
    margin-top: 6px;
    padding: 14px 20px;
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.26em;
    text-transform: uppercase;
    color: var(--text);
    border: 1px solid var(--hairline-strong);
    transition: color var(--fade), background var(--fade), border-color var(--fade);
}

.login-btn:hover {
    color: var(--bg-0);
    background: var(--text);
    border-color: var(--text);
}

.login-btn:active { opacity: 0.85; }

/* ================================================================
   5. ПОРТФОЛИО: общий лейаут (Sidebar + сетка)
   ================================================================ */

/* Пропуск к контенту — виден только при фокусе (доступность) */
.skip-link {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 300;
    padding: 10px 16px;
    font-size: 0.8rem;
    color: var(--text);
    background: var(--bg-1);
    border: 1px solid var(--hairline);
    transform: translateY(-150%);
    transition: transform var(--fade);
}

.skip-link:focus { transform: translateY(0); }

/* ----------------------------------------------------------------
   5.1 Брендинг — неброская плашка внизу по центру.
   pointer-events: none — никогда не мешает взаимодействию.
   ---------------------------------------------------------------- */
.brand-plate {
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 90;
    transform: translateX(-50%);
    text-align: center;
    line-height: 1.5;
    pointer-events: none;
    user-select: none;
    opacity: 0.5;
    white-space: nowrap;
}

.brand-role {
    display: block;
    font-size: 0.54rem;
    font-weight: 500;
    letter-spacing: 0.36em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.brand-name {
    font-family: var(--font-serif);
    font-weight: 500;
    font-size: 0.92rem;
    letter-spacing: 0.14em;
    color: var(--text);
}

/* ----------------------------------------------------------------
   5.2 Гамбургер-меню (только мобильные; тач-зона ≥ 44×44)
   ---------------------------------------------------------------- */
.menu-toggle {
    display: none;
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 130;
    width: 48px;
    height: 48px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.menu-toggle-line {
    width: 22px;
    height: 1px;
    border-radius: 1px;
    background: var(--text);
    transition: transform var(--fade) var(--ease-out), opacity var(--fade);
}

.menu-toggle.is-open .menu-toggle-line:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.is-open .menu-toggle-line:nth-child(2) { opacity: 0; }
.menu-toggle.is-open .menu-toggle-line:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ----------------------------------------------------------------
   5.3 Переключатель темы — фиксированная кнопка справа сверху.
   На мобильных сдвигается левее гамбургера (правее не поместиться).
   ---------------------------------------------------------------- */
.theme-toggle {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 150;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 1px solid var(--hairline);
    border-radius: 50%;
    transition: color var(--fade), border-color var(--fade), background var(--fade);
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--hairline-strong);
}

.theme-toggle svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Тёмная тема: показываем луну; светлая — солнце */
.theme-toggle .icon-sun { display: none; }

:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun  { display: block; }

/* ----------------------------------------------------------------
   5.4 Sidebar — вертикальное меню зон
   ---------------------------------------------------------------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 110;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 44px 30px 28px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--hairline);
    overflow-y: auto;
}

.sidebar-title {
    margin: 0 0 22px;
    font-size: 0.62rem;
    font-weight: 500;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.zone-list { display: flex; flex-direction: column; }

.zone-btn {
    width: 100%;
    min-height: var(--touch-size);
    display: block;
    padding: 11px 12px 11px 0;
    text-align: left;
    font-size: 0.92rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    border-left: 2px solid transparent;
    transition: color var(--fade), border-color var(--fade), padding-left var(--fade);
}

.zone-btn:hover { color: var(--text); }

.zone-btn.is-active {
    color: var(--text);
    border-left-color: var(--text);
    padding-left: 12px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--hairline);
}

.logout-btn {
    width: 100%;
    min-height: var(--touch-size);
    text-align: left;
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--text-faint);
    transition: color var(--fade);
}

.logout-btn:hover { color: var(--text-muted); }

/* Затемнение под мобильным меню */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 105;
    background: rgba(0, 0, 0, 0.55);
}

/* ----------------------------------------------------------------
   5.5 Main — сетка галереи
   ---------------------------------------------------------------- */
.gallery {
    position: relative;
    z-index: 1;
    margin-left: var(--sidebar-width);
    min-height: 100dvh;
    padding: 56px clamp(18px, 4vw, 56px) 110px;
}

.gallery-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 30px;
}

.gallery-zone-title {
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.34em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.gallery-count {
    font-size: 0.78rem;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

/* Сетка: минимальные поля, без рамок и карточек */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(190px, 22vw, 320px), 1fr));
    gap: var(--grid-gap);
}

/* display:grid перекрывает UA-стиль [hidden]; восстанавливаем скрытие */
.gallery-grid[hidden] { display: none; }

/* Пропорция ячейки берётся из реальных размеров файла (--ar задаёт JS) */
.grid-item {
    position: relative;
    display: block;
    padding: 0;
    border: 0;
    background: none;
    overflow: hidden;
    aspect-ratio: var(--ar, 4 / 3);
}

.grid-item img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: transform 0.6s var(--ease-out), opacity 0.4s ease;
    will-change: transform;
}

.grid-item img.is-loaded { opacity: 1; }

.grid-item:hover img,
.grid-item:focus-visible img {
    transform: scale(1.04);
}

.gallery-placeholder,
.gallery-empty {
    padding: 70px 0;
    text-align: center;
    font-size: 0.86rem;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

/* ----------------------------------------------------------------
   5.6 Лайтбокс — полноэкранный просмотр
   ---------------------------------------------------------------- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

/* Сцена лайтбокса: оба слоя лежат в одной ячейке сетки и скользят
   друг относительно друга при переключении фото */
.lightbox-stage {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
}

.lightbox-img {
    grid-area: 1 / 1;
    max-width: 94vw;
    max-height: 90dvh;
    object-fit: contain;
    will-change: transform, opacity;
    transition: transform 0.5s var(--ease-out), opacity 0.5s ease;
}

/* «Призрачный» слой только анимируется и не перехватывает клики */
.lightbox-img.is-ghost {
    pointer-events: none;
}

/* Кнопка закрытия — тач-зона 48×48 */
.lightbox-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 3;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--text-muted);
    transition: color var(--fade), opacity var(--fade);
}

.lightbox-close:hover { color: var(--text); }
.lightbox-close:active { opacity: 0.6; }

/* Стрелки навигации — прозрачные, проявляются при наведении */
.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 64px;
    height: 104px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    line-height: 1;
    color: var(--text-faint);
    transition: color var(--fade), opacity var(--fade);
}

.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }

.lightbox-prev:hover,
.lightbox-next:hover { color: var(--text); }

.lightbox-counter {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 2;
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

/* Подсказка о зуме — показывается только там, где есть мышь */
.lightbox-hint {
    position: absolute;
    right: 18px;
    bottom: 18px;
    z-index: 2;
    display: none;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
    .lightbox-hint { display: block; }
}

/* Курсоры и запрет выделения при панорамировании */
.lightbox.is-zoomed .lightbox-stage { cursor: grab; }
.lightbox.is-dragging .lightbox-stage { cursor: grabbing; user-select: none; }

/* ================================================================
   6. Адаптивность (мобильные и планшеты)
   ================================================================ */
@media (max-width: 960px) {

    /* Гамбургер виден */
    .menu-toggle { display: flex; }

    /* Переключатель темы — левее гамбургера */
    .theme-toggle { right: 72px; }

    /* Sidebar прячется за экран, открывается по кнопке */
    .sidebar {
        width: min(300px, 84vw);
        transform: translateX(-105%);
        transition: transform 0.35s var(--ease-out);
        padding-top: 92px;
        background: var(--sidebar-bg-solid);
    }

    .sidebar.is-open { transform: translateX(0); }

    /* Контент на всю ширину */
    .gallery {
        margin-left: 0;
        padding-top: 88px;
    }

    /* Плашка компактнее */
    .brand-plate { bottom: 10px; }

    /* Сетка: 2 колонки на телефонах */
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
    }

    .gallery-head { margin-bottom: 22px; }

    /* Лайтбокс на мобильных */
    .lightbox-img { max-width: 96vw; max-height: 84dvh; }

    .lightbox-prev,
    .lightbox-next {
        width: 52px;
        height: 76px;
        font-size: 1.7rem;
    }

    .lightbox-prev { left: 2px; }
    .lightbox-next { right: 2px; }
}

/* Мелкие телефоны — узкие ячейки */
@media (max-width: 380px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* ----------------------------------------------------------------
   7. Доступность: снижение движения
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}