/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f0f1a;
  --surface:  #1a1a2e;
  --border:   #2a2a4a;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --accent:   #7c3aed;
  --accent2:  #06b6d4;
  --gift-bg:  #1e1030;
  --gift-hi:  #2d1a4a;
  --green:    #22c55e;
  --red:      #ef4444;

  --rank1:  #FFD700;
  --rank2:  #C0C0C0;
  --rank3:  #CD7F32;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

/* ── Brand ───────────────────────────────────────────────────── */
.site-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
}
.brand-name {
  font-size: 17px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: .03em;
  white-space: nowrap;
}
.brand-tagline {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .06em;
  white-space: nowrap;
}

.logout-btn {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color .2s, border-color .2s;
}
.logout-btn:hover { color: var(--red); border-color: var(--red); }

/* ── Change-password modal ───────────────────────────────────────────────── */
.cp-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.cp-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  width: 340px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cp-title { font-size: 16px; font-weight: 700; }
.cp-input {
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.cp-input:focus { border-color: var(--accent); }
.cp-err {
  font-size: 12px; color: var(--red);
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.2);
  border-radius: 6px; padding: 6px 10px;
}

.btn {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
  white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-fans    { background: #1a2e1a; color: var(--green);   border: 1px solid var(--green); text-decoration: none; }

#status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
#status-dot.connected    { background: var(--green); box-shadow: 0 0 6px var(--green); }
#status-dot.monitoring   { background: var(--accent); box-shadow: 0 0 8px var(--accent);
                           animation: pulse 1.5s infinite; }
#status-dot.disconnected { background: var(--red); }

@keyframes pulse {
  0%,100% { opacity:1; } 50% { opacity:.4; }
}

#status-label { font-size: 13px; color: var(--muted); }
#current-stream-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--accent2);
  font-weight: 600;
  margin-left: 4px;
  max-width: 300px;
  overflow: hidden;
}
.stream-title-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stream-rename-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--accent2);
  border-radius: 4px;
  color: var(--accent2);
  font-size: 11px;
  padding: 1px 5px;
  cursor: pointer;
  opacity: .7;
  transition: opacity .15s;
}
.stream-rename-btn:hover { opacity: 1; }

/* ── Main layout ─────────────────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  overflow: hidden;
  height: calc(100vh - 57px);
}

/* ── Feed panel (left) ──────────────────────────────────────── */
#feed-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 1px 8px;
  font-size: 11px;
}

#feed-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#feed-list::-webkit-scrollbar { width: 4px; }
#feed-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Feed items ─────────────────────────────────────────────── */
.feed-item {
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  animation: slideIn .25s ease;
}

@keyframes slideIn {
  from { opacity:0; transform: translateY(-6px); }
  to   { opacity:1; transform: translateY(0); }
}

