/* Thai Car — dark, high-contrast, phone-first (~390px) */

:root {
  --bg: #0a0c10;
  --bg-elev: #12151c;
  --bg-card: #181c26;
  --border: #2a3142;
  --text: #f2f4f8;
  --muted: #9aa3b5;
  --accent: #3d9eff;
  --accent-2: #5eead4;
  --warn: #fbbf24;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 12px;
  --nav-h: 64px;
  --top-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

[hidden] {
  display: none !important;
}

/* —— Gate —— */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(61, 158, 255, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(94, 234, 212, 0.08), transparent 45%),
    var(--bg);
}

.gate-card {
  width: min(100%, 380px);
  padding: 28px 22px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
}

.gate-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.gate-card h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.gate-sub {
  margin: 4px 0 20px;
  color: var(--muted);
}

#gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#password {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* avoid iOS zoom */
}

#password:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #041018;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.gate-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.gate-note {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* —— App shell —— */
.app {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: rgba(10, 12, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #041018;
  font-weight: 800;
  font-size: 13px;
}

.brand strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.main {
  padding: 16px 14px 24px;
  max-width: 960px;
  margin: 0 auto;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 16px;
  color: var(--muted);
}

.hint {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.callout {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.callout h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent-2);
}

.callout ul {
  margin: 0;
  padding-left: 1.15em;
  color: var(--text);
}

.callout li + li {
  margin-top: 6px;
}

.bands {
  display: grid;
  gap: 10px;
}

.band-card {
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.band-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.band-price {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.band-card p:last-child {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* —— Toolbar / filter —— */
.toolbar {
  margin-bottom: 12px;
}

.search-wrap {
  display: block;
}

.table-filter {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
}

.table-filter:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* —— Tables: cards on mobile, scroll on wider —— */
.table-scroll {
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  display: none;
}

.data-table tbody {
  display: grid;
  gap: 10px;
}

.data-table tr {
  display: block;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.data-table tr[hidden] {
  display: none !important;
}

.data-table td {
  display: grid;
  grid-template-columns: minmax(88px, 32%) 1fr;
  gap: 6px 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42, 49, 66, 0.55);
  font-size: 13px;
  word-break: break-word;
}

.data-table td:last-child {
  border-bottom: none;
}

.data-table td::before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--accent-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 2px;
}

.data-table td:first-child {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  padding-bottom: 8px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
}

/* Wider: horizontal scroll table */
@media (min-width: 720px) {
  .bands {
    grid-template-columns: repeat(3, 1fr);
  }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    background: var(--bg-elev);
  }

  .data-table thead {
    display: table-header-group;
  }

  .data-table tbody {
    display: table-row-group;
  }

  .data-table tr {
    display: table-row;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
  }

  .data-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
  }

  .data-table th,
  .data-table td {
    display: table-cell;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: top;
    min-width: 110px;
  }

  .data-table th {
    position: sticky;
    top: 0;
    background: #1c2230;
    color: var(--accent-2);
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
  }

  .data-table td::before {
    content: none;
  }

  .data-table td:first-child {
    font-weight: 600;
    min-width: 150px;
    border-bottom: 1px solid var(--border);
    margin: 0;
    padding: 10px 12px;
  }
}

/* —— Market charts —— */
.chart-banner {
  display: inline-block;
  padding: 6px 10px;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 8px;
  color: var(--warn);
  font-weight: 600;
  font-size: 13px;
}

.chart-grid {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

.chart-card {
  margin: 0;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-card figcaption {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.chart-card canvas {
  width: 100% !important;
  max-height: 280px;
}

@media (min-width: 800px) {
  .chart-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* —— Notes —— */
.notes-stack {
  display: grid;
  gap: 10px;
}

.note-card {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.note-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent);
}

.note-card ul {
  margin: 0;
  padding-left: 1.15em;
}

.note-card li + li {
  margin-top: 6px;
}

.note-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* —— Bottom nav —— */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(18, 21, 28, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin: 0;
  padding: 6px 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.nav-btn .nav-ico {
  font-size: 16px;
  line-height: 1;
}

.nav-btn.active,
.nav-btn[aria-current="page"] {
  color: var(--accent);
}

.nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -4px;
}

@media (min-width: 720px) {
  .bottom-nav {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* —— Market live —— */
.chart-banner-live {
  background: rgba(74, 222, 128, 0.1);
  border-color: rgba(74, 222, 128, 0.35);
  color: var(--ok);
}

.market-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

@media (min-width: 520px) {
  .market-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-pill {
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-pill .stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-pill strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.market-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 14px;
  padding: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.mf-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.mf-field input,
.mf-field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.mf-field input:focus,
.mf-field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mf-grow {
  grid-column: 1 / -1;
}

.mf-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
  font-size: 13px;
  color: var(--text);
}

.mf-check input {
  width: auto;
}

@media (min-width: 720px) {
  .market-filters {
    grid-template-columns: repeat(4, 1fr);
  }
  .mf-grow {
    grid-column: span 2;
  }
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.market-cards-title {
  margin: 18px 0 10px;
  font-size: 15px;
}

.muted-count {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

.market-cards {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

@media (min-width: 560px) {
  .market-cards {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 900px) {
  .market-cards {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.listing-card {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.listing-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.listing-card:active {
  border-color: var(--accent);
}

.listing-photo {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  background: #0e1118;
  display: block;
}

.listing-photo-ph {
  aspect-ratio: 4 / 3;
  width: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #141820, #1c2433);
  color: var(--muted);
  font-size: 12px;
}

.listing-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.listing-model {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-2);
  font-weight: 700;
}

.listing-title {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.listing-price {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.listing-meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.listing-fb {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
  text-decoration: none;
}

.listing-fb:hover {
  text-decoration: underline;
}

.badge-sold {
  color: var(--danger);
  font-weight: 700;
}
.badge-pending {
  color: var(--warn);
  font-weight: 700;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: end center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 600px) {
  .modal {
    place-items: center;
  }
  .modal-sheet {
    border-radius: 16px;
    max-height: 85dvh;
  }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-body .modal-photo {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 10px;
  background: #0e1118;
}

.modal-body h3 {
  margin: 12px 40px 6px 0;
  font-size: 17px;
}

.modal-body .listing-price {
  font-size: 18px;
}

.modal-desc {
  margin: 10px 0;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 180px;
  overflow: auto;
}

.modal-attrs {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
}

.modal-attrs li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-actions a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: #061018;
  font-weight: 700;
  text-decoration: none;
  font-size: 14px;
}
