/* ==========================================================
   InstaFeed – Stylesheet v1.1
   ========================================================== */

/* ---- CSS Custom Properties (per-instance via inline style) ---- */
.instafeed-wrapper {
    --if-gap:    6px;
    --if-radius: 0px;
    --if-cols:   3;
    --if-bg:     transparent;

    width: 100%;
    margin: 0 auto;
    background: var(--if-bg);
    font-family: inherit;
}

/* ---- Dark scheme ---- */
.instafeed-dark {
    --if-bg: #111;
    color: #fff;
}
.instafeed-dark .instafeed-header { border-color: #333; }
.instafeed-dark .instafeed-btn--load-more { color: #fff; }
.instafeed-dark .instafeed-footer { border-color: #333; }

/* ==========================================================
   Header
   ========================================================== */
.instafeed-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 0 14px;
    margin-bottom: 16px;
    border-bottom: 1px solid #e2e2e2;
}
.instafeed-header__icon {
    flex-shrink: 0;
    background: linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
    color: #fff;
    border-radius: 8px;
    padding: 3px;
}
.instafeed-header__text {
    font-size: 16px;
    font-weight: 700;
}

/* ==========================================================
   Filter Bar
   ========================================================== */
.instafeed-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e2e2;
}
.instafeed-dark .instafeed-filters { border-color: #333; }

.instafeed-filter-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border-radius: var(--if-filter-radius, 999px);
    border: var(--if-filter-border, 2px) solid var(--if-filter-inactive, #50575e);
    background: transparent;
    color: var(--if-filter-inactive, #50575e);
    font-size: var(--if-filter-size, 13px);
    font-weight: 500;
    cursor: pointer;
    transition: border-color .18s, color .18s, background .18s;
    white-space: nowrap;
    line-height: 1;
}
.instafeed-filter-btn:hover {
    border-color: var(--if-filter-active, #c13584);
    color: var(--if-filter-active, #c13584);
}
.instafeed-filter-btn.is-active {
    border-color: var(--if-filter-active, #c13584);
    background: var(--if-filter-active, #c13584);
    color: #fff;
}
.instafeed-dark .instafeed-filter-btn { border-color: #555; color: #bbb; }
.instafeed-dark .instafeed-filter-btn.is-active { background: var(--if-filter-active, #c13584); border-color: var(--if-filter-active, #c13584); color: #fff; }

.instafeed-sort-select {
    margin-left: auto;
    padding: 6px 12px;
    border-radius: var(--if-filter-radius, 999px);
    border: var(--if-filter-border, 2px) solid var(--if-filter-inactive, #50575e);
    background: transparent;
    color: var(--if-filter-inactive, #50575e);
    font-size: var(--if-filter-size, 13px);
    font-weight: 500;
    cursor: pointer;
    line-height: 1;
}
.instafeed-dark .instafeed-sort-select { border-color: #555; color: #bbb; background: transparent; }
.instafeed-dark .instafeed-sort-select option { background: #1a1a1a; color: #fff; }

/* ---- Tag search (autocomplete) ---- */
/* Compact by default; grows smoothly while focused (or while it holds text, so the
   typed text and the clear button stay visible). The row keeps the expanded height so
   the filter bar and the grid below do not jump when the field grows. */
.instafeed-search { flex: 0 0 100%; display: flex; align-items: center; min-height: 50px; }
.instafeed-search__box {
    position: relative;
    width: 220px;
    max-width: 100%;
    transition: width .35s cubic-bezier(.4, 0, .2, 1);
}
/* Animate straight to the real end width (min() keeps narrow screens from finishing early). */
.instafeed-search__box:focus-within,
.instafeed-search.has-value .instafeed-search__box { width: min(440px, 100%); }
.instafeed-search__input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 36px 9px 18px;
    border-radius: var(--if-filter-radius, 999px);
    border: var(--if-filter-border, 2px) solid var(--if-filter-inactive, #50575e);
    background: #fff;
    color: #1d2327;
    font-size: 14px;
    line-height: 1.3;
    transition: padding .35s cubic-bezier(.4, 0, .2, 1), font-size .35s cubic-bezier(.4, 0, .2, 1), border-color .18s;
}
.instafeed-search__box:focus-within .instafeed-search__input,
.instafeed-search.has-value .instafeed-search__input { padding: 12px 42px 12px 20px; font-size: 16px; }
@media (max-width: 768px) {
    /* 16px+ at all times: iOS Safari zooms the page when a smaller field gets focus. */
    .instafeed-search__input { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .instafeed-search__box, .instafeed-search__input { transition: none; }
}
.instafeed-no-results { margin: 8px 0 16px; padding: 24px 0; text-align: center; color: #646970; }
.instafeed-dark .instafeed-no-results { color: #999; }
.instafeed-search__input::placeholder { color: #757575; }
.instafeed-search__input:focus { outline: none; border-color: var(--if-filter-active, #c13584); }
.instafeed-search__clear {
    display: none;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #50575e;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.instafeed-search__clear:hover { color: var(--if-filter-active, #c13584); }
.instafeed-search.has-value .instafeed-search__clear { display: block; }
.instafeed-search__list {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    margin: 0;
    padding: 4px;
    list-style: none;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    max-height: 300px;
    overflow-y: auto;
}
.instafeed-search__list[hidden] { display: none; }
.instafeed-search__option,
.instafeed-search__empty {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: #1d2327;
}
.instafeed-search__option { cursor: pointer; }
.instafeed-search__option:hover,
.instafeed-search__option.is-active { background: var(--if-filter-active, #c13584); color: #fff; }
.instafeed-search__count { font-size: 12px; opacity: .7; }
.instafeed-search__empty { color: #646970; cursor: default; }
.instafeed-dark .instafeed-search__input { background: #1e1e1e; color: #eee; border-color: #555; }
.instafeed-dark .instafeed-search__input::placeholder { color: #999; }
.instafeed-dark .instafeed-search__input:focus { border-color: var(--if-filter-active, #c13584); }
.instafeed-dark .instafeed-search__clear { color: #bbb; }
.instafeed-dark .instafeed-search__list { background: #1a1a1a; border-color: #333; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
.instafeed-dark .instafeed-search__option,
.instafeed-dark .instafeed-search__empty { color: #eee; }
.instafeed-dark .instafeed-search__empty { color: #999; }

/* Cells hidden by filter (separate from load-more hidden) */
.instafeed-cell--filtered { display: none !important; }

/* ==========================================================
   Shared Track
   ========================================================== */
.instafeed-cell {
    overflow: hidden;
    border-radius: var(--if-radius);
    background: #efefef;
}
.instafeed-cell--hidden { display: none; }

/* ==========================================================
   Layout: GRID
   ========================================================== */
.instafeed-grid-track {
    display: grid;
    gap: var(--if-gap);
    grid-template-columns: repeat(var(--if-cols), 1fr);
}

/* column shortcuts (fallback for older browsers) */
.instafeed-cols-2 { grid-template-columns: repeat(2, 1fr); }
.instafeed-cols-3 { grid-template-columns: repeat(3, 1fr); }
.instafeed-cols-4 { grid-template-columns: repeat(4, 1fr); }
.instafeed-cols-5 { grid-template-columns: repeat(5, 1fr); }
.instafeed-cols-6 { grid-template-columns: repeat(6, 1fr); }

/* ==========================================================
   Layout: HIGHLIGHT (first cell 2×2)
   ========================================================== */
.instafeed-highlight-track .instafeed-cell--featured {
    grid-column: span 2;
    grid-row:    span 2;
}

/* ==========================================================
   Layout: MASONRY (CSS multi-column)
   ========================================================== */
.instafeed-masonry-track {
    column-count: var(--if-cols);
    column-gap: var(--if-gap);
}
.instafeed-masonry-track .instafeed-cell {
    break-inside: avoid;
    margin-bottom: var(--if-gap);
}
.instafeed-masonry-track .instafeed-thumb {
    aspect-ratio: unset !important;
}
.instafeed-masonry-track .instafeed-thumb img {
    height: auto;
}
/* fallback column counts */
.instafeed-layout-masonry.instafeed-wrapper .instafeed-masonry-track { column-count: var(--if-cols, 3); }

/* ==========================================================
   Layout: CAROUSEL
   ========================================================== */
.instafeed-carousel-wrapper {
    position: relative;
    overflow: hidden;
    padding: 0 40px;
}
.instafeed-carousel-track {
    display: flex;
    gap: var(--if-gap);
    transition: transform 0.38s cubic-bezier(.4,0,.2,1);
    will-change: transform;
}
.instafeed-carousel-track .instafeed-cell {
    /* Width set dynamically by JS (responsive) */
    flex-shrink: 0;
    min-width: 0;
}
.instafeed-carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    padding: 0;
    color: #1d2327;
    transition: background .2s, box-shadow .2s;
}
.instafeed-carousel-btn:hover { background: #f6f7f7; box-shadow: 0 4px 14px rgba(0,0,0,.22); }
.instafeed-carousel-btn[disabled] { opacity: .35; cursor: not-allowed; }
.instafeed-carousel-prev { left: 0; }
.instafeed-carousel-next { right: 0; }

.instafeed-carousel-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding-top: 12px;
}
.instafeed-carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background .2s, transform .2s;
}
.instafeed-carousel-dot.is-active {
    background: #c13584;
    transform: scale(1.25);
}

/* ==========================================================
   Aspect Ratios
   ========================================================== */
.instafeed-ar-square  .instafeed-thumb { aspect-ratio: 1 / 1; }
.instafeed-ar-portrait .instafeed-thumb { aspect-ratio: 4 / 5; }
.instafeed-ar-landscape .instafeed-thumb { aspect-ratio: 16 / 9; }
.instafeed-ar-auto .instafeed-thumb { aspect-ratio: unset; }
.instafeed-ar-auto .instafeed-thumb img { height: auto; position: static; object-fit: unset; }

/* ==========================================================
   Thumb – shared
   ========================================================== */
.instafeed-item {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
.instafeed-thumb {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.instafeed-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.42s ease;
}
.instafeed-item:hover .instafeed-thumb img,
.instafeed-item:focus-visible .instafeed-thumb img {
    transform: scale(1.07);
}

/* ==========================================================
   Overlay / Caption
   ========================================================== */
.instafeed-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 14px 12px;
    background: linear-gradient(to top, rgba(0,0,0,.72) 0%, rgba(0,0,0,0) 55%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.instafeed-item:hover .instafeed-overlay,
.instafeed-item:focus-visible .instafeed-overlay { opacity: 1; }
.instafeed-caption {
    color: #fff;
    font-size: 13px;
    line-height: 1.45;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.instafeed-date {
    color: rgba(255,255,255,.72);
    font-size: 11px;
}

/* ==========================================================
   Badges
   ========================================================== */
.instafeed-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    color: #fff;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,.5));
    pointer-events: none;
    line-height: 0;
}

/* ==========================================================
   Footer – Load More & Follow
   ========================================================== */
.instafeed-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e2e2e2;
}
.instafeed-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 22px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .2s, transform .15s;
    border: 2px solid var(--btn-color, #c13584);
    color: var(--btn-color, #c13584);
    background: transparent;
}
.instafeed-btn:hover { opacity: .82; transform: translateY(-1px); }
.instafeed-btn--follow {
    background: var(--btn-color, #c13584);
    color: #fff;
    border-color: transparent;
}

/* ==========================================================
   Empty / Error
   ========================================================== */
.instafeed-error, .instafeed-empty {
    padding: 12px 16px;
    border-left: 4px solid #d63638;
    background: #fcf0f1;
    color: #1d2327;
    font-size: 14px;
    margin: 8px 0;
}
.instafeed-empty { border-color: #72aee6; background: #f0f6fc; }

/* ==========================================================
   Lightbox
   ========================================================== */
.instafeed-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.instafeed-lightbox[hidden] { display: none; }
.instafeed-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.88);
    cursor: pointer;
}
.instafeed-lightbox__inner {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    max-width: min(92vw, 860px);
    max-height: 92vh;
    width: 100%;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,.5);
    animation: if-fade-in .22s ease;
}
@keyframes if-fade-in {
    from { opacity:0; transform:scale(.96); }
    to   { opacity:1; transform:scale(1); }
}
.instafeed-lightbox__close {
    position: absolute;
    top: 10px; right: 10px;
    z-index: 2;
    background: rgba(255,255,255,.9);
    border: none;
    border-radius: 50%;
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 0; color: #1d2327;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
    transition: background .2s;
}
.instafeed-lightbox__close:hover { background: #fff; }
.instafeed-lightbox__media {
    flex: 1; overflow: hidden;
    background: #000;
    display: flex; align-items: center; justify-content: center;
    min-height: 200px; max-height: 65vh;
}
.instafeed-lightbox__img,
.instafeed-lightbox__video {
    display: block;
    max-width: 100%; max-height: 65vh;
    object-fit: contain; width: auto; height: auto;
}
.instafeed-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: rgba(255,255,255,.9);
    border: none;
    border-radius: 50%;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 0; color: #1d2327;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
    transition: background .2s;
}
.instafeed-lightbox__nav:hover { background: #fff; }
.instafeed-lightbox__nav[hidden] { display: none; }
.instafeed-lightbox__prev { left: 10px; }
.instafeed-lightbox__next { right: 10px; }
.instafeed-lightbox__counter {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    background: rgba(0,0,0,.6);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
}
.instafeed-lightbox__counter[hidden] { display: none; }
.instafeed-lightbox__info {
    padding: 14px 16px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
}
.instafeed-lightbox__caption {
    font-size: 14px; line-height: 1.55; color: #1d2327;
    margin: 0 0 10px; max-height: 90px; overflow-y: auto;
}
.instafeed-lightbox__footer {
    display: flex; align-items: center;
    justify-content: space-between; gap: 12px;
}
.instafeed-lightbox__date { font-size: 12px; color: #787c82; }
.instafeed-lightbox__link {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 13px; font-weight: 600; color: #c13584;
    text-decoration: none; transition: opacity .2s;
}
.instafeed-lightbox__link:hover { opacity: .75; }

/* ==========================================================
   Responsive
   ========================================================== */
@media (max-width: 900px) {
    .instafeed-cols-5,
    .instafeed-cols-6 { grid-template-columns: repeat(4, 1fr); }
    .instafeed-layout-masonry .instafeed-masonry-track { --if-cols: 3 !important; column-count: 3; }
}
@media (max-width: 640px) {
    .instafeed-cols-4,
    .instafeed-cols-5,
    .instafeed-cols-6 { grid-template-columns: repeat(3, 1fr); }
    .instafeed-carousel-wrapper { padding: 0 32px; }
    .instafeed-layout-masonry .instafeed-masonry-track { --if-cols: 2 !important; column-count: 2; }
}
@media (max-width: 420px) {
    .instafeed-grid-track { grid-template-columns: repeat(2, 1fr) !important; }
    .instafeed-lightbox__inner { border-radius: 0; max-width: 100vw; max-height: 100vh; height: 100%; }
}
