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

:root {
  --bg: #0c0f14;
  --surface: #141821;
  --line: #222834;
  --fg: #f0f2f6;
  --fg2: #c7ced8;
  --fg3: #8892a0;
  --accent: #4f94f0;
  --error: #e07060;
}

body {
  font-family: "Inter Tight", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg2);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 20px; width: 100%; }

.top {
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}
.top .wrap { display: flex; align-items: center; justify-content: space-between; }

.top-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

.brand { color: var(--fg); font-weight: 800; font-size: 20px; letter-spacing: -0.03em; text-decoration: none; }
.brand .accent { color: var(--accent); }
.tag { font-size: 12px; color: var(--fg3); }
.new { color: var(--accent); text-decoration: none; font-size: 14px; }
button.new { border: 0; background: transparent; cursor: pointer; padding: 0; font-family: "Inter Tight", system-ui, -apple-system, sans-serif; }
.logout-form { margin: 0; }
.hero .new { display: inline-block; margin-bottom: 8px; }

main { flex: 1; padding: 40px 0; }

.hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 40px; }
.hero h1 { color: var(--fg); font-size: 28px; margin-bottom: 8px; }
.hero p { color: var(--fg3); margin-bottom: 24px; margin-top: 16px; }

.decode-form { display: flex; gap: 10px; max-width: 640px; width: 100%; }
.decode-form input {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-transform: uppercase;
}
.decode-form input:focus { outline: none; border-color: var(--accent); }
.decode-form button {
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  color: #0c0f14;
  background: var(--fg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.decode-form button:hover { background: var(--accent); color: #fff; }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.auth-card {
  max-width: 520px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.auth-card h1 { color: var(--fg); font-size: 22px; margin-bottom: 18px; }
.auth-toolbar { margin-bottom: 14px; }
.auth-card .alert { margin-bottom: 12px; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }

.auth-field { display: flex; }
.auth-field input {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 0;
}
.auth-field input:focus { outline: none; border-color: var(--accent); }

.auth-password {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.auth-password input {
  border: none;
  border-radius: 0;
}
.auth-password:focus-within { border-color: var(--accent); }
.auth-password input:focus { border: none; }
.auth-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--fg2);
  border: none;
  border-left: 1px solid var(--line);
  cursor: pointer;
}
.eye-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.eye-slash { display: none; }
.auth-toggle.is-visible .eye-slash { display: block; }
.auth-toggle:hover { color: var(--accent); }

.auth-submit {
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  color: #0c0f14;
  background: var(--fg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  align-self: center;
  min-width: 140px;
}
.auth-submit:hover { background: var(--accent); color: #fff; }

.hint { margin-top: 10px; font-size: 12px; color: var(--fg3); }
#auctions-description { margin-bottom: 10px; }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.alert.error { background: rgba(224, 112, 96, 0.12); border: 1px solid var(--error); color: var(--error); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }
.grid .card { margin-bottom: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { color: var(--fg); font-size: 16px; margin-bottom: 14px; }

table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv th, table.kv td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: none; }
table.kv td:first-child { color: var(--fg3); width: 45%; }
table.kv td:last-child { color: var(--fg); }
table.options td:last-child { color: var(--fg2); }

.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.code { color: var(--accent); font-weight: 700; white-space: nowrap; }

.auction-links { list-style: none; margin-top: 8px; }
.auction-links li { margin-bottom: 6px; }
.auction-links a {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}
.auction-links a:hover { text-decoration: underline; }

.auction-list { list-style: none; margin: 12px 0 0; }
.auction {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 20px;
}
.auction-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.auction-photos img {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  cursor: zoom-in;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.auction-photos img:hover { border-color: var(--accent); transform: scale(1.03); }
.auction-link { margin-top: 10px; }
.auction-link a {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}
.auction-link a:hover { text-decoration: underline; }

.photos { display: flex; gap: 14px; flex-wrap: wrap; }
.photos .photo { margin: 0; display: flex; flex-direction: column; }
.photos img {
  max-width: 100%;
  width: 380px;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: zoom-in;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.photos img:hover { transform: scale(1.02); border-color: var(--accent); }
.photos figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--fg3);
  text-align: center;
}

.photo-fallback {
  width: 380px;
  max-width: 100%;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--fg3);
  font-size: 14px;
}

/* Заглушка в ряду превью аукционов — в размер миниатюры 120x90. */
.auction-photos .photo-fallback {
  width: 120px;
  height: 90px;
  border-radius: 4px;
  font-size: 11px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  cursor: zoom-out;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 101;
  width: 48px;
  height: 64px;
  font-size: 32px;
  line-height: 1;
  color: var(--fg2);
  background: rgba(20, 24, 33, 0.75);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.lightbox-nav:hover { background: var(--accent); color: #fff; }
#lightbox-prev { left: 16px; }
#lightbox-next { right: 16px; }

.history { margin-top: 40px; width: 100%; }
.history h2 { color: var(--fg); font-size: 16px; margin-bottom: 12px; text-align: left; }
.history .section-heading { width: 100%; }
.history-scroll {
  display: block;
  overflow-x: auto;
}
.history-table {
  width: 100%;
  max-width: none;
  margin: 0;
  border-collapse: collapse;
  font-size: 14px;
}
.history-table th:first-child,
.history-table td:first-child { padding-left: 0; }
.history-table th:last-child,
.history-table td:last-child { padding-right: 0; }
.history-table th {
  color: var(--fg3);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-table th:last-child {
  text-align: right;
  white-space: nowrap;
}
.history-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.history-vin {
  color: var(--accent);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 14px;
  text-decoration: none;
}
.history-vin:hover { text-decoration: underline; }
.history-label { color: var(--fg); }
.history-year { color: var(--fg2); white-space: nowrap; }
.history-date { color: var(--fg3); white-space: nowrap; text-align: right; }

.bottom {
  border-top: 1px solid var(--line);
  padding: 20px 0;
  font-size: 12px;
  color: var(--fg3);
}

.bottom .wrap { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bottom p { margin: 0; }
.bottom .copyright { margin-left: auto; }

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(12, 15, 20, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--fg2);
  font-size: 15px;
}
.loading-overlay[hidden] { display: none; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 10s linear infinite !important;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --line: #d9dee8;
  --fg: #18202d;
  --fg2: #334155;
  --fg3: #64748b;
  --accent: #1769d1;
  --error: #b42318;
}

html { background: var(--bg); }
body { background: var(--bg); color: var(--fg2); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
.decode-form input:focus-visible,
.auth-field input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
.top-controls, .auth-toolbar, .locale-form, .section-heading, .options-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-controls, .auth-toolbar { flex-wrap: wrap; justify-content: flex-end; }
.locale-form select, .options-toolbar input, .options-toolbar select {
  min-height: 40px;
  padding: 8px 10px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.control-button, .auth-toggle {
  min-height: 40px;
  padding: 8px 12px;
  color: var(--fg2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.control-button:hover, .auth-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle { width: 40px; padding: 6px; font-size: 20px; line-height: 1; }
.section-heading { justify-content: space-between; gap: 12px; }
.section-heading h2 { margin: 0; }
.muted { color: var(--fg3); font-size: 13px; }
.kv th { color: var(--fg3); width: 45%; text-align: left; font-weight: 400; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.result-hero { margin-top: 20px; }
.vin-heading { max-width: 100%; overflow-wrap: anywhere; }
.options-toolbar { flex-wrap: wrap; margin-top: 12px; margin-bottom: 14px; }
.options-toolbar input { flex: 1 1 220px; }
.options-search { position: relative; flex: 1 1 220px; }
.options-search input { width: 100%; padding-right: 38px; }
#options-search::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  top: 50%;
  right: 2px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  color: var(--fg3);
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
}
.search-clear:hover { color: var(--fg); }
.search-clear[hidden] { display: none; }
.options-toolbar select { flex: 0 1 220px; }
.options tr.is-best-match > th,
.options tr.is-best-match > td { background: rgba(79, 148, 240, 0.14); }
.options tr.is-best-match > th:first-child { box-shadow: inset 3px 0 var(--accent); }
.table-scroll, .history-scroll { overflow-x: auto; }
.empty-state { padding: 16px 0; color: var(--fg3); }
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 102;
  width: 44px;
  height: 44px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
:root[data-theme="light"] .decode-form button,
:root[data-theme="light"] .auth-submit { color: #fff; background: var(--accent); }
:root[data-theme="light"] .loading-overlay { background: rgba(244, 246, 250, 0.9); }
:root[data-theme="light"] .photo-fallback { color: var(--fg3); }

@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  main { padding: 24px 0; }
  .top-inner { align-items: flex-start; gap: 12px; }
  .top-controls { justify-content: flex-start; }
  .top-right { align-items: flex-start; }
  .decode-form { flex-direction: column; }
  .decode-form button { min-height: 46px; }
  .hero { margin-top: 20px; }
  .grid { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 16px; }
  .kv { font-size: 13px; }
  .kv tr { display: grid; grid-template-columns: minmax(105px, 38%) minmax(0, 1fr); }
  .kv th, .kv td { display: block; padding: 8px 6px; border-bottom: 1px solid var(--line); }
  .kv th { color: var(--fg3); font-weight: 600; }
  .kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
  .kv td { overflow-wrap: anywhere; }
  .photos { display: grid; grid-template-columns: 1fr; }
  .photos img, .photo-fallback { width: 100%; max-width: none; height: auto; min-height: 160px; }
  .auction-photos img { width: 100px; height: 75px; }
  .history-table { min-width: 620px; }
  .bottom .wrap { flex-direction: column; align-items: flex-start; gap: 6px; }
  .copyright { margin-left: 0 !important; }
  .lightbox-nav { width: 44px; height: 56px; }
  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .spinner { animation-duration: 10s !important; }
}
