/* ========================================== */
/* КРАТКОЕ ОГЛАВЛЕНИЕ                         */
/* ========================================== */
/*
 * ФАЙЛ: link-icons.css
 * НАЗНАЧЕНИЕ: Стилизация иконок ссылок внутри хранилища
 *
 * СОДЕРЖАНИЕ:
 * 1. .storage__links-container - Контейнер для размещения иконок ссылок
 * 2. .link-card - Карточка отдельной ссылки с drag & drop
 * 3. .link-card__icon-wrapper - Обертка для иконки (для позиционирования кнопки настроек)
 * 4. .link-card__icon / .link-card__default-icon - Иконка ссылки
 * 5. .link-card__tooltip - Всплывающая подсказка с описанием и URL
 * 6. .link-card__settings-btn - Кнопка настроек (шестеренка)
 * 7. .link-card__url-label - URL метка внизу иконки
 *
 * ОСОБЕННОСТИ:
 * - Анимации: scale(1.05) при hover на иконке, rotate(90deg) на кнопке настроек
 * - Цвета: голубая кнопка быстрого действия (#4a9ebb)
 * - Адаптивность: нет
 * - Drag & Drop: поддержка перетаскивания с z-index: 9999 и отключением событий на дочерних элементах
 * - Tooltip: всплывающая подсказка с описанием и URL
 */
/* ========================================== */

/* Контейнер для размещения иконок ссылок - абсолютное позиционирование */
/* ВАЖНО: bottom создает защитную зону для storage-controls (блок №4) */
.storage__links-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px; /* Защитная зона для storage-controls: высота кнопок (~32-40px) + отступы + запас */
    overflow: visible; /* Разрешаем tooltip выходить за границы для корректного отображения */
}

/* Когда открыта папка — сдвигаем контейнер вниз на высоту хлебных крошек */
.storage__card--in-folder .storage__links-container {
    top: 38px;
}

/* Карточка ссылки с поддержкой drag & drop */
/* ВАЖНО: z-index: auto — НЕ создаём stacking context, иначе дочерние элементы */
/* (url-label, tooltip) не смогут отображаться поверх соседних карточек */
.link-card {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0; /* Убираем gap, т.к. внутри только один элемент (iconWrapper) */
    cursor: grab;
    transition: opacity 0.3s ease;
    text-decoration: none;
    user-select: none;
    width: 80px;
}

/* Обертка для иконки - для правильного позиционирования кнопки настроек */
/* ВАЖНО: высота и ширина устанавливаются динамически через JavaScript в storage-controls.js */
.link-card__icon-wrapper {
    position: relative;
    width: 44px;
    height: 44px;
}

/* Курсор при активном перетаскивании */
.link-card:active {
    cursor: grabbing;
}

/* Состояние карточки при перетаскивании */
.link-card.dragging {
    opacity: 0.7;
    cursor: grabbing;
    z-index: 9999;
    pointer-events: none;
}

/* Иконка ссылки - изображение с закругленными углами */
.link-card__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease, transform 0.6s ease;
}

/* Эффект наведения на иконку - небольшое увеличение */
.link-card__icon:hover {
      transform: scale(1.05);
}

/* Иконка по умолчанию - используется если нет загруженного изображения */
.link-card__default-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 26px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease, transform 0.6s ease;
}

/* Эффект наведения на иконку по умолчанию */
.link-card__default-icon:hover {
  transform: scale(1.05);
}

/* Дефолтная иконка для текстовых иконок - тёмный текст "Aa" */
.link-card--text .link-card__default-icon {
    color: #1a6b6d;
    font-size: 16px;
    font-weight: 600;
    font-family: Arial, sans-serif;
}

/* Для файлов - PNG иконка без рамки (только картинка пользователя) */
.link-card--file .link-card__icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
}

