/* HDM Typesense Search */
.hdm-typesense-search {
  max-width: 960px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hdm-ts__inner {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  padding: 28px 32px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.hdm-ts__heading {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0 0 4px;
}

.hdm-ts__subtitle {
  font-size: 0.88rem;
  color: #7b7b7b;
  margin: 0 0 16px;
}

/* Form */
.hdm-ts__input-row {
  display: flex;
  gap: 8px;
  position: relative;
}

.hdm-ts__input {
  flex: 1;
  padding: 14px 16px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
  min-height: 52px;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.hdm-ts__input:focus {
  border-color: #d4a24e;
}

.hdm-ts__button {
  padding: 14px 24px;
  background: #d4a24e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.hdm-ts__button:hover,
.hdm-ts__button:active {
  background: #b8892e;
}

/* Status / error */
.hdm-ts__status {
  padding: 16px;
  text-align: center;
  color: #888;
  margin-top: 12px;
  font-size: 0.95rem;
}

/* Loading spinner */
.hdm-ts__spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #ddd;
  border-top-color: #d4a24e;
  border-radius: 50%;
  animation: hdm-ts-spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

.hdm-ts__error {
  padding: 12px 16px;
  background: #fff5f5;
  border: 1px solid #fcc;
  border-radius: 8px;
  color: #c00;
  margin-top: 12px;
  font-size: 0.9rem;
}

/* Telemetry */
.hdm-ts__telemetry {
  margin-top: 12px;
}

.hdm-ts__metrics {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.hdm-ts__metric {
  background: #f8f8f8;
  border-radius: 6px;
  padding: 6px 12px;
  text-align: center;
  flex: 1;
  min-width: 70px;
}

.hdm-ts__metric-label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #999;
}

.hdm-ts__metric-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: #333;
}

/* AI Answer */
.hdm-ts__answer {
  padding: 14px 18px;
  background: #fdf8f0;
  border-left: 3px solid #d4a24e;
  border-radius: 0 8px 8px 0;
  color: #333;
  font-size: 0.95rem;
  line-height: 1.6;
  margin-top: 14px;
  margin-bottom: 4px;
  transition: opacity 0.3s;
}

.hdm-ts__answer--loading {
  color: #999;
  font-size: 0.85rem;
  background: #fafafa;
  border-left-color: #ddd;
}

.hdm-ts__intent {
  margin-top: 12px;
  padding: 12px 14px;
  background: #f0f3f8;
  border: 1px solid #dde3ed;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #48607a;
  line-height: 1.4;
}

.hdm-ts__intent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hdm-ts__intent-label {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #2d4a6f;
}

.hdm-ts__intent-time {
  color: #999;
  font-size: 0.75rem;
}

.hdm-ts__intent-json {
  margin: 0;
  padding: 10px 12px;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Results grid */
.hdm-ts__results {
  margin-top: 16px;
}

.hdm-ts__pagination {
  margin-top: 16px;
  text-align: center;
}

.hdm-ts__button--more {
  min-width: 180px;
}

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

.hdm-ts__card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.hdm-ts__card:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.hdm-ts__img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: #fafafa;
  padding: 6px;
}

.hdm-ts__info {
  padding: 10px 12px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hdm-ts__card .hdm-ts__title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 4px;
  color: #1a1a1a;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hdm-ts__price {
  font-size: 1.05rem;
  font-weight: 700;
  color: #d4a24e;
  margin-bottom: 4px;
}

.hdm-ts__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.hdm-ts__badge,
.hdm-ts__chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  line-height: 1.2;
}

.hdm-ts__badge {
  background: #f7f2e8;
  color: #745522;
}

.hdm-ts__cats {
  font-size: 0.72rem;
  color: #999;
  margin-top: auto;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Per-result "why it matched" bullets (agent mode) */
.hdm-ts__reasons {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hdm-ts__reason {
  position: relative;
  padding-left: 16px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: #444;
}

.hdm-ts__reason::before {
  content: "\2713";
  position: absolute;
  left: 0;
  top: 0;
  color: #2e7d32;
  font-weight: 700;
}

/* Gradient placeholders while reasons stream in (async fallback path) */
.hdm-ts__reason--ph {
  padding-left: 0;
  height: 9px;
  border-radius: 4px;
  background: linear-gradient(90deg, #ececec 25%, #f6f6f6 37%, #ececec 63%);
  background-size: 400% 100%;
  animation: hdm-ts-shimmer 1.2s ease-in-out infinite;
}

.hdm-ts__reason--ph::before { content: none; }
.hdm-ts__reason--ph:nth-child(2) { width: 78%; }

@keyframes hdm-ts-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* Agent execution trace panel (Node /api/search with trace:true) */
.hdm-ts__trace {
  margin: 24px 0 0;
  padding: 14px 16px;
  background: #f8f9fb;
  border: 1px solid #d6dce4;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #2a2a2a;
}

.hdm-ts__trace > summary.hdm-ts__trace-head {
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  font-size: 14px;
  color: #1a1a1a;
  list-style-position: outside;
}

.hdm-ts__trace[open] > summary.hdm-ts__trace-head {
  margin-bottom: 8px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}

.hdm-ts__trace-section {
  margin: 6px 0;
}

.hdm-ts__trace-section > summary {
  cursor: pointer;
  padding: 3px 0;
  color: #4a5568;
  font-weight: 500;
  font-size: 12px;
}

.hdm-ts__trace-section[open] > summary {
  color: #1a1a1a;
}

.hdm-ts__trace-pre {
  margin: 4px 0 0;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Monaco, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  color: #1a1a1a;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow: auto;
}

.hdm-ts__trace-think {
  background: #fffbeb;
  border-color: #fde68a;
  color: #4d3a00;
}

.hdm-ts__trace-turns {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.hdm-ts__trace-turn {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-left: 3px solid #3b82f6;
  border-radius: 6px;
}

.hdm-ts__trace-turn-head {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}

.hdm-ts__trace-phase {
  display: inline-block;
  padding: 1px 8px;
  background: #eff6ff;
  color: #1e40af;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.hdm-ts__trace-toolsline {
  margin: 8px 0 4px;
  color: #4a5568;
  font-size: 12px;
}

.hdm-ts__trace-tools {
  list-style: decimal;
  padding-left: 22px;
  margin: 6px 0 0;
}

.hdm-ts__trace-tools > li {
  margin: 0 0 10px;
  padding: 4px 0;
}

.hdm-ts__trace-tool-head {
  font-size: 12.5px;
  color: #1a1a1a;
  margin-bottom: 4px;
}

.hdm-ts__empty {
  text-align: center;
  color: #888;
  padding: 20px;
}

.hdm-ts__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.hdm-ts__chip {
  background: #f0f3f8;
  color: #48607a;
}

/* ============================================
   TABLET (max-width: 767px)
   ============================================ */
@media (max-width: 767px) {
  .hdm-ts__inner {
    padding: 16px 14px;
    border-radius: 10px;
  }

  .hdm-ts__heading {
    font-size: 1.2rem;
    margin-bottom: 12px;
  }

  /* Stack input and button vertically */
  .hdm-ts__input-row {
    flex-direction: column;
    gap: 10px;
  }

  .hdm-typesense-search .hdm-ts__input {
    padding: 16px 16px !important;
    font-size: 16px !important; /* prevents iOS zoom on focus */
    border-radius: 8px;
    min-height: 56px !important;
    height: auto;
    box-sizing: border-box;
  }

  .hdm-typesense-search .hdm-ts__button {
    padding: 16px 20px !important;
    font-size: 1.05rem;
    border-radius: 8px;
    width: 100%;
    min-height: 56px !important;
    box-sizing: border-box;
  }

  /* 2-column grid on tablet/phone */
  .hdm-ts__grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .hdm-ts__img {
    height: 130px;
  }

  .hdm-ts__info {
    padding: 8px 10px 10px;
  }

  .hdm-ts__card .hdm-ts__title {
    font-size: 0.8rem;
  }

  .hdm-ts__price {
    font-size: 0.95rem;
  }

  .hdm-ts__answer {
    padding: 12px 14px;
    font-size: 0.9rem;
    line-height: 1.5;
  }

  /* Compact telemetry on mobile */
  .hdm-ts__metrics {
    gap: 4px;
  }

  .hdm-ts__metric {
    padding: 5px 8px;
    min-width: 60px;
  }

  .hdm-ts__metric-label {
    font-size: 0.55rem;
  }

  .hdm-ts__metric-value {
    font-size: 0.8rem;
  }
}

/* ============================================
   SMALL PHONE (max-width: 400px)
   ============================================ */
@media (max-width: 400px) {
  .hdm-ts__inner {
    padding: 14px 12px;
  }

  .hdm-ts__grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .hdm-ts__card {
    flex-direction: row;
    border-radius: 8px;
  }

  .hdm-ts__img {
    width: 100px;
    height: 100px;
    flex-shrink: 0;
    border-radius: 8px 0 0 8px;
  }

  .hdm-ts__info {
    padding: 10px 12px;
    justify-content: center;
  }

  .hdm-ts__card .hdm-ts__title {
    font-size: 0.82rem;
    -webkit-line-clamp: 2;
  }

  .hdm-ts__price {
    font-size: 1rem;
    margin-bottom: 2px;
  }

  .hdm-ts__cats {
    font-size: 0.7rem;
  }

  /* Stack telemetry 2x2 */
  .hdm-ts__metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
}

/* Instant / AI-agent mode toggle (Node search page) */
.hdm-ts__mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
}
.hdm-ts__mode-cb {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.hdm-ts__mode-track {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 11px;
  background: #c7ccd1;
  transition: background 0.18s ease;
}
.hdm-ts__mode-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s ease;
}
.hdm-ts__mode-cb:checked + .hdm-ts__mode-track {
  background: #2e7d32;
}
.hdm-ts__mode-cb:checked + .hdm-ts__mode-track .hdm-ts__mode-knob {
  transform: translateX(16px);
}
.hdm-ts__mode-cb:focus-visible + .hdm-ts__mode-track {
  outline: 2px solid #2e7d32;
  outline-offset: 2px;
}
.hdm-ts__mode-label em {
  color: #6b7280;
  font-style: normal;
}
