/* ---------- Reset & Base ---------- */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0b0c10;
    --surface: #1a1d24;
    --surface-hover: #22262f;
    --border: #2a2e38;
    --text: #e6e8ed;
    --text-muted: #8b8f9a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --radius: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---------- Header ---------- */

.header {
    position: sticky;
    top: 0;
    z-index: 100;

    background: rgba(11, 12, 16, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;

    max-width: 100%;
    margin: 0 auto;
    padding: 12px 24px;
}

.header__title {
    display: flex;
    align-items: center;
    gap: 10px;

    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header__icon {
    width: 80px;
    height: auto;
    color: var(--text);
}

.header__badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;

    background: var(--accent);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
}

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

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

/* ---------- Stats Cards ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.stat-card:hover {
    border-color: var(--accent);
}

.stat-card__label {
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.stat-card__value {
    font-size: 1.4rem;
    font-weight: 700;
}

.stat-card__value--green { color: var(--green); }
.stat-card__value--red { color: var(--red); }
.stat-card__value--yellow { color: var(--yellow); }

/* ---------- Charts ---------- */

.charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    padding: 16px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.chart-card__title {
    margin-bottom: 10px;

    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---------- Toolbar ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar__search {
    flex: 1;
    min-width: 180px;
    padding: 7px 12px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.toolbar__search--small {
    flex: 0 0 180px;
    min-width: 140px;
}

.toolbar__search:focus {
    border-color: var(--accent);
}

.toolbar__btn {
    padding: 7px 14px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.toolbar__btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.toolbar__btn--active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.toolbar__separator {
    display: block;
    width: 1px;
    height: 28px;
    background: var(--border);
}

.toolbar__select {
    padding: 7px 10px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.toolbar__select:focus {
    border-color: var(--accent);
}

.toolbar__checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;

    font-size: 0.82rem;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.toolbar__checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;

    accent-color: var(--accent);
    cursor: pointer;
}

/* ---------- Table ---------- */

.table-wrap {
    overflow-x: auto;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.table th,
.table td {
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.table th {
    position: sticky;
    top: 0;

    background: var(--surface);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.table th:hover {
    color: var(--accent);
}

.table th .sort-icon {
    margin-left: 3px;
    opacity: 0.4;
    font-size: 0.85em;
}

.table th .sort-icon--active {
    opacity: 1;
    color: var(--accent);
}

.table th.sort-primary {
    color: var(--accent);
}

.table th.sort-secondary {
    color: var(--accent);
    opacity: 0.7;
}

.sort-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 14px;
    height: 14px;
    margin-left: 2px;

    font-size: 9px;
    font-weight: 700;
    line-height: 1;

    color: #fff;
    background: var(--accent);
    border-radius: 50%;
    vertical-align: middle;
}

.table th.sort-secondary .sort-badge {
    background: var(--text-muted);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--surface-hover);
}

.table .cell-vin {
    font-family: 'Courier New', monospace;
    font-size: 0.88rem;
}

.table .cell-vin a {
    color: var(--accent);
    text-decoration: none;
}

.table .cell-vin a:hover {
    text-decoration: underline;
}

.table .cell-price {
    font-weight: 600;
}

.table .cell-km {
    font-variant-numeric: tabular-nums;
    color: #b0b8c5;
}

.table .cell-ap {
    font-size: 0.75rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table .cell-id {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.table .cell-date {
    font-size: 0.86rem;
    color: var(--text-muted);
}

.table .cell-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.table a {
    color: var(--accent);
    text-decoration: none;
}

.table a:hover {
    text-decoration: underline;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* ---------- Expandable Rows ---------- */

.row-main {
    cursor: pointer;
    transition: background 0.15s;
}

.row-main--open td {
    background: var(--surface-hover);
    border-bottom-color: transparent;
}

.row-expand {
    display: none;
}

.row-expand--open {
    display: table-row;
}

.row-expand td {
    padding: 0 !important;
    border-bottom: 2px solid var(--accent);
}

.expand-content {
    padding: 16px 20px;
    background: #161920;
}

.expand-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.expand-img {
    width: 340px;
    height: auto;
    border-radius: 8px;
    flex-shrink: 0;
}

.expand-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 24px;
    font-size: 0.82rem;
}

.expand-row b {
    color: var(--text-muted);
    font-weight: 500;
}

.expand-detail-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.expand-detail-link:hover {
    text-decoration: underline;
}

/* ---------- Detail Button ---------- */

.btn-detail {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 22px;
    height: 22px;
    padding: 0;

    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-decoration: none;
    transition: border-color 0.2s;
}

.btn-detail:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 2px 8px;

    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge--green {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

.badge--red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

/* ---------- Button: Price History ---------- */

.btn-hist {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 22px;
    height: 22px;
    padding: 0;

    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-hist:hover {
    opacity: 0.8;
}

.btn-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 48px;
    height: 22px;
    padding: 0 8px;

    background: #171a21;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-check:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: #1d2230;
}

.btn-check:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ---------- Text helpers ---------- */

.text-green { color: var(--green); }
.text-red { color: var(--red); }

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 14px;
}

.pagination__btn {
    padding: 5px 12px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s;
}

.pagination__btn:hover:not(:disabled) {
    background: var(--surface-hover);
}

.pagination__btn--active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pagination__btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.pagination__info {
    font-size: 0.82rem;
    color: var(--text-muted);
}

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

/* ---------- Modal ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;

    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    width: 92%;
    max-width: 640px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.modal__title {
    margin-bottom: 16px;
    font-size: 1.05rem;
    font-weight: 700;
}

.modal__close {
    float: right;
    padding: 4px 10px;

    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
}

.modal__close:hover {
    border-color: var(--red);
    color: var(--red);
}

/* Compact table variant inside modal */
.table--compact th,
.table--compact td {
    padding: 6px 10px;
}

/* ---------- Car Detail Page ---------- */

.car-detail__loading {
    text-align: center;
    padding: 60px;
    color: var(--text-muted);
}

.car-detail__back {
    display: inline-block;
    margin-bottom: 16px;

    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
}

.car-detail__back:hover {
    text-decoration: underline;
}

.car-detail__hero {
    display: flex;
    gap: 32px;
    align-items: flex-start;
    margin-bottom: 28px;
    padding: 24px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.car-detail__img {
    max-width: 520px;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.car-detail__hero-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.car-detail__hero-info h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.car-detail__price {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--green);
}

.car-detail__vin {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.car-detail__tesla-link {
    display: inline-block;
    margin-top: 8px;
    padding: 8px 20px;

    background: var(--accent);
    border-radius: var(--radius);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;
    transition: opacity 0.2s;
}

.car-detail__tesla-link:hover {
    opacity: 0.85;
}

.car-detail__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.car-detail__section {
    padding: 20px;
    margin-bottom: 16px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.car-detail__section h3 {
    margin-bottom: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
}

.car-detail__section dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 6px 12px;
    font-size: 0.85rem;
}

.car-detail__section dt {
    color: var(--text-muted);
    font-weight: 500;
}

.car-detail__section dd {
    margin: 0;
}

.car-detail__codes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.car-detail__code {
    display: inline-block;
    padding: 2px 10px;

    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.car-detail__raw {
    max-height: 400px;
    overflow: auto;
    padding: 12px;

    background: #0d0e12;
    border-radius: 6px;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .charts {
        grid-template-columns: 1fr;
    }

    .car-detail__hero {
        flex-direction: column;
    }

    .car-detail__grid {
        grid-template-columns: 1fr;
    }

    .expand-layout {
        flex-direction: column;
    }

    .expand-img {
        width: 100%;
        max-width: 400px;
    }

    .expand-specs {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .main {
        padding: 12px;
    }
}
