/* ══════════════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES — 7 themes
   ══════════════════════════════════════════════════════════════════ */

/* Dark (default) */
:root, html[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg2: #161616;
  --bg3: #272727;
  --bg-input: #121212;
  --border-color: #303030;
  --border-soft: #1c1c1c;
  --border-dashed: #555;
  --text: #f1f1f1;
  --text2: #aaa;
  --text3: #888;
  --accent: #3ea6ff;
  --accent-fg: #fff;
  --brand-x: #ff0000;
  --danger: #ff6b6b;
  --danger-border: #5a2323;
  --danger-hover: #2a1414;
  --success-bg: #1d3a26;
  --success-text: #6fcf97;
  --warn-bg: #3a2f1d;
  --warn-text: #f2c94c;
  --shadow: rgba(0,0,0,0.6);
}

/* Light */
html[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f2f2f2;
  --bg3: #e5e5e5;
  --bg-input: #f8f8f8;
  --border-color: #d0d0d0;
  --border-soft: #e8e8e8;
  --border-dashed: #b0b0b0;
  --text: #0f0f0f;
  --text2: #606060;
  --text3: #909090;
  --accent: #065fd4;
  --accent-fg: #ffffff;
  --brand-x: #cc0000;
  --danger: #cc2200;
  --danger-border: #e0a0a0;
  --danger-hover: #ffeee8;
  --success-bg: #e6f4ea;
  --success-text: #0d652d;
  --warn-bg: #fef7e0;
  --warn-text: #7a5c00;
  --shadow: rgba(0,0,0,0.15);
}
@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    --bg: #ffffff;
    --bg2: #f2f2f2;
    --bg3: #e5e5e5;
    --bg-input: #f8f8f8;
    --border-color: #d0d0d0;
    --border-soft: #e8e8e8;
    --border-dashed: #b0b0b0;
    --text: #0f0f0f;
    --text2: #606060;
    --text3: #909090;
    --accent: #065fd4;
    --accent-fg: #ffffff;
    --brand-x: #cc0000;
    --danger: #cc2200;
    --danger-border: #e0a0a0;
    --danger-hover: #ffeee8;
    --success-bg: #e6f4ea;
    --success-text: #0d652d;
    --warn-bg: #fef7e0;
    --warn-text: #7a5c00;
    --shadow: rgba(0,0,0,0.15);
  }
}

/* Soviet */
html[data-theme="soviet"] {
  --bg: #180404;
  --bg2: #280a0a;
  --bg3: #3c1212;
  --bg-input: #200606;
  --border-color: #6b1f1f;
  --border-soft: #4a1010;
  --border-dashed: #8b3333;
  --text: #ffeedd;
  --text2: #dd9988;
  --text3: #bb7766;
  --accent: #ff2222;
  --accent-fg: #fff;
  --brand-x: #ff6666;
  --danger: #ff8866;
  --danger-border: #882222;
  --danger-hover: #3d0808;
  --success-bg: #102010;
  --success-text: #88ee55;
  --warn-bg: #2a1800;
  --warn-text: #ffcc44;
  --shadow: rgba(0,0,0,0.7);
}

/* Marine */
html[data-theme="marine"] {
  --bg: #00101e;
  --bg2: #001828;
  --bg3: #002238;
  --bg-input: #000c16;
  --border-color: #1a4d7a;
  --border-soft: #0d2e4a;
  --border-dashed: #2266aa;
  --text: #ccebff;
  --text2: #6699bb;
  --text3: #447799;
  --accent: #0099ee;
  --accent-fg: #fff;
  --brand-x: #33bbff;
  --danger: #ff6666;
  --danger-border: #882233;
  --danger-hover: #180a0a;
  --success-bg: #003322;
  --success-text: #44cc88;
  --warn-bg: #221a00;
  --warn-text: #ffcc44;
  --shadow: rgba(0,0,0,0.7);
}

/* Nature */
html[data-theme="nature"] {
  --bg: #001008;
  --bg2: #001808;
  --bg3: #002510;
  --bg-input: #000c05;
  --border-color: #1a5c2a;
  --border-soft: #0d3318;
  --border-dashed: #2a7a38;
  --text: #ccffdd;
  --text2: #66cc88;
  --text3: #449966;
  --accent: #00cc44;
  --accent-fg: #001008;
  --brand-x: #44ff66;
  --danger: #ff6644;
  --danger-border: #883322;
  --danger-hover: #1a0808;
  --success-bg: #003318;
  --success-text: #88ff99;
  --warn-bg: #221a00;
  --warn-text: #ffcc44;
  --shadow: rgba(0,0,0,0.7);
}