/* Для изображений — возвращаем стандартный вид с рамкой (это превью фото) */
.link-card--file[data-file-category="image"] .link-card__icon {
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Подсказки иконок */

/* Всплывающая подсказка с описанием и URL ссылки */
/* ВАЖНО: z-index 10000 чтобы быть выше блока №2 (service-control) */
.link-card__tooltip {
    position: absolute;
    bottom: calc(100% + 20px);
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 255, 255, 0.842);
    color: #000000;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    white-space: normal;
    width: max-content;
    max-width: 300px;
    min-width: 150px;
    max-height: 260px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Для текстовых иконок - широкая подсказка с переносом */
.link-card--text .link-card__tooltip {
    white-space: pre-wrap !important;
    width: 100%;
    max-width: 300px !important;
    min-width: 200px !important;
}

/* Стрелка подсказки, указывающая на иконку */
.link-card__tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
}

/* Показ подсказки при наведении на карточку */
.link-card:hover .link-card__tooltip {
    opacity: 1;
}

/* Поднимаем карточку поверх всех при наведении, чтобы подсказка не перекрывалась соседними иконками */
.link-card:hover {
    z-index: 99999 !important;
}

/* Описание ссылки в подсказке */
.link-card__tooltip-description {
    font-size: 11px;
    opacity: 0.9;
    line-height: 1.4;
    margin-bottom: 8px;
    overflow-y: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
    width: 100%;
    white-space: normal;
    /* Ограничение: максимум 6 строк (~120 символов) */
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Для текстовых иконок - описание с переносом и ограничением */
.link-card--text .link-card__tooltip-description {
    white-space: pre-wrap !important;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* URL ссылки в подсказке */
.link-card__tooltip-url {
    font-weight: 600;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 6px;
    margin-top: auto;
    width: 100%;
    word-break: break-word;
    overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Кнопка быстрого действия (Play) - появляется при наведении на карточку */
.link-card__settings-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    background-color: #29abe2;
    border: none;
    border-radius: 30%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.2s ease;
    z-index: 10;
    padding: 0;
}

/* Показ кнопки при наведении на карточку */
.link-card:hover .link-card__settings-btn {
    opacity: 1;
}

/* Эффект наведения на кнопку Play - увеличение */
.link-card__settings-btn:hover {
    transform: scale(1.25);
}

/* Размер и цвет SVG иконки Play */
.link-card__settings-btn svg {
    width: 12px;
    height: 12px;
    color: #ffffff;
}

/* URL метка внизу иконки - показывается при активации опции */
.link-card__url-label {
    position: absolute;
    bottom: -15px;
    left: 0;
    right: 0;
    background-color: rgba(255, 255, 255, 0.707);
    color: #000000cb;
    font-size: 10px;
    padding: 0px 3px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius:  5px;
    display: none;
    z-index: 110000;
    pointer-events: none;
}

/* ========================================== */
/* ICON NAME LABEL - НАЗВАНИЕ ИКОНКИ          */
/* ========================================== */

/* Контейнер названия иконки под иконкой (как на рабочем столе Windows) */
.link-card__name-label {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(var(--icon-size, 44px) * 1.5);
    margin-top: 4px;
    color: var(--icon-label-color, #333);
    font-size: var(--icon-name-font-size, 11px);
    line-height: 1.3;
    text-align: center;
    z-index: 5;
    cursor: default;
    /* Жестко ограничиваем ровно двумя строками, чтобы не было видимого "хвоста" 3-й */
    max-height: 2.62em;
    overflow: hidden;
    /* BUGFIX: не блокируем клики на соседних иконках — клики проходят сквозь фон метки */
    pointer-events: none;
}

/* Текст названия - inline с фоном на каждой строке отдельно */
.link-card__name-text {
    display: inline;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 2px 4px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    word-break: break-word;
    cursor: text;
    pointer-events: auto; /* Восстанавливаем события для текста (double-click, hover) */
}

/* Кнопка закрытия (крестик) - вынесена за пределы контейнера */
.link-card__name-close {
    position: absolute;
    top: 50%;
    right: -18px; /* Вынесен за пределы контейнера */
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #999;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    pointer-events: auto; /* Восстанавливаем события для кнопки закрытия */
}

.link-card__name-label:hover .link-card__name-close {
    opacity: 1;
}

.link-card__name-close:hover {
    color: #e74c3c;
}

/* Поле ввода для редактирования названия */
.link-card__name-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid #3498db;
    border-radius: 3px;
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
    outline: none;
    box-sizing: border-box;
}

/* ========================================== */
/* TEXT ICON MARKER - ВИЗУАЛЬНАЯ ПОМЕТКА      */
/* ========================================== */

/* Маркер для текстовых иконок - белый прямоугольник (как у приложений) */
.link-card__text-marker {
    position: absolute;
    bottom: -4px;
    right: -4px;
    background: rgba(255, 255, 255, 0.95);
    color: #1a6b6d;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px;
    font-weight: bold;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    z-index: 10;
    line-height: 1;
}



/* ========================================== */
/* HIGHLIGHTED ICON - ВЫДЕЛЕННАЯ ИКОНКА       */
/* ========================================== */

/* Жёлтое свечение вокруг выделенной иконки */
.link-card--highlighted .link-card__icon-wrapper {
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.9), 0 0 10px 3px rgba(255, 193, 7, 0.5);
    border-radius: 12px;
    animation: highlight-pulse 2.5s ease-in-out infinite;
}

@keyframes highlight-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.9), 0 0 10px 3px rgba(255, 193, 7, 0.4); }
    50%       { box-shadow: 0 0 0 2px rgba(255, 193, 7, 1),   0 0 18px 5px rgba(255, 193, 7, 0.7); }
}

