﻿/* ================================================
   Tandem Sites — Viewer
   app/styles/default.app-viewer.css
   — Топ-панель, дропдаун, действия, тултипы; iframe, загрузчик, анимации, адаптив
   ================================================ */

/* ─── TOP PANEL ──────────────────────────────────────── */

#panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    height: var(--panel-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

#panel::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, rgba(124, 110, 245, 0.15) 8%, rgba(124, 110, 245, 0.55) 30%, rgba(124, 110, 245, 0.75) 50%, rgba(124, 110, 245, 0.55) 70%, rgba(124, 110, 245, 0.15) 92%, transparent 100%);
    pointer-events: none;
    z-index: 1000;
}

/* ── Panel entrance animation ── */
:root {
    --panel-enter-y: -10px;
}

@keyframes panel-entry {
    from {
        opacity: 0;
        transform: translateY(var(--panel-enter-y));
        filter: blur(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0px);
    }
}

#panel.panel--ready {
    animation: panel-entry 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Logo */
#panel-logo {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
    text-decoration: none;
    user-select: none;
}

#panel-logo svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

#panel-logo span {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text-primary);
    white-space: nowrap;
}

#panel-logo em {
    font-style: normal;
    color: var(--accent);
}

/* Divider */
.panel-divider {
    width: 1px;
    height: 28px;
    background: var(--panel-border);
    flex-shrink: 0;
}

/* Nav group: Назад + Далее рядом */
.nav-group {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.nav-group .nav-btn {
    border: none;
    border-radius: 0;
}

.nav-group .nav-btn:first-child {
    border-right: 1px solid var(--panel-border);
}

.nav-group .nav-btn:first-child:hover:not(:disabled) {
    border-right-color: var(--panel-border);
}

/* Nav buttons */
.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 16px;
    height: 38px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-btn:hover:not(:disabled) {
    background: var(--btn-hover);
    border-color: var(--accent);
    color: #c4b9ff;
}

.nav-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.nav-btn:disabled {
    opacity: 0.28;
    cursor: default;
}

.nav-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Site info */
#site-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    flex-shrink: 1;
}

#site-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.2;
}

#site-meta {
    display: flex;
    align-items: center;
    gap: 7px;
}

#site-description {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

#site-counter {
    font-size: 10.5px;
    color: var(--accent);
    font-weight: 600;
    background: rgba(124, 110, 245, 0.12);
    padding: 1px 7px;
    border-radius: 20px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.6;
}

/* ─── CUSTOM DROPDOWN ─────────────────────────────────── */

#site-select-wrap {
    position: relative;
    flex-shrink: 0;
}

#select-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px 0 14px;
    height: 38px;
    width: 300px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 12.5px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition:
        border-color var(--transition),
        background var(--transition);
    white-space: nowrap;
    overflow: hidden;
}

#select-trigger:hover,
#select-trigger.active {
    border-color: var(--accent);
    background: rgba(124, 110, 245, 0.1);
    outline: none;
}

#select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.select-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform var(--transition);
}

#select-trigger.active .select-arrow {
    transform: rotate(180deg);
}

#site-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 260px;
    background: #13131f;
    border: 1px solid rgba(124, 110, 245, 0.25);
    border-radius: var(--radius);
    z-index: 9999;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 308px;
    /* ~6 элементов; 7+ → скролл */
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 110, 245, 0.35) transparent;
}

#site-dropdown::-webkit-scrollbar {
    width: 4px;
}

#site-dropdown::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0;
}

#site-dropdown::-webkit-scrollbar-thumb {
    background: rgba(124, 110, 245, 0.35);
    border-radius: 99px;
}

#site-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(124, 110, 245, 0.65);
}

#site-dropdown.open {
    display: block;
    animation: dropdownIn 0.18s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes dropdownIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: background var(--transition);
}

.dropdown-item:hover {
    background: rgba(124, 110, 245, 0.12);
}

.dropdown-item.active {
    background: rgba(124, 110, 245, 0.18);
}

.dropdown-item.active .di-title {
    color: #c4b9ff;
}

.dropdown-item.active .di-num {
    background: rgba(124, 110, 245, 0.32);
    border-color: rgba(124, 110, 245, 0.65);
    color: #c4b9ff;
}

.di-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 6px;
    background: rgba(124, 110, 245, 0.16);
    border: 1px solid rgba(124, 110, 245, 0.32);
    color: var(--accent);
    font-size: 11.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    line-height: 1;
}

.di-num--home {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.14);
    color: var(--text-muted);
}

.di-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.di-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.di-desc {
    font-size: 11.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Actions group: открыть + скопировать */
.panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
}

#phone-toggle,
#open-btn,
#copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition);
    flex-shrink: 0;
    text-decoration: none;
    font-family: inherit;
    padding: 0;
}

