/* ========================================
   AutoTrust Car — Mobile App Design System
   ======================================== */
:root {
  --primary: #b91c1c;
  --primary-light: #dc2626;
  --primary-dark: #7f1d1d;
  --accent: #d4a843;
  --accent-light: #e0c882;
  --success: #2d8a4e;
  --warning: #d4a72c;
  --danger: #991b1b;
  --text: #1a1a1a;
  --text-sec: #4a4a4a;
  --text-muted: #8e8e8e;
  --bg: #f5f3f0;
  --card: #ffffff;
  --border: #e8e0e0;
  --border-light: #f5eeee;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
  --transition: .2s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: 'IBM Plex Sans Thai', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,.1);
}

/* ---- HEADER ---- */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 10;
  min-height: 52px;
}
.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.header-back {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #fff;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .85rem;
  font-weight: 500;
}
.header-back svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

/* ---- CONTENT ---- */
.app-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  background: var(--bg);
}
.page.active { display: block; }
.page-pad { padding: 16px; }

/* ---- TAB BAR ---- */
.tab-bar {
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  position: relative;
  z-index: 10;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .65rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.tab-item svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.tab-item.active {
  color: var(--primary);
}

/* ---- HERO (Home) ---- */
.mobile-hero {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary), var(--primary-light));
  color: #fff;
  padding: 32px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.mobile-hero::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -30%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(212,168,67,.1);
}
.mobile-hero h1 {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.3;
  position: relative;
}
.mobile-hero h1 .hl { color: var(--accent-light); }
.mobile-hero p {
  font-size: .85rem;
  color: rgba(255,255,255,.7);
  margin-top: 8px;
}
.mobile-hero .hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 100px;
  font-size: .7rem;
  margin-bottom: 12px;
}

/* ---- STATS ROW ---- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px;
  margin-top: -20px;
  position: relative;
  z-index: 2;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px;
}
.stat-card .stat-icon svg { width: 16px; height: 16px; }
.stat-card .stat-num { font-size: 1rem; font-weight: 800; color: var(--text); }
.stat-card .stat-lbl { font-size: .6rem; color: var(--text-muted); margin-top: 1px; }

/* ---- SECTION ---- */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 1.1rem; font-weight: 700; }
.section-head .see-all {
  font-size: .8rem;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
}

/* ---- VEHICLE CARD ---- */
.v-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 0 16px 16px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.v-scroll::-webkit-scrollbar { display: none; }

.v-card {
  flex-shrink: 0;
  width: 260px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  scroll-snap-align: start;
  cursor: pointer;
  transition: transform .2s;
}
.v-card:active { transform: scale(.98); }