/* Sunny */
html[data-theme="sunny"] {
  --bg: #181200;
  --bg2: #221a00;
  --bg3: #302500;
  --bg-input: #100d00;
  --border-color: #5c4a00;
  --border-soft: #3d3200;
  --border-dashed: #8b7200;
  --text: #fff8cc;
  --text2: #ccaa44;
  --text3: #aa8833;
  --accent: #ffaa00;
  --accent-fg: #181200;
  --brand-x: #ff8800;
  --danger: #ff5533;
  --danger-border: #882211;
  --danger-hover: #1a0500;
  --success-bg: #102a00;
  --success-text: #88ee44;
  --warn-bg: #300800;
  --warn-text: #ff9944;
  --shadow: rgba(0,0,0,0.7);
}

/* ══════════════════════════════════════════════════════════════════
   BASE
   ══════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Roboto, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}
a { color: inherit; text-decoration: none; }

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 4px; }
.brand .x { color: var(--brand-x); }
.search {
  flex: 1;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
}
.search input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px 0 0 20px;
  padding: 8px 16px;
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.search button {
  background: var(--bg3);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 20px 20px 0;
  padding: 8px 18px;
  color: var(--text);
  cursor: pointer;
}
.upload-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 18px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.upload-btn:hover { background: var(--bg3); }

/* ── Layout ─────────────────────────────────────────────────────── */
.layout { display: flex; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  padding: 12px 0;
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
  overflow-y: auto;
}
.sidebar a.item {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 10px;
  margin: 0 8px 2px;
  color: var(--text);
}
.sidebar a.item:hover { background: var(--bg3); }
.sidebar a.item.active { background: var(--bg3); font-weight: 600; }
.sidebar hr { border: none; border-top: 1px solid var(--border-color); margin: 12px 16px; }
.sidebar .section-title { font-size: 13px; color: var(--text2); padding: 8px 24px 4px; }

.main { flex: 1; padding: 24px; min-width: 0; }

/* ── Video grid ─────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}
.card { cursor: pointer; }
.thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg3);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  color: var(--text3);
  font-size: 13px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .dur {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.8);
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
  color: #fff;
}
.card-body { display: flex; gap: 12px; padding-top: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--accent-fg); font-size: 14px;
}
.card-meta .title {
  font-size: 15px; font-weight: 500; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta .sub { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ── Watch page ─────────────────────────────────────────────────── */
