:root {
  --bg: #11151c;
  --panel: #1b222d;
  --panel-2: #202a37;
  --panel-3: #151b24;
  --line: #303c4c;
  --text: #e7edf5;
  --muted: #93a0b1;
  --accent: #47b6e8;
  --accent-2: #6fd6a9;
  --danger: #f26b6b;
  --warning: #f5b95f;
  --purple: #a889ff;
  --radius: 10px;
  --shadow: 0 14px 32px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: #0d1117;
  border-right: 1px solid #252e3a;
  padding: 18px 14px;
  display: flex; flex-direction: column;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 8px 10px 22px; }
.brand-mark {
  width: 39px; height: 39px; border-radius: 9px;
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #081018;
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); }
.nav { display: grid; gap: 5px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; border-radius: 7px; color: #aeb9c7;
}
.nav a:hover, .nav a.active { background: #1b2430; color: #fff; }
.nav-icon { width: 20px; text-align: center; opacity: .9; }
.sidebar-footer { margin-top: auto; padding: 12px 9px 4px; color: var(--muted); font-size: 12px; }
.logout-button { width: 100%; margin-top: 10px; }

.main { min-width: 0; }
.topbar {
  height: 68px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid #252e3a; background: rgba(17,21,28,.93);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-meta { color: var(--muted); font-size: 13px; }
.content { padding: 26px 28px 60px; max-width: 1600px; margin: 0 auto; }

.grid { display: grid; gap: 18px; }
.grid.cards { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 16px; }
.card-body { padding: 18px; }
.stat { padding: 18px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 29px; font-weight: 750; margin-top: 7px; }
.stat-foot { color: var(--muted); font-size: 12px; margin-top: 6px; }

.form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
.form-grid.subscription { grid-template-columns: 1.1fr 2fr 1fr 1fr auto; }
label { display: grid; gap: 7px; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%; background: #10161f; color: var(--text); border: 1px solid #354254;
  border-radius: 7px; padding: 10px 11px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(71,182,232,.12); }
.check { display: flex; align-items: center; gap: 9px; color: var(--text); white-space: nowrap; min-height: 40px; }
.check input { width: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 13px; border-radius: 7px; border: 1px solid transparent;
  background: var(--accent); color: #071119; font-weight: 700;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: #263241; color: var(--text); border-color: #3a485b; }
.btn.success { background: var(--accent-2); color: #07140e; }
.btn.danger { background: rgba(242,107,107,.12); color: #ff9b9b; border-color: rgba(242,107,107,.38); }
.btn.warning { background: rgba(245,185,95,.13); color: #ffd28b; border-color: rgba(245,185,95,.4); }
.btn.small { padding: 6px 9px; font-size: 12px; }
.btn.block { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #2b3543; text-align: left; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: var(--panel-3); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.018); }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }
.truncate { max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.error-text { color: #ff9999; max-width: 440px; white-space: normal; }

.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge.queued { background: rgba(168,137,255,.15); color: #c8b5ff; }
.badge.downloading, .badge.processing { background: rgba(71,182,232,.15); color: #82d7ff; }
.badge.completed { background: rgba(111,214,169,.14); color: #91ebc4; }
.badge.skipped { background: rgba(245,185,95,.14); color: #ffd28b; }
.badge.failed, .badge.cancelled { background: rgba(242,107,107,.14); color: #ff9999; }
.badge.enabled { background: rgba(111,214,169,.14); color: #91ebc4; }
.badge.disabled { background: rgba(147,160,177,.14); color: #b3bdca; }
.progress { width: 150px; height: 7px; background: #0e141c; border-radius: 999px; overflow: hidden; border: 1px solid #303b4a; }
.progress > span { display: block; height: 100%; background: var(--accent); min-width: 2px; }
.progress-line { display: flex; align-items: center; gap: 8px; }

.flash { margin-bottom: 18px; padding: 12px 14px; border-radius: 8px; border: 1px solid; }
.flash.info { background: rgba(71,182,232,.1); border-color: rgba(71,182,232,.35); color: #a9e3ff; }
.flash.success { background: rgba(111,214,169,.1); border-color: rgba(111,214,169,.35); color: #aff2d1; }
.flash.error { background: rgba(242,107,107,.1); border-color: rgba(242,107,107,.35); color: #ffb0b0; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.section-title h2 { margin: 0; font-size: 17px; }
.empty { text-align: center; color: var(--muted); padding: 34px 15px; }
.notice { padding: 12px 14px; border: 1px solid #39475a; background: #151d27; border-radius: 8px; color: #b9c5d3; font-size: 13px; line-height: 1.55; }
.storage-bar { height: 10px; background: #0e141c; border-radius: 999px; overflow: hidden; border: 1px solid #303b4a; margin: 12px 0 8px; }
.storage-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 30% 20%, #1a2c3b, transparent 35%), #0d1117; }
.auth-card { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 24px 60px rgba(0,0,0,.4); padding: 28px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-mark { margin: 0 auto 12px; }
.auth-brand h1 { margin: 0 0 6px; font-size: 23px; }
.auth-brand p { margin: 0; color: var(--muted); }
.auth-form { display: grid; gap: 15px; }

.channel-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 13px; margin-bottom: 20px; }
.channel-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.channel-card strong { display: block; margin-bottom: 6px; }
.channel-card span { color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) {
  .grid.cards, .channel-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .form-grid, .form-grid.subscription { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(3,1fr); }
  .nav a { justify-content: center; }
  .nav a span:last-child { display: none; }
  .sidebar-footer { display: none; }
  .topbar { position: static; padding: 0 16px; }
  .content { padding: 18px 14px 40px; }
  .grid.cards, .grid.two, .grid.three, .channel-grid, .form-grid, .form-grid.subscription { grid-template-columns: 1fr; }
}

/* v1.2 channel pages, subscription import choices, and filename templates */
.subscription-form {
  display: grid;
  grid-template-columns: 1.1fr 2fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}
.subscription-form .wide { grid-column: span 2; }
.subscription-form .form-action { align-self: end; }
.channel-link { color: #d9f2ff; }
.channel-link:hover { color: var(--accent); text-decoration: underline; }
.channel-card-link { display: block; transition: transform .15s ease, border-color .15s ease; }
.channel-card-link:hover { transform: translateY(-2px); border-color: var(--accent); }
.channel-card .view-link { display: block; margin-top: 10px; color: var(--accent); }
.detail-toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-stats { margin-bottom: 20px; }
.stat-value.small-value { font-size: 18px; line-height: 1.25; }
.media-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.media-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); min-width: 0; }
.media-player { background: #070b10; aspect-ratio: 16 / 9; display: grid; place-items: center; position: relative; }
.media-player video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.media-player audio { width: calc(100% - 24px); position: absolute; bottom: 12px; }
.audio-art { font-size: 54px; color: var(--accent); opacity: .75; }
.media-info { padding: 14px; }
.media-info h3 { margin: 0 0 8px; font-size: 15px; overflow-wrap: anywhere; }
.settings-divider { height: 1px; background: var(--line); margin: 5px 0; }
.form-heading { margin: 0; font-size: 16px; }
.template-preview { color: var(--muted); font-size: 12px; margin-top: -6px; overflow-wrap: anywhere; }
.template-preview code, .notice code { color: #b9eaff; background: #0c121a; padding: 2px 5px; border-radius: 4px; }
.token-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 7px; margin-top: 10px; }
.token { text-align: left; background: #10161f; color: var(--text); border: 1px solid #354254; border-radius: 7px; padding: 8px; cursor: pointer; }
.token:hover { border-color: var(--accent); }
.token code { display: block; margin-bottom: 4px; }
.token span { color: var(--muted); font-size: 11px; }

@media (max-width: 1200px) {
  .subscription-form { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .subscription-form .wide { grid-column: span 1; }
  .media-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .subscription-form, .media-grid, .token-grid { grid-template-columns: 1fr; }
}

.checkbox-row { display: flex; align-items: center; gap: 9px; color: var(--text); }
.checkbox-row input { width: auto; }

.skip-text { color: #ffd28b; max-width: 440px; white-space: normal; }
.filter-hint { margin-top: 9px; font-size: 12px; }
