/* Andy Search — main stylesheet
   Brand: #0065BF (Saltire Blue) | Accent Light: #1A8FFF
*/

/* ===== Fonts (loaded via <link> in HTML for non-blocking) ===== */

/* ===== Custom Properties (Dark default) ===== */
:root {
    color-scheme: dark;

    --brand: #0065BF;
    --brand-bright: #1A8FFF;
    --brand-dim: #004A8C;
    --brand-glow: rgba(0, 101, 191, 0.18);
    --brand-muted: rgba(0, 101, 191, 0.07);

    --bg: #111111;
    --bg-raised: #191919;
    --bg-surface: #1f1f1f;
    --bg-input: #151515;
    --bg-hover: #282828;

    --text: #e5e5e5;
    --text-2: #999999;
    --text-3: #8a8a8a;

    --link: var(--brand);
    --link-visited: #004A8C;
    --link-hover: var(--brand-bright);
    --url: #5cb85c;

    --warning-bg: rgba(255, 160, 40, 0.07);
    --warning-border: rgba(255, 160, 40, 0.25);
    --warning-text: #ffaa33;

    --border: #272727;
    --border-subtle: #1e1e1e;

    --r-sm: 6px;
    --r: 10px;
    --r-lg: 14px;
    --r-pill: 100px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 20px var(--brand-glow);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-brand: 'Quicksand', var(--font);

    --max-w: 740px;
    --max-w-wide: 1100px;
    --header-h: 56px;

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --t-fast: 0.12s var(--ease);
    --t: 0.2s var(--ease);
}

/* ===== Light Mode (system preference OR explicit) ===== */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;

        --bg: #f5f5f5;
        --bg-raised: #ffffff;
        --bg-surface: #fafafa;
        --bg-input: #efefef;
        --bg-hover: #e8e8e8;

        --text: #1a1a1a;
        --text-2: #555555;
        --text-3: #666666;

        --link: #0055a5;
        --link-visited: #003d7a;
        --link-hover: #1A8FFF;
        --url: #2a7a2a;

        --warning-bg: rgba(255, 160, 40, 0.06);
        --warning-border: rgba(255, 160, 40, 0.2);
        --warning-text: #b06e00;

        --border: #dddddd;
        --border-subtle: #eeeeee;

        --brand-glow: rgba(0, 101, 191, 0.3);
        --brand-muted: rgba(0, 101, 191, 0.08);

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
        --shadow: 0 3px 12px rgba(0, 0, 0, 0.07);
        --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.1);
        --shadow-glow: 0 0 20px var(--brand-glow);
    }
}

/* Explicit light theme override (user toggled) */
:root[data-theme="light"] {
    color-scheme: light;

    --bg: #f5f5f5;
    --bg-raised: #ffffff;
    --bg-surface: #fafafa;
    --bg-input: #efefef;
    --bg-hover: #e8e8e8;

    --text: #1a1a1a;
    --text-2: #555555;
    --text-3: #666666;

    --link: #0055a5;
    --link-visited: #003d7a;
    --link-hover: #1A8FFF;
    --url: #2a7a2a;

    --warning-bg: rgba(255, 160, 40, 0.06);
    --warning-border: rgba(255, 160, 40, 0.2);
    --warning-text: #b06e00;

    --border: #dddddd;
    --border-subtle: #eeeeee;

    --brand-glow: rgba(0, 101, 191, 0.3);
    --brand-muted: rgba(0, 101, 191, 0.08);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow: 0 3px 12px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px var(--brand-glow);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--link);
    text-decoration: none;
    transition: color var(--t-fast);
}

a:visited { color: var(--link-visited); }
a:hover { color: var(--link-hover); }

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===== Accessibility ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ===== Shared Search Box ===== */
.search-box {
    width: 100%;
    padding: 0.7rem 1rem;
    font-size: 1rem;
    font-family: var(--font);
    background: var(--bg-input);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: var(--r);
    outline: none;
    transition: border-color var(--t), box-shadow var(--t);
}

.search-box:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-glow);
}