#phone-toggle:hover,
#open-btn:hover,
#copy-btn:hover {
    background: var(--btn-hover);
    border-color: var(--accent);
    color: #c4b9ff;
}

#phone-toggle svg,
#open-btn svg,
#copy-btn svg {
    width: 15px;
    height: 15px;
}

/* Недоступные кнопки на главной */
#phone-toggle.disabled,
#open-btn.disabled,
#copy-btn.disabled {
    opacity: 0.28;
    cursor: default;
}

#phone-toggle.disabled:hover,
#open-btn.disabled:hover,
#copy-btn.disabled:hover {
    background: transparent;
    border-color: var(--panel-border);
    color: var(--text-muted);
}

/* Состояние "Скопировано" */
#copy-btn .icon-check {
    display: none;
}

#copy-btn.copied {
    border-color: rgba(74, 222, 128, 0.45);
    color: #4ade80;
    background: rgba(74, 222, 128, 0.08);
}

#copy-btn.copied .icon-copy {
    display: none;
}

#copy-btn.copied .icon-check {
    display: block;
}

.actions-divider {
    width: 1px;
    height: 20px;
    background: var(--panel-border);
    flex-shrink: 0;
    margin: 0 2px;
}

/* ─── CUSTOM TOOLTIP ──────────────────────────────────── */

#tip {
    position: fixed;
    transform: translateX(-50%);
    background: rgba(14, 14, 26, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.01em;
    padding: 6px 11px;
    border-radius: 8px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 9999;
    opacity: 0;
    translate: 0 -4px;
    transition:
        opacity 0.18s ease,
        translate 0.18s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#tip.visible {
    opacity: 1;
    translate: 0 0;
}

/* ─── FRAME PLACEHOLDER ───────────────────────────────── */

#frame-placeholder {
    display: none;
}

/* ─── IFRAME ──────────────────────────────────────────── */

#viewer-frame {
    position: fixed;
    top: var(--panel-h);
    left: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - var(--panel-h));
    border: none;
    outline: none;
    background: #0b0b14;
    z-index: 1;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    transition:
        opacity 0.28s ease,
        width 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        left 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        top 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        border-radius 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

#viewer-frame.loading {
    opacity: 0;
}

#viewer-frame:focus,
#viewer-frame:focus-visible {
    outline: none;
}

/* ─── LOADER OVERLAY ──────────────────────────────────── */

#loader {
    position: fixed;
    top: var(--panel-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: #0b0b14;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    z-index: 100;
    transition: opacity 0.3s ease;
}

#loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-progress-wrap {
    width: 260px;
    height: 3px;
    background: rgba(124, 110, 245, 0.15);
    border-radius: 99px;
    overflow: hidden;
}

.loader-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #a89cf7);
    border-radius: 99px;
    transition: width 0.4s ease;
}

.loader-text {
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.03em;
    margin-top: 14px;
}

/* ─── SLIDE TRANSITION ────────────────────────────────── */

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-animate {
    animation: fadeSlideIn 0.25s ease forwards;
}

/* ─── RESPONSIVE ──────────────────────────────────────── */

@media (max-width: 680px) {
    :root {
        --panel-h: 56px;
        --panel-enter-y: 10px;
    }

    #panel {
        gap: 8px;
        padding: 0 12px;
    }

    #panel-logo span {
        display: none;
    }

    #site-description {
        display: none;
    }

    #site-info {
        display: none;
    }

    #site-select-wrap {
        flex: 1;
        min-width: 0;
    }

    #select-trigger {
        width: 100%;
        min-width: 0;
    }

    .nav-btn span {
        display: none;
    }

    .nav-btn {
        padding: 0 11px;
    }

    #site-dropdown {
        position: fixed;
        top: var(--panel-h);
        left: 8px;
        right: 8px;
        min-width: unset;
        width: auto;
        max-height: calc(100dvh - var(--panel-h) - 16px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .di-title,
    .di-desc {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    /* Скрываем panel-actions — на мобиле их заменяет #mobile-actions-btn */
    .panel-actions {
        display: none;
    }

    /* ── ПАНЕЛЬ ПЕРЕМЕЩАЕТСЯ ВНИЗ ── */

    #panel {
        top: auto;
        bottom: 0;

    }

    /* Градиентная линия — теперь над панелью */
    #panel::after {
        bottom: auto;
        top: -2px;
    }

    /* Фрейм: полностью от 0 до нижней панели */
    #viewer-frame {
        top: 0;
        bottom: var(--panel-h);
        height: calc(100dvh - var(--panel-h));
    }

    /* Оверлей загрузки: тоже занимает свободное пространство над фреймом */
    #loader {
        top: 0;
        bottom: var(--panel-h);
    }

    /* Дропдаун открывается вверх */
    #site-dropdown {
        top: auto;
        bottom: calc(var(--panel-h) + 6px);
    }
}

@media (max-width: 420px) {
    #select-trigger {
        font-size: 11px;
    }
}
