/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0f1117; color: #e2e8f0; min-height: 100vh; }

/* ── Header ── */
header { display: flex; justify-content: space-between; align-items: center; padding: 16px 28px; background: #1a1d27; border-bottom: 1px solid #2d3148; position: sticky; top: 0; z-index: 100; }
.logo { font-size: 20px; font-weight: 700; color: #fff; }
.subtitle { margin-left: 10px; color: #64748b; font-size: 14px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.last-update { font-size: 12px; color: #64748b; }

/* ── Buttons ── */
.btn { padding: 9px 18px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { background: #334155; color: #64748b; cursor: not-allowed; }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid #334155; }
.btn-ghost:hover { background: #1e293b; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; padding: 12px 28px 0; background: #1a1d27; border-bottom: 1px solid #2d3148; }
.tab { padding: 10px 20px; background: transparent; border: none; border-bottom: 2px solid transparent; color: #94a3b8; font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s; }
.tab:hover { color: #e2e8f0; }
.tab.active { color: #3b82f6; border-bottom-color: #3b82f6; }
.tab.disabled { opacity: .4; cursor: not-allowed; }
.tab-content { display: none; padding: 24px 28px; }
.tab-content.active { display: block; }

/* ── Stats ── */
.stats-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 140px; background: #1a1d27; border: 1px solid #2d3148; border-radius: 12px; padding: 20px; text-align: center; }
.stat-card.available { border-color: #22c55e44; }
.stat-card.sold      { border-color: #ef444444; }
.stat-card.archived  { border-color: #94a3b844; }
.stat-card.price     { border-color: #f59e0b44; }
.stat-value { font-size: 28px; font-weight: 700; color: #fff; }
.stat-label { font-size: 12px; color: #64748b; margin-top: 4px; }
.stat-card.available .stat-value { color: #22c55e; }
.stat-card.sold .stat-value      { color: #ef4444; }
.stat-card.archived .stat-value  { color: #94a3b8; }
.stat-card.price .stat-value     { color: #f59e0b; }

/* ── Filters ── */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { background: #1a1d27; border: 1px solid #2d3148; border-radius: 8px; color: #e2e8f0; padding: 8px 12px; font-size: 14px; outline: none; transition: border .15s; }
.filters input:focus, .filters select:focus { border-color: #3b82f6; }
#filterSearch { flex: 2; min-width: 240px; }
.price-range { display: flex; align-items: center; gap: 6px; }
.price-range input { width: 90px; font-size: 14px; }
.price-range-sep { color: #64748b; }
.price-range-label { color: #94a3b8; font-size: 13px; font-weight: 600; letter-spacing: .03em; white-space: nowrap; }
.results-info { font-size: 13px; color: #64748b; margin-bottom: 16px; }

/* ── Cars Grid ── */
.cars-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }

/* ── Car Card ── */
.car-card { background: #1a1d27; border: 1px solid #2d3148; border-radius: 14px; overflow: hidden; transition: transform .15s, border-color .15s; cursor: pointer; }
.car-card:hover { transform: translateY(-3px); border-color: #3b82f688; }
.car-card.sold    { opacity: .7; }
.car-card.archived { opacity: .45; }

.car-photo { width: 100%; height: 185px; object-fit: cover; background: #111827; display: block; }
.car-photo-placeholder {
  width: 100%; height: 185px;
  background: linear-gradient(135deg, #111827 0%, #1a1d27 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  border-bottom: 1px solid #1e293b;
}
.car-photo-placeholder svg { width: 80px; opacity: 0.35; }
.car-photo-placeholder span {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  color: #334155; text-transform: uppercase;
}

.car-body { padding: 16px; }
.car-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.car-name { font-size: 15px; font-weight: 600; color: #fff; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.car-sku  { font-size: 11px; color: #64748b; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.car-header > div:first-child { min-width: 0; overflow: hidden; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.badge-available { background: #22c55e22; color: #22c55e; border: 1px solid #22c55e44; }
.badge-sold      { background: #ef444422; color: #ef4444; border: 1px solid #ef444444; }
.badge-archived  { background: #94a3b822; color: #94a3b8; border: 1px solid #94a3b844; }
.badge-unavailable { background: #f59e0b22; color: #f59e0b; border: 1px solid #f59e0b44; }

.car-price { font-size: 22px; font-weight: 700; color: #3b82f6; margin: 10px 0 6px; }
.car-price-krw { font-size: 12px; color: #64748b; margin-bottom: 12px; }

.car-specs { display: flex; flex-wrap: wrap; gap: 6px; }
.spec { background: #0f1117; border: 1px solid #2d3148; border-radius: 6px; padding: 4px 8px; font-size: 12px; color: #94a3b8; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: #00000088; z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: #1a1d27; border: 1px solid #2d3148; border-radius: 16px; max-width: 700px; width: 95%; max-height: 90vh; overflow-y: auto; position: relative; padding: 28px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: #2d3148; border: none; border-radius: 8px; color: #94a3b8; width: 32px; height: 32px; cursor: pointer; font-size: 16px; z-index: 10; }

/* ── Carousel ── */
.carousel {
  position: relative; width: 100%; margin-bottom: 20px;
  border-radius: 12px; overflow: hidden; background: #0f1117;
  aspect-ratio: 16/10;
}
.carousel-track {
  display: flex; height: 100%;
  transition: transform 0.35s cubic-bezier(.4,0,.2,1);
}
.carousel-img {
  min-width: 100%; width: 100%; height: 100%;
  object-fit: cover; flex-shrink: 0;
}
.carousel-img-broken { display: none !important; }
.carousel-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,.55); border: none; color: #fff;
  font-size: 28px; line-height: 1; cursor: pointer;
  width: 40px; height: 56px; border-radius: 6px;
  transition: background .15s; z-index: 2;
}
.carousel-btn:hover { background: rgba(0,0,0,.8); }
.carousel-prev { left: 10px; }
.carousel-next { right: 10px; }
.carousel-dots {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 5px; z-index: 2;
}
.cdot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,.4); cursor: pointer;
  transition: background .2s, transform .2s;
}
.cdot.active { background: #fff; transform: scale(1.3); }
.modal-no-photo {
  width: 100%; aspect-ratio: 16/10; background: #111827;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; border-radius: 12px;
  margin-bottom: 20px;
}
.modal-no-photo svg { width: 80px; opacity: .25; }
.modal-no-photo span { color: #334155; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.modal-title { font-size: 22px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.modal-sku   { font-size: 13px; color: #64748b; margin-bottom: 16px; }
.modal-price { font-size: 28px; font-weight: 700; color: #3b82f6; margin-bottom: 4px; }
.modal-price-krw { font-size: 14px; color: #64748b; margin-bottom: 20px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-field { background: #0f1117; border-radius: 10px; padding: 12px 16px; }
.modal-field-label { font-size: 11px; color: #64748b; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.modal-field-value { font-size: 15px; color: #e2e8f0; font-weight: 500; }
.modal-link { display: inline-block; margin-top: 20px; color: #3b82f6; font-size: 14px; text-decoration: none; }
.modal-link:hover { color: #60a5fa; }

/* ── Logs table ── */
.section-title { font-size: 16px; font-weight: 600; color: #fff; margin-bottom: 16px; }
.logs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.logs-table th { text-align: left; padding: 10px 12px; background: #1a1d27; color: #64748b; border-bottom: 1px solid #2d3148; font-weight: 500; }
.logs-table td { padding: 10px 12px; border-bottom: 1px solid #1e293b; color: #e2e8f0; }
.logs-table tr:hover td { background: #1e293b; }
.log-status-success { color: #22c55e; font-weight: 600; }
.log-status-error   { color: #ef4444; font-weight: 600; }
.log-status-running { color: #f59e0b; font-weight: 600; }
.log-empty { padding: 40px; text-align: center; color: #64748b; }
.log-row-running td { background: rgba(245,158,11,0.05); }
.log-row-running td { animation: pulse-row 2s ease-in-out infinite; }
@keyframes pulse-row { 0%,100%{opacity:1} 50%{opacity:.7} }
.log-new  { color: #22c55e; font-weight: 700; }
.log-upd  { color: #60a5fa; font-weight: 600; }
.log-gone { color: #f87171; font-weight: 600; }
.log-no-errors { color: #334155; }
.log-err-btn {
  background: none; border: 1px solid #ef4444; color: #ef4444;
  border-radius: 4px; padding: 1px 6px; font-size: 11px;
  cursor: pointer; margin-left: 6px;
}
.log-err-btn:hover { background: rgba(239,68,68,.1); }

/* Error popup */
.error-popup-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.error-popup {
  background: #1a1d27; border: 1px solid #ef4444; border-radius: 12px;
  padding: 24px 28px; max-width: 560px; width: 90%; position: relative;
}
.error-popup h3 { color: #ef4444; margin: 0 0 14px; font-size: 16px; }
.error-popup pre {
  color: #e2e8f0; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow-y: auto;
  background: #0f1117; border-radius: 8px; padding: 12px;
  margin: 0;
}
.error-popup-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: #64748b;
  font-size: 18px; cursor: pointer; line-height: 1;
}
.error-popup-close:hover { color: #e2e8f0; }

/* ── Empty state ── */
.empty-state { grid-column: 1/-1; padding: 60px 20px; text-align: center; color: #64748b; }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Pagination ── */
.pagination { display: flex; gap: 8px; margin-top: 24px; justify-content: center; flex-wrap: wrap; }
.page-btn { background: #1a1d27; border: 1px solid #2d3148; border-radius: 8px; color: #94a3b8; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.page-btn:hover { border-color: #3b82f6; color: #3b82f6; }
.page-btn.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

/* ── Toast ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 12px 20px; font-size: 14px; color: #e2e8f0; transform: translateY(100px); opacity: 0; transition: all .3s; z-index: 300; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: #22c55e44; }
.toast.error   { border-color: #ef444444; }

/* ── Spinner ── */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid #ffffff44; border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f1117; }
::-webkit-scrollbar-thumb { background: #2d3148; border-radius: 3px; }

/* ══════════ MOBILE (≤ 640px) ══════════ */
@media (max-width: 640px) {
  /* Header */
  header { padding: 12px 16px; }
  .subtitle { display: none; }
  .last-update { font-size: 11px; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Tabs */
  .tabs { padding: 0 8px; overflow-x: auto; gap: 0; }
  .tab { padding: 10px 14px; font-size: 13px; white-space: nowrap; }
  .tab-content { padding: 16px 12px; }

  /* Stats */
  .stats-row { gap: 10px; }
  .stat-card { min-width: 120px; padding: 14px 10px; }
  .stat-value { font-size: 22px; }

  /* Filters */
  .filters { gap: 8px; }
  #filterSearch { min-width: 100%; }
  .price-range { width: 100%; }
  .price-range input { flex: 1; width: auto; }
  .filters select { flex: 1; }

  /* Cars grid: 1 column */
  .cars-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Logs table: горизонтальный скролл */
  .logs-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .logs-table { font-size: 12px; min-width: 560px; }
  .logs-table th, .logs-table td { padding: 8px 10px; }
}

/* ══════════ TABLET (641–1024px) ══════════ */
@media (min-width: 641px) and (max-width: 1024px) {
  .logs-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .logs-table { min-width: 680px; }
  .cars-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ── AED Settings Panel ──────────────────────────────────────────────────── */
.aed-panel {
  background: #0f1117;
  border-bottom: 1px solid #1e293b;
  padding: 1rem 1.5rem;
  animation: slideDown .2s ease;
}
.aed-panel.hidden { display: none; }
@keyframes slideDown { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:translateY(0); } }

.aed-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
  font-size: .85rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.aed-panel-close {
  background: none; border: none; color: #64748b;
  cursor: pointer; font-size: 1rem; padding: .2rem .4rem;
}
.aed-panel-close:hover { color: #f1f5f9; }

.aed-fields {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  margin-bottom: .75rem;
}
.aed-field {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  min-width: 160px;
}
.aed-field label {
  font-size: .75rem;
  color: #64748b;
  font-weight: 500;
}
.aed-field input {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: .375rem;
  color: #f1f5f9;
  padding: .4rem .6rem;
  font-size: .875rem;
  width: 120px;
  outline: none;
  transition: border-color .15s;
}
.aed-field input:focus { border-color: #3b82f6; }
.aed-field small { font-size: .7rem; color: #475569; }

.aed-panel-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.aed-formula {
  font-size: .8rem;
  color: #475569;
  font-family: monospace;
}

/* ── AED Price on Cards ───────────────────────────────────────────────────── */
.car-price-aed {
  font-size: 1.25rem;
  font-weight: 700;
  color: #34d399;   /* зелёный — это итоговая цена для клиента */
  margin-bottom: .1rem;
}
.car-price {
  font-size: .85rem;
  color: #94a3b8;
  font-weight: 500;
}
.car-price-krw {
  font-size: .75rem;
  color: #475569;
}

/* ── AED Price in Modal ───────────────────────────────────────────────────── */
.modal-price-aed {
  font-size: 1.75rem;
  font-weight: 800;
  color: #34d399;
  margin-bottom: .2rem;
}
.modal-price {
  font-size: 1rem;
  color: #94a3b8;
  font-weight: 500;
}
.modal-price-krw {
  font-size: .85rem;
  color: #475569;
}

.btn-secondary {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
}
.btn-secondary:hover {
  background: #334155;
  color: #f1f5f9;
}

/* ── Encar link on card ──────────────────────────────────────────────────── */
.card-encar-link {
  display: block;
  margin-top: .6rem;
  padding: .2rem 0;
  font-size: .75rem;
  color: #3b82f6;
  text-decoration: none;
  background: none;
  border: none;
  transition: color .15s;
}
.card-encar-link:hover {
  color: #60a5fa;
}

/* ── Gallery ─────────────────────────────────────────────────────────────── */
.gallery { margin-bottom: 1rem; }

.gallery-main-wrap {
  position: relative;
  background: #0a0d14;
  border-radius: .5rem;
  overflow: hidden;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-main {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.4rem;
  cursor: pointer;
  z-index: 2;
  line-height: 1;
  transition: background .15s;
  display: flex; align-items: center; justify-content: center;
}
.gallery-arrow:hover { background: rgba(0,0,0,.8); }
.gallery-prev { left: .5rem; }
.gallery-next { right: .5rem; }
.gallery-counter {
  position: absolute;
  bottom: .5rem;
  right: .75rem;
  background: rgba(0,0,0,.6);
  color: #cbd5e1;
  font-size: .72rem;
  padding: .15rem .45rem;
  border-radius: .25rem;
}

.gallery-thumbs {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding: .5rem 0 .25rem;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.gallery-thumbs::-webkit-scrollbar { height: 4px; }
.gallery-thumbs::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.gallery-thumb {
  flex-shrink: 0;
  width: 72px;
  height: 52px;
  object-fit: cover;
  border-radius: .25rem;
  cursor: pointer;
  opacity: .55;
  border: 2px solid transparent;
  transition: opacity .15s, border-color .15s;
}
.gallery-thumb:hover { opacity: .85; }
.gallery-thumb.active {
  opacity: 1;
  border-color: #3b82f6;
}
