/* ThumbLab — Creator Analytics & Thumbnail A/B Lab */

:root {
  --red: #ff2d55;
  --red-soft: rgba(255, 45, 85, 0.14);
  --accent: #ff2d55;
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Dark (default) ---- */
:root[data-theme="dark"] {
  --bg: #0c0d10;
  --panel: #16181d;
  --panel-2: #1d2027;
  --line: #262a33;
  --text: #eef0f4;
  --muted: #9aa1ad;
  --muted-2: #6b7280;
  --chart-grid: rgba(255,255,255,.06);
}
/* ---- Light ---- */
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e6e8ec;
  --text: #14161a;
  --muted: #5d6470;
  --muted-2: #9aa1ad;
  --chart-grid: rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand-mark { font-size: 22px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: transparent; border: 0; color: var(--muted);
  font: inherit; font-weight: 500; cursor: pointer; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.is-active { background: var(--red-soft); color: var(--text); }
.nav-ico { font-size: 15px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.channel-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 8px; border-radius: var(--radius-sm);
}
.channel-av { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--line); }
.channel-name { font-weight: 600; font-size: 13px; }
.channel-sub { color: var(--muted); font-size: 11px; }

/* ---------- Main ---------- */
.main { padding: 26px 30px 60px; max-width: 1180px; width: 100%; }
.view { display: none; animation: fade .25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.page-head p { margin: 4px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); padding: 9px 16px; border: 1px solid transparent;
  transition: transform .05s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-ok { background: var(--ok); color: #04210f; }
.btn-ok:hover { filter: brightness(1.06); }
.btn-danger { background: transparent; border-color: var(--line); color: var(--red); }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- Range toggle ---------- */
.range-toggle, .seg {
  display: inline-flex; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px;
}
.range-toggle button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.range-toggle button.is-active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi-delta { font-size: 12px; font-weight: 600; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--red); }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }

/* ---------- Video table ---------- */
.vid-table { display: flex; flex-direction: column; }
.vid-row {
  display: grid; grid-template-columns: 96px 1fr 120px 90px 90px; gap: 14px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.vid-row:first-child { border-top: 0; }
.vid-thumb { width: 96px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--panel-2); }
.vid-title { font-weight: 600; font-size: 13px; line-height: 1.35; }
.vid-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.vid-metric { text-align: right; font-variant-numeric: tabular-nums; }
.vid-metric b { font-size: 14px; }
.vid-metric span { display: block; color: var(--muted); font-size: 11px; }
.bar-mini { height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.bar-mini > i { display: block; height: 100%; background: var(--red); border-radius: 4px; }

/* ---------- Videos grid ---------- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.video-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.video-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--panel-2); }
.video-card .vc-body { padding: 12px 14px 14px; }
.video-card h4 { margin: 0 0 8px; font-size: 13px; line-height: 1.35; }
.vc-stats { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.vc-stats b { color: var(--text); }

/* ---------- A/B test cards ---------- */
.test-list { display: flex; flex-direction: column; gap: 18px; }
.test-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.test-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.test-head-l { min-width: 0; }
.test-title { font-weight: 700; font-size: 15px; }
.test-vid { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.test-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.status-pill { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.status-idle { background: var(--panel-2); color: var(--muted); }
.status-running { background: var(--red-soft); color: var(--red); }
.status-running::before { content: "●"; margin-right: 5px; animation: pulse 1.2s infinite; }
.status-done { background: var(--ok-soft); color: var(--ok); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.test-body { padding: 18px; }
.variants { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.variant {
  border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden;
  background: var(--panel-2); position: relative; transition: border-color .2s, box-shadow .2s;
}
.variant.is-live { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.variant.is-winner { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); }
.variant-img-wrap { position: relative; }
.variant img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--line); }
.variant-tag { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; }
.variant-live-tag { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--red); color: #fff; }
.variant-win-tag { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--ok); color: #04210f; }
.variant-stats { padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vstat { }
.vstat b { font-size: 15px; font-variant-numeric: tabular-nums; }
.vstat span { display: block; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; }
.ctr-bar { height: 5px; background: var(--line); border-radius: 4px; margin: 0 12px 12px; overflow: hidden; }
.ctr-bar > i { display: block; height: 100%; background: var(--red); }
.variant.is-winner .ctr-bar > i { background: var(--ok); }

.test-progress { margin-top: 16px; }
.progress-track { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.progress-track > i { display: block; height: 100%; background: var(--red); transition: width .4s ease; }
.progress-meta { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 12px; }

.winner-banner {
  margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--ok-soft); border: 1px solid rgba(34,197,94,.35);
  display: flex; align-items: center; gap: 12px;
}
.winner-banner .wb-ico { font-size: 22px; }
.winner-banner b { color: var(--ok); }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-ico { font-size: 44px; margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 0 18px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.4); max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input[type="text"], select {
  font: inherit; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
input[type="text"]:focus, select:focus { outline: none; border-color: var(--red); }

.variant-uploads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.upload-slot {
  aspect-ratio: 16/9; border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--muted); font-size: 22px; background: var(--panel-2); position: relative; overflow: hidden;
  transition: border-color .15s, color .15s;
}
.upload-slot:hover { border-color: var(--red); color: var(--red); }
.upload-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.upload-slot .rm { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 6px; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  font-weight: 600; font-size: 13px; box-shadow: var(--shadow); z-index: 100; animation: toastin .2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .channel-chip { display: none; }
  .nav { flex-direction: row; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 50px; }
  .vid-row { grid-template-columns: 72px 1fr 70px; }
  .vid-row .col-hide { display: none; }
}
