/* =========================================================
   SireaFly — custom styles on top of Bootstrap 5
   ========================================================= */

:root,
[data-bs-theme="light"] {
    --sf-radius: .75rem;
    --sf-shadow: 0 .5rem 1.5rem rgba(16, 24, 40, .08);
    --sf-hero-from: #0d6efd;
    --sf-hero-to: #6610f2;

    /* Surfaces */
    --sf-body-bg: #fff;
    --sf-surface: #fff;
    --sf-surface-muted: #f8f9fa;
    --sf-surface-sunken: #f1f3f5;
    --sf-admin-bg: #f4f6f9;
    --sf-border: rgba(0, 0, 0, .06);
    --sf-border-strong: rgba(0, 0, 0, .12);

    /* Chrome */
    --sf-navbar-bg: rgba(255, 255, 255, .92);
    --sf-navbar-brand: #111;
    --sf-nav-link: #444;
    --sf-footer-link: #495057;

    /* Accents */
    --sf-tag-bg: #eef2f7;
    --sf-tag-color: #334;
    --sf-donate-banner: linear-gradient(135deg, #fff5f6, #fdeef6);
}

[data-bs-theme="dark"] {
    --sf-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .45);
    --sf-hero-from: #0a4bb3;
    --sf-hero-to: #4a0fb0;

    --sf-body-bg: #12151a;
    --sf-surface: #1a1f27;
    --sf-surface-muted: #1e242e;
    --sf-surface-sunken: #232934;
    --sf-admin-bg: #0f1216;
    --sf-border: rgba(255, 255, 255, .1);
    --sf-border-strong: rgba(255, 255, 255, .18);

    --sf-navbar-bg: rgba(18, 21, 26, .92);
    --sf-navbar-brand: #f1f3f5;
    --sf-nav-link: #adb5bd;
    --sf-footer-link: #adb5bd;

    --sf-tag-bg: #2a313d;
    --sf-tag-color: #ced4da;
    --sf-donate-banner: linear-gradient(135deg, #2a1b21, #2a1826);

    /* Bootstrap surface overrides so cards/inputs sit on our palette */
    --bs-body-bg: #12151a;
    --bs-body-bg-rgb: 18, 21, 26;
    --bs-tertiary-bg: #1e242e;
    --bs-tertiary-bg-rgb: 30, 36, 46;
    --bs-secondary-bg: #232934;
    --bs-secondary-bg-rgb: 35, 41, 52;
    --bs-border-color: rgba(255, 255, 255, .12);
    --bs-border-color-translucent: rgba(255, 255, 255, .1);
}

html { color-scheme: light; }
[data-bs-theme="dark"] { color-scheme: dark; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--sf-body-bg);
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
    position: absolute;
    top: .5rem;
    left: .5rem;
    z-index: 1080;
    background: var(--sf-surface);
    color: var(--bs-body-color);
    padding: .5rem 1rem;
    border-radius: .5rem;
}

/* ---------- Navbar ---------- */
.sf-navbar {
    background: var(--sf-navbar-bg);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--sf-border);
}
.sf-navbar .navbar-brand { color: var(--sf-navbar-brand); }
.sf-navbar .nav-link { color: var(--sf-nav-link); font-weight: 500; }
.sf-navbar .nav-link.active,
.sf-navbar .nav-link:hover { color: var(--bs-primary); }
.sf-nav-search { min-width: 240px; }

/* ---------- Hero ---------- */
.sf-hero {
    background: linear-gradient(135deg, var(--sf-hero-from), var(--sf-hero-to));
    position: relative;
    overflow: hidden;
}
.sf-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.18), transparent 45%),
                      radial-gradient(circle at 80% 0%, rgba(255,255,255,.12), transparent 40%);
    pointer-events: none;
}
.sf-hero .container { position: relative; z-index: 1; }
.sf-hero-search { max-width: 680px; }
.sf-hero-search .input-group { border-radius: 999px; overflow: hidden; }
.sf-hero-tag {
    color: #fff;
    background: rgba(255, 255, 255, .18);
    border-radius: 999px;
    padding: .15rem .7rem;
    margin: 0 .15rem .3rem 0;
    display: inline-block;
    font-size: .82rem;
}
.sf-hero-tag:hover { background: rgba(255, 255, 255, .32); text-decoration: none; }

