/* ═══════════════════════════════════════════════════════
   CoreAuto Design System — Dark Automotive Theme
   ═══════════════════════════════════════════════════════ */

:root {
  --bg:           #080e1a;
  --bg-card:      #0f1929;
  --bg-surface:   #131f30;
  --bg-surface2:  #1a2840;
  --border:       rgba(255,255,255,0.08);
  --border-focus: #3b82f6;
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-green: #22c55e;
  --accent-red:   #ef4444;
  --text:         #e2e8f0;
  --text-muted:   #64748b;
  --text-dim:     #94a3b8;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    20px;
  --shadow:       0 4px 24px rgba(0,0,0,0.5);
}

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

[hidden] {
  display: none !important;
}

html { scroll-behavior: smooth; }

body {
  font-family: system-ui,-apple-system,"Segoe UI",sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }

/* ── Layout ─────────────────────────────────────────── */

#app {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ── Header ─────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  background: rgba(8,14,26,0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.app-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.menu-toggle-btn {
  font-size: 1rem;
  padding-inline: 12px;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 15%, #93c5fd 45%, #3b82f6 75%, #22d3ee 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-link {
  text-decoration: none;
  color: inherit;
}

.app-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.top-nav-link {
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  transition: all 0.15s ease;
}

.top-nav-link:hover {
  text-decoration: none;
  border-color: var(--border);
  color: var(--text);
}

.top-nav-link--active {
  background: var(--bg-surface2);
  border-color: var(--border);
  color: var(--text);
}

.side-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(2, 6, 23, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-start;
}

.side-menu-overlay[hidden] {
  display: none !important;
}

.side-menu {
  width: min(360px, 88vw);
  height: 100%;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.side-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.side-menu-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-menu-links a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg-surface);
}

.side-menu-links a:hover {
  border-color: var(--accent);
}

/* ── Main ────────────────────────────────────────────── */

.app-main {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  background: none;
  color: var(--text);
}

.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px rgba(59,130,246,0.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 18px rgba(59,130,246,0.5);
}

.btn-secondary {
  background: var(--bg-surface2);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); }

.btn-danger {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.4);
  color: #fca5a5;
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.22); }

.btn-favorite {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-favorite:hover { border-color: #f472b6; color: #f9a8d4; }

/* ── Inputs ──────────────────────────────────────────── */

input, textarea, select {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 0.85rem;
  background: var(--bg-surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--border-focus); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }
textarea { resize: vertical; border-radius: var(--radius-sm); }
input[type="checkbox"] { width: auto; }

/* ── Filters ─────────────────────────────────────────── */

.filters-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid var(--border);
}

.hero-banner {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 90% at 90% 0%, rgba(59,130,246,0.25) 0%, rgba(59,130,246,0) 60%),
    linear-gradient(160deg, var(--bg-card) 0%, var(--bg-surface) 100%);
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.hero-content {
  min-width: 0;
}

.hero-title {
  font-size: 1.35rem;
  line-height: 1.2;
  margin-bottom: 6px;
}

.hero-subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(95px, 1fr));
  gap: 10px;
}

.hero-stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.02);
  padding: 8px 10px;
  text-align: center;
}

.hero-stat span {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
}

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

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
}
.field span { color: var(--text-dim); font-weight: 500; }

.filters-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ── Cards grid ──────────────────────────────────────── */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ── Card ────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  border-color: rgba(59,130,246,0.35);
}

.card-image {
  position: relative;
  padding-top: 58%;
  background: var(--bg-surface);
  overflow: hidden;
}
.card-image img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}
.card:hover .card-image img { transform: scale(1.04); }

.card-no-photo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.card-photo-count {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.card-price {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-green);
  white-space: nowrap;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.card-footer { margin-top: auto; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.card-detail-btn { font-size: 0.8rem; padding: 6px 14px; }

/* ── Admin section ───────────────────────────────────── */

.admin-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid rgba(59,130,246,0.25);
  box-shadow: 0 0 24px rgba(59,130,246,0.07);
}

.admin-card-header { margin-bottom: 12px; }
.admin-card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
}

