/* ==========================================
   LINK CATALOG — Блок №8: интерактивный каталог
   v3.0
   ==========================================
   1. .links-catalog           — секция
   2. .links-catalog__expanded — развёрнутый вид
   3. .links-catalog__fab      — свёрнутая кнопка ~150×150
   4. .lc-col / .lc-cat        — колонки и категории
   5. .lc-item                 — иконка-ссылка + меню + quick-add
   ========================================== */

.links-catalog {
    --lc-ink: #0f4446;
    --lc-accent: #1a6b6d;
    --lc-accent-soft: rgba(26, 107, 109, 0.1);
    --lc-line: rgba(15, 68, 70, 0.12);
    --lc-surface: #f7faf9;
    --lc-panel: #ffffff;
    --lc-quick: #29abe2;

    /* Как у хранилища / виджетов — без расширения шире storage */
    margin: 36px auto 48px;
    max-width: 1000px;
    width: 100%;
}

/* ---------- Развёрнутый вид ---------- */
/* Без собственного градиента — сквозь блок виден единый фон страницы */

.links-catalog__expanded {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 8px 0 12px;
    box-shadow: none;
    overflow: visible;
    animation: lcExpandIn 0.35s ease;
}

@keyframes lcExpandIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.links-catalog.is-collapsed .links-catalog__expanded {
    display: none;
}

.links-catalog__header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px 20px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--lc-line);
}

.links-catalog__tools {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    min-width: min(320px, 100%);
}

.links-catalog__collapse-mini {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid rgba(26, 107, 109, 0.28);
    background: rgba(255, 255, 255, 0.72);
    color: var(--lc-accent);
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.links-catalog__collapse-mini:hover {
    background: var(--lc-accent);
    border-color: var(--lc-accent);
    color: #fff;
}

.links-catalog__title {
    margin: 0;
    font-size: clamp(1.6rem, 2.4vw, 2.1rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--lc-ink);
    line-height: 1.2;
}

.links-catalog__subtitle {
    margin: 8px 0 0;
    max-width: 42ch;
    font-size: 14px;
    line-height: 1.45;
    color: color-mix(in srgb, var(--lc-ink) 72%, transparent);
}

.links-catalog__search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid var(--lc-line);
    color: var(--lc-accent);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.links-catalog__search:focus-within {
    border-color: rgba(26, 107, 109, 0.45);
    box-shadow: 0 0 0 3px var(--lc-accent-soft);
}

.links-catalog__search-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: var(--lc-ink);
}

.links-catalog__search-input::placeholder {
    color: rgba(15, 68, 70, 0.45);
}

/* ---------- 3 колонки ---------- */

.links-catalog__columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 14px;
    align-items: start;
}

.lc-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.lc-cat {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--lc-line);
    border-radius: 14px;
    padding: 10px 8px 8px;
    overflow: visible;
    transition: box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.lc-cat:hover {
    box-shadow: 0 8px 24px rgba(15, 68, 70, 0.08);
    border-color: var(--lc-accent);
    background: rgba(255, 255, 255, 0.68);
}

.lc-cat.is-filtered-out {
    display: none;
}

.lc-cat__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 2px 8px;
    border-bottom: 1px dashed var(--lc-line);
}

.lc-cat__icon {
    font-size: 18px;
    line-height: 1;
}

.lc-cat__name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--lc-ink);
    letter-spacing: 0.01em;
}

.lc-cat__count {
    font-weight: 400;
    color: rgba(15, 68, 70, 0.5);
    margin-left: 4px;
    font-size: 13px;
}

