:root {
  --bg: #ffffff; --bg2: #f2f2f2; --bg3: #e5e5e5; --hover: #e9e9e9; --card: #ffffff;
  --text: #0f0f0f; --text2: #606060; --line: #e0e0e0;
  --accent: #ff3b30; --accent2: #d92b21; --gold: #c98a00; --green: #1a8f3c; --blue: #065fd4;
  --chip: #f2f2f2; --chip-on: #0f0f0f; --chip-on-text: #fff;
  --shadow: 0 4px 24px rgba(0,0,0,.14);
  --side: 232px; --top: 56px;
}
:root[data-theme="dark"] {
  --bg: #0f0f0f; --bg2: #212121; --bg3: #303030; --hover: #272727; --card: #181818;
  --text: #f1f1f1; --text2: #aaaaaa; --line: #303030;
  --gold: #ffcc33; --green: #3ecf6e; --blue: #3ea6ff;
  --chip: #272727; --chip-on: #f1f1f1; --chip-on-text: #0f0f0f;
  --shadow: 0 4px 24px rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 Roboto, Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* top bar */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top); display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 16px; background: var(--bg); z-index: 30; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo { flex: none; display: flex; align-items: center; gap: 6px; font-size: 19px; letter-spacing: -.5px; white-space: nowrap; }
.logo img { width: 30px; height: 30px; }
.logo b { color: var(--accent); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--hover); }
.search { flex: 0 1 640px; display: flex; min-width: 0; }
.search input { flex: 1; min-width: 0; height: 40px; padding: 0 16px; border: 1px solid var(--line); border-right: 0; border-radius: 20px 0 0 20px;
  background: var(--bg); outline: none; }
.search input:focus { border-color: var(--blue); }
.search button { width: 64px; height: 40px; border: 1px solid var(--line); border-radius: 0 20px 20px 0; background: var(--bg2); cursor: pointer; display: grid; place-items: center; }
.scan-btn { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 500; white-space: nowrap; }
.scan-btn svg { width: 20px; height: 20px; }
.scan-btn:hover { background: var(--accent2); }
.scan-btn.running svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; display: none; }
.scan-progress.on { display: block; }
.scan-progress div { height: 100%; width: 0; background: var(--accent); transition: width .5s; }

/* sidebar */
.sidebar { position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); padding: 12px; overflow-y: auto; background: var(--bg); z-index: 20; }
.sidebar nav a { display: flex; align-items: center; gap: 22px; height: 40px; padding: 0 12px; border-radius: 10px; }
.sidebar nav a:hover { background: var(--hover); }
.sidebar nav a.on { background: var(--bg2); font-weight: 500; }
.sidebar nav a span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar nav a em { font-style: normal; font-size: 12px; color: var(--text2); }
.sidebar nav a em.hot { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; }
.sidebar hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.side-foot { font-size: 12px; color: var(--text2); padding: 16px 12px; line-height: 1.6; }
body.mini .sidebar { width: 72px; padding: 4px; }
body.mini .sidebar nav a { flex-direction: column; gap: 4px; height: 70px; justify-content: center; font-size: 10px; padding: 0; }
body.mini .sidebar nav a span { flex: none; max-width: 64px; }
body.mini .sidebar nav a em, body.mini .side-foot, body.mini .sidebar hr { display: none; }

main { margin-left: var(--side); padding: calc(var(--top) + 8px) 24px 40px; min-height: 100vh; }
body.mini main { margin-left: 72px; }

