/* ═══════════════════════════════════════════════════════════════════════════
   Vehicle Service Advisor — Styles
   Dark theme matching Dave's shop tools
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary:    #0f1117;
    --bg-secondary:  #161821;
    --bg-card:       #1a1d2b;
    --bg-card-hover: #1f2235;
    --bg-input:      #121420;
    --border:        #2a2d3e;
    --border-focus:  #4f8cff;
    --text-primary:  #e8eaf0;
    --text-secondary:#8b8fa3;
    --text-muted:    #5a5e72;
    --accent:        #4f8cff;
    --accent-hover:  #6ba0ff;
    --accent-glow:   rgba(79, 140, 255, 0.15);
    --green:         #34d399;
    --green-bg:      rgba(52, 211, 153, 0.08);
    --orange:        #fb923c;
    --orange-bg:     rgba(251, 146, 60, 0.08);
    --red:           #f87171;
    --red-bg:        rgba(248, 113, 113, 0.08);
    --yellow:        #fbbf24;
    --yellow-bg:     rgba(251, 191, 36, 0.08);
    --purple:        #a78bfa;
    --radius:        10px;
    --radius-sm:     6px;
    --shadow:        0 2px 12px rgba(0,0,0,0.3);
    --transition:    0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}
.header-content {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.logo-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent), #7c5cff);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.logo-icon svg { width: 22px; height: 22px; }
.app-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* ── Container ───────────────────────────────────────────────────────────── */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}
.card-icon { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.input-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
}
.tab-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.input-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}
.input-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}
.input-group { display: flex; flex-direction: column; gap: 0.35rem; }
.input-group.flex-grow { flex: 1; }
.field-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}
.optional { color: var(--text-muted); font-weight: 400; }

input[type="text"],
input[type="number"],
textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
    width: 100%;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 48px; }

.mileage-wrap {
    position: relative;
}
.mileage-wrap input { padding-right: 2.5rem; }
.mileage-unit {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.error-msg {
    color: var(--red);
    font-size: 0.8rem;
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--red-bg);
    border-radius: var(--radius-sm);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-accent {
    background: var(--accent);
    color: #fff;
}
.btn-accent:hover { background: var(--accent-hover); }
.btn-accent:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    transition: var(--transition);
}
.btn-icon:hover { color: var(--red); background: var(--red-bg); }

.btn-generate {
    background: linear-gradient(135deg, var(--accent), #7c5cff);
    color: #fff;
    padding: 0.85rem 2rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius);
    border: none;
    box-shadow: 0 4px 24px rgba(79, 140, 255, 0.25);
}
.btn-generate:hover {
    box-shadow: 0 6px 32px rgba(79, 140, 255, 0.35);
    transform: translateY(-1px);
}
.btn-generate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.generate-row { display: flex; justify-content: center; }

/* ── Toggle Buttons ───────────────────────────────────────────────────────── */
.toggle-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}
.toggle-btn:hover { border-color: var(--text-muted); color: var(--text-primary); }
.toggle-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}
.badge-nhtsa {
    font-size: 0.6rem;
    font-weight: 700;
    background: var(--green);
    color: #000;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ── VIN Details Card ─────────────────────────────────────────────────────── */
.vin-details {
    margin-top: 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    animation: slideDown 0.3s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.vin-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.vin-details-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}
.vin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.6rem;
}
.vin-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.vin-field-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.vin-field-value {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* ── Results ──────────────────────────────────────────────────────────────── */
.results-card { animation: slideDown 0.3s ease; }
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.results-actions { display: flex; gap: 0.5rem; }

/* Official NHTSA bar */
.official-badge-bar {
    margin-bottom: 1rem;
}
.official-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--green-bg);
    color: var(--green);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.recalls-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.recall-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: 3px solid var(--orange);
    border-radius: var(--radius-sm);
    padding: 1rem;
}
.recall-item h4 { font-size: 0.9rem; color: var(--orange); margin-bottom: 0.4rem; font-weight: 600; }
.recall-item .recall-campaign { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 500; }
.recall-item p { font-size: 0.83rem; color: var(--text-secondary); line-height: 1.5; }
.recall-item .recall-remedy { margin-top: 0.5rem; color: var(--green); font-weight: 500; font-size: 0.83rem; }
.recall-none {
    padding: 1rem;
    background: var(--green-bg);
    border: 1px solid rgba(52, 211, 153, 0.15);
    border-radius: var(--radius-sm);
    color: var(--green);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* AI Report markdown */
.ai-report-content {
    font-size: 0.88rem;
    line-height: 1.7;
    color: var(--text-secondary);
}
.ai-report-content h1, .ai-report-content h2 {
    color: var(--accent);
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 1.5rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.ai-report-content h3 {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 1.2rem;
    margin-bottom: 0.4rem;
}
.ai-report-content h4 {
    color: var(--purple);
    font-size: 0.88rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.3rem;
}
.ai-report-content p { margin-bottom: 0.6rem; }
.ai-report-content strong { color: var(--text-primary); }
.ai-report-content ul, .ai-report-content ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}
.ai-report-content li { margin-bottom: 0.3rem; }
.ai-report-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.82rem;
}
.ai-report-content th {
    background: var(--bg-input);
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.ai-report-content td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.ai-report-content tr:nth-child(even) td { background: rgba(255,255,255,0.015); }
.ai-report-content code {
    background: var(--bg-input);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.82rem;
    color: var(--green);
}
.ai-report-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 0.5rem 1rem;
    margin: 0.75rem 0;
    background: var(--accent-glow);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-primary);
    font-style: italic;
}
.ai-report-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