/* Значок звезды в левом нижнем углу */
.link-card__highlight-badge {
    position: absolute;
    bottom: -6px;
    left: -6px;
    width: 18px;
    height: 18px;
    background: #fff9c4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    z-index: 15;
    pointer-events: none;
    line-height: 1;
}

/* ========================================== */
/* RESPONSIVE - МОБИЛЬНАЯ АДАПТАЦИЯ           */
/* ========================================== */

/* Touch-layout: ≤880px или планшет landscape с touch (881–1024px, pointer: coarse) */
@media (max-width: 880px), ((min-width: 881px) and (max-width: 1024px) and (pointer: coarse)) {
    /* Когда открыта папка — добавляем отступ сверху под хлебные крошки */
    .storage__card--in-folder .storage__links-container {
        padding-top: 46px !important; /* 38px высота крошек + 8px зазор */
        top: 0 !important;
    }

    /* Контейнер - переключаем на flex layout */
    .storage__links-container {
        position: static !important;
        display: flex !important;
        flex-wrap: wrap;
        gap: 12px;
        padding: 15px;
        padding-bottom: 175px; /* Защитная зона для storage-controls: 3 строки кнопок (добавить + текст/файлы + действия) */
        align-items: flex-start;
        align-content: flex-start;
        justify-content: flex-start;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        overflow-x: clip;
        overflow-y: visible;
    }

    /* Карточка - убираем absolute positioning */
    /* ВАЖНО: position: relative нужен для правильного позиционирования tooltip и кнопки настроек */
    .link-card {
        position: relative !important;
        /* Фиксированная ширина = max-width названия иконки (74px).
           Без неё карточка сужается когда название скрыто, и иконки "прилипают".
           Отступ между иконками должен быть стабильным независимо от видимости названия. */
        width: 74px;
        cursor: pointer;
        /* Убираем динамические top/left от JS */
        top: auto !important;
        left: auto !important;
        transform: none !important;
    }

    /* Отключаем десктопный dragging на мобильных */
    .link-card.dragging {
        opacity: 1;
        z-index: 1;
    }

    /* Мобильное перетаскивание — карточка «поднимается» над сеткой */
    .link-card.touch-dragging {
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28) !important;
        cursor: grabbing !important;
    }

    /* Иконка-цель для дропа — подсвечиваем куда можно поменяться */
    .link-card.touch-drop-target {
        outline: 2px dashed #1a6b6d !important;
        outline-offset: 4px !important;
        border-radius: 14px !important;
        opacity: 0.6 !important;
    }

    /* Во время touch-drag полностью скрываем подсказки, чтобы не перекрывали зоны дропа */
    .link-card.touch-dragging .link-card__tooltip,
    .link-card.touch-drop-target .link-card__tooltip {
        opacity: 0 !important;
        display: none !important;
    }

    /* Обертка - увеличиваем размер для touch */
    .link-card__icon-wrapper {
        width: 54px;
        height: 54px;
    }

    /* Иконка - увеличиваем для удобства tap */
    .link-card__icon {
        width: 54px;
        height: 54px;
    }

    /* Иконка по умолчанию */
    .link-card__default-icon {
        width: 54px;
        height: 54px;
        font-size: 38px;
    }

    /* Tooltip - увеличиваем */
    .link-card__tooltip {
        font-size: 13px;
        padding: 12px 16px;
        max-width: 270px;
    }

    .link-card__tooltip-description {
        font-size: 12px;
        max-width: 240px;
    }

    .link-card__tooltip-url {
        font-size: 12px;
    }

    /* Кнопка настроек - увеличиваем для touch */
    /* ВАЖНО: z-index выше tooltip (1100), чтобы кнопка была кликабельной */
    .link-card__settings-btn {
        top: -12px;
        right: -12px;
        width: 26px;
        height: 26px;
        z-index: 1100;
    }

    /* Скрываем кнопку настроек на мобильных по умолчанию */
    .link-card .link-card__settings-btn {
        opacity: 0;
        pointer-events: none;
    }

    /* Показываем кнопку и tooltip когда карточка активна (после первого клика) */
    .link-card.touch-active .link-card__settings-btn {
        opacity: 1;
        pointer-events: auto;
    }

    .link-card.touch-active .link-card__tooltip {
        opacity: 1;
    }

    .link-card__settings-btn svg {
        width: 15px;
        height: 15px;
    }

    /* URL метка */
    .link-card__url-label {
        font-size: 11px;
        bottom: -16px;
        padding: 2px 4px;
    }

    /* Название иконки — переключаем на статичное позиционирование,
       иначе абсолютный элемент не добавляет высоту flex-item и
       название перекрывает иконки нижнего ряда */
    .link-card__name-label {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        width: max-content;
        max-width: 74px;
        margin-top: 4px;
        font-size: var(--icon-name-font-size, 12px);
    }

    .link-card__name-text {
        padding: 3px 5px;
    }

    .link-card__name-close {
        width: 16px;
        height: 16px;
        right: -20px;
        font-size: 14px;
        opacity: 1; /* На мобильных крестик всегда виден */
    }

    .storage__card {
        overflow-x: clip;
    }

    .link-card.touch-active {
        z-index: 200;
    }

    .link-card.touch-active .link-card__tooltip {
        max-width: min(260px, calc(100vw - 32px));
    }
}

