:root {
    --bg: #0a0c11;
    --panel: #12151f;
    --panel-2: #171c29;
    --border: #242a3a;
    --border-soft: #1b2030;
    --text: #edf0f7;
    --text-dim: #b6bdd0;
    --muted: #7d8598;
    --accent-1: #6d5efc;
    --accent-2: #22d3ee;
    --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    --good: #22c55e;
    --bad: #f43f5e;
    --warn: #f7b955;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-lift: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 0;
    font-family: "Segoe UI", ui-sans-serif, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background:
        radial-gradient(1100px 560px at 8% -12%, rgba(109, 94, 252, 0.16), transparent 60%),
        radial-gradient(900px 480px at 100% -6%, rgba(34, 211, 238, 0.1), transparent 55%),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0 2rem 3.5rem;
}

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 0;
    margin-bottom: 1.6rem;
    background: rgba(10, 12, 17, 0.82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-soft);
}

.brand {
    min-width: 0;
    text-align: center;
}

.brand-title {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.brand-subtitle {
    font-size: 0.82rem;
    color: var(--muted);
}

/* ---------- Top bar actions (logo, contact, settings) ---------- */

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1.1rem;
    min-width: 0;
}

.logo-link {
    display: flex;
    align-items: center;
    min-width: 0;
    opacity: 0.92;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.logo-link:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.brand-logo {
    height: 30px;
    max-width: 100%;
    width: auto;
    display: block;
}

.contact-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.15rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
    color: #fff;
    background: var(--accent-grad);
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(109, 94, 252, 0.3);
    transition: filter 0.15s ease, transform 0.15s ease;
}

.contact-btn:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* ---------- Settings popover ---------- */

.settings-wrap {
    position: relative;
}

.settings-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.settings-btn:hover {
    border-color: var(--accent-1);
    background: var(--panel-2);
}

.settings-btn[aria-expanded="true"] {
    border-color: var(--accent-1);
    color: #fff;
    background: var(--panel-2);
}

.settings-btn svg {
    transition: transform 0.3s ease;
}

.settings-btn[aria-expanded="true"] svg {
    transform: rotate(45deg);
}

.settings-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.6rem);
    width: 320px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lift);
    padding: 1.1rem 1.2rem 1.3rem;
    animation: pop-in 0.15s ease;
}

@keyframes pop-in {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.settings-panel-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.9rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--border-soft);
}

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.88rem;
    font-weight: 600;
    margin-top: 0.9rem;
    margin-bottom: 0.5rem;
}

.field-value {
    color: #fff;
    background: var(--accent-grad);
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.field-help {
    color: var(--muted);
    font-size: 0.76rem;
    margin: 0.35rem 0 0;
    line-height: 1.4;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent-1);
    height: 4px;
    cursor: pointer;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.86rem;
    margin-top: 1.1rem;
    cursor: pointer;
}

.checkbox-row input {
    accent-color: var(--accent-1);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.settings-panel hr {
    border: none;
    border-top: 1px solid var(--border-soft);
    margin: 1.2rem 0 0.9rem;
}

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

.small {
    font-size: 0.8rem;
}

/* ---------- Main content ---------- */

.content {
    padding-top: 0.2rem;
}

.intro {
    color: var(--text-dim);
    font-size: 1rem;
    max-width: 760px;
    margin: 0 0 1.8rem;
    line-height: 1.5;
}

h4 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.3rem;
    font-size: 1.02rem;
}

/* ---------- Upload dropzone ---------- */

.upload-section {
    margin-bottom: 2.2rem;
}

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-align: center;
    padding: 1.8rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1.5px dashed var(--border);
    background: var(--panel);
    color: var(--text-dim);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.dropzone:hover {
    border-color: var(--accent-2);
    background: var(--panel-2);
}

.dropzone.is-dragover {
    border-color: var(--accent-1);
    background: var(--panel-2);
    transform: scale(1.005);
}

.dropzone svg {
    color: var(--accent-2);
    margin-bottom: 0.3rem;
}

.dropzone-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
}

.dropzone-help {
    font-size: 0.8rem;
    color: var(--muted);
}

.dropzone-filename {
    margin-top: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent-2);
    max-width: 100%;
    overflow-wrap: anywhere;
}

.dropzone-filename:empty {
    display: none;
}

/* ---------- Sample gallery ---------- */

.sample-section {
    margin-bottom: 2rem;
}

.sample-section h4 svg {
    color: var(--accent-2);
}

.sample-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.sample-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.55rem;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.sample-card:hover {
    transform: translateY(-3px);
    border-color: var(--border);
    box-shadow: var(--shadow-lift);
}

.sample-card.is-selected {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 1px var(--accent-1), var(--shadow-lift);
}

.thumb-box {
    position: relative;
    width: 100%;
    height: 140px;
    border-radius: var(--radius-sm);
    background: #0c0e13;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.55rem;
}

.thumb-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.2s ease;
}

.sample-card:hover .thumb-box img {
    transform: scale(1.04);
}

.thumb-check {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-grad);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 800;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.sample-card.is-selected .thumb-check {
    opacity: 1;
    transform: scale(1);
}

