:root {
    --brand-primary: #071c33;
    --brand-accent: #f06422;
    --brand-accent-dark: #cb4b11;
    --surface: #ffffff;
    --surface-soft: #f5f7fa;
    --surface-blue: #edf4fb;
    --text: #152033;
    --muted: #657084;
    --border: #dbe2ea;
    --success: #16834b;
    --danger: #bd2832;
    --facebook: #1877f2;
    --shadow: 0 16px 45px rgba(7, 28, 51, .10);
    --radius: 18px;
    --radius-small: 12px;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--surface-soft);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 11px;
    padding: 12px 13px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 4px rgba(240, 100, 34, .13);
}
textarea { resize: vertical; min-height: 170px; }
small { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.muted { color: var(--muted); }
.eyebrow {
    margin: 0 0 7px;
    color: var(--brand-accent);
    font-weight: 800;
    font-size: .78rem;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 68px;
    padding: 10px clamp(14px, 3vw, 34px);
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid rgba(219,226,234,.9);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; text-decoration: none; min-width: 0; }
.brand img { width: min(255px, 54vw); height: 46px; object-fit: contain; object-position: left center; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; min-width: 0; }
.header-title { color: var(--muted); font-size: .92rem; white-space: nowrap; }
.user-chip {
    background: var(--surface-blue);
    color: var(--brand-primary);
    padding: 8px 11px;
    border-radius: 999px;
    font-weight: 700;
    font-size: .85rem;
    white-space: nowrap;
}
.icon-link {
    text-decoration: none;
    color: var(--brand-primary);
    font-weight: 750;
    padding: 7px 5px;
    font-size: .9rem;
}

.page-shell { width: min(1280px, calc(100% - 28px)); margin: 24px auto 54px; }
.app-footer { padding: 26px 16px 40px; color: var(--muted); text-align: center; font-size: .84rem; }
.app-footer p { margin: 0; }

.btn {
    border: 0;
    border-radius: 11px;
    min-height: 43px;
    padding: 10px 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
    font-weight: 800;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { cursor: wait; opacity: .65; transform: none; }
.btn-primary { background: var(--brand-accent); color: #fff; box-shadow: 0 9px 22px rgba(240,100,34,.24); }
.btn-primary:hover { background: var(--brand-accent-dark); }
.btn-secondary { background: var(--brand-primary); color: #fff; }
.btn-facebook { background: var(--facebook); color: #fff; box-shadow: 0 9px 22px rgba(24,119,242,.22); }
.btn-ghost { background: #fff; color: var(--brand-primary); border: 1px solid var(--border); }
.btn-danger { background: #fff1f2; color: var(--danger); border: 1px solid #fecdd3; }
.btn-small { min-height: 36px; padding: 7px 11px; font-size: .84rem; border-radius: 9px; }
.btn-large { min-height: 52px; padding: 13px 22px; }

.flash {
    margin: 0 0 18px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
}
.flash ul { margin: 8px 0 0; padding-left: 20px; }
.flash-success { background: #ecfdf3; color: #0f6b3d; border-color: #b7ebce; }
.flash-error { background: #fff0f1; color: #9e1c28; border-color: #ffc9ce; }

.hero-strip {
    background: linear-gradient(130deg, var(--brand-primary), #0b315c);
    color: #fff;
    border-radius: 22px;
    padding: clamp(22px, 5vw, 46px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}
.hero-strip::after {
    content: "";
    position: absolute;
    width: 240px;
    height: 240px;
    right: -90px;
    top: -120px;
    border-radius: 50%;
    background: rgba(240,100,34,.20);
}
.hero-strip h1 { margin: 0 0 8px; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1.08; max-width: 760px; }
.hero-strip p:not(.eyebrow) { margin: 0; max-width: 720px; color: #cbd8e5; }
.hero-stat { position: relative; z-index: 1; min-width: 170px; text-align: center; padding: 20px; background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.14); border-radius: 18px; }
.hero-stat strong { display: block; font-size: 2.5rem; line-height: 1; }
.hero-stat span { display: block; margin-top: 7px; color: #d5e0ea; font-size: .9rem; }

.filter-bar {
    margin: 20px 0 12px;
    padding: 14px;
    display: grid;
    grid-template-columns: minmax(240px, 1.6fr) minmax(150px, .7fr) minmax(150px, .7fr) auto auto;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(7,28,51,.05);
}
.inventory-summary { margin: 14px 3px; color: var(--muted); }
.inventory-summary strong { color: var(--text); }
.vehicle-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.vehicle-card { background: #fff; border: 1px solid var(--border); border-radius: 17px; overflow: hidden; box-shadow: 0 10px 30px rgba(7,28,51,.06); min-width: 0; }
.vehicle-card-image { display: block; position: relative; aspect-ratio: 4 / 3; background: #e9eef4; overflow: hidden; }
.vehicle-card-image img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.vehicle-card:hover .vehicle-card-image img { transform: scale(1.025); }
.status-badge, .photo-count { position: absolute; bottom: 11px; padding: 6px 9px; border-radius: 999px; font-weight: 800; font-size: .72rem; }
.status-badge { left: 11px; background: #e8fff2; color: #107143; }
.photo-count { right: 11px; background: rgba(7,28,51,.88); color: #fff; }
.vehicle-card-body { padding: 17px; }
.vehicle-kicker { margin: 0 0 4px; color: var(--brand-accent); text-transform: uppercase; font-size: .72rem; font-weight: 850; letter-spacing: .08em; }
.vehicle-card h2 { margin: 0; font-size: 1.15rem; line-height: 1.25; }
.trim-line { margin: 5px 0 0; color: var(--muted); min-height: 24px; font-size: .88rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.spec-row { margin: 13px 0 15px; display: flex; flex-wrap: wrap; gap: 8px; }
.spec-row span { background: var(--surface-soft); border-radius: 999px; padding: 6px 8px; color: #4d596b; font-size: .77rem; }
.card-price-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-price-row strong { font-size: 1rem; color: var(--brand-primary); }

.empty-state { margin-top: 20px; padding: 48px 22px; text-align: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.empty-state h2 { margin-top: 0; }
.back-link { display: inline-block; margin: 0 0 16px; text-decoration: none; color: var(--brand-primary); font-weight: 800; }

.vehicle-detail-shell { width: min(1180px, calc(100% - 28px)); }
.vehicle-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 18px; }
.vehicle-heading h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.06; }
.vehicle-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 1.02rem; }
.vehicle-source-price { min-width: 220px; padding: 14px 16px; text-align: right; background: #fff; border: 1px solid var(--border); border-radius: 14px; }
.vehicle-source-price span { display: block; color: var(--muted); font-size: .77rem; }
.vehicle-source-price strong { display: block; margin-top: 3px; color: var(--brand-primary); font-size: 1.12rem; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(17px, 3vw, 28px); margin: 0 0 18px; box-shadow: 0 9px 32px rgba(7,28,51,.05); }
.panel h1, .panel h2 { margin-top: 0; }
.panel-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.panel-heading h2 { margin: 0 0 4px; font-size: 1.28rem; }
.panel-heading p { margin: 0; color: var(--muted); }
.split-heading { justify-content: space-between; gap: 20px; }
.split-heading > div:first-child { display: flex; align-items: flex-start; gap: 12px; }
.step-number { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; background: var(--brand-accent); font-weight: 900; box-shadow: 0 6px 18px rgba(240,100,34,.24); }
.selection-tools, .template-buttons { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.selection-counter { min-width: 50px; text-align: center; background: var(--surface-blue); color: var(--brand-primary); border-radius: 999px; padding: 7px 9px; font-size: .84rem; }
.photo-selector { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.selectable-photo { position: relative; display: block; border: 3px solid transparent; border-radius: 13px; overflow: hidden; background: #e7ecf2; cursor: pointer; aspect-ratio: 4 / 3; transition: border-color .15s ease, transform .15s ease; }
.selectable-photo:hover { transform: translateY(-1px); }
.selectable-photo input { position: absolute; opacity: 0; pointer-events: none; }
.selectable-photo img { width: 100%; height: 100%; object-fit: cover; }
.selectable-photo.is-selected { border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(240,100,34,.13); }
.selectable-photo input:disabled + img { opacity: .48; filter: grayscale(.15); }
.photo-order { position: absolute; left: 7px; bottom: 7px; background: rgba(7,28,51,.84); color: #fff; border-radius: 8px; padding: 4px 7px; font-size: .68rem; font-weight: 700; }
.check-mark { position: absolute; right: 7px; top: 7px; width: 28px; height: 28px; display: none; align-items: center; justify-content: center; border-radius: 50%; background: var(--brand-accent); color: #fff; font-weight: 900; }
.selectable-photo.is-selected .check-mark { display: flex; }
.photo-actions { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.helper-text { flex-basis: 100%; margin: 0; color: var(--muted); font-size: .78rem; }
.listing-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field-with-copy { display: block; min-width: 0; }
.field-with-copy > span, .field > label { display: block; margin-bottom: 6px; color: #344155; font-weight: 750; font-size: .86rem; }
.field-wide { grid-column: 1 / -1; }
.input-copy-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 7px; }
.input-copy-row input[readonly] { background: #f7f9fb; color: #4d596b; }
.copy-button, .inline-copy { border: 0; cursor: pointer; color: var(--brand-primary); background: var(--surface-blue); font-weight: 800; border-radius: 9px; padding: 8px 10px; white-space: nowrap; }
.inline-copy { display: inline; padding: 4px 7px; }
.warning-text { display: block; color: #a64517; margin-top: 6px; }
.textarea-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; color: var(--muted); font-size: .8rem; }
.final-panel { border-color: rgba(24,119,242,.25); background: linear-gradient(180deg, #fff, #f7fbff); }
.final-actions { display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 10px; }
.source-link-line { margin: 15px 0 0; color: var(--muted); font-size: .82rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid h2 { margin: 14px 0 -2px; font-size: 1.15rem; }
.field { min-width: 0; }
.field small { display: block; margin-top: 5px; }
.stack-form { display: grid; gap: 15px; }
.stack-form label span { display: block; margin-bottom: 6px; font-weight: 750; }

.login-page, .install-page { background: radial-gradient(circle at 85% 15%, rgba(240,100,34,.17), transparent 34%), linear-gradient(135deg, #06172a, #0c3157); }
.login-shell, .install-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 14px; }
.login-card, .install-card { width: min(470px, 100%); background: #fff; border-radius: 24px; padding: clamp(24px, 5vw, 42px); box-shadow: 0 30px 80px rgba(0,0,0,.24); }
.install-card { width: min(900px, 100%); }
.login-logo, .install-logo { width: min(330px, 90%); margin: 0 auto 18px; }
.login-card h1, .install-card h1 { margin: 0 0 7px; text-align: center; }
.login-card > p, .install-card > p { text-align: center; margin-top: 0; }

.admin-shell { width: min(1180px, calc(100% - 28px)); }
.admin-hero { padding: 28px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.admin-hero h1 { margin: 0 0 7px; }
.admin-hero p:last-child { color: var(--muted); margin: 0; max-width: 760px; }
.stat-grid { margin: 17px 0; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 13px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 15px; padding: 20px; }
.stat-card strong { display: block; font-size: 1.9rem; color: var(--brand-primary); }
.stat-card span { color: var(--muted); font-size: .84rem; }
.admin-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.admin-nav-card { display: flex; gap: 15px; align-items: center; text-decoration: none; background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 21px; transition: transform .15s ease, box-shadow .15s ease; }
.admin-nav-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.admin-nav-icon { font-size: 2rem; }
.admin-nav-card h2 { margin: 0 0 3px; font-size: 1.05rem; }
.admin-nav-card p { margin: 0; color: var(--muted); font-size: .84rem; }
.diagnostic-list { margin: 0; }
.diagnostic-list > div { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 15px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.diagnostic-list > div:last-child { border-bottom: 0; }
.diagnostic-list dt { font-weight: 800; }
.diagnostic-list dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.user-list { display: grid; gap: 10px; }
.user-row { display: grid; grid-template-columns: auto minmax(130px,1fr) auto auto minmax(210px,auto) auto; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 13px; }
.user-avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-primary); color: #fff; font-weight: 900; }
.user-main strong, .user-main span { display: block; }
.user-main span { color: var(--muted); font-size: .8rem; }
.inline-form { margin: 0; }
.inline-reset-form { display: grid; grid-template-columns: minmax(95px,1fr) auto; gap: 6px; }
.inline-reset-form input { min-width: 0; padding: 8px 9px; }
.pill { display: inline-flex; padding: 6px 9px; border-radius: 999px; font-size: .72rem; font-weight: 850; }
.pill-success { color: #0e7040; background: #e8fff2; }
.pill-muted { color: #6d7685; background: #edf0f3; }
.activity-table-wrap { overflow-x: auto; }
.activity-table { width: 100%; border-collapse: collapse; min-width: 700px; }
.activity-table th, .activity-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
.activity-table th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }

.app-toast { position: fixed; left: 50%; bottom: 22px; z-index: 9999; transform: translate(-50%, 18px); opacity: 0; background: var(--brand-primary); color: #fff; padding: 11px 15px; border-radius: 999px; box-shadow: 0 13px 40px rgba(0,0,0,.24); font-weight: 750; font-size: .88rem; transition: opacity .2s ease, transform .2s ease; pointer-events: none; }
.app-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.app-toast.toast-error { background: var(--danger); }

@media (max-width: 1050px) {
    .vehicle-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .photo-selector { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .listing-fields { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .filter-bar { grid-template-columns: minmax(220px,1.2fr) minmax(140px,.7fr) minmax(140px,.7fr) auto; }
    .filter-bar .btn-ghost { grid-column: 1 / -1; }
    .user-row { grid-template-columns: auto minmax(130px,1fr) auto; }
    .user-row .inline-form, .user-row .inline-reset-form { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .app-header { min-height: 60px; padding: 8px 12px; }
    .brand img { width: min(210px, 58vw); height: 40px; }
    .header-title, .user-chip { display: none; }
    .icon-link { font-size: .82rem; }
    .page-shell, .vehicle-detail-shell, .admin-shell { width: min(100% - 20px, 680px); margin-top: 14px; }
    .hero-strip { align-items: flex-start; padding: 23px 18px; }
    .hero-stat { display: none; }
    .filter-bar { grid-template-columns: 1fr 1fr; padding: 10px; }
    .search-field { grid-column: 1 / -1; }
    .filter-bar .btn { width: 100%; }
    .vehicle-grid { grid-template-columns: 1fr; gap: 13px; }
    .vehicle-card { display: grid; grid-template-columns: 42% minmax(0, 1fr); min-height: 164px; }
    .vehicle-card-image { height: 100%; aspect-ratio: auto; }
    .vehicle-card-body { padding: 13px; min-width: 0; }
    .vehicle-card h2 { font-size: 1rem; }
    .trim-line { min-height: 0; font-size: .78rem; }
    .spec-row { margin: 8px 0; gap: 5px; }
    .spec-row span { font-size: .68rem; padding: 5px 7px; }
    .card-price-row { align-items: flex-end; }
    .card-price-row strong { font-size: .84rem; }
    .card-price-row .btn { min-height: 34px; padding: 6px 9px; font-size: .75rem; }
    .status-badge { top: 8px; bottom: auto; font-size: .62rem; }
    .photo-count { bottom: 8px; right: 8px; font-size: .62rem; }
    .vehicle-heading { align-items: flex-start; flex-direction: column; gap: 12px; }
    .vehicle-source-price { width: 100%; text-align: left; }
    .panel { border-radius: 14px; padding: 15px 13px; }
    .split-heading { flex-direction: column; }
    .selection-tools, .template-buttons { width: 100%; justify-content: flex-start; }
    .photo-selector { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
    .photo-actions { display: grid; grid-template-columns: 1fr; }
    .listing-fields { grid-template-columns: 1fr; }
    .final-actions { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .install-card { padding: 23px 16px; border-radius: 18px; }
    .admin-hero { align-items: flex-start; flex-direction: column; padding: 20px; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .admin-card-grid { grid-template-columns: 1fr; }
    .diagnostic-list > div { grid-template-columns: 1fr; gap: 3px; }
    .user-row { grid-template-columns: auto minmax(0,1fr); align-items: start; }
    .user-row .pill { justify-self: start; grid-column: 2; }
    .user-row .inline-form, .user-row .inline-reset-form { grid-column: 1 / -1; }
    .inline-reset-form { grid-template-columns: 1fr auto; }
}

@media (max-width: 410px) {
    .vehicle-card { grid-template-columns: 40% minmax(0,1fr); }
    .vehicle-card-body { padding: 10px; }
    .vehicle-kicker { font-size: .62rem; }
    .vehicle-card h2 { font-size: .9rem; }
    .trim-line { display: none; }
    .spec-row span:nth-child(n+2) { display: none; }
    .filter-bar { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 15px; }
}

.history-list { display: grid; gap: 12px; }
.history-card { border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.history-card-heading { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.history-card-heading strong, .history-card-heading span { display: block; }
.history-card-heading div > span { color: var(--muted); font-size: .78rem; margin-top: 3px; }
.history-form { margin-top: 12px; display: grid; grid-template-columns: 130px minmax(220px,1fr) auto auto; gap: 8px; }
@media (max-width: 760px) {
    .header-actions .icon-link:first-of-type { display: none; }
    .history-form { grid-template-columns: 1fr; }
}
.limit-warning { margin: 0 0 15px; padding: 13px 15px; border: 1px solid #f5c58d; background: #fff7e8; color: #8b4b0f; border-radius: 12px; }