.lc-cat__add-tab {
    flex-shrink: 0;
    border: 1px solid rgba(26, 107, 109, 0.28);
    background: var(--lc-accent-soft);
    color: var(--lc-accent);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.lc-cat__add-tab:hover {
    background: var(--lc-accent);
    color: #fff;
}

.lc-cat__add-tab.added {
    background: #2e7d32;
    border-color: #2e7d32;
    color: #fff;
}

.lc-cat__body {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.lc-cat__grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    /* вертикаль без изменений; горизонталь — плотнее */
    gap: 4px 0;
    overflow: visible;
}

/* Подсветка подраздела (группа иконок) — плотнее фона, чтобы читалась поверх hover всего .lc-cat */
.lc-item.is-subcat-hot {
    background: rgba(255, 255, 255, 0.62);
    border-radius: 10px;
    box-shadow: 0 0 0 1px rgba(26, 107, 109, 0.22);
}

.lc-item.is-subcat-hot[data-subcat-edge="start"] {
    box-shadow:
        0 0 0 1px rgba(26, 107, 109, 0.22),
        inset 3px 0 0 var(--lc-accent);
}

.lc-item.is-subcat-hot[data-subcat-edge="end"] {
    box-shadow:
        0 0 0 1px rgba(26, 107, 109, 0.22),
        inset -3px 0 0 var(--lc-accent);
}

.lc-item.is-subcat-hot[data-subcat-edge="both"] {
    box-shadow:
        0 0 0 1px rgba(26, 107, 109, 0.22),
        inset 3px 0 0 var(--lc-accent),
        inset -3px 0 0 var(--lc-accent);
}

/* ---------- Иконка ссылки ---------- */

.lc-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px 0 2px;
    border-radius: 10px;
    cursor: default;
    user-select: none;
    min-width: 0;
    transition: background 0.15s ease, transform 0.18s ease;
}

.lc-item:hover,
.lc-item.is-active {
    background:  rgba(255, 255, 255, 0.42);
    transform: translateY(-1px);
    z-index: 40;
}

.lc-item.is-filtered-out {
    display: none;
}

.lc-item__icon-wrap {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: linear-gradient(160deg, #fff 0%, #eef5f4 100%);
    border: 1px solid var(--lc-line);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(15, 68, 70, 0.05);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    overflow: visible;
}

.lc-item:hover .lc-item__icon-wrap,
.lc-item.is-active .lc-item__icon-wrap {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(15, 68, 70, 0.1);
}

.lc-item__favicon {
    width: 26px;
    height: 26px;
    object-fit: contain;
    border-radius: 4px;
}

.lc-item__favicon-fallback {
    display: none;
    font-size: 14px;
    line-height: 1;
}

.lc-item__label {
    max-width: 100%;
    width: 100%;
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    color: rgba(15, 68, 70, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    min-width: 0;
}

.lc-item__label-line {
    display: block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-align: center;
}

/* Quick-add — как в хранилище */
.lc-item__quick {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 30%;
    background: var(--lc-quick);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.15s ease;
    z-index: 6;
    padding: 0;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.lc-item:hover .lc-item__quick,
.lc-item.is-active .lc-item__quick {
    opacity: 1;
    pointer-events: auto;
}

.lc-item__quick:hover {
    transform: scale(1.2);
}

.lc-item__quick.added {
    background: #2e7d32;
    opacity: 1;
    pointer-events: auto;
}

/* Подсказка — как у иконок в хранилище, чуть менее прозрачная */
.lc-item__tooltip {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 18px);
    transform: translateX(-50%);
    background-color: rgba(255, 255, 255, 0.99);
    color: #000000;
    min-width: 150px;
    max-width: 220px;
    width: max-content;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.lc-item__tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: rgba(255, 255, 255, 0.99);
}

.lc-item__tooltip-name {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #000000;
}

.lc-item__tooltip-desc {
    display: block;
    font-size: 11px;
    opacity: 0.9;
    word-break: break-word;
    overflow-wrap: break-word;
    color: #000000;
}

.lc-item__tooltip-subcat {
    display: block;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 11px;
    font-weight: 600;
    color: #1a6b6d;
}

.lc-item:hover .lc-item__tooltip {
    opacity: 1;
}

/* Меню: от правого нижнего угла иконки, на 5px ближе (выше и левее); только после клика */
.lc-item__menu {
    position: absolute;
    top: 100%;
    left: 100%;
    right: auto;
    bottom: auto;
    transform: translate(-5px, -5px) scale(0.98);
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 160px;
    padding: 4px 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 25;
}

.lc-item.is-active .lc-item__menu {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-5px, -5px) scale(1);
}

.lc-item__menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-dark, #333);
    font-size: 13px;
    font-weight: 400;
    text-align: left;
    padding: 5px 12px;
    border-radius: 0;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    box-sizing: border-box;
    transition: background-color 0.1s ease;
}