.search-box::placeholder {
    color: var(--text-3);
}

/* ===== Autocomplete Dropdown ===== */
.suggest-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    z-index: 200;
    overflow: hidden;
}

.suggest-dropdown[hidden] {
    display: none;
}

.suggest-item {
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    color: var(--text);
    cursor: pointer;
    transition: background var(--t-fast);
}

.suggest-item:hover,
.suggest-item.active {
    background: var(--bg-hover);
}

.suggest-item + .suggest-item {
    border-top: 1px solid var(--border-subtle);
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.5rem;
    font-size: 0.92rem;
    font-family: var(--font);
    font-weight: 600;
    border: none;
    border-radius: var(--r);
    cursor: pointer;
    transition: background var(--t), transform 0.1s ease, box-shadow var(--t);
}

.btn-primary {
    background: var(--brand);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--brand-bright);
    box-shadow: var(--shadow-glow);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-secondary {
    background: transparent;
    color: var(--text-2);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* ========================================================================
   THEME TOGGLE
   ======================================================================== */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-3);
    cursor: pointer;
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
    flex-shrink: 0;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--text-3);
    background: var(--bg-hover);
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
}

/* Show sun icon in dark mode, moon icon in light mode */
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }

:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .theme-toggle .icon-sun { display: none; }
    :root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: block; }
}

/* ========================================================================
   AI TOGGLE
   ======================================================================== */
.ai-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--brand);
    cursor: pointer;
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), opacity var(--t-fast);
    flex-shrink: 0;
}

.ai-toggle:hover {
    border-color: var(--brand);
    background: var(--bg-hover);
}

.ai-toggle.ai-off {
    color: var(--text-3);
    opacity: 0.5;
}

.ai-toggle.ai-off:hover {
    opacity: 0.8;
    border-color: var(--text-3);
}

.ai-toggle svg {
    width: 16px;
    height: 16px;
}

/* Toggle switch (settings panel) */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--text-3);
    border-radius: 22px;
    cursor: pointer;
    transition: background var(--t-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform var(--t-fast);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--brand);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* ========================================================================
   HOME PAGE
   ======================================================================== */
.view-home {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1.25rem;
    padding-bottom: 20vh;
}

.view-home .container {
    text-align: center;
    max-width: 540px;
    width: 100%;
}

.view-home .theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1.25rem;
}

.hero-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
}

.hero-brand .logo-icon {
    width: 96px;
    height: 96px;
}

.hero-brand .brand-text {
    font-family: var(--font-brand);
    font-size: clamp(2rem, 5vw, 2.5rem);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.hero-brand .brand-text span {
    color: var(--brand);
}

.hero-brand .tagline {
    font-size: 0.85rem;
    color: var(--text-3);
    font-weight: 400;
    letter-spacing: 0.01em;
}

.home-search-form .search-input-wrapper {
    margin-bottom: 1rem;
}

.home-search-form .search-box {
    font-size: 1.1rem;
    padding: 0.85rem 1.4rem;
    border-radius: var(--r-pill);
}

.home-search-form .buttons {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}

.home-search-form .buttons .btn-primary,
.home-search-form .buttons .btn-secondary {
    border-radius: var(--r-pill);
    padding: 0.55rem 1.5rem;
}

/* ========================================================================
   SETTINGS PANEL (home footer)
   ======================================================================== */
.home-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.6rem 1rem;
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    text-align: center;
}

.settings-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-family: var(--font);
    color: var(--text-3);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: var(--r-sm);
    transition: color var(--t-fast), background var(--t-fast);
}

.settings-toggle:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.settings-toggle svg {
    opacity: 0.7;
}

.settings-panel {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    align-items: center;
    margin-top: 0.6rem;
    flex-wrap: wrap;
}