.admin-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.admin-note { grid-column: 1/-1; font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* ── Listing detail page ─────────────────────────────── */

.listing-gallery {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.gallery-main {
  position: relative;
  width: 100%;
  padding-top: 52%;
  background: var(--bg-surface);
  overflow: hidden;
}

.gallery-main-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 2;
  backdrop-filter: blur(4px);
}
.gallery-arrow:hover { background: rgba(59,130,246,0.75); }
.gallery-arrow--prev { left: 12px; }
.gallery-arrow--next { right: 12px; }

.gallery-thumbs {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.gallery-thumb {
  width: 72px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: border-color 0.15s, opacity 0.15s;
  opacity: 0.7;
}
.gallery-thumb:hover { opacity: 1; }
.gallery-thumb--active { border-color: var(--accent); opacity: 1; }

.listing-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.listing-title { font-size: 1.6rem; font-weight: 700; line-height: 1.25; }

.listing-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.listing-price-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.listing-price {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent-green);
  white-space: nowrap;
}

.listing-specs-section,
.listing-desc-section,
.listing-contact-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.listing-specs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.spec-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.spec-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.spec-value { font-size: 0.95rem; font-weight: 600; color: var(--text); }

.listing-desc { font-size: 0.9rem; color: var(--text-dim); line-height: 1.65; white-space: pre-wrap; }

.listing-contact-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.contact-name  { font-size: 1rem; font-weight: 600; }
.contact-email { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.contact-call-btn { font-size: 0.95rem; padding: 10px 22px; }

/* ── Listing page layout inspired by marketplace style ───────────────── */

.listing-page-main {
  margin-top: 16px;
}

.listing-top {
  margin-bottom: 10px;
}

.listing-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: start;
}

.listing-left-col {
  min-width: 0;
}

.listing-right-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 78px;
}

.listing-info-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}

.listing-fav-btn {
  width: 100%;
  margin-top: 10px;
  margin-bottom: 10px;
}

.listing-spec-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.spec-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}

.spec-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.spec-row .spec-label {
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.86rem;
}

.spec-row .spec-value {
  text-align: right;
  font-size: 0.95rem;
}

/* ── Empty / Not found ───────────────────────────────── */

.empty-state {
  padding: 40px 20px;
  text-align: center;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Toasts ──────────────────────────────────────────── */

#toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
.toast-success { border-color: var(--accent-green); color: #86efac; }
.toast-error   { border-color: var(--accent-red);   color: #fca5a5; }
.toast-info    { border-color: var(--accent);        color: #93c5fd; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Auth controls ───────────────────────────────────── */

#authControls { display: flex; gap: 8px; align-items: center; }
#authControls button { white-space: nowrap; }
#profileSection { display: flex; gap: 8px; align-items: center; }
#profileSection[hidden] { display: none !important; }

#authControls {
  gap: 6px;
}

#profileName {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ── Auth modal ──────────────────────────────────────── */

.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.auth-modal-overlay[hidden] { display: none !important; }

.auth-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
}
.auth-modal[hidden] { display: none !important; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-form[hidden] { display: none !important; }
.auth-form h2 { font-size: 1.2rem; margin-bottom: 4px; }

#authSwitchMode {
  margin-top: 14px;
}

#authCloseBtn {
  margin-top: 10px;
}

.contacts-modal {
  max-width: 520px;
}

.contacts-static {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.contacts-static a {
  color: var(--accent);
}

#contactsModalOverlay {
  z-index: 1300;
}

.contacts-close-btn {
  margin-top: 14px;
}

/* ── List section ────────────────────────────────────── */

.list-section {}

.app-footer {
  border-top: 1px solid var(--border);
  margin-top: 28px;
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.app-footer-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.app-footer a {
  color: var(--text-dim);
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 680px) {
  #app { padding-inline: 10px; }

  .cards-grid { grid-template-columns: 1fr; }

  .filters-grid { grid-template-columns: 1fr 1fr; }

  .listing-hero { flex-direction: column; }
  .listing-price-block { align-items: flex-start; }
  .listing-title { font-size: 1.25rem; }
  .listing-price { font-size: 1.45rem; }

  .gallery-main { padding-top: 65%; }

  .app-header {
    width: 100%;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .app-header-main {
    width: 100%;
    justify-content: flex-start;
  }

  #authControls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding-bottom: 2px;
  }

  .hero-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

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

  .top-nav {
    width: 100%;
  }

  .top-nav-link {
    flex: 1 1 calc(50% - 6px);
    text-align: center;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .listing-layout {
    grid-template-columns: 1fr;
  }

  .listing-right-col {
    position: static;
  }
}

/* ── Optional light theme ─────────────────────────────────────────────── */

body.theme-light {
  --bg: #f2f4f7;
  --bg-card: #ffffff;
  --bg-surface: #f8fafc;
  --bg-surface2: #eef2f7;
  --border: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --text-muted: #64748b;
  --text-dim: #334155;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.1);
}

body.theme-light .app-header {
  background: rgba(242, 244, 247, 0.92);
}

body.theme-light .app-title {
  background: linear-gradient(135deg, #0f172a 15%, #1d4ed8 60%, #0ea5e9 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
