:root {
    --page-bg: #f6f8fb;
    --surface: #ffffff;
    --surface-border: #e7ebf1;
    --text-main: #1f2937;
    --text-soft: #6b7280;
    --brand: #2d6cdf;
    --brand-dark: #1f57ba;
    --brand-soft: #eef2ff;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--text-main);
}

/* Page shell */
.search-page {
    max-width: 980px;
}

.search-hero {
    background: radial-gradient(circle at top right, #eef2ff 0%, #ffffff 55%), var(--surface);
    border: 1px solid #dbe4ff;
    border-radius: 14px;
    padding: 1.25rem;
}

#searchHeroSection {
    transition: opacity 0.26s ease, transform 0.26s ease;
}

#searchHeroSection.search-hero-hiding {
    opacity: 0;
    transform: translateY(-4px);
}

.search-title {
    margin: 0 0 0.35rem 0;
    font-size: 1.65rem;
}

.search-subtitle {
    margin: 0;
    color: var(--text-soft);
}

.search-panel {
    position: relative;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 14px;
    padding: 1rem;
}

.search-input {
    min-height: 46px;
    border-radius: 10px;
    border: 1px solid #9db7eb;
    text-align: left;
}

.form-check-input {
    border-color: #9db7eb;
}

.search-button {
    min-height: 46px;
    border-radius: 10px;
    border: 1px solid #bfdbfe;
    background: #dbeafe;
    color: #1e3a8a;
    font-weight: 600;
}

    .search-button:hover {
        background: var(--brand);
        border-color: var(--brand-dark);
        color: #ffffff;
    }

.results-meta {
    color: var(--text-soft);
    font-size: 0.95rem;
}

/* Search form alignment */
.search-form {
    justify-content: flex-start;
}

/* Remove this block:
.search-form > div {
    display: inline-block
}
*/

/* Keep stable order always */
.search-form > :nth-child(1) { order: 1; } /* input */
.search-form > :nth-child(2) { order: 2; } /* button */
.search-form > :nth-child(3) { order: 3; } /* checkbox row */

/* Desktop: keep left aligned */
@media (min-width: 992px) {
    .search-options {
        justify-content: flex-start;
    }
}

/* Result cards */
.result-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 1rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-left: 4px solid #dbe4ff;
    border-radius: 14px;
    padding: 1rem;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

    .result-card:hover {
        border-left-color: var(--brand);
        box-shadow: 0 8px 20px rgba(45, 108, 223, 0.1);
        transform: translateY(-1px);
    }

.result-link {
    font-size: 0.88rem;
    color: var(--brand);
    text-decoration: none;
    word-break: break-all;
}

    .result-link:hover {
        text-decoration: underline;
    }

.result-title {
    margin: 0.65rem 0 0.35rem 0;
    font-size: 1.15rem;
}

.result-preview {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    padding: 0.75rem;
    background: #fcfdff;
}

.result-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--brand);
}

.empty-state {
    background: var(--brand-soft);
    border: 1px dashed #c7d2fe;
    border-radius: 14px;
    padding: 1rem;
    color: var(--text-soft);
}

/* ===== External HTML containment (critical fix) ===== */
.preview-html {
    max-width: 100%;
    overflow-x: auto;
}

    /* Keep foreign markup inside card */
    .preview-html * {
        box-sizing: border-box;
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Desktop == mobile: always stacked */
    .preview-html main,
    .preview-html section,
    .preview-html .content {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        margin: 0 0 1rem 0 !important;
        padding: 0 !important;
        text-align: left !important;
    }

    /* Cancel foreign flex/grid layouts that create narrow columns */
    .preview-html [class*="content"] {
        display: block !important;
    }

    /* Spacing for text blocks */
    .preview-html p,
    .preview-html h1,
    .preview-html h2,
    .preview-html h3,
    .preview-html h4,
    .preview-html h5,
    .preview-html h6,
    .preview-html ul,
    .preview-html ol {
        margin-top: 0.6rem;
        margin-bottom: 0.6rem;
    }

        .preview-html h1:first-child,
        .preview-html h2:first-child,
        .preview-html h3:first-child,
        .preview-html h4:first-child,
        .preview-html h5:first-child,
        .preview-html h6:first-child,
        .preview-html p:first-child {
            margin-top: 0;
        }

        .preview-html p:last-child,
        .preview-html ul:last-child,
        .preview-html ol:last-child {
            margin-bottom: 0;
        }

    /* Preview heading scale */
    .preview-html h1 {
        font-size: 1.4rem;
        line-height: 1.25;
    }

    .preview-html h2 {
        font-size: 1.23rem;
        line-height: 1.25;
    }

    .preview-html h3 {
        font-size: 1.05rem;
        line-height: 1.25;
    }

    .preview-html h4 {
        font-size: 0.95rem;
        line-height: 1.3;
    }

    .preview-html h5 {
        font-size: 0.86rem;
        line-height: 1.3;
    }

    .preview-html h6 {
        font-size: 0.78rem;
        line-height: 1.3;
    }

    /* Image rules only inside preview */
    .preview-html img,
    .preview-html section > img,
    .preview-html .content > img {
        float: none !important;
        clear: both !important;
        display: block !important;
        width: 100% !important;
        max-width: 380px !important;
        height: auto !important;
        margin: 0 auto 0.75rem auto !important; /* keskitys */
        border-radius: 8px !important;
    }

    /* Keep text full width under image */
    .preview-html h1,
    .preview-html h2,
    .preview-html h3,
    .preview-html h4,
    .preview-html h5,
    .preview-html h6,
    .preview-html p {
        width: 100% !important;
        max-width: none !important;
    }

    /* Centered lists inside preview */
    .preview-html ul,
    .preview-html ol {
        display: table;
        width: auto;
        max-width: 100%;
        margin: 0.6rem auto;
        padding-left: 1.25rem;
        text-align: left;
    }

    .preview-html li {
        text-align: left;
    }

/* Hotlink-placeholder kuvat pieneksi vain hakutulosten preview-alueella */
.preview-html img[src*="hotlink" i],
.preview-html img[src*="blocked" i],
.preview-html img[src*="stop" i] {
   display:none;
}

.search-tags {
    position: relative;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.search-tag {
    position: relative;
    z-index: 31;
    pointer-events: auto;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #1e3a8a;
    border-radius: 999px;
    padding: .2rem .65rem;
    font-weight: 500;
}

@media (max-width: 576px) {
    .container,
    .container-fluid,
    .container-lg,
    .container-md,
    .container-sm,
    .container-xl,
    .container-xxl {
        --bs-gutter-x: 1.5rem;
        --bs-gutter-y: 0;
        width: 100%;
        padding-right: calc(var(--bs-gutter-x) * .1);
        padding-left: calc(var(--bs-gutter-x) * .1);
        margin-right: auto;
        margin-left: auto;
    }

    .result-preview {
        padding: 0.25rem;
    }
}

/* Search loading indicator */
.search-loading-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    background: #f8fbff;
    color: var(--text-soft);
    font-size: 0.95rem;
}

.search-loading-spinner {
    width: 0.95rem;
    height: 0.95rem;
    border: 2px solid #bfdbfe;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: search-spin 0.8s linear infinite;
}

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