.settings-panel[hidden] {
    display: none;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.settings-label {
    font-size: 0.75rem;
    color: var(--text-3);
    font-weight: 500;
}

.settings-select {
    font-size: 0.78rem;
    font-family: var(--font);
    padding: 0.25rem 0.5rem;
    background: var(--bg-input);
    color: var(--text-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: border-color var(--t-fast);
}

.settings-select:focus {
    border-color: var(--brand);
    outline: none;
}

/* ========================================================================
   RESULTS HEADER
   ======================================================================== */
.results-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: var(--max-w-wide);
    margin: 0 auto;
    padding: 0.5rem 2rem;
    height: var(--header-h);
}

.logo-sm {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    flex-shrink: 0;
}

.logo-sm:hover { text-decoration: none; }

.logo-sm .logo-icon {
    width: 36px;
    height: 36px;
}

.logo-sm .brand-text {
    font-family: var(--font-brand);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

.logo-sm .brand-text span {
    color: var(--brand);
}

.header-search {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
}

.header-search .search-box {
    padding: 0.45rem 4.2rem 0.45rem 0.75rem;
    font-size: 0.92rem;
    border-radius: var(--r);
}

.search-submit {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    border-radius: var(--r-sm);
    transition: color var(--t-fast);
}

.search-submit:hover {
    color: var(--brand);
}

.search-clear {
    position: absolute;
    right: 34px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    border-radius: var(--r-sm);
    transition: color var(--t-fast), opacity var(--t-fast);
    opacity: 0.6;
}

.search-clear:hover {
    color: var(--text);
    opacity: 1;
}

/* ===== Nav Tabs ===== */
.nav-tabs {
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}

.nav-tabs ul {
    display: flex;
    list-style: none;
    max-width: var(--max-w-wide);
    margin: 0 auto;
    padding: 0 2rem;
}

.nav-tabs a {
    display: block;
    padding: 0.55rem 1.1rem;
    color: var(--text-2);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 2.5px solid transparent;
    transition: color var(--t-fast), border-color var(--t-fast);
    text-decoration: none;
}

.nav-tabs a:visited { color: var(--text-2); }
.nav-tabs a:hover { color: var(--text); text-decoration: none; }

.nav-tabs a.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

.tab-beta {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--bg-raised);
    background: var(--brand);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 0.2rem;
}

/* ===== Engine Warnings ===== */
.engine-warnings {
    max-width: var(--max-w-wide);
    margin: 0.75rem auto 0;
    padding: 0 2rem;
}

.engine-warnings:empty { display: none; }

.engine-warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--r-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    color: var(--warning-text);
    line-height: 1.5;
}

/* ===== Spelling Correction ===== */
.spelling-correction {
    max-width: var(--max-w-wide);
    margin: 0.75rem auto 0;
    padding: 0.5rem 2rem;
    font-size: 0.88rem;
    color: var(--text-2);
}

.spelling-correction a {
    color: var(--link);
    text-decoration: none;
}

.spelling-correction a:hover {
    text-decoration: underline;
}

/* ========================================================================
   RESULTS LAYOUT
   ======================================================================== */
.results-view {
    min-height: 100vh;
}

.results-body {
    display: flex;
    gap: 2.5rem;
    max-width: var(--max-w-wide);
    margin: 0 auto;
    padding: 1rem 2rem 2rem;
}

.results-main {
    flex: 1;
    min-width: 0;
}

.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-2);
    font-size: 0.95rem;
}

/* ===== News Cards ===== */
.news-card {
    display: flex;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.news-card:last-child {
    border-bottom: none;
}

.news-thumb {
    flex-shrink: 0;
    width: 140px;
    height: 90px;
    border-radius: var(--r-sm);
    overflow: hidden;
    background: var(--bg-surface);
}

.news-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.news-body {
    flex: 1;
    min-width: 0;
}

.news-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 0 0 0.3rem;
}

.news-title a {
    color: var(--link);
    text-decoration: none;
}

.news-title a:visited {
    color: var(--link-visited);
}

.news-title a:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.news-snippet {
    font-size: 0.85rem;
    color: var(--text-2);
    line-height: 1.55;
    margin: 0 0 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-3);
}

.news-source {
    font-weight: 500;
    color: var(--text-2);
}