a.lc-item__menu-btn {
    color: var(--text-dark, #333);
}

.lc-item__menu-btn:hover {
    background-color: rgba(26, 107, 109, 0.1);
    color: var(--text-dark, #333);
}

.lc-item__menu-btn:active {
    background-color: rgba(26, 107, 109, 0.2);
}

.lc-item__menu-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    line-height: 1;
}

.lc-item__menu-text {
    flex: 1;
    min-width: 0;
}

.lc-item__menu-btn.added {
    color: #2e7d32;
}

/* ---------- Подвал развёрнутого вида ---------- */

.links-catalog__footer {
    display: flex;
    justify-content: center;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--lc-line);
}

.links-catalog__collapse-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(26, 107, 109, 0.3);
    background: rgba(255, 255, 255, 0.82);
    color: var(--lc-accent);
    border-radius: 999px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.links-catalog__collapse-btn:hover {
    background: var(--lc-accent);
    color: #fff;
    transform: translateY(-1px);
}

/* ---------- Свёрнутая FAB ~150×150 ---------- */

.links-catalog__fab {
    display: none;
    width: 150px;
    height: 150px;
    margin: 8px auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.28);
    backdrop-filter: blur(14px) saturate(1.35);
    -webkit-backdrop-filter: blur(14px) saturate(1.35);
    color: var(--lc-ink);
    cursor: pointer;
    box-shadow:
        0 8px 28px rgba(15, 68, 70, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.65);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    animation: lcFabIn 0.3s ease;
}

.links-catalog.is-collapsed .links-catalog__fab {
    display: flex;
}

.links-catalog__fab[hidden] {
    display: none !important;
}

.links-catalog.is-collapsed .links-catalog__fab[hidden] {
    display: flex !important;
}

@keyframes lcFabIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.links-catalog__fab:hover {
    transform: translateY(-3px) scale(1.03);
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.75);
    box-shadow:
        0 14px 36px rgba(15, 68, 70, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.links-catalog__fab-icon {
    opacity: 0.9;
    color: var(--lc-accent);
}

.links-catalog__fab-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center;
    line-height: 1.25;
    max-width: 7.5em;
    color: var(--lc-ink);
}

.links-catalog__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: rgba(15, 68, 70, 0.55);
    font-size: 14px;
}

/* ---------- Адаптив ---------- */

@media (max-width: 960px) {
    .links-catalog__columns {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .links-catalog {
        margin: 24px auto 36px;
    }

    .links-catalog__expanded {
        padding: 4px 0 10px;
    }

    .links-catalog__columns {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .lc-cat__grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px 0;
    }

    .links-catalog__header {
        margin-bottom: 14px;
    }

    .links-catalog__tools {
        width: 100%;
        min-width: 0;
        align-items: stretch;
    }

    .links-catalog__collapse-mini {
        align-self: flex-end;
    }

    .links-catalog__search {
        width: 100%;
        min-width: 0;
    }

    /* На тач: полное описание при первом тапе; меню и quick тоже */
    .lc-item__tooltip {
        display: block;
        opacity: 0;
        pointer-events: none;
    }

    .lc-item.is-active .lc-item__tooltip {
        opacity: 1;
    }

    .lc-item__quick {
        opacity: 0;
        pointer-events: none;
    }

    .lc-item.is-active .lc-item__quick {
        opacity: 1;
        pointer-events: auto;
    }

    .lc-item__menu {
        opacity: 0;
        pointer-events: none;
    }

    .lc-item.is-active .lc-item__menu {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (hover: none) {
    .lc-item__tooltip {
        opacity: 0;
        pointer-events: none;
    }

    .lc-item.is-active .lc-item__tooltip {
        opacity: 1;
    }
}
