/* ── Modal Overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 0 32px;
  width: 100%;
  max-width: 600px;
  max-height: 93vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); max-height: 90vh; }
}

.modal-drag-handle {
  width: 36px;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  margin: 12px auto 0;
}

@media (min-width: 640px) { .modal-drag-handle { display: none; } }

/* ── Modal Header ── */
.modal-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 5;
}

.modal h2 { font-size: 1rem; font-weight: 700; color: var(--text); }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text2);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--surface3); color: var(--text); }

/* ── Modal Body ── */
.modal-body { padding: 20px; }

.form-section { margin-bottom: 20px; }

.form-section-title {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.form-group { margin-bottom: 12px; }

.form-group label {
  display: block;
  font-size: 0.72rem;
  color: var(--text2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 5px;
}

.form-group input,
.form-group select { width: 100%; padding: 10px 12px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ── PI Hint ── */
.pi-hint {
  font-size: 0.7rem;
  margin-top: 5px;
  min-height: 15px;
  font-weight: 600;
  transition: color 0.2s;
}

/* ── Autocomplete ── */
.ac-wrap { position: relative; }
.ac-wrap input { padding-right: 34px; }

.ac-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  display: none;
  line-height: 1;
}

.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
}

.ac-list.show { display: block; }

.ac-item {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}

.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.hl { background: var(--surface3); }

.ac-item-left    { flex: 1; min-width: 0; }
.ac-item-name    { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-item-sub     { font-size: 0.68rem; color: var(--text2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-no-result    { padding: 12px 14px; font-size: 0.82rem; color: var(--text2); font-style: italic; }

/* ── Tag Checkboxes ── */
.tag-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chk  { display: none; }

.tag-chk-label {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid var(--border2);
  background: var(--surface2);
  color: var(--text2);
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  min-height: 34px;
  display: flex;
  align-items: center;
  user-select: none;
}

.tag-chk:checked + .tag-chk-label { border-color: currentColor; opacity: 1; }

.tag-chk-label.lbl-road-racing   { color:#93c5fd; }
.tag-chk-label.lbl-street-racing { color:#c4b5fd; }
.tag-chk-label.lbl-touge         { color:#f9a8d4; }
.tag-chk-label.lbl-dirt-racing   { color:#fdba74; }
.tag-chk-label.lbl-cross-country { color:#86efac; }
.tag-chk-label.lbl-drift         { color:#fde047; }
.tag-chk-label.lbl-drag          { color:#5eead4; }

.tag-chk:checked + .tag-chk-label.lbl-road-racing   { background:rgba(59,130,246,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-street-racing { background:rgba(168,85,247,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-touge         { background:rgba(236,72,153,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-dirt-racing   { background:rgba(249,115,22,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-cross-country { background:rgba(34,197,94,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-drift         { background:rgba(234,179,8,0.15); }
.tag-chk:checked + .tag-chk-label.lbl-drag          { background:rgba(20,184,166,0.15); }

/* ── Modal Footer ── */
.modal-footer {
  padding: 0 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}