/* TikTok Live Monitor v1.2.0 - redesign.
   Arah visual: dark "ops console" ala 21st.dev (bento grid, Magic Card
   spotlight, Number Ticker, Shimmer CTA, pulsing live dot) dengan
   token warna brand TikTok (cyan #25F4EE, pink #FE2C55) dan aturan
   ui-ux-pro-max-skill: kontras 4.5:1, target sentuh 44px, satu aksi
   utama yang jelas, progressive disclosure, tanpa horizontal scroll,
   hormati prefers-reduced-motion. Mobile-first: 280px (flip phone
   lipat) sampai 1440px (PC). */

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #17171f;
  --surface-3: #1e1e2a;
  --border: #26262f;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --cyan: #25f4ee;
  --pink: #fe2c55;
  --pink-soft: #ff5c7a;
  --amber: #f5c518;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #4d7cfe;
  --radius: 16px;
  --radius-sm: 10px;
  --pad: clamp(14px, 2.5vw, 22px);
  --fs: 16px;
  --h1: clamp(1.25rem, 3.5vw, 1.7rem);
  --h2: clamp(1.05rem, 2.5vw, 1.25rem);
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--fs);
  line-height: 1.5;
}

h1, h2, .kpi strong, .stat strong { font-family: "Space Grotesk", "Inter", system-ui, sans-serif; }
h1 { font-size: var(--h1); margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: var(--h2); margin: 0 0 10px; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); font-size: 0.85em; }

.wrap { width: min(1200px, 100% - 24px); margin-inline: auto; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(12px, 3vw, 28px);
  border-bottom: 1px solid var(--border);
  background: rgba(14, 14, 22, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  color: #0a0a0f;
}
.logo svg { width: 26px; height: 26px; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.9em; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.badge {
  /* inline-flex + align-items: teks selalu rata tengah vertikal, tidak
     peduli seberapa tinggi item lain di baris yang sama (dulu tombol
     Keluar yang lebih tinggi membuat badge ikut meregang dan teksnya
     menempel di atas). */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-sim { background: #2a2305; color: var(--amber); border-color: #4a3d08; }
.badge-live { background: #3d0a14; color: #ff8fa3; border-color: #6b1220; }
.badge-est { background: #12283d; color: #7cc4ff; border-color: #1d3f61; }

/* ---------- Kartu umum ---------- */
main { padding-block: 16px 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin-bottom: 0; flex: 1; }
.live-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border);
  flex: 0 0 auto;
}
body.is-running .live-dot { background: var(--green); animation: pulse-dot 1.6s ease-in-out infinite; }
body.is-running.mode-live .live-dot { background: var(--pink); }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ---------- Landing & login (v1.3.0) ---------- */
body:not(.authed) .topbar, body:not(.authed) main, body:not(.authed) .footer { display: none; }
#landingView, #loginView { display: none; }
body.show-landing #landingView { display: flex; }
body.show-login #loginView { display: block; }
#landingView {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px 12px;
}
.landing-hero {
  max-width: 560px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.logo-lg { width: 72px; height: 72px; border-radius: 20px; }
.logo-lg svg { width: 40px; height: 40px; }
.tagline { color: var(--muted); font-size: 1.05rem; margin: 0; }
.feature-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.feature-list li { padding-left: 28px; position: relative; }
.feature-list li::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: var(--cyan);
  font-weight: 700;
}
.login-card { max-width: 420px; margin: 48px auto; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-error {
  display: none;
  color: #ffb4c0;
  background: #3d0a14;
  border: 1px solid #6b1220;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.9rem;
}
#logoutBtn { display: none; }
body.authed #logoutBtn { display: inline-flex; }

/* ---------- Bagian buka-tutup / collapsible (v1.3.1) ---------- */
.collapsible { padding: 0; overflow: hidden; }
.collapsible > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: var(--pad);
  font-weight: 700;
  font-size: 1.05rem;
  user-select: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before {
  content: "\25B8";
  color: var(--cyan);
  transition: transform 0.2s ease;
  flex: 0 0 auto;
  font-size: 1.1rem;
  line-height: 1;
}
.collapsible[open] > summary::before { transform: rotate(90deg); }
.collapsible > summary .count {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.collapsible-body { padding: 0 var(--pad) var(--pad); }

/* ---------- Landing: cara kerja (v1.3.1) ---------- */
.steps { display: grid; gap: 10px; margin: 8px 0 4px; text-align: left; width: 100%; }
.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.step-num {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--pink));
  color: #0a0a0f;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
.step b { display: block; }
.step p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

/* ---------- Login: tombol lihat password (v1.3.1) ---------- */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 96px; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* ---------- Setup: alur 3 langkah ---------- */
.setup { display: flex; flex-direction: column; gap: 20px; }
.step-label {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; margin: 0 0 10px;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--cyan);
  font-size: 0.85rem; font-weight: 700; flex: 0 0 auto;
}
.mode-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.mode-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  text-align: left;
  padding: 14px 16px;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.mode-card:hover { border-color: var(--muted); }
.mode-card.selected { border-color: var(--cyan); background: #0f1f21; box-shadow: 0 0 0 1px var(--cyan); }
.mode-card.selected .mode-title::after {
  content: "Dipilih";
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cyan);
  color: #0a0a0f;
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: middle;
}
.mode-icon { display: inline-flex; color: var(--cyan); margin-bottom: 2px; }
.mode-icon svg { width: 24px; height: 24px; }
#modeLiveCard.selected .mode-icon { color: var(--pink); }
#modeLiveCard.selected { border-color: var(--pink); background: #210f16; box-shadow: 0 0 0 1px var(--pink); }
#modeLiveCard.selected .mode-title::after { background: var(--pink); color: #fff; }
.mode-title { font-weight: 700; font-size: 1.05rem; font-family: "Space Grotesk", "Inter", sans-serif; }
.mode-desc { color: var(--muted); font-size: 0.9em; }

.step-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
label, .label { font-weight: 600; font-size: 0.9em; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
body.mode-live #backendUrl { border-color: var(--pink); }
.input-prefix { display: flex; align-items: center; }
.input-prefix > span {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface-3);
  color: var(--muted); font-weight: 600;
}
.input-prefix input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* Aksi utama: satu CTA besar; Berhenti menggantikannya saat jalan. */
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-width: 0;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-icon { width: 18px; height: 18px; flex: 0 0 auto; }
.btn-primary {
  flex: 1 1 100%;
  background: linear-gradient(135deg, var(--pink), var(--pink-soft));
  border-color: var(--pink);
  color: #fff;
  font-size: 1.05rem;
  position: relative;
  overflow: hidden;
}
.btn-primary::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.35) 50%, transparent 60%);
  transform: translateX(-120%);
  animation: shimmer 2.8s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 60% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}
