/* /insights/auto-industry/ — interactive subreddit finder + guide.
   Prefix: aii- (Auto Industry Insights). Reuses site tokens (--orange, --navy,
   --border, --bg-page, --radius, .container, .btn, .page-hero) — no new
   color system, just a small pastel badge palette for the 8 segments. */

.aii-tool { background: #fff; padding-top: 52px; }
.aii-tool .container { max-width: 1080px; }

/* ---- Segment legend --------------------------------------------------- */
.aii-legend {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  margin: 28px 0 40px;
}
@media (min-width: 640px) { .aii-legend { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .aii-legend { grid-template-columns: repeat(4, 1fr); } }
.aii-legend__card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--bg-page);
}
.aii-legend__card p {
  margin: 8px 0 0;
  font-size: .86rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---- Segment badges (shared: legend, filter chips, table) -------------- */
.aii-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
  line-height: 1.4;
}
.aii-badge .aii-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.seg-general  { background: #EEF2FF; color: #4338CA; }
.seg-general  .aii-dot { background: #4338CA; }
.seg-brand    { background: #FFF1E9; color: #C2410C; }
.seg-brand    .aii-dot { background: #C2410C; }
.seg-ev       { background: #ECFDF5; color: #047857; }
.seg-ev       .aii-dot { background: #047857; }
.seg-repair   { background: #FFFBEB; color: #B45309; }
.seg-repair   .aii-dot { background: #B45309; }
.seg-buying   { background: #EFF6FF; color: #1D4ED8; }
.seg-buying   .aii-dot { background: #1D4ED8; }
.seg-offroad  { background: #F5F3FF; color: #6D28D9; }
.seg-offroad  .aii-dot { background: #6D28D9; }
.seg-lifestyle{ background: #FDF2F8; color: #BE185D; }
.seg-lifestyle .aii-dot { background: #BE185D; }
.seg-b2b      { background: #F1F5F9; color: #334155; }
.seg-b2b      .aii-dot { background: #334155; }

/* ---- Filter bar --------------------------------------------------------- */
.aii-filters {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 24px;
  box-shadow: 0 20px 45px -30px rgba(15, 23, 42, .35);
  margin-bottom: 22px;
}
.aii-filters__row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.aii-filters__row + .aii-filters__row { margin-top: 16px; }
.aii-search {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  padding: 0 14px;
  flex: 1 1 240px;
  min-width: 200px;
}
.aii-search svg { flex-shrink: 0; color: var(--text-muted); }
.aii-search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 11px 0;
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--navy);
  min-width: 0;
}
.aii-search:focus-within { outline: 2px solid var(--orange); outline-offset: 1px; background: #fff; }

.aii-select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--navy);
  flex: 0 0 auto;
}
.aii-select:focus { outline: 2px solid var(--orange); outline-offset: 1px; background: #fff; }

.aii-chip-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  flex-basis: 100%;
  margin: 0 0 -2px;
}
.aii-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.aii-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .84rem;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.aii-chip:hover { border-color: var(--navy); color: var(--navy); }
.aii-chip.is-active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.aii-chip .aii-dot { width: 7px; height: 7px; border-radius: 50%; }

.aii-reset {
  background: none;
  border: none;
  color: var(--orange);
  font-weight: 600;
  font-size: .86rem;
  cursor: pointer;
  padding: 6px 4px;
  flex-shrink: 0;
  margin-left: auto;
}
.aii-reset:hover { text-decoration: underline; }

.aii-count { font-size: .86rem; color: var(--text-muted); margin: 0 0 12px; }
.aii-count b { color: var(--navy); }

/* "Copy list" floats above the table's own top-right corner — not a column
   beside it (that would eat into the table's width and readd the overflow
   risk), just anchored to the top-right, out of the table's own box. */
.aii-table-wrap { position: relative; margin-top: 46px; }
.aii-copy-btn {
  position: absolute;
  top: -46px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--navy);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .84rem;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.aii-copy-btn:hover { border-color: var(--navy); }
.aii-copy-btn.is-copied { border-color: #047857; background: #ECFDF5; color: #047857; }
.aii-copy-btn.is-failed { border-color: #DC2626; background: #FEF2F2; color: #B91C1C; }

/* ---- Table --------------------------------------------------------------- */
.aii-table-scroll {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 640px;
}
table.aii-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  table-layout: fixed;
}
.aii-table th:nth-child(1), .aii-table td:nth-child(1) { width: 18%; } /* Subreddit */
.aii-table th:nth-child(2), .aii-table td:nth-child(2) { width: 8%; }  /* Members */
.aii-table th:nth-child(3), .aii-table td:nth-child(3) { width: 8%; }  /* Founded */
.aii-table th:nth-child(4), .aii-table td:nth-child(4) { width: 14%; } /* Segment */
.aii-table th:nth-child(5), .aii-table td:nth-child(5) { width: 8%; }  /* Posts */
.aii-table th:nth-child(6), .aii-table td:nth-child(6) { width: 9%; }  /* Fit */
.aii-table th:nth-child(7), .aii-table td:nth-child(7) { width: 35%; } /* About */
.aii-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-page);
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--navy);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}
.aii-table thead th.is-sorted { color: var(--orange); }
.aii-table thead th .aii-sort-ico { display: inline-block; margin-left: 4px; opacity: .5; }
.aii-table thead th.is-sorted .aii-sort-ico { opacity: 1; }
.aii-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text-muted);
  overflow: hidden;
}
.aii-table tbody tr:last-child td { border-bottom: none; }
.aii-table tbody tr:hover td { background: var(--bg-page); }
.aii-table tbody tr[hidden] { display: none; }

.aii-sub-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
}
.aii-sub-name:hover { color: var(--orange); }
.aii-sub-name svg { flex-shrink: 0; opacity: .55; }
.aii-sub-name__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.aii-sub-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-page);
  border: 1px solid var(--border);
}
.aii-sub-icon--blank { display: inline-block; }

.aii-founded { white-space: nowrap; }
.aii-posttype {
  display: inline-block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.aii-private {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  color: var(--cold);
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
}
.aii-tier {
  display: inline-block;
  font-size: .78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.aii-tier--direct { background: #ECFDF5; color: #047857; }
.aii-tier--indirect { background: #F1F5F9; color: #64748B; }
.aii-desc { line-height: 1.5; overflow: visible; white-space: normal; }
.aii-members { white-space: nowrap; font-weight: 600; color: var(--navy); }
.aii-empty { padding: 40px 16px; text-align: center; color: var(--text-muted); }
.aii-scroll-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 0;
  font-size: .82rem;
  color: var(--cold);
}
.aii-scroll-note[hidden] { display: none; }
.aii-scroll-note svg { flex-shrink: 0; }

/* ---- Responsive: stacked cards instead of a scrolling table --------------- */
@media (max-width: 760px) {
  .aii-table-scroll { max-height: none; overflow-y: visible; border: none; border-radius: 0; }
  .aii-table thead { display: none; }
  .aii-table, .aii-table tbody, .aii-table tr, .aii-table td { display: block; width: auto !important; }
  .aii-table tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    padding: 4px 14px;
  }
  .aii-table tbody tr:hover td { background: transparent; }
  .aii-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
    min-width: 0;
  }
  .aii-table tbody td:last-child { border-bottom: none; }
  .aii-table tbody td::before {
    content: attr(data-label);
    font-family: var(--font-head);
    font-weight: 700;
    color: var(--navy);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .02em;
    flex-shrink: 0;
  }
  .aii-table tbody td.aii-desc {
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .aii-table tbody td.aii-desc::before { margin-bottom: 4px; }
  .aii-sub-name__text { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
}

/* ---- Guide article (mirrors .bttr-article typography) -------------------- */
.aii-guide { background: var(--bg-page); }
.aii-guide .container { max-width: 780px; }
.aii-guide h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
.aii-guide h3 { font-size: 1.15rem; margin-top: 1.9em; }
.aii-guide h4 {
  font-family: var(--font-head);
  font-size: 1rem;
  color: var(--navy);
  margin: 0 0 4px;
}
.aii-guide p, .aii-guide li { color: var(--text-muted); font-size: 1.02rem; line-height: 1.65; }
.aii-guide ul { list-style: disc; padding-left: 22px; margin-bottom: 1em; }
.aii-guide li { margin-bottom: .5em; }
.aii-guide a:not(.btn) { color: var(--orange); font-weight: 600; text-decoration: none; }
.aii-guide a:not(.btn):hover { text-decoration: underline; }

.aii-playbook {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  margin: 1.6em 0;
}
@media (min-width: 640px) { .aii-playbook { grid-template-columns: 1fr 1fr; } }
.aii-playbook__card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.aii-playbook__card p { font-size: .92rem; margin: 0 0 8px; }
.aii-playbook__card p:last-child { margin: 0; }
.aii-playbook__ex { font-size: .82rem; color: var(--cold); }
.aii-playbook__ex a { font-weight: 600; }

.aii-note {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--orange);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  margin: 1.8em 0;
}
.aii-note p { margin: 0 0 10px; }
.aii-note p:last-child { margin: 0; }
.aii-note p.aii-note__meta { font-size: .84rem; color: var(--cold); }

.aii-guide__cta {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  margin-top: 2em;
  text-align: left;
}
.aii-guide__cta p { margin: 0 0 14px; color: var(--navy); font-weight: 500; }
.aii-guide__cta p:last-child { margin: 0; }
