/* mechanic.css — AI Mechanic chat page styles.
   Depends on theme.css for CSS variables. Standalone page, not part of browse/ flow.
   Owns: mechanic page layout, vehicle selector, chat area.
   Does NOT own: nav, footer, browse cards, or landing page sections. */

/* ── Nav link classes (reused from browse layout) ────────────────────────── */
.nav-link {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-muted);
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: color 0.15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.nav-link:hover { color: var(--accent); }
.nav-link-active { color: var(--accent); }

/* ── Page layout ─────────────────────────────────────────────────────────── */
.mechanic-main {
  min-height: calc(100vh - 60px - 56px);
  padding: 24px 16px 64px;
  display: flex;
  justify-content: center;
}

.mechanic-container {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.mechanic-header {
  text-align: center;
  padding-bottom: 4px;
}

.mechanic-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(212, 168, 67, 0.25);
  border-radius: 3px;
  padding: 3px 10px;
  margin-bottom: 12px;
}

.mechanic-title {
  font-family: var(--sans);
  font-size: clamp(24px, 7vw, 42px);
  font-weight: 700;
  color: var(--fg);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.mechanic-subtitle {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--fg-muted);
  margin: 0;
}

/* ── Vehicle selector ────────────────────────────────────────────────────── */
.vehicle-selector {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.selector-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.selector-icon {
  color: var(--accent);
  font-size: 8px;
}

/* Mobile: 2-col grid, stacks button below */
.selector-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.selector-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.selector-field-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: 0.05em;
}

.selector-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  /* 44px touch target */
  padding: 0 32px 0 12px;
  height: 44px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238a8880' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: var(--bg-elevated);
  transition: border-color 0.15s;
  width: 100%;
  /* Prevent zoom on iOS (font must be >= 16px or set explicitly) */
  font-size: max(16px, 14px);
}

.selector-select:focus {
  outline: none;
  border-color: var(--accent);
}

.selector-select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Year select and clear button — full row on mobile */
.selector-year-group {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.selector-clear {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 14px;
  height: 44px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.selector-clear:hover {
  color: var(--fg);
  border-color: var(--fg-muted);
}

.vehicle-pill {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  background: var(--accent-glow);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 20px;
  padding: 5px 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.03em;
}

/* ── Chat area ───────────────────────────────────────────────────────────── */
.chat-area {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 400px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 260px;
  max-height: 480px;
  -webkit-overflow-scrolling: touch;
}

/* ── Welcome state ───────────────────────────────────────────────────────── */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 12px;
  gap: 10px;
  margin: auto;
}

.welcome-icon {
  font-size: 32px;
  color: var(--accent);
  opacity: 0.6;
  line-height: 1;
}

.welcome-heading {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 600;
  color: var(--fg);
  margin: 0;
}

.welcome-sub {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--fg-muted);
  margin: 0;
  max-width: 380px;
  line-height: 1.6;
}

.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.example-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--fg-muted);
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  text-align: left;
  min-height: 44px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.example-chip:hover {
  border-color: var(--accent);
  color: var(--fg);
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.chat-msg {
  max-width: 95%;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 14px;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--fg);
  border-bottom-right-radius: 2px;
}

.chat-msg-ai {
  align-self: flex-start;
  background: linear-gradient(135deg, rgba(212, 168, 67, 0.06) 0%, var(--bg-elevated) 100%);
  border: 1px solid rgba(212, 168, 67, 0.2);
  color: var(--fg);
  border-bottom-left-radius: 2px;
  width: 100%;
  max-width: 100%;
  padding: 16px;
}

.chat-msg-error {
  align-self: flex-start;
  background: rgba(220, 80, 80, 0.08);
  border: 1px solid rgba(220, 80, 80, 0.25);
  color: #e08080;
}

/* ── AI response internals ───────────────────────────────────────────────── */
.ai-diagnosis {
  color: var(--fg);
  margin-bottom: 14px;
  line-height: 1.65;
}

.ai-advice {
  color: var(--fg-muted);
  font-size: 13px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
  line-height: 1.6;
}

.ai-parts-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 10px;
}

/* Part cards in AI response — single column on mobile */
.ai-parts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* ── Part card ───────────────────────────────────────────────────────────── */
.part-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  transition: border-color 0.15s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 64px;
}

.part-card:hover {
  border-color: var(--accent);
}

.part-card-system {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  text-transform: uppercase;
}

.part-card-name {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}

.part-card-oem {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}

.part-card-desc {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.4;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.part-card-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  margin-top: 6px;
}

/* ── Loading animation ───────────────────────────────────────────────────── */
.chat-loading {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  width: auto;
  max-width: 80px;
}

.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: dotPulse 1.2s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* ── Chat input area ─────────────────────────────────────────────────────── */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
  background: var(--bg-elevated);
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.chat-input-wrap:focus-within { border-color: var(--accent); }

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 120px;
  overflow-y: auto;
}
.chat-input::placeholder { color: var(--fg-dim); }

/* Touch-friendly send button — 44px min */
.chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--accent);
  border: none;
  color: #0a0a0c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.chat-send:hover { background: var(--accent-dim); }
.chat-send:active { transform: scale(0.95); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.chat-hint {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 7px;
  letter-spacing: 0.02em;
}

/* ── Responsive: tablet 641px+ ──────────────────────────────────────────── */
@media (min-width: 641px) {
  .mechanic-main { padding: 36px 24px 72px; }
  .mechanic-container { gap: 24px; }
  .vehicle-selector { padding: 20px 24px; }

  /* 3-col selector on tablet — Year + Clear in their own cells */
  .selector-row {
    grid-template-columns: 1fr 1fr 1fr auto;
    align-items: end;
  }
  .selector-year-group {
    display: contents; /* unwrap — year select and clear become direct grid children */
  }
  /* Year select in col 3, clear in col 4 */

  .chat-messages { padding: 20px 24px; max-height: 520px; }
  .chat-msg { max-width: 90%; }
  .chat-msg-ai { padding: 18px 20px; }
  .ai-parts-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .chat-input-area { padding: 14px 20px; }
}

/* ── Responsive: desktop 901px+ ─────────────────────────────────────────── */
@media (min-width: 901px) {
  .mechanic-main { padding: 48px 24px 80px; }
  .mechanic-container { gap: 28px; }
  .mechanic-subtitle { font-size: 16px; }
  .chat-send { width: 36px; height: 36px; }
}