.watch-layout { display: flex; gap: 24px; padding: 24px; align-items: flex-start; }
.watch-main { flex: 1; min-width: 0; max-width: 960px; }
.watch-side { width: 380px; flex-shrink: 0; }
.player-wrap { width: 100%; background: #000; border-radius: 12px; overflow: hidden; }
.player-wrap video { width: 100%; max-height: 540px; display: block; cursor: pointer; }

@media (max-width: 900px) {
  .watch-layout { flex-direction: column; padding: 16px; gap: 16px; }
  .watch-main { max-width: none; }
  .watch-side { width: 100%; }
  .watch-side #recs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
  .watch-side .rec-item { flex-direction: column; }
  .watch-side .rec-thumb { width: 100%; }
}
.watch-title { font-size: 20px; font-weight: 600; margin: 16px 0 8px; }
.watch-meta { display: flex; justify-content: space-between; align-items: center; color: var(--text2); font-size: 14px; border-bottom: 1px solid var(--border-color); padding-bottom: 16px; }
.channel-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.channel-row .name { font-weight: 600; }

.rec-item { display: flex; gap: 8px; cursor: pointer; margin-bottom: 12px; }
.rec-thumb {
  width: 168px; aspect-ratio: 16/9; background: var(--bg3); border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 12px;
  overflow: hidden; position: relative;
}
.rec-thumb img { width: 100%; height: 100%; object-fit: cover; }
.rec-meta .title { font-size: 14px; font-weight: 500; line-height: 1.3; }
.rec-meta .sub { font-size: 12px; color: var(--text2); margin-top: 4px; }

.watch-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.watch-tags .tag-pill {
  background: var(--bg3); color: var(--text2); font-size: 13px; padding: 4px 12px; border-radius: 14px;
}

.empty-state { color: var(--text3); text-align: center; padding: 80px 20px; font-size: 15px; }
.empty-state a { color: var(--accent); }

/* ── Studio ─────────────────────────────────────────────────────── */
.studio-page { padding: 24px; max-width: 1200px; margin: 0 auto; }
.studio-table { width: 100%; border-collapse: collapse; }
.studio-table th { text-align: left; font-size: 13px; color: var(--text2); padding: 8px 12px; border-bottom: 1px solid var(--border-color); }
.studio-table td { padding: 12px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.studio-thumb {
  width: 120px; aspect-ratio: 16/9; background: var(--bg3); border-radius: 6px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 11px; flex-shrink: 0;
}
.studio-thumb img { width: 100%; height: 100%; object-fit: cover; }
.studio-title-input, .studio-desc-input {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 6px;
  padding: 6px 8px; color: var(--text); font-size: 14px; margin-bottom: 6px;
}
.studio-desc-input { resize: vertical; min-height: 40px; }
.status-pill { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--bg3); color: var(--text2); }
.status-pill.ready { background: var(--success-bg); color: var(--success-text); }
.status-pill.processing { background: var(--warn-bg); color: var(--warn-text); }

.tag-editor { position: relative; max-width: 280px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.tag-chip {
  background: var(--bg3); color: var(--text); font-size: 12px; padding: 3px 8px 3px 10px; border-radius: 12px;
  display: flex; align-items: center; gap: 6px;
}
.tag-chip .remove { cursor: pointer; color: var(--text3); font-weight: bold; }
.tag-chip .remove:hover { color: var(--text); }
.tag-input {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 6px;
  padding: 5px 8px; color: var(--text); font-size: 13px;
}
.tag-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--bg2); border: 1px solid var(--border-color);
  border-radius: 6px; margin-top: 2px; max-height: 160px; overflow-y: auto; z-index: 20; display: none;
}
.tag-suggestions div { padding: 6px 10px; font-size: 13px; cursor: pointer; }
.tag-suggestions div:hover, .tag-suggestions div.active { background: var(--bg3); }
.studio-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn-small {
  font-size: 12px; padding: 5px 12px; border-radius: 14px; border: 1px solid var(--border-color);
  background: transparent; color: var(--text); cursor: pointer;
}
.btn-small:hover { background: var(--bg3); }
.btn-small.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-small.danger { border-color: var(--danger-border); color: var(--danger); }
.btn-small.danger:hover { background: var(--danger-hover); }
.save-hint { font-size: 12px; color: var(--success-text); margin-left: 8px; display: none; }

/* ── Upload ─────────────────────────────────────────────────────── */
.upload-page { max-width: 640px; margin: 40px auto; padding: 0 20px; }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text2); }
.field input[type=text] {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 8px;
  padding: 10px 12px; color: var(--text); font-size: 14px; outline: none;
}
#dropzone { border: 2px dashed var(--border-dashed); border-radius: 12px; padding: 60px 20px; text-align: center; cursor: pointer; transition: 0.2s; }
#dropzone:hover, #dropzone.drag { border-color: var(--accent); background: var(--bg2); }
#dropzone button { font-size: 16px; padding: 12px 28px; border-radius: 24px; border: none; background: var(--accent); color: #fff; cursor: pointer; }
#status { margin-top: 16px; font-size: 14px; color: var(--text2); }
#progressWrap { width: 100%; background: var(--bg3); border-radius: 6px; margin-top: 10px; display: none; }
#progressBar { height: 8px; width: 0%; background: var(--accent); border-radius: 6px; transition: width 0.15s; }
input[type=file] { display: none; }

/* ── History ─────────────────────────────────────────────────────── */
.history-page { max-width: 1100px; margin: 0 auto; padding: 24px; }
.history-controls {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border-color);
}
.history-controls h1 { font-size: 18px; margin: 0; }
.history-controls .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history-day-label { font-size: 15px; font-weight: 600; margin: 20px 0 10px; color: var(--text2); }
.history-item {
  display: flex; align-items: center; gap: 14px; padding: 8px; border-radius: 8px; cursor: pointer;
}
.history-item:hover { background: var(--bg2); }
.history-item .history-thumb {
  width: 160px; aspect-ratio: 16/9; background: var(--bg3); border-radius: 8px; flex-shrink: 0;
  overflow: hidden; position: relative; display: flex; align-items: center; justify-content: center;
  color: var(--text3); font-size: 12px;
}
.history-item .history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-item .history-meta { flex: 1; min-width: 0; }
.history-item .history-meta .title { font-size: 14px; font-weight: 500; }
.history-item .history-meta .sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.history-item .remove-btn {
  background: transparent; border: none; color: var(--text3); font-size: 18px; cursor: pointer;
  padding: 6px 10px; border-radius: 50%; flex-shrink: 0;
}
.history-item .remove-btn:hover { background: var(--bg3); color: var(--text); }