/* ---------- Donation button ---------- */
.btn-donate {
    background: linear-gradient(135deg, #ff5f6d, #ff2d55);
    border: none;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 .35rem .9rem rgba(255, 45, 85, .28);
}
.btn-donate:hover,
.btn-donate:focus {
    background: linear-gradient(135deg, #ff4757, #e0214a);
    color: #fff;
    box-shadow: 0 .5rem 1.1rem rgba(255, 45, 85, .38);
    text-decoration: none;
}
.btn-donate i { margin-right: .25rem; }

.sf-donate-banner {
    background: var(--sf-donate-banner);
    border: 1px solid rgba(255, 45, 85, .15);
}

.sf-resolutions .list-group-item { border-color: var(--sf-border); }
.sf-resolutions .list-group-item:hover { background: var(--sf-surface-muted); }

.sf-color-dot {
    display: inline-block;
    width: .8rem;
    height: .8rem;
    border-radius: 50%;
    border: 1px solid var(--sf-border-strong);
    vertical-align: middle;
    margin: 0 .25rem;
}

.sf-repeater-row { background: var(--sf-surface-muted); }

/* ---------- Wallpaper masonry ---------- */
/* CSS multi-column packing: the tiles keep each image's real aspect ratio and
   flow into whichever column has room, with no fixed row heights and no JS.
   Front-end only — the admin tables never use .sf-grid. */
.sf-grid {
    column-count: 2;
    column-gap: .6rem;
}
.sf-grid > * {
    /* A tile must never be split across a column boundary. */
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    display: block;
    width: 100%;
    margin-bottom: .6rem;
}

@media (min-width: 768px) {
    .sf-grid { column-count: 3; column-gap: 1rem; }
    .sf-grid > * { margin-bottom: 1rem; }
}
@media (min-width: 992px) {
    .sf-grid { column-count: 3; column-gap: 1.1rem; }
    .sf-grid > * { margin-bottom: 1.1rem; }
}
@media (min-width: 1200px) {
    .sf-grid { column-count: 4; }
}
@media (min-width: 1400px) {
    .sf-grid { column-count: 5; column-gap: 1.25rem; }
    .sf-grid > * { margin-bottom: 1.25rem; }
}

.sf-card {
    position: relative;
    border-radius: var(--sf-radius);
    overflow: hidden;
    background: var(--sf-surface-sunken);
    box-shadow: var(--sf-shadow);
}
/* The card is a Bootstrap .card, i.e. a column flex container, so this box is
   a flex item: min-height:auto would let a tall (portrait) image push it past
   the aspect ratio and every tile in the row would get a different height.
   Pinning min-height and taking the image out of flow keeps all tiles identical. */
.sf-card-media {
    position: relative;
    display: block;
    /* Fallback only — the card sets the image's real ratio inline. */
    aspect-ratio: 16 / 10;
    flex: 0 0 auto;
    min-height: 0;
    overflow: hidden;
}
.sf-card-media img,
.sf-card-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.sf-card-media img {
    object-fit: cover;
    object-position: center;
    transition: transform .4s ease;
    border-radius: 0;
}
.sf-card:hover .sf-card-media img { transform: scale(1.06); }
.sf-card-placeholder { background: var(--sf-surface-muted); }

.sf-card-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 2.5rem .75rem .6rem;
    background: linear-gradient(to top, rgba(0, 0, 0, .78), transparent);
    color: #fff;
    opacity: 0;
    transition: opacity .25s ease;
}
.sf-card:hover .sf-card-overlay,
.sf-card:focus-within .sf-card-overlay { opacity: 1; }
.sf-card-title {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sf-card-meta { font-size: .75rem; opacity: .85; }

.sf-badge-quality,
.sf-badge-featured {
    position: absolute;
    top: .5rem;
    border-radius: 999px;
    font-size: .72rem;
    padding: .1rem .55rem;
    color: #fff;
    background: rgba(0, 0, 0, .6);
}
.sf-badge-quality { left: .5rem; font-weight: 600; letter-spacing: .02em; }
.sf-badge-featured { right: .5rem; background: #ffc107; color: #212529; }

/* Downloadable sizes, listed on the tile itself. Fades out on hover so it
   never fights the title overlay for the same corner. */
.sf-card-sizes {
    position: absolute;
    left: .5rem;
    bottom: .5rem;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    max-width: calc(100% - 1rem);
    transition: opacity .25s ease;
}
.sf-size-chip {
    background: rgba(0, 0, 0, .62);
    backdrop-filter: blur(2px);
    color: #fff;
    font-size: .68rem;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: .02em;
    padding: .05rem .4rem;
    border-radius: 999px;
    white-space: nowrap;
}
.sf-card:hover .sf-card-sizes,
.sf-card:focus-within .sf-card-sizes { opacity: 0; }

.sf-card-download {
    position: absolute;
    right: .5rem;
    bottom: .5rem;
    opacity: 0;
    transform: translateY(6px);
    transition: all .25s ease;
    border-radius: 999px;
}
.sf-card:hover .sf-card-download,
.sf-card:focus-within .sf-card-download { opacity: 1; transform: none; }

/* ---------- Category tiles ---------- */
.sf-category-tile {
    background: var(--sf-surface-muted);
    border: 1px solid var(--sf-border);
    color: inherit;
    transition: all .2s ease;
}
.sf-category-tile:hover {
    background: var(--sf-surface);
    box-shadow: var(--sf-shadow);
    transform: translateY(-2px);
    text-decoration: none;
}

/* ---------- Tags ---------- */
.sf-tag {
    background: var(--sf-tag-bg);
    color: var(--sf-tag-color);
    font-weight: 500;
    margin: 0 .25rem .35rem 0;
    padding: .4rem .7rem;
    border-radius: 999px;
}
.sf-tag:hover { background: var(--bs-primary); color: #fff; }

/* ---------- Detail page ---------- */
.sf-detail-stage {
    background: var(--sf-surface-sunken);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
}
.sf-detail-stage img { max-height: 78vh; object-fit: contain; }
.sf-meta-list .list-group-item { padding-left: 0; padding-right: 0; border-color: var(--sf-border); }

/* ---------- Filters ---------- */
.sf-filters .form-control,
.sf-filters .form-select { border-radius: .5rem; }

/* ---------- Footer ---------- */
.sf-footer { background: var(--sf-surface-muted); border-top: 1px solid var(--sf-border); }
.sf-footer a { color: var(--sf-footer-link); }
.sf-footer a:hover { color: var(--bs-primary); }

/* ---------- Back to top ---------- */
.sf-back-to-top {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: none;
    z-index: 1030;
    box-shadow: var(--sf-shadow);
}
.sf-back-to-top.show { display: block; }

/* =========================================================
   Login + Admin
   ========================================================= */
.sf-login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--sf-hero-from), var(--sf-hero-to));
}

.sf-admin { background: var(--sf-admin-bg); }
.sf-sidebar {
    width: 250px;
    min-height: calc(100vh - 56px);
    background: var(--sf-surface);
    border-right: 1px solid var(--sf-border);
    position: sticky;
    top: 56px;
    align-self: flex-start;
}
.sf-sidebar .nav-link {
    color: var(--bs-body-color);
    border-radius: .5rem;
    padding: .55rem .75rem;
    margin-bottom: .15rem;
    font-weight: 500;
}
.sf-sidebar .nav-link i { width: 1.25rem; }
.sf-sidebar .nav-link:hover { background: var(--sf-surface-sunken); }
.sf-sidebar .nav-link.active { background: var(--bs-primary); color: #fff; }
.sf-admin-main { min-width: 0; }

.sf-stat-icon { font-size: 1.75rem; line-height: 1; }
.sf-thumb-sm {
    width: 56px;
    height: 42px;
    object-fit: cover;
    border-radius: .35rem;
    flex-shrink: 0;
}
.sf-preview-box {
    max-width: 100%;
    max-height: 220px;
    border-radius: .5rem;
    border: 1px solid var(--sf-border-strong);
}
.min-w-0 { min-width: 0; }

/* =========================================================
   Theme toggle + dark-mode refinements
   ========================================================= */
.sf-theme-toggle .dropdown-menu { min-width: 9rem; }
.sf-theme-toggle .dropdown-item i { width: 1rem; }
.sf-theme-toggle .dropdown-item.active,
.sf-theme-toggle .dropdown-item:active {
    background-color: var(--bs-primary);
    color: #fff;
}
.sf-theme-toggle .dropdown-toggle::after { margin-left: .4rem; }

/* Avoid a white flash on the very first paint before CSS variables resolve. */
[data-bs-theme="dark"] body { background-color: var(--sf-body-bg); }

[data-bs-theme="dark"] .sf-navbar .navbar-brand { color: var(--sf-navbar-brand); }
[data-bs-theme="dark"] .sf-navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255,255,255,0.65%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
[data-bs-theme="dark"] .sf-navbar .navbar-toggler { border-color: var(--sf-border-strong); }

[data-bs-theme="dark"] .sf-badge-featured { background: #ffc107; color: #212529; }

[data-bs-theme="dark"] .sf-card { background: var(--sf-surface-sunken); }
[data-bs-theme="dark"] .sf-detail-stage { background: var(--sf-surface-sunken); }

[data-bs-theme="dark"] .sf-tag:hover { color: #fff; }

/* Bootstrap utility classes that hardcode a light surface. */
[data-bs-theme="dark"] .bg-white { background-color: var(--sf-surface) !important; }
[data-bs-theme="dark"] .text-bg-light {
    background-color: var(--sf-surface-sunken) !important;
    color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .sf-footer { background: var(--sf-surface-muted); }

/* Login screen keeps its gradient; the card follows the theme. */
[data-bs-theme="dark"] .sf-login-body { background: linear-gradient(135deg, #0a1020, #1a0a2e); }

.sf-thead th {
    background-color: var(--sf-surface-muted);
    color: var(--bs-secondary-color);
    font-weight: 600;
}

@media print {
    .sf-navbar, .sf-footer, .sf-back-to-top, .sf-sidebar { display: none !important; }
}

/* Cookie consent banner & modal */
.sf-cookie-banner {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    max-width: 440px;
    z-index: 1080;
    background: var(--sf-surface);
    border: 1px solid var(--sf-border-strong);
    border-radius: var(--sf-radius);
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    padding: 1.25rem;
    animation: sfSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-bs-theme="dark"] .sf-cookie-banner {
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.65);
}

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

@media (max-width: 575.98px) {
    .sf-cookie-banner {
        bottom: 0;
        right: 0;
        left: 0;
        max-width: 100%;
        border-radius: var(--sf-radius) var(--sf-radius) 0 0;
        border-bottom: 0;
        padding: 1.1rem;
    }
}

.sf-cookie-category {
    background: var(--sf-surface-muted);
    border-color: var(--sf-border) !important;
}

.sf-cookie-table th,
.sf-cookie-table td {
    font-size: 0.8125rem;
    padding: 0.35rem 0.5rem;
    background: transparent;
}

.cursor-pointer {
    cursor: pointer;
}
