:root {
    --bg: #f3f5f9;
    --bg-accent: radial-gradient(1200px 480px at 12% -10%, rgba(79, 70, 229, 0.09), transparent 60%),
        radial-gradient(900px 420px at 100% 0%, rgba(15, 143, 127, 0.08), transparent 55%);
    --panel: #ffffff;
    --panel-muted: #f6f8fb;
    --panel-raised: #ffffff;
    --border: #e2e7f0;
    --border-strong: #ccd4e2;
    --text: #151b28;
    --muted: #667085;
    --muted-soft: #98a2b3;
    --blue: #4f46e5;
    --blue-soft: #eef1ff;
    --green: #0f8f7f;
    --green-soft: #e8f9f4;
    --amber: #b7791f;
    --amber-soft: #fdf3e2;
    --danger: #c0362c;
    --danger-soft: #fdeeed;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 38, 0.05);
    --shadow: 0 12px 30px -14px rgba(20, 24, 38, 0.14), 0 2px 6px rgba(20, 24, 38, 0.04);
    --shadow-hover: 0 20px 40px -18px rgba(20, 24, 38, 0.2), 0 4px 10px rgba(20, 24, 38, 0.06);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --dur-fast: 160ms;
    --dur: 260ms;
    --dur-slow: 420ms;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0f17;
        --bg-accent: radial-gradient(1200px 480px at 12% -10%, rgba(99, 102, 241, 0.16), transparent 60%),
            radial-gradient(900px 420px at 100% 0%, rgba(16, 185, 129, 0.1), transparent 55%);
        --panel: #131826;
        --panel-muted: #171d2d;
        --panel-raised: #1a2033;
        --border: #232a3d;
        --border-strong: #313a52;
        --text: #eef1f8;
        --muted: #97a1b8;
        --muted-soft: #6b7488;
        --blue: #818cf8;
        --blue-soft: rgba(99, 102, 241, 0.16);
        --green: #34d399;
        --green-soft: rgba(16, 185, 129, 0.14);
        --amber: #f0b657;
        --amber-soft: rgba(217, 155, 47, 0.16);
        --danger: #f2685f;
        --danger-soft: rgba(220, 71, 58, 0.16);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
        --shadow: 0 16px 34px -16px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.25);
        --shadow-hover: 0 24px 46px -18px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.3);
    }
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-accent), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

::selection {
    background: var(--blue);
    color: #fff;
}

/* ---------- motion primitives ---------- */

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.97);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shimmer {
    0% {
        background-position: -300px 0;
    }
    100% {
        background-position: 300px 0;
    }
}

@keyframes pulseDot {
    0%,
    100% {
        box-shadow: 0 0 0 0 currentColor;
        opacity: 1;
    }
    70% {
        box-shadow: 0 0 0 6px transparent;
        opacity: 0.55;
    }
}