.sample-select-btn {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    min-height: 2.2rem;
    font-weight: 650;
    font-size: 0.85rem;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sample-select-btn:hover {
    border-color: var(--accent-1);
}

.sample-card.is-selected .sample-select-btn {
    background: var(--accent-grad);
    border-color: transparent;
    color: #fff;
}

.sample-select-btn[disabled] {
    cursor: default;
}

/* ---------- Result panels ---------- */

.result-grid {
    display: flex;
    gap: 1.6rem;
    flex-wrap: wrap;
}

.panel {
    flex: 1 1 420px;
    min-width: 0;
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
}

.panel h4 {
    margin-bottom: 0.8rem;
}

.result-image {
    width: 100%;
    border-radius: var(--radius-sm);
    display: block;
}

.hidden {
    display: none !important;
}

.banner {
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.4;
}

.banner-info {
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.25);
    color: #bfeaf5;
}

.banner-warning {
    background: rgba(247, 185, 85, 0.1);
    border: 1px solid rgba(247, 185, 85, 0.3);
    color: #f9dcac;
}

.banner-error {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: #f9b8b0;
    margin-top: 0.8rem;
}

.spinner-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--muted);
    padding: 0.9rem 0;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent-1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.status-card {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
}

.status-card.good {
    border-left: 4px solid var(--good);
    background: rgba(34, 197, 94, 0.1);
}

.status-card.bad {
    border-left: 4px solid var(--bad);
    background: rgba(244, 63, 94, 0.1);
}

.status-card.unknown {
    border-left: 4px solid var(--warn);
    background: rgba(247, 185, 85, 0.1);
}

.status-title {
    font-size: 1.05rem;
    font-weight: 800;
}

.status-card.good .status-title::before {
    content: "\2713  ";
    color: var(--good);
}

.status-card.bad .status-title::before {
    content: "\26A0  ";
    color: var(--bad);
}

.status-card.unknown .status-title::before {
    content: "?  ";
    color: var(--warn);
}

.status-meta {
    font-size: 0.82rem;
    overflow-wrap: anywhere;
}

.metrics-row {
    display: flex;
    gap: 0.8rem;
    margin-top: 1rem;
}

.metric {
    flex: 1;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-top: 3px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.8rem;
    text-align: center;
}

.metric-closed {
    border-top-color: var(--good);
}

.metric-open {
    border-top-color: var(--bad);
}

.metric-partial {
    border-top-color: var(--warn);
}

.metric-label {
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: 0.15rem;
}

.raw-details {
    margin-top: 1rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
}

.raw-details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-dim);
}

.raw-details pre {
    margin: 0.6rem 0 0;
    font-size: 0.83rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--text-dim);
}

.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    text-align: center;
    margin-top: 1.1rem;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.92rem;
    background: var(--accent-grad);
    color: white;
    text-decoration: none;
    box-shadow: 0 6px 18px rgba(109, 94, 252, 0.3);
    transition: filter 0.15s ease, transform 0.15s ease;
}

.download-btn:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

@media (max-width: 720px) {
    .app-shell {
        padding: 0 1rem 2.5rem;
    }

    .topbar {
        grid-template-columns: 1fr auto;
        gap: 0.75rem;
        padding: 0.9rem 0 0.85rem;
        margin-bottom: 1.2rem;
    }

    .brand {
        grid-column: 1 / -1;
        grid-row: 2;
        padding-top: 0.15rem;
    }

    .topbar-actions {
        grid-column: 2;
        grid-row: 1;
        gap: 0.6rem;
    }

    .brand-logo {
        height: 26px;
        max-width: min(42vw, 150px);
    }

    .contact-btn {
        display: none;
    }

    .settings-btn {
        min-height: 44px;
        padding: 0.55rem 0.85rem;
    }

    .settings-panel {
        position: fixed;
        top: 4.25rem;
        right: 1rem;
        left: 1rem;
        width: auto;
        max-height: calc(100dvh - 5.25rem);
        overflow-y: auto;
    }

    .intro {
        font-size: 0.92rem;
        margin-bottom: 1.35rem;
    }

    .upload-section {
        margin-bottom: 1.7rem;
    }

    .dropzone {
        min-height: 150px;
        padding: 1.4rem 1rem;
    }

    .sample-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .thumb-box {
        height: clamp(105px, 30vw, 140px);
    }

    .sample-select-btn {
        min-height: 44px;
    }

    .result-grid {
        gap: 1rem;
    }

    .panel {
        flex-basis: 100%;
        padding: 0.9rem;
    }

    .metrics-row {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .metric {
        min-width: 0;
        padding: 0.6rem 0.35rem;
    }

    .metric-value {
        font-size: 1.15rem;
    }

    .download-btn {
        min-height: 44px;
    }
}

@media (max-width: 380px) {
    .app-shell {
        padding-right: 0.75rem;
        padding-left: 0.75rem;
    }

    .brand-title {
        font-size: 1.12rem;
    }

    .brand-subtitle {
        font-size: 0.76rem;
    }

    .brand-logo {
        height: 23px;
        max-width: 130px;
    }

    .settings-btn {
        padding-inline: 0.7rem;
    }

    .settings-panel {
        right: 0.75rem;
        left: 0.75rem;
        padding: 1rem;
    }

    .sample-grid {
        grid-template-columns: 1fr;
    }

    .thumb-box {
        height: 150px;
    }

    .metrics-row {
        grid-template-columns: 1fr;
    }

    .metric {
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-top-width: 1px;
        border-left: 3px solid var(--border);
        text-align: left;
    }

    .metric-closed {
        border-left-color: var(--good);
    }

    .metric-open {
        border-left-color: var(--bad);
    }

    .metric-partial {
        border-left-color: var(--warn);
    }
}
