
html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    overflow-x: hidden;
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: #eef2f7
}

.container {
    max-width: 100%;
    min-height: 100%;
    margin: 0 auto;
    padding: 24px
}

/* Two-column layout: left sidebar narrow, right content flexible */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 20px;
    align-items: stretch;
    min-height: calc(100dvh - 48px);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-self: start;
}

.traffic-context {
    display: flex;
    min-height: 0;
}

.traffic-context__pill {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.2;
}

.traffic-context__label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.68rem;
    font-weight: 700;
    color: rgba(167, 176, 190, 0.8);
}

.traffic-context__value {
    color: #eef2f7;
    font-weight: 700;
}

.traffic-context__campaign {
    padding-left: 8px;
    margin-left: 2px;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(238, 242, 247, 0.72);
    word-break: break-word;
}

.brand-row {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    min-height: 24px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
}

.brand-mark img {
    display: block;
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.brand {
    font-size: 1.6rem;
    margin: 0;
    font-weight: 800;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    letter-spacing: 0.02em;
    display: inline-block;
    vertical-align: bottom;
    line-height: 1;
    transform: translateY(3px);
}

/* Search form styles */
.search-form {
    position: relative;
    width: 100%;
    max-width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    border-radius: 9999px;
    background: #202124;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 1px 2px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(167, 176, 190, 0.9);
    display: inline-flex;
    align-items: center;
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 40px;
    padding: 0 16px 0 40px;
    /* left padding for icon */
    border: 0;
    border-radius: 9999px;
    background: transparent;
    color: #eef2f7;
    outline: none;
    box-shadow: none;
    appearance: none;
    font-size: 0.95rem;
    line-height: 1;
}

.search-input::placeholder {
    color: rgba(167, 176, 190, 0.55);
}

.search-input:focus {
    outline: none;
}

.content {
    min-width: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}
.grid-shell {
    position: relative;
    min-width: 100%;
    min-height: 100%;
}

.cards-loader {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 160ms ease;
    z-index: 3;
    background: linear-gradient(180deg, rgba(15, 17, 21, 0.18), rgba(15, 17, 21, 0.42));
    backdrop-filter: blur(4px) saturate(0.9);
    -webkit-backdrop-filter: blur(4px) saturate(0.9);
    border-radius: 16px;
}

.cards-loader[data-visible='true'] {
    opacity: 1;
}

.cards-spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(167, 176, 190, 0.2);
    border-top-color: var(--accent);
    border-right-color: rgba(255, 255, 255, 0.65);
    animation: cards-spin 0.85s linear infinite;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03) inset, 0 0 22px rgba(255, 90, 122, 0.12);
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.08) 0 36%, transparent 37%);
}

.grid-shell[aria-busy='true'] .grid {
    opacity: 0.34;
    filter: blur(1.6px) saturate(0.8);
    pointer-events: none;
}

.header {
    display: flex;
    gap: 8px;
    min-height: 32px;
    align-items: center;
}

.input,
.button,
.small {
    padding: 8px 12px;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    color: inherit;
}

.button {
    width: 28px;
    height: 28px;
    background: linear-gradient(180deg, var(--accent), #e54967);
    color: #fff;
    font-weight: 700;
}

.grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 3%;
}

.card {
    background: transparent;
    border-radius: 12px;
    overflow: visible;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 264px;
}

.card .title-wrap {
    width: 100%;
    text-align: center;
    padding: 6px 4px
}

.card .title {
    font-size: 0.85rem;
    margin: 0;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden
}

/* Footer below thumbnail: left-aligned title, same width as thumb */
.card .footer {
    width: 100%;
    max-width: 240px;
    /* match .card .thumb max-width */
    box-sizing: border-box;
    text-align: left;
    padding: 6px 8px 8px 6px;
}

.card .footer .title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    font-size: 0.9rem;
}

.card .thumb {
    position: relative;
    width: 100%;
    max-width: 240px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.98);
}

.card .thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 14px;
    /* don't intercept pointer events so anchor receives clicks */
    pointer-events: none;
    z-index: 1;
}

/* Maintain 9:16 aspect ratio */
.thumb::before {
    content: '';
    display: block;
    padding-top: 177.78%;
}

.thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block
}

/* Make the anchor cover the full thumbnail area so it's fully clickable */
.thumb a,
.thumb .thumb-link {
    position: absolute;
    inset: 0;
    display: block;
    text-decoration: none;
    color: inherit;
    z-index: 2;
    /* ensure anchor sits above overlay */
}

.thumb a img,
.thumb .thumb-link img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.small-muted {
    color: var(--muted)
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center
}

.error {
    color: #ff8aa2
}

@keyframes cards-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Detect device theme and apply appropriate colors */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --panel: #121417;
        --muted: #a7b0be;
        --accent: #ff5a7a;
        color-scheme: dark;
    }

    body {
        background: var(--bg);
        color: #eef2f7
    }
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #ffffff;
        --panel: #f6f7f9;
        --muted: #536277;
        --accent: #ff5a7a;
        color-scheme: light;
    }

    body {
        background: var(--bg);
        color: #0b1220;
    }

    .card .thumb {
        border-color: transparent;
        box-shadow: 0 16px 36px rgba(11, 18, 32, 0.12), 0 4px 14px rgba(11, 18, 32, 0.08);
    }

    .card .footer .title {
        color: #0b1220;
        text-shadow: none;
    }

    .search-input {
        color: #eef2f7;
    }

    .traffic-context__pill {
        border-color: rgba(11, 18, 32, 0.12);
        background: rgba(11, 18, 32, 0.04);
        color: #536277;
    }

    .traffic-context__label {
        color: #6b7280;
    }

    .traffic-context__value {
        color: #0b1220;
    }

    .traffic-context__campaign {
        border-left-color: rgba(11, 18, 32, 0.1);
        color: #475569;
    }
}

/* Responsive: stack sidebar above content on small screens and center cards */
@media (max-width: 700px) {
    .layout {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .sidebar {
        order: 0;
        width: 100%;
    }

    .traffic-context {
        width: 100%;
    }

    .content {
        order: 1;
        width: 100%;
    }

    /* center the cards horizontally in the content area */
    .content .grid {
        justify-content: center;
    }

    .cards-loader {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        z-index: 999;
    }

    .card {
        margin: 6px;
    }
}