/* ── Sources page ────────────────────────────────────────────────── */
.source-form {
  background: var(--bg2); border: 1px solid var(--border-color); border-radius: 12px;
  padding: 20px; margin-bottom: 24px;
}
.source-form .field select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 6px;
  padding: 8px 10px; color: var(--text); font-size: 14px;
}
.source-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.source-form .field input, .source-form .field select { width: 100%; }
.source-card {
  background: var(--bg2); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px 20px;
  margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.source-card .info { flex: 1; }
.source-card .name { font-weight: 600; font-size: 15px; }
.source-card .meta { font-size: 13px; color: var(--text2); margin-top: 4px; }
.source-card .err { font-size: 12px; color: var(--danger); margin-top: 4px; }
.builtin-pill { font-size: 11px; background: var(--success-bg); color: var(--success-text); padding: 2px 8px; border-radius: 10px; margin-left: 8px; }

/* ══════════════════════════════════════════════════════════════════
   ACCOUNT MENU
   ══════════════════════════════════════════════════════════════════ */

.acct-wrap { position: relative; display: flex; align-items: center; }

.acct-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-fg);
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.acct-btn:hover { border-color: var(--text2); }

.acct-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  z-index: 200;
  box-shadow: 0 4px 24px var(--shadow);
  overflow: hidden;
  display: none;
}
.acct-dropdown.open { display: block; }

.acct-panel { display: none; }
.acct-panel.active { display: block; max-height: 70vh; overflow-y: auto; }

.acct-header {
  display: flex; align-items: center; gap: 12px; padding: 16px;
}
.acct-avatar-lg {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: var(--accent-fg); flex-shrink: 0;
}
.acct-name { font-weight: 600; font-size: 14px; }
.acct-hr { border: none; border-top: 1px solid var(--border-color); margin: 4px 0; }

.acct-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  font-size: 14px; color: var(--text);
  text-decoration: none; cursor: pointer;
  background: transparent; border: none; width: 100%; text-align: left;
  font-family: inherit;
}
.acct-item:hover { background: var(--bg3); }
.acct-item .acct-icon { width: 22px; flex-shrink: 0; text-align: center; font-size: 16px; }
.acct-item .acct-label { flex: 1; }
.acct-item .acct-value { font-size: 12px; color: var(--text2); }
.acct-item .acct-arrow { color: var(--text2); font-size: 16px; }
.acct-item .acct-stub { font-size: 11px; color: var(--text3); margin-left: auto; padding: 2px 6px; border: 1px solid var(--border-color); border-radius: 4px; }

.acct-back {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; font-weight: 600; font-size: 15px;
  border-bottom: 1px solid var(--border-color);
}
.acct-back-btn {
  background: transparent; border: none; cursor: pointer; color: var(--text);
  font-size: 20px; line-height: 1; padding: 0 4px; display: flex; align-items: center;
}
.acct-back-btn:hover { color: var(--accent); }

.acct-option {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  font-size: 14px; color: var(--text); cursor: pointer;
}
.acct-option:hover { background: var(--bg3); }
.acct-radio {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--text2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.acct-radio.checked { border-color: var(--accent); }
.acct-radio.checked::after {
  content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
}
.acct-swatch {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid var(--border-color);
}

/* ══════════════════════════════════════════════════════════════════
   SETTINGS PAGE
   ══════════════════════════════════════════════════════════════════ */

.settings-page { max-width: 720px; margin: 0 auto; padding: 32px 24px; }
.settings-page h1 { font-size: 22px; margin-bottom: 32px; }
.settings-section { margin-bottom: 40px; }
.settings-section h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text2); border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px; margin-bottom: 4px;
}
.settings-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--border-soft);
}
.settings-row:last-child { border-bottom: none; }
.settings-swatch { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; border: 1px solid var(--border-color); }
.settings-row-name { flex: 1; font-size: 14px; }
.settings-row-tag { font-size: 12px; color: var(--accent); }

.toggle-wrap { position: relative; width: 44px; height: 24px; cursor: pointer; flex-shrink: 0; }
.toggle-wrap input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 100%; height: 100%; background: var(--bg3); border-radius: 12px; transition: background 0.2s;
}
.toggle-wrap input:checked + .toggle-track { background: var(--accent); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left 0.2s; pointer-events: none;
}
.toggle-wrap input:checked ~ .toggle-thumb { left: 23px; }

.lang-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-top: 4px;
}
.lang-btn {
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border-color);
  background: transparent; color: var(--text); font-size: 14px; cursor: pointer; text-align: left;
}
.lang-btn:hover { background: var(--bg3); }
.lang-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