.v-card-img {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--border-light);
}
.v-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.v-card-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
}
.v-badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
}
.v-badge-feat { background: var(--accent); color: var(--primary-dark); }
.v-badge-res { background: #7c3aed; }

.v-grade {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.grade-A { background: linear-gradient(135deg, #22c55e, #15803d); }
.grade-B { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.grade-C { background: linear-gradient(135deg, #eab308, #a16207); }

.v-card-body { padding: 12px; }
.v-card-title { font-size: .9rem; font-weight: 600; }
.v-card-sub { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }
.v-card-specs {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  font-size: .7rem;
  color: var(--text-muted);
}
.v-card-specs span { display: flex; align-items: center; gap: 3px; }
.v-card-specs svg { width: 11px; height: 11px; fill: var(--text-muted); opacity: .6; }
.v-card-price {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.v-card-price .price { font-size: 1.05rem; font-weight: 800; color: var(--primary); }
.v-card-price .inst { font-size: .65rem; color: var(--text-muted); }

/* ---- LIST CARD (Vehicles page) ---- */
.v-list { padding: 0 16px 16px; }
.v-list-card {
  display: flex;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .2s;
}
.v-list-card:active { transform: scale(.98); }
.v-list-card .v-list-img {
  width: 130px;
  min-height: 110px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.v-list-card .v-list-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.v-list-card .v-list-img .v-grade {
  width: 26px;
  height: 26px;
  font-size: .6rem;
  bottom: 6px;
  right: 6px;
}
.v-list-body {
  padding: 10px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.v-list-body .title { font-size: .85rem; font-weight: 600; }
.v-list-body .sub { font-size: .7rem; color: var(--text-muted); margin-top: 1px; }
.v-list-body .specs {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: .65rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.v-list-body .price { font-size: .95rem; font-weight: 800; color: var(--primary); margin-top: 6px; }

/* ---- FILTER BAR ---- */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-sec);
  background: var(--card);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---- WHY US ---- */
.why-section {
  background: var(--primary);
  margin: 0;
  padding: 24px 16px;
}
.why-section h2 { color: #fff; text-align: center; font-size: 1.1rem; margin-bottom: 4px; }
.why-section .why-sub { color: rgba(255,255,255,.6); text-align: center; font-size: .8rem; margin-bottom: 16px; }
.why-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.why-card {
  background: rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: 16px 12px;
}
.why-card .why-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(212,168,67,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.why-card .why-icon svg { width: 18px; height: 18px; fill: var(--accent); }
.why-card h3 { font-size: .8rem; font-weight: 700; color: #fff; margin-bottom: 4px; }
.why-card p { font-size: .7rem; color: rgba(255,255,255,.6); line-height: 1.5; }

/* ---- BRAND TAGS ---- */
.brand-section { padding: 16px; }
.brand-section h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.brand-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.brand-tag {
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-sec);
  cursor: pointer;
  transition: var(--transition);
}
.brand-tag:active { border-color: var(--primary); color: var(--primary); }

/* ---- DETAIL PAGE ---- */
.detail-img {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  background: var(--border-light);
}
.detail-info { padding: 16px; }
.detail-info h1 { font-size: 1.2rem; font-weight: 700; }
.detail-info .sub { font-size: .85rem; color: var(--text-muted); margin-top: 2px; }

.detail-price-box {
  margin: 12px 16px;
  padding: 16px;
  background: rgba(185,28,28,.04);
  border: 1px solid rgba(185,28,28,.1);
  border-radius: var(--radius);
  text-align: center;
}
.detail-price-box .label { font-size: .8rem; color: var(--primary); font-weight: 600; }
.detail-price-box .amount { font-size: 1.5rem; font-weight: 800; color: var(--primary); margin-top: 4px; }
.detail-price-box .inst { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

.detail-grade-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 16px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.detail-grade-bar .grade-label { font-size: .85rem; color: var(--text-sec); }
.detail-grade-bar .grade-score { font-size: 1rem; font-weight: 800; }

.detail-specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 16px;
}
.detail-spec-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--card);
  border-radius: var(--radius-sm);
}
.detail-spec-item .spec-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(185,28,28,.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.detail-spec-item .spec-icon svg { width: 16px; height: 16px; fill: var(--primary); }
.detail-spec-item .spec-label { font-size: .65rem; color: var(--text-muted); }
.detail-spec-item .spec-value { font-size: .8rem; font-weight: 600; }

.detail-section { padding: 16px; }
.detail-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.detail-section p { font-size: .85rem; color: var(--text-sec); line-height: 1.7; }

.inspection-bar { margin-bottom: 12px; }
.inspection-bar .bar-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.inspection-bar .bar-lbl { font-size: .8rem; color: var(--text-sec); }
.inspection-bar .bar-score { font-size: .8rem; font-weight: 700; }
.inspection-bar .bar-track { height: 6px; background: var(--border-light); border-radius: 3px; overflow: hidden; }
.inspection-bar .bar-fill { height: 100%; border-radius: 3px; }

.detail-actions {
  display: flex;
  gap: 10px;
  padding: 16px;
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border-light);
  z-index: 5;
}
.detail-actions .btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .85rem;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}
.detail-actions .btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn-line { background: #06c755; color: #fff; }
.btn-primary { background: var(--primary); color: #fff; }

/* ---- CALCULATOR ---- */
.calc-card {
  background: var(--card);
  border-radius: var(--radius);
  margin: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.calc-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}
.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
  transition: var(--transition);
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(185,28,28,.08);
}
input[type="range"] {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  appearance: none;
  cursor: pointer;
  border: none;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.range-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.range-header .label { font-size: .8rem; color: var(--text-sec); }
.range-header .value { font-size: .8rem; font-weight: 700; color: var(--primary); }

.term-opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.term-btn {
  padding: 8px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-sec);
  cursor: pointer;
  background: var(--card);
  transition: var(--transition);
  font-family: inherit;
}
.term-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(185,28,28,.03); }

.calc-result {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-radius: var(--radius);
  margin: 0 16px 16px;
  padding: 24px;
  color: #fff;
  text-align: center;
}
.calc-result .monthly { font-size: 2rem; font-weight: 800; margin: 8px 0; }
.calc-result .monthly-label { font-size: .8rem; opacity: .7; }
.calc-result .details { margin-top: 16px; }
.calc-result .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .85rem; }
.calc-result .row .rl { opacity: .7; }
.calc-result hr { border: none; border-top: 1px solid rgba(255,255,255,.15); margin: 6px 0; }

/* ---- TRADE-IN ---- */
.condition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.cond-option {
  padding: 14px 10px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  background: var(--card);
}
.cond-option:active, .cond-option.active {
  border-color: var(--primary);
  background: rgba(185,28,28,.03);
}
.cond-option .cond-name { font-size: .8rem; font-weight: 600; margin-top: 4px; }
.cond-option .cond-desc { font-size: .65rem; color: var(--text-muted); }
.cond-icon { font-size: 1.2rem; }

.result-box {
  margin: 16px;
  padding: 24px;
  text-align: center;
  background: linear-gradient(135deg, rgba(185,28,28,.04), rgba(200,164,92,.06));
  border: 1px solid rgba(185,28,28,.1);
  border-radius: var(--radius);
  display: none;
}
.result-box.active { display: block; }
.result-box .rl { font-size: .85rem; color: var(--primary); font-weight: 600; }
.result-box .amount { font-size: 1.5rem; font-weight: 800; color: var(--primary); margin: 8px 0; }
.result-box .note { font-size: .8rem; color: var(--text-muted); }

/* ---- CONTACT ---- */
.contact-cards { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.contact-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.contact-card .c-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(185,28,28,.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.contact-card .c-icon svg { width: 20px; height: 20px; fill: var(--primary); }
.contact-card .c-label { font-size: .75rem; color: var(--text-muted); }
.contact-card .c-value { font-size: 1rem; font-weight: 700; color: var(--primary); }
.contact-card .c-note { font-size: .7rem; color: var(--text-muted); margin-top: 2px; }

.contact-map {
  margin: 0 16px 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}
.contact-map .map-placeholder {
  height: 200px;
  background: linear-gradient(135deg, var(--border-light), var(--border));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.contact-map .map-placeholder svg { width: 32px; height: 32px; fill: var(--text-muted); margin-bottom: 8px; }
.contact-map .map-info { padding: 16px; }
.contact-map .map-info h3 { font-size: .9rem; font-weight: 700; }
.contact-map .map-info p { font-size: .8rem; color: var(--text-sec); margin-top: 4px; }

.line-cta {
  margin: 0 16px 16px;
  padding: 16px;
  background: #06c755;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
}
.line-cta svg { width: 24px; height: 24px; fill: #fff; }

/* ---- Utility ---- */
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }

/* Scrollbar */
.page::-webkit-scrollbar { width: 0; }
