/* VIN Intelligence Dashboard — dark theme (GitHub Dark inspired) ----------- */

:root {
    --bg:        #0d1117;
    --surface:   #161b22;
    --surface-2: #1c232c;
    --border:    #30363d;
    --text:      #c9d1d9;
    --muted:     #8b949e;
    --accent:    #58a6ff;
    --green:     #3fb950;
    --amber:     #d29922;
    --red:       #f85149;
    --mono:      #d2a8ff;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Inline code / monospace utility ----------------------------------------- */
code, .mono {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: var(--mono);
}
.num {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    text-align: right;
}

/* Top nav ----------------------------------------------------------------- */
nav.top {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
nav.top a {
    color: var(--text);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
}
nav.top a:hover { background: var(--surface-2); text-decoration: none; }
nav.top a.active {
    background: var(--accent);
    color: var(--bg);
    font-weight: 600;
}
nav.top .spacer { flex: 1; }
nav.top .badge {
    padding: 0.2rem 0.55rem; border-radius: 999px;
    background: var(--green);
    color: var(--bg);
    font-size: 0.75rem; font-weight: 600;
}
nav.top .badge.amber { background: var(--amber); }
nav.top form { display: inline; }
nav.top button.logout {
    background: transparent; color: var(--text);
    border: 1px solid var(--border);
    padding: 0.2rem 0.6rem; border-radius: 4px; cursor: pointer;
}
nav.top button.logout:hover { background: var(--surface-2); }

/* Page main --------------------------------------------------------------- */
main { max-width: 1200px; margin: 1.5rem auto; padding: 0 1.25rem; }
h1 { margin: 0 0 1rem 0; font-size: 1.5rem; }
h2 { margin: 1.5rem 0 0.5rem 0; font-size: 1.15rem; color: var(--text); }
h3 { margin: 1rem 0 0.5rem 0; font-size: 0.85rem; color: var(--muted);
     text-transform: uppercase; letter-spacing: 0.06em; }

/* Tiles ------------------------------------------------------------------- */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}
.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
}
.tile .label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tile .value {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 0.25rem;
    color: var(--text);
    /* Long monospace identifiers (e.g. the NHTSA vPIC version) must wrap inside
       narrow tiles instead of overflowing the page. */
    overflow-wrap: anywhere;
    word-break: break-word;
}
.tile .value.accent { color: var(--accent); }

/* Tables ------------------------------------------------------------------ */
table.data {
    width: 100%; border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
table.data th, table.data td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
table.data th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.expanded td { background: var(--surface-2); }

/* Status pills ------------------------------------------------------------ */
.pill {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-2);
    color: var(--muted);
}
.pill.ok   { background: rgba(63, 185, 80, 0.15);  color: var(--green); }
.pill.warn { background: rgba(210, 153, 34, 0.15); color: var(--amber); }
.pill.err  { background: rgba(248, 81, 73, 0.15);  color: var(--red); }

/* Histogram --------------------------------------------------------------- */
.histogram {
    display: flex; align-items: flex-end; gap: 4px;
    height: 240px;
    padding: 0.75rem 1rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.histogram .bar {
    flex: 1;
    background: var(--accent);
    position: relative;
    min-height: 2px;
    border-radius: 1px 1px 0 0;
}
.histogram .bar .label {
    position: absolute;
    bottom: -18px; left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--muted);
}

/* Login page -------------------------------------------------------------- */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-form {
    display: flex; flex-direction: column; gap: 0.75rem;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 320px;
}
.login-form h1 { text-align: center; margin-bottom: 0.5rem; color: var(--text); }
.login-form input, .login-form button {
    padding: 0.6rem;
    font-size: 1rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}
.login-form button {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}
.login-form button:hover { filter: brightness(1.1); }
.login-error {
    padding: 0.5rem;
    background: rgba(248, 81, 73, 0.08);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: 4px;
    color: var(--red);
    font-size: 0.9rem;
}

/* Banners ----------------------------------------------------------------- */
.banner {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin: 1rem 0;
    border: 1px solid;
}
.banner.warn {
    background: rgba(210, 153, 34, 0.08);
    border-color: rgba(210, 153, 34, 0.3);
    color: var(--amber);
}
.banner.error {
    background: rgba(248, 81, 73, 0.08);
    border-color: rgba(248, 81, 73, 0.3);
    color: var(--red);
}

/* Provenance cards (Lookup page) ----------------------------------------- */
.provenance {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.provenance .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
}
.provenance .card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: var(--text);
    text-transform: none;
    letter-spacing: normal;
}
.provenance .card dl {
    margin: 0;
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.25rem 0.75rem;
    font-size: 0.9rem;
}
.provenance .card dt { color: var(--muted); }
.provenance .card dd { margin: 0; color: var(--text); }

/* Forms ------------------------------------------------------------------- */
form.filter {
    display: flex; flex-wrap: wrap; gap: 0.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 1rem;
}
form.filter label {
    display: flex; flex-direction: column;
    font-size: 0.75rem;
    color: var(--muted);
}
form.filter input, form.filter select {
    padding: 0.4rem;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
}
form.filter input:focus, form.filter select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}
form.filter button {
    align-self: flex-end;
    padding: 0.4rem 1rem;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}
form.filter button:hover { filter: brightness(1.1); }

/* Pagination + Tabbar ----------------------------------------------------- */
.paginator { display: flex; gap: 0.5rem; align-items: center; margin: 1rem 0; }
.paginator a {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 4px;
    color: var(--text);
}
.paginator a:hover { background: var(--surface-2); text-decoration: none; }
.paginator .current { font-weight: 600; color: var(--text); }

.tabbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tabbar a {
    padding: 0.4rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
}
.tabbar a:hover { background: var(--surface-2); text-decoration: none; }
.tabbar a.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 600;
}

/* htmx loading indicators ------------------------------------------------- */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }
.inline-spinner {
    display: inline-block; width: 12px; height: 12px;
    border: 2px solid rgba(150, 150, 150, 0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: dashboard-spin 800ms linear infinite;
    vertical-align: middle; margin-left: 0.5rem;
}
@keyframes dashboard-spin { to { transform: rotate(360deg); } }

/* Global error banner (injected by dashboard.js) -------------------------- */
.banner.error.global {
    position: fixed; bottom: 1rem; right: 1rem; max-width: 420px;
    background: rgba(248, 81, 73, 0.12);
    border: 1px solid rgba(248, 81, 73, 0.4);
    color: var(--red);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    font-size: 0.9rem;
}

/* Run rows: keyboard focus + open state ----------------------------------- */
tr.run-row { cursor: pointer; }
tr.run-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.run-row.open td { background: var(--surface-2); }

/* Page-size selector ------------------------------------------------------ */
.page-size {
    font-size: 0.8rem;
    color: var(--muted);
    margin-left: 0.5rem;
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}
.page-size select {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
}

/* pre / error blocks ------------------------------------------------------ */
pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Mobile responsive ------------------------------------------------------- */
@media (max-width: 768px) {
    nav.top { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0.75rem; }
    nav.top a { padding: 0.2rem 0.4rem; font-size: 0.85rem; }
    main { padding: 0 0.75rem; margin: 1rem auto; }
    .provenance { grid-template-columns: 1fr; }
    .tile .value { font-size: 1.2rem; }
}

/* Always allow horizontal scroll for wide tables -------------------------- */
table.data { display: block; overflow-x: auto; }
@media (min-width: 769px) {
    table.data { display: table; }
}

/* Run-detail expanded card ------------------------------------------------ */
.run-detail {
    padding: 0.75rem;
    margin-top: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