@keyframes floatBrand {
    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-2px) rotate(-3deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- layout shell ---------- */

.page-shell {
    width: min(1680px, 100%);
    margin: 0 auto;
    padding: 16px;
    animation: fadeIn var(--dur-slow) var(--ease) both;
}

.topbar,
.filters,
.stat-card,
.market-prices-section,
.insights-panel,
.listings-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.topbar {
    min-height: 68px;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    position: sticky;
    top: 12px;
    z-index: 20;
    backdrop-filter: saturate(1.4) blur(14px);
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    animation: fadeInUp var(--dur-slow) var(--ease) both;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 11px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: linear-gradient(145deg, var(--blue), #7c3aed);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 800;
    box-shadow: 0 8px 18px -6px rgba(79, 70, 229, 0.55);
    animation: floatBrand 6s ease-in-out infinite;
}

.eyebrow {
    margin: 0 0 3px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: 1.08rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1rem;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.topbar-status {
    min-width: 260px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.topbar-status span:first-child {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px 5px 9px;
    border-radius: 999px;
    background: var(--green-soft);
    color: var(--green);
    font-weight: 800;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.topbar-status span:first-child::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: currentColor;
    animation: pulseDot 2.2s ease-in-out infinite;
}

.topbar-status[data-state="error"] span:first-child {
    background: var(--danger-soft);
    color: var(--danger);
}

.topbar-status[data-state="loading"] span:first-child {
    background: var(--blue-soft);
    color: var(--blue);
}

.topbar-actions,
.filters-actions {
    display: flex;
    gap: 8px;
}

.button {
    height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 0 13px;
    background: var(--panel);
    color: var(--text);
    font-weight: 800;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.button:hover {
    transform: translateY(-1px);
    border-color: var(--muted-soft);
    box-shadow: var(--shadow-sm);
}

.button:active {
    transform: translateY(0) scale(0.97);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
    box-shadow: none;
}

.button-primary {
    border-color: var(--blue);
    background: linear-gradient(145deg, var(--blue), #6d28d9);
    color: #fff;
}

.button-primary:hover {
    box-shadow: 0 10px 22px -10px rgba(79, 70, 229, 0.65);
}

.button-soft,
.button-ghost {
    background: var(--panel-muted);
}

.main-layout {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.filters {
    padding: 14px;
    animation: fadeInUp var(--dur-slow) var(--ease) both;
    animation-delay: 40ms;
}

.filters-header,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-caption {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.filters-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1.8fr) repeat(7, minmax(118px, 1fr));
    gap: 10px;
}

.parser-status-line {
    margin-top: 10px;
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--panel-muted);
    color: var(--muted);
    font-weight: 800;
    animation: scaleIn var(--dur) var(--ease) both;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.parser-status-line[data-tone="progress"] {
    border-color: color-mix(in srgb, var(--blue) 35%, var(--border));
    background: var(--blue-soft);
    color: var(--blue);
}

.parser-status-line[data-tone="success"] {
    border-color: color-mix(in srgb, var(--green) 35%, var(--border));
    background: var(--green-soft);
    color: var(--green);
}

.parser-status-line[data-tone="error"] {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    background: var(--danger-soft);
    color: var(--danger);
}

.control {
    display: grid;
    gap: 5px;
}

.control span {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
}

.control input,
.control select {
    width: 100%;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-muted);
    color: var(--text);
    padding: 0 11px;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.control input:hover,
.control select:hover {
    border-color: var(--border-strong);
}

.control input:focus,
.control select:focus {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent);
    border-color: var(--blue);
    background: var(--panel);
}

/* ---------- stats ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.stat-card {
    padding: 14px;
    border-left: 3px solid transparent;
    animation: fadeInUp var(--dur-slow) var(--ease) both;
    animation-delay: calc(80ms + min(var(--i, 0), 6) * 45ms);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.stat-card:nth-child(1) {
    border-left-color: var(--blue);
}

.stat-card:nth-child(2) {
    border-left-color: var(--green);
}

.stat-card:nth-child(3) {
    border-left-color: #7c3aed;
}

.stat-card:nth-child(4) {
    border-left-color: var(--amber);
}

.stat-label {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    display: block;
    margin: 7px 0 4px;
    font-size: 1.6rem;
    line-height: 1.1;
    font-weight: 850;
    letter-spacing: -0.01em;
    animation: fadeIn var(--dur) var(--ease) both;
}

.stat-hint {
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.75fr);
    gap: 12px;
    align-items: start;
}

.market-prices-section,
.insights-panel,
.listings-section {
    padding: 14px;
    animation: fadeInUp var(--dur-slow) var(--ease) both;
    animation-delay: 90ms;
}

.side-stack {
    display: grid;
    gap: 12px;
}

.leaderboard,
.market-prices,
.listing-grid {
    display: grid;
    gap: 8px;
}

.market-prices {
    max-height: 920px;
    overflow: auto;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.market-price-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(330px, 1.2fr) auto;
    gap: 10px;
    align-items: center;
    padding: 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--panel);
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    animation: fadeInUp var(--dur) var(--ease) both;
    animation-delay: calc(min(var(--i, 0), 14) * 28ms);
}

.market-price-row:hover,
.listing-card:hover {
    border-color: var(--muted-soft);
    background: var(--panel-raised);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.market-price-model {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.market-price-model strong,
.listing-card-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 850;
}

.market-price-model span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.market-price-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.market-price-stats div {
    padding: 8px;
    border-radius: var(--radius-sm);
    background: var(--panel-muted);
    border: 1px solid transparent;
    transition: background var(--dur-fast) var(--ease);
}

.market-price-stats span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.market-price-stats strong {
    font-size: 0.92rem;
}

.market-price-action {
    height: 32px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0 11px;
    background: var(--text);
    color: var(--bg);
    font-size: 0.78rem;
    font-weight: 850;
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.market-price-action:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.market-price-action:active:not(:disabled) {
    transform: translateY(0) scale(0.96);
}

.market-price-action:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.leader-row {
    display: grid;
    gap: 6px;
    animation: fadeInUp var(--dur) var(--ease) both;
    animation-delay: calc(min(var(--i, 0), 8) * 40ms);
}

.leader-row-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 800;
}

.leader-row-header span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leader-row-header span:last-child {
    color: var(--muted);
}

.leader-track {
    height: 6px;
    border-radius: 999px;
    background: var(--panel-muted);
    overflow: hidden;
}

.leader-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--green), #22c3a6);
    width: var(--w, 0%);
    transform-origin: left center;
    animation: fillBar 800ms var(--ease) both;
    animation-delay: calc(120ms + min(var(--i, 0), 8) * 40ms);
}

@keyframes fillBar {
    from {
        width: 0%;
    }
    to {
        width: var(--w, 0%);
    }
}

/* ---------- listings ---------- */

.listing-grid {
    margin-top: 8px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.listing-card {
    display: grid;
    overflow: hidden;
    align-content: start;
    padding: 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--panel);
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    animation: fadeInUp var(--dur) var(--ease) both;
    animation-delay: calc(min(var(--i, 0), 18) * 32ms);
}

.listing-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.listing-card-media {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: linear-gradient(145deg, #171e2c, #2d3a56);
}

.listing-card-media img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transition: transform var(--dur-slow) var(--ease);
}

.listing-card:hover .listing-card-media img {
    transform: scale(1.05);
}

.listing-card-placeholder {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: 2rem;
    font-weight: 900;
}

.listing-source-chip {
    position: absolute;
    left: 10px;
    top: 10px;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    color: #151b28;
    font-size: 0.7rem;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.listing-card-body {
    display: grid;
    gap: 10px;
    padding: 13px;
}

.listing-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 10px;
    min-width: 0;
}

.listing-card-subtitle {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.listing-card-price {
    flex: 0 0 auto;
    font-weight: 850;
    white-space: nowrap;
}

.listing-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.listing-card-description {
    min-height: 3.9em;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.3;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--panel-muted);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.pill-powertrain {
    background: var(--blue-soft);
    color: var(--blue);
}

.pill-strong {
    background: var(--green-soft);
    color: var(--green);
}

.listing-card-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.35;
}

.listing-card-footer span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.listing-card-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 11px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: 0.78rem;
    font-weight: 800;
    transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.listing-card-link:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ---------- loading & empty states ---------- */

.empty-state {
    padding: 16px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-strong);
    background: var(--panel-muted);
    color: var(--muted);
    font-weight: 700;
    animation: fadeIn var(--dur) var(--ease) both;
}

.loading-placeholder {
    height: 84px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: transparent;
    background: linear-gradient(
        90deg,
        var(--panel-muted) 0%,
        var(--panel-muted) 35%,
        color-mix(in srgb, var(--border-strong) 55%, var(--panel-muted)) 50%,
        var(--panel-muted) 65%,
        var(--panel-muted) 100%
    );
    background-size: 600px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}

.listing-grid .loading-placeholder {
    height: 300px;
    border-radius: var(--radius);
}

/* ---------- responsive ---------- */

@media (max-width: 1180px) {
    .topbar,
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        position: static;
    }

    .topbar-status,
    .topbar-actions {
        justify-content: flex-start;
    }

    .filters-grid,
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .control-search {
        grid-column: 1 / -1;
    }
}

@media (max-width: 760px) {
    .page-shell {
        padding: 10px;
    }

    .filters-grid,
    .stats-grid,
    .market-price-row,
    .market-price-stats {
        grid-template-columns: 1fr;
    }

    .filters-header,
    .section-heading,
    .listing-card-header {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions,
    .filters-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