/* chips + filters */
.chips { position: sticky; top: var(--top); z-index: 10; background: var(--bg); display: flex; gap: 12px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 32px; padding: 0 12px; border-radius: 8px; border: 0; background: var(--chip); cursor: pointer; font-weight: 500; white-space: nowrap; }
.chip:hover { background: var(--bg3); }
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0 16px; }
.filters label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text2); }
.filters select, .filters input { height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 8px; color: var(--text); }
.filters .count { margin-left: auto; color: var(--text2); font-size: 13px; }
.btn { height: 36px; padding: 0 16px; border-radius: 18px; border: 0; background: var(--bg2); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--bg3); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.red { background: var(--accent); color: #fff; }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; }

/* grid + cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 40px 16px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 28px 14px; }
.card { cursor: pointer; min-width: 0; position: relative; }
.thumb { position: relative; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: var(--bg2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.card:hover .thumb img { transform: scale(1.03); }
.badge { position: absolute; font-size: 12px; font-weight: 500; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.8); color: #fff; }
.badge.br { right: 8px; bottom: 8px; }
.badge.tl { left: 8px; top: 8px; background: var(--accent); }
.badge.tr { right: 8px; top: 8px; background: rgba(0,0,0,.75); color: #ffd60a; }
.play { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .2s; background: rgba(0,0,0,.25); }
.play span { width: 56px; height: 56px; border-radius: 50%; background: rgba(0,0,0,.7); display: grid; place-items: center; }
.play svg { fill: #fff; stroke: none; width: 28px; height: 28px; margin-left: 4px; }
.thumb:hover .play { opacity: 1; }
.meta { display: flex; gap: 12px; padding-top: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; background: var(--bg3); }
.meta-text { min-width: 0; flex: 1; }
.title { font-size: 16px; font-weight: 500; line-height: 22px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0 0 4px; }
.grid.small .title { font-size: 14px; line-height: 20px; }
.sub { color: var(--text2); font-size: 13px; line-height: 19px; }
.sub b { color: var(--text); font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 10px; background: var(--bg2); color: var(--text2); white-space: nowrap; }
.tag.hot { color: var(--gold); }
.tag.green { color: var(--green); }
.card-actions { position: absolute; top: 8px; left: 8px; display: none; gap: 6px; }
.card:hover .card-actions { display: flex; }
.card-actions button { width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.75); color: #fff; display: grid; place-items: center; cursor: pointer; }
.card-actions button svg { width: 17px; height: 17px; }
.card-actions button.on { background: var(--accent); }
.card:hover .badge.tl { display: none; }
.more { display: flex; justify-content: center; margin: 32px 0; }
.empty { text-align: center; color: var(--text2); padding: 80px 20px; }
.empty h2 { color: var(--text); font-weight: 500; }

/* page heads + stats */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 8px; }
.page-head h1 { font-size: 24px; margin: 0; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--text2); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.stat { background: var(--bg2); border-radius: 12px; padding: 14px 16px; }
.stat .k { color: var(--text2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .h { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* channel page */
.banner { height: clamp(90px, 16vw, 200px); border-radius: 16px; background: var(--bg2) center/cover no-repeat; margin-top: 8px; }
.ch-head { display: flex; gap: 24px; align-items: center; margin: 20px 0; flex-wrap: wrap; }
.ch-head .big-avatar { width: 140px; height: 140px; border-radius: 50%; object-fit: cover; background: var(--bg3); }
.ch-head h1 { font-size: 34px; margin: 0; line-height: 1.15; }
.ch-head .sub { font-size: 14px; margin-top: 6px; }
.ch-head .desc { color: var(--text2); max-width: 760px; margin: 8px 0 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 20px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 12px 14px; cursor: pointer; font-weight: 500; color: var(--text2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-color: var(--text); }
.panel { background: var(--bg2); border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
textarea.note { width: 100%; min-height: 110px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 10px; resize: vertical; }
.chart svg { width: 100%; height: 180px; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .l1 { stroke: var(--accent); stroke-width: 2.5; }
.chart .l2 { stroke: var(--blue); stroke-width: 2.5; }
.chart text { fill: var(--text2); stroke: none; font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text2); }
.legend i { display: inline-block; width: 10px; height: 3px; vertical-align: middle; margin-right: 6px; }

/* niches + title lab */
.niche-list { display: grid; gap: 12px; }
.niche { display: grid; grid-template-columns: 210px 1fr auto; gap: 16px; align-items: center; background: var(--bg2); border-radius: 12px; padding: 14px 16px; cursor: pointer; }
.niche:hover { background: var(--bg3); }
.niche h3 { margin: 0; font-size: 16px; }
.bar { height: 10px; border-radius: 5px; background: var(--bg3); overflow: hidden; margin-top: 8px; }
.bar div { height: 100%; background: linear-gradient(90deg, var(--accent), #ff9500); border-radius: 5px; }
.faces { display: flex; }
.faces img { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--bg2); margin-left: -8px; object-fit: cover; background: var(--bg3); }
.formula { background: var(--bg2); border-radius: 12px; padding: 14px 16px; }
.formula h4 { margin: 0; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.formula ul { margin: 8px 0 0; padding-left: 18px; color: var(--text2); font-size: 13px; }
.formula li { margin: 3px 0; cursor: pointer; }
.formula li:hover { color: var(--text); }
.cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.cloud span { background: var(--bg); border-radius: 14px; padding: 4px 10px; }
.cloud span small { color: var(--text2); margin-left: 4px; }
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--text2); font-weight: 500; }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
.copy { cursor: pointer; color: var(--blue); font-size: 12px; margin-left: 6px; white-space: nowrap; }

/* settings */
.form-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.form-row input[type=number], .form-row input[type=time] { height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; width: 150px; }
textarea.queries { width: 100%; min-height: 260px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 10px; font-family: Consolas, monospace; font-size: 13px; }
.ok { color: var(--green); font-weight: 500; }
.warn { color: var(--accent); font-weight: 500; }
.help { color: var(--text2); font-size: 13px; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { position: relative; width: min(980px, 100%); background: var(--card); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); max-height: 94vh; overflow: auto; }
.modal-close { position: absolute; right: 8px; top: 8px; z-index: 2; }
.player { aspect-ratio: 16/9; width: 100%; border-radius: 12px; overflow: hidden; background: #000; }
.player iframe { width: 100%; height: 100%; border: 0; }
.modal h2 { font-size: 19px; margin: 14px 0 6px; padding-right: 30px; }
.toast { position: fixed; left: 24px; bottom: 24px; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; z-index: 60;
  opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none; }
.toast.on { opacity: 1; transform: none; }
.skeleton .thumb { animation: pulse 1.2s infinite alternate; }
@keyframes pulse { to { opacity: .5; } }

/* public read-only site */
body.live #scanBtn, body.live #scanProgress, body.live .card-actions, body.live #saveBtn, body.live #hideBtn,
body.live .sidebar a[data-route="saved"], body.live .sidebar a[data-route="hidden"], body.live .sidebar a[data-route="settings"],
body.live .note-panel { display: none !important; }
body.live .two { grid-template-columns: 1fr; }

@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  :root { --side: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; width: 240px; box-shadow: var(--shadow); }
  body.open .sidebar { transform: none; }
  body.mini .sidebar { width: 240px; padding: 12px; }
  body.mini main, main { margin-left: 0; padding-left: 16px; padding-right: 16px; }
  .logo span { display: none; }
  .scan-btn span { display: none; }
  .niche { grid-template-columns: 1fr; }
  .ch-head .big-avatar { width: 80px; height: 80px; }
  .ch-head h1 { font-size: 24px; }
  .grid { grid-template-columns: 1fr; }
}
