:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --ok: #34d399;
  --err: #f87171;
  --yt: #ff4444;
  --ig: #e1306c;
  --tt: #25f4ee;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #e2e5ea;
    --text: #14161a;
    --muted: #667085;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px 24px 60px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Pretendard", -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
header h1 { font-size: 19px; margin: 0; letter-spacing: -0.3px; }

.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.idle { background: var(--ok); }
.dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.error { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 18px;
}
#addForm { display: flex; gap: 8px; }
#urlInput {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 13px;
}
#urlInput:focus { outline: none; border-color: var(--accent); }

.msg { font-size: 12.5px; margin-top: 8px; min-height: 18px; color: var(--muted); }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

.channels { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hint { color: var(--muted); font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 5px 8px 5px 6px; border-radius: 20px; font-size: 12.5px;
}
.chip.err { border-color: var(--err); }
.chip a { color: var(--text); text-decoration: none; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip a:hover { color: var(--accent); }
.chip .pf {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--muted);
}
.chip.youtube .pf { background: var(--yt); }
.chip.instagram .pf { background: var(--ig); }
.chip.tiktok .pf { background: #000; color: var(--tt); }
.chip .cnt { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip .fol {
  background: var(--bg); border-radius: 10px; padding: 1px 7px;
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.chip .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.chip .x:hover { color: var(--err); }

.tabs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 600; }
.spacer { flex: 1; }
#search, #sort {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-size: 13px;
}
#search:focus, #sort:focus { outline: none; border-color: var(--accent); }

/* 모드 전환 (내 채널 / 추천) */
.modes { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.mode {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 9px 16px; cursor: pointer; font-size: 14px;
  margin-bottom: -1px;
}
.mode:hover { color: var(--text); }
.mode.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* 추천 패널 */
.rec-panel { margin-bottom: 16px; }
.rec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.rec-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.rec-actions { display: flex; gap: 8px; }

/* 추천 카드 */
.card.rec { border-color: var(--line); }
.card.rec .reason {
  color: var(--muted); font-size: 12px; line-height: 1.45;
  border-left: 2px solid var(--accent); padding-left: 8px;
}
.score {
  position: absolute; top: 8px; right: 8px; min-width: 26px; text-align: center;
  font-size: 11.5px; font-weight: 700; padding: 3px 6px; border-radius: 5px;
  color: #fff; font-variant-numeric: tabular-nums;
}
.score.hi { background: var(--ok); }
.score.mid { background: var(--accent); }
.score.lo { background: var(--muted); }
.hide {
  margin-left: auto; background: none; border: 1px solid var(--line);
  color: var(--muted); font-size: 11px; padding: 2px 8px;
  border-radius: 5px; cursor: pointer;
}
.hide:hover { border-color: var(--err); color: var(--err); }

/* 구독자·팔로워 규모 필터 */
.tiers {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: -4px 0 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.tiers-label { color: var(--muted); font-size: 12px; margin-right: 4px; }
.tier {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.tier:hover { color: var(--text); border-color: var(--accent); }
.tier.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--panel-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.badge {
  position: absolute; top: 8px; left: 8px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; padding: 3px 7px;
  border-radius: 5px; color: #fff; background: rgba(0,0,0,.65);
}
.badge.youtube { background: var(--yt); }
.badge.instagram { background: var(--ig); }
.badge.tiktok { background: #000; color: var(--tt); }
.dur {
  position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,.78);
  color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

.body { padding: 11px 12px 13px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.title {
  color: var(--text); text-decoration: none; font-size: 13.5px; font-weight: 600;
  line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.title:hover { color: var(--accent); }
.meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11.5px; }
.meta .ch { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fol-inline {
  color: var(--accent); font-variant-numeric: tabular-nums;
  opacity: .85; margin-left: 2px;
}
.stats {
  flex-wrap: wrap;
  display: flex; gap: 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: 8px; margin-top: auto;
  font-variant-numeric: tabular-nums;
}
.delta { color: var(--ok); font-weight: 600; margin-left: auto; }
.ratio { color: var(--accent); font-weight: 600; margin-left: auto; }

.empty { display: none; text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------------- 제품 분석 창 ---------------- */
.card .thumb, .card .title {
  background: none; border: 0; padding: 0; font: inherit;
  color: inherit; cursor: pointer; text-align: left; width: 100%;
}
.thumb-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.55); color: #fff; font-size: 13px; font-weight: 600;
  opacity: 0; transition: opacity .15s;
}
.card:hover .thumb-hint { opacity: 1; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
/* 클래스 선택자가 브라우저 기본 [hidden]{display:none} 을 이기므로 명시적으로 다시 숨깁니다.
   이게 없으면 모달이 항상 떠 있고 닫기 버튼을 눌러도 사라지지 않습니다. */
.modal[hidden] { display: none; }
.modal-back { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.modal-box {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; width: min(880px, 100%); max-height: 88vh; overflow-y: auto;
  padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.modal-x {
  position: absolute; top: 12px; right: 14px; background: none; border: 0;
  color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer;
}
.modal-x:hover { color: var(--text); }

.m-head { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.m-thumb { width: 200px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.m-meta { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.m-meta h2 { font-size: 15px; margin: 0; line-height: 1.45; font-weight: 600; }
.m-stats { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.m-section { border-top: 1px solid var(--line); padding-top: 16px; }
.m-title {
  font-size: 13px; font-weight: 700; margin: 20px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.m-title:first-child { margin-top: 0; }
.m-sub { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.btn.tiny { padding: 3px 9px; font-size: 11.5px; margin-left: auto; }
.m-loading { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }
.m-err { color: var(--err); font-size: 13px; padding: 12px 0; }
.m-warn { color: var(--err); font-size: 12.5px; margin-bottom: 10px; }
.m-note { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.5; }

.conf { font-size: 11px; padding: 2px 7px; border-radius: 5px; color: #fff; font-weight: 600; }
.conf.hi { background: var(--ok); } .conf.mid { background: var(--accent); } .conf.lo { background: var(--muted); }
.cached { font-size: 11px; color: var(--muted); font-weight: 400; }

.m-prod { background: var(--panel-2); border-radius: 10px; padding: 14px; }
.m-prod-name { font-size: 16px; font-weight: 700; }
.m-prod-cat { color: var(--accent); font-size: 12.5px; margin-top: 2px; }
.m-feats { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.7; }

.kw-box { display: flex; flex-direction: column; gap: 8px; }
.kw-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kw-lang { color: var(--muted); font-size: 11.5px; width: 48px; flex-shrink: 0; }
.kw {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
}
.kw:hover { border-color: var(--accent); }
.kw.copied { background: var(--ok); border-color: var(--ok); color: #fff; }

.plat-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.plat {
  display: flex; align-items: center; gap: 9px; text-decoration: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; color: var(--text); overflow: hidden;
}
.plat:hover { border-color: var(--accent); }
.plat-ic {
  width: 30px; height: 24px; border-radius: 5px; display: grid; place-items: center;
  font-size: 9.5px; font-weight: 800; color: #fff; background: var(--muted); flex-shrink: 0;
}
.plat-ic.tiktok { background: #000; color: var(--tt); }
.plat-ic.instagram { background: var(--ig); }
.plat-ic.youtube { background: var(--yt); }
.plat-ic.douyin { background: #161823; color: #fe2c55; }
.plat-ic.xiaohongshu { background: #ff2442; }
.plat-ic.taobao { background: #ff5000; }
.plat-ic\.1688, .plat-ic { }
.plat-name { font-size: 12.5px; font-weight: 600; flex-shrink: 0; }
.plat-q {
  font-size: 11px; color: var(--muted); margin-left: auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px;
}

.quick-box { min-height: 10px; }
.quick-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: 10px; }
.quick {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  text-decoration: none; color: var(--text); font-size: 11.5px;
}
.quick img, .quick .noimg {
  width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 7px;
  background: var(--panel-2); display: block;
}
.quick-badge {
  position: absolute; top: 5px; left: 5px; font-size: 8.5px; font-weight: 700;
  text-transform: uppercase; padding: 2px 5px; border-radius: 4px; color: #fff;
  background: rgba(0,0,0,.7);
}
.quick-badge.youtube { background: var(--yt); }
.quick-badge.instagram { background: var(--ig); }
.quick-t { line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.quick-v { color: var(--muted); font-variant-numeric: tabular-nums; }
.quick:hover .quick-t { color: var(--accent); }

/* ---------------- 로그인 화면 ---------------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { font-size: 17px; margin: 0; letter-spacing: -0.3px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
.login-box input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 13px; border-radius: 8px; font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box .btn { padding: 11px; font-size: 14px; }
.login-err {
  color: var(--err); font-size: 12.5px; background: rgba(248,113,113,.1);
  border: 1px solid var(--err); border-radius: 7px; padding: 8px 10px;
}
.login-note { color: var(--muted); font-size: 11.5px; margin: 4px 0 0; text-align: center; }

/* ---------------- 일괄 등록 ---------------- */
.bulk-text {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 11px 13px;
  font: 13px/1.6 "Consolas", "D2Coding", monospace; resize: vertical;
}
.bulk-text:focus { outline: none; border-color: var(--accent); }
.bulk-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.bulk-actions .btn { margin-left: auto; }
.bulk-rows { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.bulk-row {
  display: flex; align-items: center; gap: 9px; font-size: 12.5px;
  padding: 6px 10px; border-radius: 7px; background: var(--panel-2);
}
.bulk-row.ok .bulk-mark { color: var(--ok); }
.bulk-row.no .bulk-mark { color: var(--err); }
.bulk-mark { font-weight: 700; width: 12px; flex-shrink: 0; }
.bulk-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-why { margin-left: auto; color: var(--muted); font-size: 11.5px; flex-shrink: 0; }

/* ---------------- 채널 목록 표 ---------------- */
.ch-table-wrap { overflow-x: auto; margin-top: 4px; }
.ch-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ch-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.ch-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ch-table tr:last-child td { border-bottom: 0; }
.ch-table .pf {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #fff; background: var(--muted);
}
.ch-table .pf.youtube { background: var(--yt); }
.ch-table .pf.instagram { background: var(--ig); }
.ch-table .pf.tiktok { background: #000; color: var(--tt); }
.ch-name { font-weight: 600; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-link a {
  color: var(--accent); text-decoration: none; font-size: 11.5px;
  display: inline-block; max-width: 300px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.ch-link a:hover { text-decoration: underline; }
.ch-table .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.ch-table .good { color: var(--ok); }
.ch-table .bad { color: var(--err); }

/* ---------------- 플랫폼별 채널 요약 ---------------- */
.ch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.ch-sum {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 6px 11px; border-radius: 9px; font-size: 12.5px;
}
.ch-sum:hover { border-color: var(--accent); }
.ch-sum.open { border-color: var(--accent); background: var(--panel); }
.ch-sum .pf {
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #fff; background: var(--muted);
}
.ch-sum.youtube .pf { background: var(--yt); }
.ch-sum.instagram .pf { background: var(--ig); }
.ch-sum.tiktok .pf { background: #000; color: var(--tt); }
.ch-sum-name { font-weight: 600; }
.ch-sum-n {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 11px;
  min-width: 18px; text-align: center; padding: 1px 6px; border-radius: 9px;
  font-variant-numeric: tabular-nums;
}
.ch-sum-v { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ch-sum-err {
  background: var(--err); color: #fff; font-size: 10.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 9px;
}
.ch-caret { color: var(--muted); font-size: 10px; }
.ch-total { color: var(--muted); font-size: 12px; margin-left: 4px; }

.ch-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  padding: 10px; background: var(--bg); border-radius: 9px;
  max-height: 190px; overflow-y: auto;
}
.ch-chips .chip { padding: 4px 7px 4px 10px; font-size: 12px; }

/* ---------------- 나의 작업 목록 ---------------- */
.mode-n {
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 9px; margin-left: 4px;
  font-variant-numeric: tabular-nums; vertical-align: 1px;
}
.mode-n:empty { display: none; }
.keep {
  margin-left: auto; background: none; border: 1px solid var(--line);
  color: var(--muted); font-size: 11px; padding: 2px 9px;
  border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.keep:hover { border-color: var(--ok); color: var(--ok); }
.keep.out:hover { border-color: var(--err); color: var(--err); }
.keep:disabled { opacity: .4; cursor: default; }
.card.rec .keep { margin-left: 0; }