.btn-danger { flex: 1 1 100%; background: #3d0a14; border-color: #6b1220; color: #ff8fa3; }
.btn-accent { background: #2a1a4d; border-color: #4c2d8f; color: #c4b5fd; }
#startBtn { display: inline-flex; }
#stopBtn { display: none; }
#lionBtn { display: none; }
body.is-running #startBtn { display: none; }
body.is-running #stopBtn { display: inline-flex; }
body.mode-sim.is-running #lionBtn { display: inline-flex; }

.status {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.status::before {
  content: "";
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
  margin-top: 6px;
}
body.is-running .status { color: var(--text); }
body.is-running .status::before { background: var(--green); animation: pulse-dot 1.6s ease-in-out infinite; }
body.has-error .status { color: #ffb4c0; border-color: #6b1220; }
body.has-error .status::before { background: var(--red); animation: none; }

.advanced { border-top: 1px solid var(--border); padding-top: 12px; }
.advanced summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
}
.advanced-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding-top: 12px; }
.segmented { display: flex; }
.seg {
  flex: 1;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  min-width: 0;
}
.seg:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.seg:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg.active { background: var(--pink); border-color: var(--pink); color: #fff; font-weight: 700; }

/* ---------- KPI hero (Magic Card) ---------- */
.kpis {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  min-width: 0;
  overflow-wrap: anywhere;
  position: relative;
  overflow: hidden;
}
.kpi.magic::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), rgba(37, 244, 238, 0.12), transparent 65%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.kpi.magic:hover::before { opacity: 1; }
.kpi-money.magic::before { background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), rgba(245, 197, 24, 0.12), transparent 65%); }
.kpi-label { display: block; color: var(--muted); font-size: 0.85em; margin-bottom: 4px; position: relative; }
.kpi strong {
  display: block;
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  position: relative;
}
.kpi small { display: block; margin-top: 4px; position: relative; }

