:root, [data-theme="dark"] {
  --bg: #0f1115; --card: #181b22; --line: #262b35; --fg: #e6e8eb;
  --muted: #8b93a1; --accent: #3273dc; --badge-auto: #2f7d4f;
  --badge-unlinked: #8a6d1f; --badge-manual: #6a3fb0;
  --topbar-bg: rgba(15,17,21,0.82); --nav-bg: #14171d; --input-bg: #222733;
  --hover: #1d212a; --tile-bg: #161a21; --tile-active: #18202e;
  --user-bubble: #1f3350; --user-bubble-border: #2a4a6e; --shadow: rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f4f6f9; --card: #ffffff; --line: #e2e5ea; --fg: #1b1f27;
  --muted: #5e6772; --accent: #2563c9; --badge-auto: #2f7d4f;
  --badge-unlinked: #9a7a1f; --badge-manual: #6a3fb0;
  --topbar-bg: rgba(255,255,255,0.85); --nav-bg: #eceef2; --input-bg: #f1f3f6;
  --hover: #eef2f8; --tile-bg: #f7f8fa; --tile-active: #e6f0fd;
  --user-bubble: #dcebfd; --user-bubble-border: #b9d4f7; --shadow: rgba(0,0,0,.12);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; gap: 20px; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--topbar-bg); backdrop-filter: saturate(140%) blur(10px); }
.brand { font-weight: 700; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.mainnav { display: flex; gap: 2px; padding: 4px; border-radius: 12px;
  background: var(--nav-bg); border: 1px solid var(--line); }
.mainnav a { padding: 7px 16px; border-radius: 9px; color: var(--muted); font-weight: 500;
  font-size: 14px; transition: background .12s, color .12s; }
.mainnav a:hover { color: var(--fg); text-decoration: none; }
.mainnav a.active { background: var(--accent); color: #fff;
  box-shadow: 0 1px 6px rgba(50,115,212,.4); }
.add-competitor { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.add-competitor input { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; }
.add-competitor input[type=text] { min-width: 240px; }
.add-competitor button { background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 16px; cursor: pointer; }
main { max-width: 1000px; margin: 0 auto; padding: 20px; }
h1 { font-size: 22px; } h2 { font-size: 16px; margin: 0 0 10px; }

.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 14px 0 18px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; }
.metric .m-label { font-size: 13px; color: var(--muted); }
.metric .m-val { font-size: 24px; font-weight: 600; margin-top: 4px; }

.accounts { list-style: none; padding: 0; }
.accounts li { padding: 8px 0; border-bottom: 1px solid var(--line); }

table.videos { width: 100%; border-collapse: collapse; }
table.videos th, table.videos td { text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line); }
table.videos th a { color: var(--muted); }
table.videos th a.active { color: var(--fg); font-weight: 700; }
table.videos tbody tr { cursor: pointer; }
table.videos tbody tr:hover { background: var(--hover); }
.vcell { display: flex; align-items: center; gap: 10px; }
.thumb { width: 44px; height: 60px; object-fit: cover; border-radius: 6px; }
.placeholder { background: var(--input-bg); border: 1px dashed var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: var(--muted); }
.placeholder.tall { width: 100%; aspect-ratio: 9/16; max-height: 420px; }
.cap { color: var(--fg); }

td.posted span.small { display: block; color: var(--muted); }
td.views .split { display: block; font-size: 12px; margin-top: 2px; }
td.views .org { color: #4a9d6e; }
td.views .paid { color: #c79a3a; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; text-transform: uppercase;
  letter-spacing: .4px; background: #333; color: #fff; }   /* colored chips: keep light text in both themes */
.badge.auto { background: var(--badge-auto); }
.badge.unlinked { background: var(--badge-unlinked); }
.badge.manual { background: var(--badge-manual); }

.grid { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; margin-bottom: 16px; }
.card.player video { width: 100%; border-radius: 8px; display: block; }
.card.player.solo { max-width: 320px; }   /* competitor video: no retention grid, keep player compact */
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.kv td:nth-child(odd) { color: var(--muted); width: 22%; }

.comments { list-style: none; padding: 0; margin: 0; }
.comments li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.comments[data-collapsed="1"] li.extra { display: none; }
.comments .author { font-weight: 600; } .comments .likes { color: var(--muted); margin-left: 8px; }
.toggle-comments { margin-top: 10px; background: var(--input-bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.analysis { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.analysis:first-child { border-top: none; margin-top: 0; }
.analysis h3 { font-size: 14px; margin: 14px 0 4px; color: var(--muted); }
.verdict { white-space: pre-wrap; }
.ideas-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ideas-head h2 { margin: 0; }
.create-btn { background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 9px 22px; cursor: pointer; font-weight: 600; box-shadow: 0 1px 6px rgba(50,115,212,.4); }
.create-btn:hover { filter: brightness(1.08); }
.ideas-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.idea-tile { position: relative; display: block; padding: 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--tile-bg);
  transition: border-color .12s, background .12s, transform .08s; }
.idea-tile:hover { border-color: var(--badge-auto); }
.idea-tile input { position: absolute; top: 12px; right: 12px; accent-color: var(--accent); }
.idea-tile:has(input:checked) { border-color: var(--accent); background: var(--tile-active);
  box-shadow: 0 0 0 1px var(--accent) inset; }
.tile-title { font-weight: 600; padding-right: 22px; margin-bottom: 8px; }
.tile-title .tag { display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .4px; padding: 2px 7px; border-radius: 8px; margin-left: 4px;
  background: var(--badge-unlinked); color: #fff; vertical-align: middle; }
.tile-title .tag.og { background: var(--badge-auto); }
.tile-body { font-size: 12.5px; color: var(--fg); }
.tile-body p { margin: 6px 0; }
.tile-body b { color: var(--muted); font-weight: 600; }
@media (max-width: 760px) { .ideas-grid { grid-template-columns: 1fr; } }
.back { display: inline-block; margin-bottom: 8px; }
button.action { font-size: 12px; font-weight: 600; margin-left: 10px; vertical-align: middle;
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 5px 12px; cursor: pointer; }
button.action:disabled { opacity: .55; cursor: default; }
.job-status:empty { display: none; }
.link-form { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; }
.link-form input { width: 80px; background: var(--input-bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.link-form button { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.ws-page { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 360px; }
.ws-topline { display: flex; align-items: baseline; gap: 14px; margin-bottom: 10px; }
.ws-topline .back { margin: 0; }
.ws-topline .ws-h { font-size: 18px; font-weight: 600; }
.ws-empty { text-align: center; margin: 24px 0; }
.ws-chat { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column;
  gap: 12px; padding: 4px 4px 8px; scroll-behavior: smooth; }
.composer-wrap { flex-shrink: 0; padding-top: 8px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap;
  background: var(--card); border: 1px solid var(--line); line-height: 1.55; }
.msg.user .bubble { background: var(--user-bubble); border-color: var(--user-bubble-border); }

/* Claude-style composer */
.composer { background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 14px 16px 10px; box-shadow: 0 6px 24px var(--shadow); }
.composer textarea { width: 100%; background: transparent; color: var(--fg); border: 0;
  resize: none; font: inherit; line-height: 1.5; max-height: 220px; outline: none; }
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.model-badge { font-size: 14px; font-weight: 600; color: var(--fg); }
.model-badge .muted { font-weight: 400; margin-left: 4px; }
.send-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 18px; line-height: 1; display: flex;
  align-items: center; justify-content: center; }
.send-btn:hover { filter: brightness(1.08); }
.composer.disabled { opacity: .85; }
.mode-chips { display: flex; gap: 8px; justify-content: center; margin: 12px 0 4px; }
.mode-chips .chip { background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 12px; padding: 7px 18px; cursor: pointer; font-size: 14px; }
.mode-chips .chip.active { border-color: var(--accent); color: #fff; background: var(--tile-active); }
.mode-chips .chip:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 700px) { .grid { grid-template-columns: 1fr; } }

/* auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.auth-label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.auth-input { width: 100%; background: var(--input-bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font: inherit; }
.auth-btn { width: 100%; margin-top: 18px; background: var(--accent); color: #fff; border: 0;
  border-radius: 9px; padding: 11px; font-weight: 600; cursor: pointer; }
.auth-btn:hover { filter: brightness(1.08); }
.auth-error { background: #3a1f24; border: 1px solid #7d2f3a; color: #f0b4bd;
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 0 0 6px; }

/* user box in topbar */
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.userbox .uname { color: var(--muted); }
.userbox .logout { color: var(--muted); }
.userbox .logout:hover { color: var(--fg); }
.badge.admin-tag { background: var(--badge-manual); }

/* user management */
.user-form { display: flex; flex-direction: column; gap: 10px; }
.uf-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.uf-row input, .uf-row select { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 11px; font: inherit; }
.uf-sections { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }
.chk input { accent-color: var(--accent); }
button.action.danger { background: #7d2f3a; }
.inline-edit { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-edit input { width: 90px; background: var(--input-bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; }
.inline-edit .action { margin-left: 0; }

/* theme toggle (settings) */
.theme-toggle { display: flex; gap: 12px; flex-wrap: wrap; }
.theme-opt { display: inline-flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 10px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--tile-bg); font-size: 14px; }
.theme-opt.active { border-color: var(--accent); background: var(--tile-active);
  box-shadow: 0 0 0 1px var(--accent) inset; }
.theme-opt input { accent-color: var(--accent); }
.theme-opt .swatch { width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--line); }
.theme-opt .swatch.dark { background: #0f1115; }
.theme-opt .swatch.light { background: #f4f6f9; }
