/* Tesla Skin Library — minimal CSS, system fonts, dark theme. */

:root {
  --bg: #0b0d12;
  --bg-card: #151821;
  --bg-elev: #1b1f2a;
  --fg: #e6e8ee;
  --fg-dim: #9aa0ad;
  --accent: #e53935;
  --accent-2: #ff7043;
  --good: #4caf50;
  --bad: #ef5350;
  --warning: #fbc02d;
  --border: #2a2f3d;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg-elev);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* layout ---------------------------------------------------------- */

.topbar {
  display: flex; align-items: center;
  background: linear-gradient(180deg, #131722 0%, #0d1018 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); padding: 14px 0; margin-right: 24px; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 22px; color: var(--accent); }
.brand-name { letter-spacing: 0.5px; }

.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  color: var(--fg-dim);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.nav a:hover { background: var(--bg-elev); color: var(--fg); text-decoration: none; }
.nav a.active { background: var(--bg-elev); color: var(--fg); }

.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

.footer {
  text-align: center;
  padding: 24px;
  color: var(--fg-dim);
  border-top: 1px solid var(--border);
  margin-top: 32px;
  font-size: 12px;
}

/* sections ------------------------------------------------------- */

.hero h1 { font-size: 28px; margin: 0 0 8px; }
.hero .lead { color: var(--fg-dim); max-width: 720px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 24px 0; }
.kpi { background: var(--bg-card); padding: 16px; border-radius: 10px; box-shadow: var(--shadow); }
.kpi-value { font-size: 24px; font-weight: 600; color: var(--fg); }
.kpi-label { color: var(--fg-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }
.kpi.ok { border-left: 3px solid var(--good); }
.kpi.warn { border-left: 3px solid #ffb84d; }
.kpi.bad { border-left: 3px solid var(--bad); }
.kpi.bad { border-left: 3px solid var(--bad); }
.kpi.warning { border-left: 3px solid var(--warning); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 24px 0; }
@media (max-width: 800px) { .row { grid-template-columns: 1fr; } }

.crumbs a { color: var(--fg-dim); }
.crumbs { margin-bottom: 16px; }

/* tables --------------------------------------------------------- */

.data { width: 100%; border-collapse: collapse; margin: 12px 0; }
.data th, .data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.data th { color: var(--fg-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.data tr:hover { background: var(--bg-card); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data.full th, .data.full td { font-size: 12px; padding: 6px 10px; }

/* library grid --------------------------------------------------- */

/* Three top-N leaderboards above the filter form (rendered only on
   the unfiltered landing). Each chart is a small numbered list with
   thumb + name + the stat it ranks by. */
.top-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
              gap: 14px; margin-bottom: 18px; }
.top-chart  { background: var(--bg-card); padding: 14px 16px;
              border-radius: 10px; box-shadow: var(--shadow); }
.top-chart h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase;
                letter-spacing: 1px; color: var(--fg-dim); }
.top-list   { list-style: none; padding: 0; margin: 0;
              counter-reset: toprank; }
.top-list li { counter-increment: toprank; }
.top-list .top-row { display: flex; align-items: center; gap: 10px;
                     padding: 6px 8px; border-radius: 6px;
                     color: inherit; text-decoration: none;
                     transition: background .12s; }
.top-list .top-row::before {
  content: counter(toprank); min-width: 18px; text-align: right;
  color: var(--fg-dim); font-size: 12px; font-variant-numeric: tabular-nums;
}
.top-list .top-row:hover { background: var(--bg-elev); }
.top-list .top-row img { width: 44px; height: 44px; object-fit: cover;
                         border-radius: 5px; background: rgba(255,255,255,0.05); }
.top-list .top-meta { flex: 1; min-width: 0;
                      display: flex; justify-content: space-between; gap: 8px;
                      align-items: baseline; }
.top-list .top-name { flex: 1; min-width: 0;
                      white-space: nowrap; overflow: hidden;
                      text-overflow: ellipsis; font-size: 13px; }
.top-list .top-stat { color: var(--fg-dim); font-size: 12px;
                      white-space: nowrap; font-variant-numeric: tabular-nums; }

.filters { background: var(--bg-card); padding: 16px; border-radius: 10px; box-shadow: var(--shadow); margin-bottom: 16px; }
.filters form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select, .filters button { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--fg); }
.filters button { background: var(--accent); border-color: var(--accent); color: white; cursor: pointer; font-weight: 500; }
.filters button:hover { background: var(--accent-2); }
.filters input.search { flex: 1; min-width: 200px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.card {
  background: var(--bg-card); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
  transition: transform 0.1s, box-shadow 0.1s;
  color: var(--fg);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.card .thumb { aspect-ratio: 1; background: #000; overflow: hidden; display: grid; place-items: center; }
.card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.card .no-thumb { color: var(--bad); font-size: 11px; padding: 12px; text-align: center; }
.card-meta { padding: 10px; font-size: 12px; }
.card-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 11px; }
.card-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }

.card-ok { border-color: var(--good); }
.card-bad { border-color: var(--bad); opacity: 0.7; }

/* detail page --------------------------------------------------- */

.detail { display: grid; grid-template-columns: 360px 1fr; gap: 24px; margin-top: 16px; }
@media (max-width: 800px) { .detail { grid-template-columns: 1fr; } }
.detail-image { background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 1; display: grid; place-items: center; }
.detail-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.detail-image .placeholder { text-align: center; }
.detail-image .placeholder .big { font-size: 60px; color: var(--bad); }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 12px 0; }
.kv.wide { grid-template-columns: 180px 1fr; }
.kv dt { color: var(--fg-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; padding-top: 2px; }
.kv dd { margin: 0; word-break: break-word; }
.kv code.sha { font-size: 11px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; background: var(--bg-elev); }
.badge.ok { background: var(--good); color: #000; }
.badge.bad { background: var(--bad); color: #fff; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.tag-form { display: inline; }
.tag { background: var(--bg-elev); border: 1px solid var(--border); padding: 2px 8px; border-radius: 12px; font-size: 11px; color: var(--fg); cursor: pointer; }
.tag:hover { background: var(--border); }
.tag-add { display: inline-flex; align-items: center; gap: 4px; }
.tag-add input { padding: 4px 6px; border-radius: 4px; background: var(--bg-elev); border: 1px solid var(--border); color: var(--fg); }
.tag-add button { padding: 4px 8px; border-radius: 4px; background: var(--accent); color: white; border: 0; cursor: pointer; }

textarea { width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--fg); padding: 10px; border-radius: 8px; font-family: inherit; font-size: 13px; }
button.primary { background: var(--accent); color: white; padding: 8px 16px; border: 0; border-radius: 6px; cursor: pointer; font-weight: 500; }
button.danger { background: var(--bad); color: white; padding: 8px 16px; border: 0; border-radius: 6px; cursor: pointer; font-weight: 500; }
.row-actions { margin-top: 8px; }

/* misc ----------------------------------------------------------- */

.flashes { margin: 12px 0; }
.flash { padding: 8px 14px; border-radius: 6px; margin-bottom: 6px; }
.flash-info { background: rgba(33, 150, 243, 0.15); border: 1px solid rgba(33, 150, 243, 0.4); }
.flash-error { background: rgba(244, 67, 54, 0.15); border: 1px solid rgba(244, 67, 54, 0.4); }

.muted { color: var(--fg-dim); }
.small { font-size: 12px; }

.empty { text-align: center; padding: 60px 24px; }

.pager { display: flex; gap: 12px; justify-content: center; padding: 16px; align-items: center; }
.pager a { background: var(--bg-card); padding: 6px 14px; border-radius: 6px; }

pre { background: var(--bg-elev); padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; }

.card-form { background: var(--bg-card); padding: 16px; border-radius: 10px; }
.card-form label { display: flex; gap: 8px; align-items: center; margin: 6px 0; }

/* live active-run card + progress ------------------------------ */

.trigger-form { display: flex; gap: 12px; align-items: center; margin: 18px 0; flex-wrap: wrap; }
.trigger-form .inline { display: inline-flex; gap: 6px; align-items: center; color: var(--fg-dim); }

.active-run {
  background: linear-gradient(135deg, rgba(33,150,243,0.18), rgba(33,150,243,0.05));
  border: 1px solid rgba(33,150,243,0.45);
  border-radius: 12px;
  padding: 18px 22px;
  margin: 18px 0;
}
.active-state { margin-bottom: 8px; }
.active-state[hidden] { display: none; }

/* detail-page image toggle (Car preview vs Skin source) */
.img-toggle button { background: transparent; border: 0; padding: 6px 12px;
                     border-radius: 6px; color: var(--fg-dim); cursor: pointer;
                     font: inherit; }
.img-toggle button.active { background: var(--accent); color: #fff; }
.img-toggle button:hover:not(.active) { background: rgba(255,255,255,0.06); color: var(--fg); }

/* Album-style image carousel (library detail page).
 * Two slides sit side-by-side in a horizontal track; we translate the
 * track to show one at a time. Pointer / touch swipe drags the track
 * live; release past a threshold commits the slide. */
.detail-image .carousel-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform .35s cubic-bezier(.22,.61,.36,1);
  touch-action: pan-y;            /* allow vertical scroll, we handle horizontal */
  cursor: grab;
}
.detail-image .carousel-track:active { cursor: grabbing; }
.detail-image .carousel-slide {
  flex: 0 0 100%;
  min-width: 100%;
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.detail-image .carousel-slide img {
  width: 100%; height: auto; max-height: 80vh;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none;
}
.detail-image .carousel-caption {
  position: absolute; left: 12px; bottom: 12px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,0.45); color: #fff;
  font-size: 12px; letter-spacing: 0.5px;
  pointer-events: none;
}
.detail-image .carousel-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgba(0,0,0,0.45); color: #fff; font-size: 22px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, opacity .15s;
}
.detail-image .carousel-nav:hover { background: rgba(0,0,0,0.7); }
.detail-image .carousel-nav:disabled { opacity: 0.25; cursor: default; }
.detail-image .carousel-nav.prev { left: 8px; }
.detail-image .carousel-nav.next { right: 8px; }
.detail-image .carousel-dots {
  position: absolute; left: 50%; bottom: 14px;
  transform: translateX(-50%);
  display: inline-flex; gap: 8px; padding: 5px 10px;
  background: rgba(0,0,0,0.45); border-radius: 999px;
}
.detail-image .carousel-dots .dot {
  width: 10px; height: 10px; padding: 0;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.35); cursor: pointer;
  transition: background .15s, transform .15s;
}
.detail-image .carousel-dots .dot:hover { background: rgba(255,255,255,0.6); }
.detail-image .carousel-dots .dot.active {
  background: #fff; transform: scale(1.25);
}
.detail-image .carousel-dots.single .dot { background: rgba(255,255,255,0.6); cursor: default; }
/* Swipe / drag hint shown alongside the dots so users discover the
 * gesture. Subtle but visible — fades slightly after first interaction
 * (handled by JS adding .carousel-hint-seen). */
.detail-image .carousel-hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,0.35); color: rgba(255,255,255,0.85);
  font-size: 11px; letter-spacing: 0.5px;
  pointer-events: none;
  transition: opacity .4s;
}
.detail-image .carousel-hint-seen .carousel-hint { opacity: 0; }
.active-run h2 { margin-top: 0; color: var(--accent); font-size: 17px; font-weight: 600; }
.active-run[hidden] { display: none; }
.active-grid { display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: center; margin-bottom: 12px; }
.active-pct { text-align: center; }
.active-pct .big { font-size: 36px; font-weight: 700; color: var(--accent); line-height: 1; }
.active-meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.active-meta dt { color: var(--fg-dim); font-size: 12px; align-self: center; }
.active-meta dd { margin: 0; font-size: 13px; }
.active-meta code { font-size: 12px; }
progress { width: 100%; height: 8px; appearance: none; -webkit-appearance: none; }
progress::-webkit-progress-bar { background: rgba(255,255,255,0.08); border-radius: 4px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; transition: width 0.3s ease; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 4px; }

/* batch retry button -------------------------------------------- */

.batch-retry-form { margin-top: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.batch-retry-form .danger { padding: 8px 14px; font-size: 13px; }

/* card layout + per-card download button ----------------------- */

.card-wrap { position: relative; }
.dl-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 50%;
  font-size: 16px;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  backdrop-filter: blur(4px);
  z-index: 2;
}
.card-wrap:hover .dl-btn { opacity: 1; }
.dl-btn:hover { transform: scale(1.1); background: var(--accent); }
.thumb-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

/* detail-page action buttons ------------------------------- */

.row-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
.row-actions .inline-form { display: inline; margin: 0; }
.row-actions .dl-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.row-actions .dl-link:hover { filter: brightness(1.1); }