/* Второй диапазон: от 490px до 340px */
/* Компактный режим для маленьких экранов */
@media (max-width: 490px) {
    /* Контейнер - меньше gap и padding */
    .storage__links-container {
        gap: 10px;
        padding: 12px;
        padding-bottom: 155px; /* Защитная зона для storage-controls: 3 строки компактных кнопок (добавить + текст/файлы + действия) */
    }

    /* Карточка - компактный размер, ширина = max-width названия для ≤490px */
    .link-card {
        width: 62px;
    }

    /* Обертка - компактный размер */
    .link-card__icon-wrapper {
        width: 50px;
        height: 50px;
    }

    /* Иконка - компактный размер */
    .link-card__icon {
        width: 50px;
        height: 50px;
    }

    /* Иконка по умолчанию - компактный размер */
    .link-card__default-icon {
        width: 50px;
        height: 50px;
        font-size: 34px;
    }

    /* Tooltip - компактный размер */
    .link-card__tooltip {
        font-size: 12px;
        padding: 10px 14px;
        max-width: 240px;
    }

    .link-card__tooltip-description {
        font-size: 11px;
        max-width: 210px;
    }

    .link-card__tooltip-url {
        font-size: 11px;
    }

    /* Кнопка настроек - компактный размер */
    /* ВАЖНО: z-index выше tooltip (1100), чтобы кнопка была кликабельной */
    .link-card__settings-btn {
        top: -10px;
        right: -10px;
        width: 24px;
        height: 24px;
        z-index: 1100;
    }

    .link-card__settings-btn svg {
        width: 14px;
        height: 14px;
    }

    /* URL метка */
    .link-card__url-label {
        font-size: 10px;
        bottom: -15px;
        padding: 1px 3px;
    }

    /* Название иконки - уменьшаем max-width для компактных экранов */
    .link-card__name-label {
        max-width: 62px;
    }
}
