:root {
  --bg: #07080b;
  --bg-elevated: #12141c;
  --bg-hover: #1a1e2a;
  --border: #242a3a;
  --text: #e9edf5;
  --text-dim: #8892a6;
  --accent: #29aaff;
  --accent-dim: #163a57;
  --accent-glow: rgba(41, 170, 255, 0.35);
  --neon-red: #ff2d4d;
  --neon-red-dim: #4a1420;
  --neon-red-glow: rgba(255, 45, 77, 0.35);
  --danger: #ff4f6d;
  --radius: 10px;
  --font-display: "Orbitron", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background:
    radial-gradient(ellipse 900px 500px at 15% -10%, rgba(255, 45, 77, 0.08), transparent 60%),
    radial-gradient(ellipse 900px 500px at 100% 0%, rgba(41, 170, 255, 0.08), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--bg-elevated), #0d0f16);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  transition: all 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-logo-img {
  height: 34px;
  width: auto;
  filter: drop-shadow(0 0 6px var(--neon-red-glow)) drop-shadow(0 0 10px var(--accent-glow));
  transition: height 0.25s ease, filter 0.25s ease;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, #ffffff 0%, #cfe6ff 35%, var(--accent) 70%, var(--neon-red) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  display: none;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.source-form {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

#source-input {
  flex: 1;
  min-width: 180px;
  max-height: 160px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
}

#source-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

.login-caption {
  display: none;
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.account-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 200px;
  font-size: 14px;
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}

button {
  cursor: pointer;
  font-size: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

button:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

button:active {
  transform: translateY(1px);
}

button[type="submit"] {
  background: linear-gradient(90deg, var(--accent-dim), var(--neon-red-dim));
  border-color: var(--accent);
  font-weight: 600;
}

button[type="submit"]:hover {
  background: linear-gradient(90deg, var(--accent), var(--neon-red));
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow), 0 0 16px var(--neon-red-glow);
  color: #0a0b0f;
}

.icon-btn {
  padding: 8px 10px;
  font-size: 16px;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: margin-left 0.2s ease;
}

.sidebar.collapsed {
  margin-left: -320px;
}

.sidebar-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

#search-input,
#group-select {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  width: 100%;
}

#search-input:focus,
#group-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.channel-count {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.channel-item:hover {
  background: var(--bg-hover);
}

.channel-item.active {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  box-shadow: inset 0 0 20px var(--accent-glow);
}

.channel-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  background: #000;
  border-radius: 4px;
  flex-shrink: 0;
}

.channel-logo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-dim);
}

.channel-meta {
  min-width: 0;
}

.channel-name {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-group {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 16px;
  gap: 12px;
}

.video-wrap {
  position: relative;
  flex: 1;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border: 1px solid var(--border);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
}

#video {
  width: 100%;
  height: 100%;
  background: #000;
}

.overlay-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.4);
}

.overlay-msg.error {
  color: var(--danger);
}

.overlay-msg.hidden {
  display: none;
}

.player-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.now-playing {
  font-size: 14px;
  color: var(--text-dim);
}

.player-actions {
  display: flex;
  gap: 8px;
}

.ghost-btn {
  background: transparent;
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    z-index: 20;
  }

  .sidebar.collapsed {
    margin-left: -320px;
  }
}

/* Full-screen login splash: while gated behind IPTV login, the whole
   topbar (brand + login-form/source-form) takes over the viewport, and
   the rest of the app is hidden until a channel list is loaded. */
body.pre-login .layout {
  display: none;
}

body.pre-login .topbar {
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background:
    radial-gradient(ellipse 700px 500px at 20% 15%, rgba(255, 45, 77, 0.12), transparent 60%),
    radial-gradient(ellipse 700px 500px at 80% 85%, rgba(41, 170, 255, 0.12), transparent 60%),
    #07080b;
  border-bottom: none;
}

body.pre-login #toggle-sidebar {
  display: none;
}

body.pre-login .brand {
  flex-direction: column;
  gap: 2px;
  margin-top: -6px;
}

body.pre-login .brand-logo-img {
  height: 64px;
}

body.pre-login .brand-text {
  align-items: center;
  text-align: center;
}

body.pre-login .brand-name {
  font-size: 22px;
}

body.pre-login .brand-tagline {
  display: block;
  font-size: 10px;
}

body.pre-login .login-caption {
  display: block;
}

body.pre-login .login-form,
body.pre-login .source-form {
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  width: min(380px, 90vw);
  background: rgba(18, 20, 28, 0.7);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 50px rgba(41, 170, 255, 0.08), 0 0 80px rgba(255, 45, 77, 0.05);
}

body.pre-login .login-form input,
body.pre-login .source-form textarea {
  flex: 0 0 auto;
  min-width: 0;
  padding: 12px 14px;
}

body.pre-login .source-form textarea {
  height: 90px;
}

body.pre-login .remember-label {
  justify-content: center;
}

body.pre-login #advanced-toggle-btn {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  font-size: 13px;
  opacity: 0.7;
}

body.pre-login #advanced-toggle-btn:hover {
  color: var(--text);
  background: transparent;
  box-shadow: none;
  opacity: 1;
}

.admin-wrap {
  max-width: 480px;
  margin: 60px auto;
  padding: 0 16px;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.admin-brand .brand-logo-img {
  height: 44px;
}

.admin-brand .brand-name {
  font-size: 22px;
}

.admin-brand .brand-tagline {
  display: block;
  font-size: 11px;
}

.admin-wrap h1 {
  font-size: 16px;
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 24px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
}

.admin-form h2 {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--accent);
  margin: 6px 0 -4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
}

.admin-form input,
.admin-form select {
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.admin-form input:focus,
.admin-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.admin-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.admin-msg {
  margin: 0;
  font-size: 13px;
}

.admin-error {
  color: var(--danger);
}

.admin-success {
  color: #6bd68a;
}

.admin-hint {
  margin: -6px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.admin-category-fetch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-category-fetch input {
  flex: 1;
  min-width: 120px;
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.admin-categories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.admin-categories-list:empty {
  display: none;
}

.admin-category-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