.feed-item.gift {
  background: var(--gift-bg);
  border: 1px solid #3d1a6e;
}
.feed-item.gift.big {
  background: linear-gradient(135deg, #2d1a4a, #1a1030);
  border-color: var(--accent);
}

.feed-item.system {
  background: #0d1f2d;
  border: 1px solid #1e3a4a;
  color: var(--accent2);
  font-size: 12px;
}

.gift-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

/* Fan level badge (WeChat Lv.1-100) */
.lv-badge {
  font-size: 11px;
  font-weight: 700;
  font-family: "Courier New", monospace;
  border: 1px solid;
  border-radius: 3px;
  padding: 0 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.feed-username {
  font-weight: 700;
  color: var(--accent2);
}
.feed-gift-name {
  font-weight: 600;
}
.feed-count { color: var(--muted); font-size: 12px; }
.feed-value { color: #f97316; font-size: 12px; font-weight: 600; }
.feed-time  { color: var(--muted); font-size: 11px; }

/* Pre-gift comments container */
.pre-gift-comments {
  margin-top: 6px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
  border-left: 2px solid var(--accent2);
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.8;
  flex-wrap: wrap;
  word-break: break-word;
}

/* Fan's own comment in pre-gift block */
.pgc-self { color: #94a3b8; }

/* Someone else mentioning the fan */
.pgc-mention { color: #94a3b8; }

/* Sender name badge for mention */
.pgc-sender {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #F59E0B;
  background: rgba(245,158,11,.12);
  border-radius: 3px;
  padding: 0 4px;
  margin-right: 4px;
  vertical-align: middle;
}

/* Separator between comment items */
.pgc-sep {
  color: var(--border);
  margin: 0 5px;
  font-size: 11px;
}

/* ── Stats panel (right) ────────────────────────────────────── */
#stats-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tier section headers */
.tier-section { margin-bottom: 4px; }

.tier-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  border-top: 2px solid;
  background: rgba(255,255,255,0.03);
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  z-index: 1;
}

.tier-range {
  font-size: 11px;
  font-weight: 400;
  opacity: .7;
  flex: 1;
}

/* Avatar in feed and stats */
.feed-avatar {
  width: 20px; height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  vertical-align: middle;
}

.fan-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* Tier editor modal */
.tier-editor-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.tier-editor-overlay.open { display: flex; }

.tier-editor-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tier-editor-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.tier-editor-body {
  display: flex;
  gap: 8px;
  align-items: center;
}

#tier-level-input {
  width: 100px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  outline: none;
}
#tier-level-input:focus { border-color: var(--accent); }
#tier-level-input::-webkit-inner-spin-button { opacity: 1; }

.tier-confirm-btn {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tier-confirm-btn:hover { opacity: .85; }

.tier-editor-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  align-self: flex-start;
  transition: color .15s;
}
.tier-editor-clear:hover { color: var(--red); border-color: var(--red); }

/* Profile link */
.profile-link {
  font-size: 14px;
  text-decoration: none;
  opacity: .6;
  transition: opacity .15s;
  flex-shrink: 0;
}
.profile-link:hover { opacity: 1; }

/* Clickable fan name */
.fan-name-editable {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.fan-name-editable:hover { opacity: .8; }

/* Custom tier badge indicator */
.rank-tier.custom { outline: 1px solid currentColor; }

/* Location / gender badge */
.ext-info {
  font-size: 11px;
  color: var(--muted);
  margin-left: 3px;
}

.fan-avatar-placeholder {
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

/* Fan stats section */
#fan-stats-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.fan-stats-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.fan-stats-list::-webkit-scrollbar { width: 4px; }
.fan-stats-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Fan row */
.fan-row {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .15s;
  cursor: default;
}
.fan-row:hover { background: #22223a; }

.fan-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fan-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.fan-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fan-value-col {
  text-align: right;
  flex-shrink: 0;
}
.fan-total-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--rank1);
}
.fan-gift-count {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

/* Fan meta row */
.fan-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.fan-meta-row strong {
  color: var(--text);
  font-weight: 600;
}

.meta-sep {
  color: var(--border);
  font-size: 13px;
  padding: 0 2px;
}

/* Gift details collapsible */
.gift-details {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

.gift-details > summary {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 5px;
}
.gift-details > summary::-webkit-details-marker { display: none; }
.gift-details > summary::before {
  content: '▶';
  font-size: 9px;
  transition: transform .15s;
  display: inline-block;
}
.gift-details[open] > summary::before {
  transform: rotate(90deg);
}
.gift-details > summary:hover { color: var(--text); }

.gift-events-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.gift-event {
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  border-left: 2px solid var(--accent);
}

.gift-event-header {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* Rank number circles (shared) */
.rank-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  flex-shrink: 0;
}
.rank-1 { background: var(--rank1); color: #000; }
.rank-2 { background: var(--rank2); color: #000; }
.rank-3 { background: var(--rank3); color: #fff; }
.rank-other { background: var(--border); color: var(--muted); }

.rank-tier {
  font-size: 11px;
  border-radius: 4px;
  padding: 0 6px;
  display: inline-block;
  white-space: nowrap;
}

/* ── Summary bar ─────────────────────────────────────────────── */
#summary-bar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 20px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.stat-item { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 20px; font-weight: 800; }
.stat-value.gifts-color   { color: var(--accent); }
.stat-value.value-color   { color: var(--rank1); }
.stat-value.viewers-color { color: var(--accent2); }
.stat-value.givers-color  { color: var(--green); }

/* ── Empty state ─────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  gap: 8px;
  font-size: 14px;
  padding: 20px;
  text-align: center;
}
.empty-icon { font-size: 40px; opacity: .5; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13px;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  z-index: 999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: 50vh 1fr; }
  #feed-panel { border-right: none; border-bottom: 1px solid var(--border); }
}
