/* ─── CarSearch AI Partners — API page (.pak-*) ─────────────────────────────
   Styles for public/js/partner-api.js: the tab panel, the two key cards, the
   dealership table that turns into stacked cards on a phone, the quick-start
   steps and the usage bars. Tokens only, no literal colours, so every theme in
   app.css keeps working. Mobile target: 390px wide with no page overflow.   */

.pak, .pak-panel { min-width: 0; }
.pak-panel > .card { margin-bottom: 14px; }
/* Card headings: .card-h / .card-sub are scoped to .portal and #admin-body in
   the shared sheets, so the partner pages need their own copy. */
.pak .card-h { font-size: 16px; font-weight: 700; margin: 0 0 4px; color: var(--text); }
.pak .card-sub { font-size: 13.5px; line-height: 1.55; color: var(--text-muted); margin: 0 0 14px; }
.pak .card-sub code, .pak .pak-kv code { font-size: 12.5px; }

/* Tab bar (shared component in public/js/ui-tabs.js). On a phone the bar
   scrolls sideways instead of making the page scroll. */
.ui-tabs { flex-wrap: wrap; }
@media (max-width: 720px) {
  .ui-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .ui-tabs::-webkit-scrollbar { display: none; }
  .ui-tabs .admin-tab { flex: 0 0 auto; }
}

/* ── Keys tab ───────────────────────────────────────────────────────────── */
.pak-keycards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; align-items: start; }
.pak-keycard { margin-bottom: 0; min-width: 0; }
.pak-keycard .card-sub { margin-bottom: 12px; }
.pak-kv { display: grid; gap: 8px; margin: 0 0 14px; }
.pak-kv > div { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.pak-kv dt { flex: 0 0 84px; font-size: 12.5px; color: var(--text-muted); }
.pak-kv dd { margin: 0; min-width: 0; font-size: 13.5px; color: var(--text); word-break: break-all; }
.pak-prefix { font-size: 12.5px; word-break: break-all; }
.pak-empty { color: var(--text-muted); margin: 0 0 14px; }
.pak-card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pak-keylist { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.pak-keylist-h { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 8px; }
.pak-keyrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.pak-keyrow:last-child { border-bottom: none; }
.pak-keyrow-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 12.5px; }
.pak-keyrow-actions { display: flex; gap: 8px; }

/* ── Code boxes: scroll inside themselves, never widen the page ─────────── */
.pak-code { min-width: 0; }
.pak-pre { white-space: pre; overflow-x: auto; word-break: normal; max-height: 240px; }
.pak-codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; min-width: 0; }
.pak-codes .key-once { margin-top: 0; }

/* ── Dealerships tab ────────────────────────────────────────────────────── */
.pak-toolbar { flex-wrap: wrap; gap: 10px; }
.pak-search { flex: 0 1 320px; min-width: 0; }
.pak-tablewrap { max-height: none; }
.pak-table td { vertical-align: top; }
.pak-table tbody tr { cursor: default; }
.pak-table .pak-row-act { text-align: right; white-space: nowrap; }
.pak-example > td { background: var(--surface-2); padding: 0 12px 14px; }
.pak-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }

/* ── Quick start tab ────────────────────────────────────────────────────── */
.pak-steps { list-style: none; counter-reset: pakstep; margin: 4px 0 0; padding: 0; }
.pak-steps > li { counter-increment: pakstep; position: relative; padding: 0 0 18px 44px; border-left: 2px solid var(--border); margin-left: 13px; }
.pak-steps > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.pak-steps > li::before {
  content: counter(pakstep);
  position: absolute; left: -14px; top: 0;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--on-primary);
  font-size: 13px; font-weight: 700;
}
.pak-steps h3 { margin: 2px 0 4px; font-size: 15px; color: var(--text); }
.pak-steps p { margin: 0 0 10px; color: var(--text-muted); font-size: 13.5px; }
.pak-docs { margin: 14px 0 0; }

/* ── Usage tab ──────────────────────────────────────────────────────────── */
.pak-stats { display: flex; flex-wrap: wrap; gap: 20px; margin: 4px 0 16px; }
.pak-stat { display: flex; flex-direction: column; }
.pak-stat-n { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; }
.pak-stat-l { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.pak-chart { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.pak-barcell { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; }
.pak-bar { position: relative; display: block; width: 100%; border-radius: 2px 2px 0 0; background: var(--primary); }
.pak-bar-err { position: absolute; left: 0; right: 0; bottom: 0; display: block; background: var(--danger); }
.pak-chart-x { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); margin: 6px 2px 0; }
.pak-usage-wrap { margin-top: 16px; }

/* ── Phone: 390px, stacked cards, 16px inputs, full-width buttons ───────── */
@media (max-width: 640px) {
  .pak-panel > .card { padding-left: 14px; padding-right: 14px; }
  .pak-keycards { grid-template-columns: 1fr; }
  .pak-card-actions { flex-direction: column; align-items: stretch; }
  .pak-card-actions .btn { width: 100%; }
  .pak-search { flex: 1 1 100%; }
  .pak-toolbar input[type="search"], .pak-panel input, .pak-panel select, .pak-panel textarea { font-size: 16px; }
  .pak-codes { grid-template-columns: 1fr; }

  /* Tables become stacked cards. The selectors carry the table element so they
     beat the shared "table.grid scrolls sideways on a phone" rule in app.css. */
  .pak-tablewrap { border: none; background: none; box-shadow: none; overflow: visible; }
  table.pak-table { display: block; width: auto; overflow: visible; white-space: normal; }
  table.pak-table thead { display: none; }
  table.pak-table tbody, table.pak-table tr, table.pak-table td { display: block; width: auto; min-width: 0; }
  table.pak-table tr[hidden], table.pak-table td[hidden] { display: none; }
  table.pak-table tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 10px; }
  table.pak-table tbody tr:hover { background: var(--surface); }
  table.pak-table td { border: none; padding: 5px 0; }
  table.pak-table td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 2px; }
  table.pak-table td[data-label=""]::before { display: none; }
  table.pak-table .pak-row-act { text-align: left; }
  table.pak-table .pak-row-act .btn { width: 100%; }
  table.pak-table tbody tr.pak-example { padding: 0 0 10px; border: none; background: none; box-shadow: none; }
  table.pak-table tr.pak-example > td { background: none; padding: 0; }
  table.pak-table .key-uid { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
  .pak-chart { height: 90px; gap: 2px; }
  .pak-pager .btn { flex: 1 1 auto; }
}