.news-age::before {
    content: "·";
    margin-right: 0.5rem;
}

@media (max-width: 600px) {
    .news-card {
        flex-direction: column-reverse;
        gap: 0.6rem;
    }

    .news-thumb {
        width: 100%;
        height: 160px;
        border-radius: var(--r-sm);
    }
}

/* ===== AI Answer Card ===== */
.ai-answer {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--r);
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
}

.ai-answer-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--brand);
    margin-bottom: 0.5rem;
}

.ai-answer-body {
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.65;
}

.ai-cursor::after {
    content: '▊';
    animation: blink 0.8s step-end infinite;
    color: var(--brand);
    font-size: 0.8em;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ===== Result Item ===== */
.result-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-subtle);
}

.result-item:first-child {
    padding-top: 0.4rem;
}

.result-item:last-child {
    border-bottom: none;
}

.result-title {
    font-size: 1.12rem;
    font-weight: 600;
    line-height: 1.35;
    margin-bottom: 0.2rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-title a {
    color: var(--link);
    text-decoration: none;
}

.result-title a:visited { color: var(--link-visited); }

.result-title a:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.result-url {
    font-size: 0.8rem;
    color: var(--url);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

.result-snippet {
    font-size: 0.88rem;
    color: var(--text-2);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.code-snippet {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.82rem;
    color: var(--text);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 0.6rem 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    overflow: hidden;
    max-height: 6rem;
    margin: 0;
}

.result-cached {
    display: inline-block;
    margin-top: 0.3rem;
    font-size: 0.72rem;
    color: var(--text-3);
    text-decoration: none;
    transition: color var(--t-fast);
}

.result-cached:hover {
    color: var(--text-2);
    text-decoration: underline;
}

.result-source {
    display: inline-block;
    margin-top: 0.2rem;
    margin-left: 0.5rem;
    font-size: 0.68rem;
    color: var(--brand);
    opacity: 0.7;
    font-style: italic;
}

/* ===== Infobox Sidebar ===== */
.infobox {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--r);
    overflow: hidden;
    align-self: flex-start;
    position: sticky;
    top: calc(var(--header-h) + 52px);
}

.infobox-thumbnail {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: var(--bg-surface);
    padding: 0.75rem;
}

.infobox-thumbnail[src=""],
.infobox-thumbnail[src="/proxy/image?url="],
.infobox-thumbnail.img-error {
    display: none;
}

.infobox-link[href=""] {
    display: none;
}

.infobox-body {
    padding: 0.85rem 1rem;
}

.infobox h2 {
    font-family: var(--font-brand);
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: var(--text);
    line-height: 1.3;
}

.infobox-extract {
    font-size: 0.82rem;
    color: var(--text-2);
    line-height: 1.6;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.infobox-link {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--brand-dim);
    transition: color var(--t-fast);
}

.infobox-link:hover {
    color: var(--brand);
}

.infobox-link:visited {
    color: var(--brand-dim);
}

/* ===== Try Other Engines ===== */
.try-engines {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1.5rem 0;
    padding: 0.75rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

.try-engines-label {
    font-size: 0.82rem;
    color: var(--text-3);
    margin-right: 0.25rem;
}

.try-engine-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    text-decoration: none;
    transition: border-color var(--t-fast), background var(--t-fast);
}

.try-engine-btn:hover {
    border-color: var(--brand);
    background: var(--bg-hover);
    text-decoration: none;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 1.75rem 0 1rem;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    height: 2.1rem;
    padding: 0 0.45rem;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--t-fast);
}

.pagination a {
    color: var(--text);
    background: var(--bg-surface);
    border: 1px solid var(--border);
}

.pagination a:visited { color: var(--text); }

.pagination a:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

.pagination .active {
    background: var(--brand);
    color: #ffffff;
    font-weight: 700;
    border: none;
}

.pagination .disabled {
    color: var(--text-3);
    pointer-events: none;
}

/* ========================================================================
   IMAGES GRID
   ======================================================================== */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem 1rem;
    max-width: var(--max-w-wide);
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

.image-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    overflow: hidden;
    text-decoration: none;
    transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--text-3);
    text-decoration: none;
}