/* Disclaimer */
.disclaimer {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--yellow-bg);
    border: 1px solid rgba(251, 191, 36, 0.15);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    color: var(--yellow);
    font-weight: 500;
}

/* ── Loading ──────────────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.85);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}
.spinner {
    width: 44px; height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
.app-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
    body { background: #fff; color: #000; }
    .app-header, .vehicle-input-card, .options-card, .generate-row,
    .results-actions, .app-footer, .loading-overlay { display: none !important; }
    .card { border: 1px solid #ddd; box-shadow: none; background: #fff; }
    .results-card { display: block !important; }
    .ai-report-content h1, .ai-report-content h2 { color: #333; border-bottom-color: #ddd; }
    .ai-report-content h3, .ai-report-content h4 { color: #444; }
    .ai-report-content, .ai-report-content p, .ai-report-content li,
    .ai-report-content td { color: #333; }
    .ai-report-content th { background: #f0f0f0; color: #333; }
    .recall-item { border-left-color: #e67e22; }
    .recall-item h4 { color: #e67e22; }
    .disclaimer { background: #fff9e6; color: #856404; border-color: #ffc107; }
    .official-badge { background: #e6f9f0; color: #1a7a4c; }
    @page { margin: 0.75in; }
    .results-card::before {
        content: "Vehicle Service Report";
        display: block;
        font-size: 1.4rem;
        font-weight: 700;
        margin-bottom: 1rem;
        color: #333;
    }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .container { padding: 1rem 0.75rem; gap: 1rem; }
    .card { padding: 1.15rem; }
    .input-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .input-row { flex-direction: column; align-items: stretch; }
    .input-row .btn { width: 100%; justify-content: center; }
    .vin-grid { grid-template-columns: repeat(2, 1fr); }
    .toggle-grid { gap: 0.4rem; }
    .toggle-btn { flex: 1 1 calc(50% - 0.4rem); justify-content: center; font-size: 0.75rem; padding: 0.5rem 0.6rem; }
    .results-header { flex-direction: column; align-items: flex-start; }
    .btn-generate { width: 100%; justify-content: center; }
    .header-subtitle { display: none; }
}
@media (max-width: 480px) {
    .input-grid-4 { grid-template-columns: 1fr; }
    .vin-grid { grid-template-columns: 1fr 1fr; }
    .toggle-btn { flex: 1 1 100%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RO banner + embed skin
   ═══════════════════════════════════════════════════════════════════════════ */

/* "2021 BMW M340i — from this repair order". Also the honest place to say the
   RO had no VIN on it, which is why it has a warning variant rather than just
   being hidden on failure: silently showing an empty VIN field would leave the
   tech wondering whether the lookup ran at all. */
.ro-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent-glow);
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.4;
}
.ro-banner svg { flex: 0 0 auto; color: var(--accent); }
.ro-banner--warn { border-left-color: var(--orange); background: var(--orange-bg); }
.ro-banner--warn svg { color: var(--orange); }
.ro-banner--busy { border-left-color: var(--text-muted); background: transparent; }
.ro-banner--busy svg { color: var(--text-muted); }

/* ── Embed mode (?embed=1) ──────────────────────────────────────────────────
   The extension frames this page in a modal that already has its own title bar
   and close button, so the page's own header and footer are pure duplication
   in there — and vertical space in a modal is the scarcest thing there is.

   This is the ONLY place the embed skin is defined. Everything else on the
   page keeps reading the same tokens it always did; the modal's host can
   push Shopmonkey's live surface colours over them at runtime (see the
   hlx-theme listener in index.html) and the whole page follows. */
body.embed .app-header,
body.embed .app-footer { display: none !important; }

body.embed { min-height: 0; }

body.embed .container {
    max-width: none;
    padding: 1rem 1.25rem 1.5rem;
}

/* With the VIN arriving from the repair order, the VIN tab is a status line
   rather than an input — but it stays on screen and stays editable, because
   the decode is NHTSA's and NHTSA is wrong about some cars. Overriding the
   vehicle by hand has to remain one click away. */
body.embed.embed-has-order .input-tabs { margin-bottom: 0.75rem; }

/* The modal is not a print surface; the host page is. Keeping the print button
   is still right (it prints the report, not the modal), so nothing is hidden
   here — this rule only exists to document that the omission is deliberate. */