/* ---------- Stat sekunder ---------- */
.stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px var(--pad);
  min-width: 0;
  overflow-wrap: anywhere;
}
.stat-label { display: block; color: var(--muted); font-size: 0.85em; margin-bottom: 2px; }
.stat strong { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: 2px; }

/* ---------- Grid konten (bento) ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.grid .card { margin-bottom: 0; }
.feed-toolbar, .catalog-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; align-items: center; }
.search-box { display: flex; align-items: center; flex: 1 1 200px; min-width: 0; }
.search-box svg { width: 18px; height: 18px; color: var(--muted); margin-right: -32px; margin-left: 12px; position: relative; z-index: 1; flex: 0 0 auto; }
.search-box input { padding-left: 38px; }
.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.feed li {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow-wrap: anywhere;
  min-width: 0;
  animation: feed-in 0.25s ease-out both;
}
@keyframes feed-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.feed li.gift { border-left: 4px solid var(--amber); }
.feed li.chat { border-left: 4px solid var(--blue); }
.feed li.system { border-left: 4px solid var(--muted); color: var(--muted); }
.feed .who { font-weight: 700; }
.feed time { color: var(--muted); font-size: 0.8em; }
.empty-note { margin-top: 10px; }
.top-list { margin: 0; padding-left: 22px; }
.top-list li { padding: 6px 0; overflow-wrap: anywhere; }
.top-list li:nth-child(1) { font-weight: 700; }
.top-list li:nth-child(1)::marker { content: "1. "; color: var(--amber); font-weight: 700; }
.top-list li:nth-child(2)::marker { content: "2. "; color: #c0c0c8; font-weight: 700; }
.top-list li:nth-child(3)::marker { content: "3. "; color: #d08a4e; font-weight: 700; }
.clip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.clip-list li { padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); overflow-wrap: anywhere; }
.clip-list .clip-status { font-weight: 700; color: var(--amber); }

/* Grafik batang sederhana */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
  padding: 8px 4px 0;
  border-bottom: 1px solid var(--border);
}
.chart .bar {
  flex: 1 1 0;
  min-width: 6px;
  background: linear-gradient(180deg, var(--cyan), #0e7490);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
}

/* ---------- Tabel ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.gift-img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; background: var(--surface-2); display: block; }
.gift-img-feed { display: inline-block; vertical-align: middle; width: 28px; height: 28px; margin-right: 6px; }
.gift-emoji { font-size: 1.6rem; line-height: 1; display: inline-block; }
.feed li .gift-emoji { font-size: 1.25rem; }
table { width: 100%; border-collapse: collapse; min-width: 520px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--surface-2); }

.footer { color: var(--muted); font-size: 0.9em; padding-bottom: 24px; }

/* ---------- Tablet 560px ---------- */
@media (min-width: 560px) {
  .mode-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feed { max-height: 420px; }
  .btn-primary, .btn-danger { flex: 1 1 auto; }
  .btn-accent { flex: 0 0 auto; }
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .step { flex-direction: column; }
}

/* ---------- Laptop kecil 900px ---------- */
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .step-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .advanced-body { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Desktop 1024px: bento 2 kolom, feed tinggi ---------- */
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feed-card { grid-row: span 2; }
  .feed { max-height: 480px; }
}

/* ---------- PC lebar 1440px ---------- */
@media (min-width: 1440px) {
  .wrap { width: min(1360px, 100% - 32px); }
}

/* ---------- Flip phone 380px ke bawah ---------- */
@media (max-width: 380px) {
  body { font-size: 15px; }
  .badges .badge { font-size: 0.72rem; padding: 3px 8px; }
  .kpi strong { font-size: 1.35rem; }
  .topbar { padding: 12px; }
  .logo { width: 38px; height: 38px; }
  table { min-width: 460px; }
}

/* ---------- Hormati prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .btn-primary::after { animation: none; }
  .feed li { animation: none; }
  body.is-running .live-dot, body.is-running .status::before { animation: none; }
  .kpi.magic::before { display: none; }
  * { transition-duration: 0.01ms !important; }
}
