:root {
  --bg: #f4f1ea;
  --card-bg: #ffffff;
  --ink: #2b2b2b;
  --muted: #767268;
  --accent: #d9622b;
  --accent-dark: #b84e1f;
  --accent-soft: #fbe6d8;
  --danger: #c0392b;
  --danger-dark: #9c2d20;
  --success: #3a8f4c;
  --border: #e4ddcf;
  --radius: 16px;
  --plate-yellow: #f6c945;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
  text-decoration: none;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 44px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:active { background: var(--accent-dark); }

.btn-secondary {
  background: var(--card-bg);
  color: var(--ink);
  border: 2px solid var(--border);
}

.btn-danger {
  background: #fceceb;
  color: var(--danger);
  border: 2px solid #f2c9c4;
}
.btn-danger:active { background: #f8d9d5; }

.btn-danger-solid {
  background: var(--danger);
  color: white;
}
.btn-danger-solid:active { background: var(--danger-dark); }

.btn-icon {
  border-radius: 999px;
  min-width: 44px;
  min-height: 44px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  font-size: 1.1rem;
}

.btn-block {
  width: 100%;
  display: block;
  text-align: center;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

main#app {
  padding: 16px;
  max-width: 1000px;
  margin: 0 auto;
  padding-bottom: 90px;
}

/* ---------- Hero / home page ---------- */

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #f0954f 100%);
  color: white;
  border-radius: 20px;
  padding: 26px 22px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "🏁";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 4.5rem;
  opacity: 0.25;
}

.hero h2 {
  margin: 0 0 4px;
  font-size: 1.7rem;
  font-weight: 800;
}

.hero p {
  margin: 0 0 16px;
  opacity: 0.92;
  font-size: 1rem;
}

.stat-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat-chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.95rem;
}

.hero .btn-primary {
  background: white;
  color: var(--accent-dark);
  font-weight: 800;
}
.hero .btn-primary:active { background: #f2e9e2; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1 1 220px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0 14px;
  font-size: 1rem;
  background: var(--card-bg);
}

.sort-select {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 0 12px;
  font-size: 0.95rem;
  background: var(--card-bg);
  color: var(--ink);
}

/* ---------- Grid overview ---------- */

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

.car-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.car-card .thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #ece7db;
}

.car-card .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.car-card .thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  color: #c9c1af;
}

.value-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(43, 43, 43, 0.82);
  color: white;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.brand-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.car-card .car-name {
  padding: 10px 12px 12px;
  font-weight: 600;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 1.1rem;
}

/* ---------- Detail view ---------- */

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-header .spacer { flex: 1; }

.plate {
  display: inline-block;
  background: var(--plate-yellow);
  color: #1a1a1a;
  border: 3px solid #1a1a1a;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  margin-bottom: 18px;
  overflow-wrap: anywhere;
}

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

.field-row {
  display: flex;
  gap: 14px;
}
.field-row .field-block { flex: 1; margin-bottom: 0; }

.field-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.field-input, .field-textarea {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 1.15rem;
  font-family: inherit;
  color: var(--ink);
  padding: 4px 0;
}

.value-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.value-input-row input { max-width: 160px; }
.value-input-row .suffix { color: var(--muted); font-weight: 600; }

.field-textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.4;
}

.photos-section {
  margin-bottom: 18px;
}

.photo-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 8px;
}

.main-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: #ece7db;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.main-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111;
}
.main-photo .thumb-placeholder { font-size: 4rem; color: #c9c1af; }

.thumb-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 10px;
}

.thumb-item {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border-radius: 12px;
  overflow: hidden;
  border: 3px solid transparent;
}
.thumb-item.is-main {
  border-color: var(--accent);
}
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-item .thumb-star {
  position: absolute;
  bottom: 2px;
  left: 2px;
  font-size: 0.95rem;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}
.thumb-item .thumb-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: white;
  border: none;
  font-size: 0.95rem;
  line-height: 1;
}

.add-photo-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.add-photo-row label.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.add-photo-row input[type="file"] {
  display: none;
}

.save-bar {
  position: sticky;
  bottom: 0;
  margin: 20px -16px 18px;
  padding: 12px 16px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.save-bar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.save-bar-status {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--success);
}
.save-bar-status.is-dirty { color: var(--muted); }

.danger-zone {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 2px dashed var(--border);
  text-align: center;
}
.danger-zone p {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 0.95; }