.image-card .image-thumb {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: linear-gradient(
        110deg,
        var(--bg-input) 30%,
        var(--bg-hover) 50%,
        var(--bg-input) 70%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    will-change: background-position;
    contain: strict;
}

.image-card .image-thumb.loaded {
    animation: none;
    background: var(--bg-input);
    will-change: auto;
    contain: none;
}

.image-card .image-details {
    padding: 0.55rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-height: 2.5rem;
}

.image-card .image-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

.image-card .image-source {
    font-size: 0.7rem;
    color: var(--url);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.image-card {
    cursor: pointer;
}

.image-card.selected {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    border-radius: var(--r);
}

/* ===== Image Preview Panel ===== */
.image-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100vh;
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    overflow: hidden;
}

.image-panel.open {
    transform: translateX(0);
}

.image-panel[aria-hidden="true"] {
    pointer-events: none;
}

.image-panel-header {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.image-panel-close {
    background: none;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-panel-close:hover {
    background: var(--bg-surface);
    color: var(--text);
}

.image-panel-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: hidden;
    background: var(--bg-surface);
}

.image-panel-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.image-panel-info {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.image-panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-panel-source {
    font-size: 0.78rem;
    color: var(--text-2);
    margin-bottom: 0.75rem;
}

.image-panel-actions {
    display: flex;
    gap: 0.5rem;
}

.image-panel-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.image-panel-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

body.panel-open .images-view {
    margin-right: 420px;
    transition: margin-right 0.2s ease;
}

@media (max-width: 900px) {
    .image-panel {
        width: 100%;
        border-left: none;
    }

    body.panel-open .images-view {
        margin-right: 0;
    }
}

/* Images page pagination */
.images-view .pagination {
    max-width: var(--max-w-wide);
    margin: 0 auto;
    padding: 1rem 1.5rem 2rem;
}

/* ========================================================================
   ERROR PAGE
   ======================================================================== */
.error-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 2rem 1.25rem;
}

.error-inner {
    max-width: 400px;
}

.error-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 2rem;
    text-decoration: none;
}

.error-brand:hover { text-decoration: none; }

.error-brand .logo-icon {
    width: 52px;
    height: 52px;
}

.error-brand .brand-text {
    font-family: var(--font-brand);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.error-brand .brand-text span {
    color: var(--brand);
}

.error-code {
    font-family: var(--font-brand);
    font-size: clamp(3.5rem, 10vw, 5.5rem);
    font-weight: 700;
    color: var(--brand);
    line-height: 1;
    margin-bottom: 0.4rem;
}

.error-message {
    font-size: 1rem;
    color: var(--text-2);
    margin-bottom: 2rem;
    line-height: 1.5;
}

.error-home {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 1.5rem;
    background: var(--brand);
    color: #ffffff;
    border-radius: var(--r-pill);
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
    transition: background var(--t), box-shadow var(--t);
}

.error-home:hover {
    background: var(--brand-bright);
    box-shadow: var(--shadow-glow);
    text-decoration: none;
}

.error-home:visited { color: #ffffff; }

/* ========================================================================
   ADMIN DASHBOARD
   ======================================================================== */
.admin-view {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 1.25rem 3rem;
}

/* Admin nav bar */
.admin-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.admin-nav .admin-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.admin-nav .admin-brand:hover { text-decoration: none; }

.admin-nav .admin-brand .logo-icon {
    width: 26px;
    height: 26px;
}

.admin-nav .admin-brand h1 {
    font-family: var(--font-brand);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}

.admin-nav .admin-brand h1 span {
    color: var(--brand);
    font-weight: 600;
}

.admin-nav .admin-back {
    font-size: 0.82rem;
    color: var(--text-3);
    text-decoration: none;
    transition: color var(--t-fast);
}

.admin-nav .admin-back:hover { color: var(--text); }

/* Admin login */
.admin-login {
    text-align: center;
    padding: 4rem 0;
    max-width: 340px;
    margin: 0 auto;
}

.admin-login p {
    color: var(--text-2);
    margin-bottom: 1.5rem;
    font-size: 0.92rem;
}

.admin-login-form {
    display: flex;
    gap: 0.5rem;
}

.admin-login input[type="password"] {
    flex: 1;
    padding: 0.55rem 0.85rem;
    font-size: 0.92rem;
    font-family: var(--font);
    border: 2px solid var(--border);
    border-radius: var(--r);
    background: var(--bg-input);
    color: var(--text);
    outline: none;
    transition: border-color var(--t);
}

.admin-login input[type="password"]:focus {
    border-color: var(--brand);
}

/* Overview stats row */
.admin-stats {
    display: flex;
    gap: 2.5rem;
    padding: 1.25rem 0;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.admin-stat {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.admin-stat .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.admin-stat .stat-label {
    font-size: 0.72rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* Section headings */
.admin-section {
    margin-bottom: 2rem;
}

.admin-section h2 {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
    letter-spacing: 0.01em;
}

/* Engine table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-size: 0.85rem;
}

.admin-table th {
    color: var(--text-3);
    font-weight: 500;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
}

.admin-table td {
    border-bottom: 1px solid var(--border-subtle);
}

.admin-table tbody tr:hover td {
    background: var(--brand-muted);
}

.latency-bar {
    display: inline-block;
    height: 4px;
    background: var(--brand);
    border-radius: 2px;
    min-width: 3px;
    vertical-align: middle;
    margin-right: 0.4rem;
}

/* Cache row — simple inline stats */
.cache-stats {
    display: flex;
    gap: 2rem;
    align-items: baseline;
}

.cache-stat {
    font-size: 0.88rem;
    color: var(--text-2);
}

.cache-stat strong {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Admin actions */
.admin-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
}

.admin-actions .btn-secondary {
    font-size: 0.8rem;
    padding: 0.4rem 1rem;
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */
@media (max-width: 768px) {
    .results-body {
        flex-direction: column-reverse;
    }

    .infobox {
        width: 100%;
        position: static;
    }

    .hero-brand .logo-icon {
        width: 80px;
        height: 80px;
    }

    .images-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 1rem 0.75rem;
        padding: 0 1rem;
    }

    .admin-stats {
        flex-wrap: wrap;
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    .home-search-form .buttons {
        flex-direction: column;
    }

    .home-search-form .buttons .btn-primary,
    .home-search-form .buttons .btn-secondary {
        width: 100%;
    }

    .hero-brand .brand-text {
        font-size: 1.75rem;
    }

    .images-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem 0.5rem;
    }

    .logo-sm .brand-text {
        display: none;
    }

    .admin-login-form {
        flex-direction: column;
    }

    .admin-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .admin-stats {
        gap: 1rem;
    }

    .cache-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ========================================================================
   LOADING STATES
   ======================================================================== */

/* --- Top progress bar (activates on navigation) --- */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: var(--brand);
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.progress-bar.active {
    opacity: 1;
    animation: progress-fill 1.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes progress-fill {
    0%   { width: 0; }
    15%  { width: 30%; }
    50%  { width: 60%; }
    80%  { width: 82%; }
    100% { width: 92%; }
}

/* --- Button loading state --- */
.btn-loading {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px 0 0 -8px;
    border: 2.5px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: btn-spin 0.55s linear infinite;
}

.btn-primary.btn-loading::after {
    border-top-color: #ffffff;
}

.btn-secondary.btn-loading::after {
    border-top-color: var(--text-2);
}

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

/* --- Search submit spinner (replaces icon) --- */
.search-submit.is-loading svg {
    display: none;
}

.search-submit.is-loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: btn-spin 0.55s linear infinite;
}

/* --- Image shimmer placeholder --- */
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========================================================================
   ANIMATIONS
   ======================================================================== */
@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    .progress-bar.active {
        width: 92%;
        animation: none;
    }
    .image-thumb {
        animation: none;
    }
}
