/* ============================================================================
   ECU Catalog 2.0 — Web edition
   Dark theme UI, matching the original desktop application's look & feel.
   ========================================================================== */

:root {
    --bg:            #111419;
    --bg-panel:      #171b21;
    --bg-card:       #1b2027;
    --bg-list:       #12161b;
    --bg-table:      #11151a;
    --bg-input:      #20252d;
    --bg-hover:      #202731;
    --bg-selected:   #2d5379;

    --border:        #292f38;
    --border-strong: #303742;
    --border-input:  #3a424e;

    --text:          #e7ebf0;
    --text-bright:   #f4f6f8;
    --text-dim:      #c9d1da;
    --muted:         #8f99a6;
    --muted-2:       #6f7781;

    --accent:        #6299cf;
    --accent-strong: #3f74a9;

    --danger:        #e06c75;

    --radius:        8px;
    --radius-sm:     5px;

    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, Helvetica, Arial, sans-serif;
    --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: #15191f; }
::-webkit-scrollbar-thumb { background: #3a424d; border-radius: 6px; border: 2px solid #15191f; }
::-webkit-scrollbar-thumb:hover { background: #4b5663; }

/* ---- Top bar ---- */
.topbar {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    flex: 0 0 auto;
}
.topbar-inner {
    max-width: 1500px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
}
.logo { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 8px; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.app-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: 0.2px;
    line-height: 1.15;
}
.app-subtitle {
    margin: 0;
    font-size: 12px;
    color: var(--muted);
}
.topbar-stats {
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
}
.topbar-stats strong { color: var(--text-dim); font-weight: 600; }

/* ---- Layout ---- */
.layout {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 330px 1fr;
    gap: 14px;
    max-width: 1500px;
    width: 100%;
    margin: 0 auto;
    padding: 14px 20px;
    min-height: 0;
}

.sidebar {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    max-height: calc(100vh - 120px);
    position: sticky;
    top: 14px;
}

.panel-heading {
    font-size: 13px;
    font-weight: 650;
    color: var(--text-bright);
    letter-spacing: 0.2px;
}

.control {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 14px;
    font-family: var(--font);
    width: 100%;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(98, 153, 207, 0.22);
}
select.control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238f99a6' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}
input.control::placeholder { color: var(--muted-2); }

/* ---- Model list ---- */
.model-list {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0 -4px;
    padding: 0 4px;
    min-height: 0;
}

.model-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 7px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.model-item:hover { background: var(--bg-hover); }
.model-item.selected {
    background: var(--bg-selected);
    border-color: var(--accent-strong);
}
.model-item.no-data { opacity: 0.65; }

.model-thumb {
    width: 76px;
    height: 48px;
    flex: 0 0 auto;
    border-radius: 4px;
    background: #f4f5f6 center/contain no-repeat;
    border: 1px solid var(--border-strong);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6d7680;
    font-weight: 700;
    font-size: 13px;
}
.model-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.model-item-info { min-width: 0; display: flex; flex-direction: column; }
.model-item-name {
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.model-item-meta {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Content ---- */
.content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    min-height: 0;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 12px 14px;
}

/* Header card */
.header-card { display: flex; gap: 16px; align-items: center; }
.preview {
    width: 210px;
    height: 126px;
    flex: 0 0 auto;
    background: #f4f5f6 center/contain no-repeat;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6d7680;
    font-weight: 700;
    font-size: 20px;
    overflow: hidden;
}
.preview img { width: 100%; height: 100%; object-fit: contain; }
.info { min-width: 0; }
.model-title {
    margin: 0 0 2px;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-bright);
    overflow-wrap: anywhere;
}
.model-meta {
    margin: 0 0 4px;
    font-size: 14px;
    color: #b8c2ce;
    overflow-wrap: anywhere;
}
.muted { color: var(--muted); }

/* VIN card */
.vin-card { display: flex; flex-direction: column; gap: 8px; }
.vin-row { display: flex; gap: 8px; }
.vin-row .control { flex: 1 1 auto; width: auto; }
.vin-details {
    background: var(--bg-list);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    max-height: 240px;
    overflow-y: auto;
}
.vin-details dl { margin: 0; display: grid; grid-template-columns: 160px 1fr; row-gap: 4px; column-gap: 12px; }
.vin-details dt { color: var(--muted); font-weight: 600; }
.vin-details dd { margin: 0; color: var(--text); }
.vin-section-title {
    margin: 10px 0 6px;
    font-weight: 700;
    color: var(--text-bright);
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 3px;
}

/* Buttons */
.btn {
    background: #242a32;
    color: var(--text);
    border: 1px solid #3b444f;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 14px;
    font-family: var(--font);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: #2b333d; border-color: var(--accent); }
.btn:active { background: #20262e; }
.btn:disabled {
    color: var(--muted-2);
    background: #1c2026;
    border-color: #2b3037;
    cursor: not-allowed;
}
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

/* Search row */
.search-row { display: flex; gap: 8px; }
.search-row .scope { flex: 0 0 auto; width: 170px; }
.search-row .grow { flex: 1 1 auto; width: auto; }

.result-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}
.result-label {
    color: var(--text-dim);
    font-weight: 600;
}
.result-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

/* ---- Table ---- */
.table-wrap {
    flex: 1 1 auto;
    min-height: 240px;
    max-height: calc(100vh - 400px);
    overflow: auto;
    background: var(--bg-table);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #222831;
    color: #cbd3dc;
    font-weight: 650;
    text-align: left;
    padding: 9px 10px;
    border-bottom: 1px solid #353d48;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
thead th.sel-col { cursor: default; width: 34px; }
thead th .sort-arrow { opacity: 0.55; font-size: 11px; margin-left: 3px; }

tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid #1f242b;
    vertical-align: top;
    color: #dde3e9;
    word-break: break-word;
}
tbody tr:nth-child(even) { background: #151a20; }
tbody tr:hover { background: #1b222c; }
tbody tr.selected { background: var(--bg-selected); }

td.cell-copy { cursor: pointer; }
td.cell-copy:hover { color: #ffffff; }

.vehicle-cell { font-weight: 600; color: var(--text-bright); }
.hide-vehicle [data-col="vehicle"] { display: none; }
.star-cell { font-family: var(--mono); font-size: 12.5px; }
.ecu-cell { font-weight: 600; }
.also-cell .chip {
    display: inline-block;
    background: #242a32;
    border: 1px solid #343c47;
    border-radius: 10px;
    padding: 1px 8px;
    margin: 1px 3px 1px 0;
    font-size: 11.5px;
    color: #c7d0da;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    pointer-events: none;
}
.empty-title { margin: 0; font-size: 15px; color: var(--text-dim); font-weight: 600; }
.empty-hint { margin: 0; font-size: 13px; color: var(--muted); }

/* ---- Status bar / toast ---- */
.statusbar {
    flex: 0 0 auto;
    background: var(--bg);
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12.5px;
    padding: 7px 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast {
    position: fixed;
    bottom: 46px;
    left: 50%;
    transform: translateX(-50%);
    background: #242a33;
    color: var(--text-bright);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 16px;
    font-size: 13.5px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    z-index: 100;
    animation: toast-in 0.18s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- Loading state ---- */
.model-list.loading, .content.loading { position: relative; }
.spinner {
    width: 26px;
    height: 26px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Responsive ---- */
@media (max-width: 920px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { max-height: none; position: static; }
    .model-list { max-height: 320px; }
    .header-card { flex-direction: column; align-items: stretch; }
    .preview { width: 100%; height: 160px; }
    .search-row { flex-wrap: wrap; }
    .search-row .scope { width: 100%; }
    .topbar-stats { display: none; }
    .result-bar { flex-wrap: wrap; }
    .result-actions { margin-left: 0; }
}
