:root {
  --bg: #061224;
  --bg-2: #08182e;
  --panel: #0a1f37;
  --panel-2: #0d2946;
  --line: #123a61;
  --text: #dff0ff;
  --muted: #86a7c8;
  --accent: #0fd0ff;
  --accent-2: #12f59f;
  --danger: #ff6077;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(800px 400px at 10% -10%, rgba(15, 208, 255, 0.15), rgba(15, 208, 255, 0)),
    linear-gradient(180deg, #03101f, #07172b 40%, #061325);
  color: var(--text);
}

button:focus-visible,
input:focus-visible,
.group-item:focus-visible,
.main-tab:focus-visible,
.channel-item:focus-visible,
.load-btn:focus-visible,
.player-fullscreen-btn:focus-visible,
.install-btn:focus-visible,
.action-btn:focus-visible {
  outline: 2px solid #2ee6ff;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(46, 230, 255, 0.25);
}

.mktv-logo-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #08213b, #081a30);
  padding: 18px;
}

.auth-card h1 {
  margin: 0 0 6px;
  letter-spacing: 0.22em;
}

.auth-logo-wrap {
  width: min(280px, 100%);
  margin: 0 0 8px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.auth-tab {
  border: 1px solid #14507c;
  border-radius: 10px;
  background: #0a2743;
  color: var(--text);
  padding: 9px;
  font-family: inherit;
  cursor: pointer;
}

.auth-tab.active {
  background: linear-gradient(120deg, #0a5e99, #08807f);
}

.auth-form {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.auth-form input,
.action-btn {
  border: 1px solid #1a4f7b;
  border-radius: 10px;
  padding: 10px;
  background: #061c31;
  color: var(--text);
  font-family: inherit;
}

.action-btn {
  background: linear-gradient(120deg, #0a5e99, #08807f);
  cursor: pointer;
  font-weight: 600;
}

.action-btn.danger {
  background: linear-gradient(120deg, #8b2440, #b22d54);
  border-color: #b93661;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #051322, #04111f);
  border-right: 1px solid #0f3557;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  padding-bottom: 92px;
  overflow: hidden;
}

.brand-row {
  border-bottom: 1px solid #0f3557;
  padding: 0 0 2px;
  display: flex;
  align-items: center;
  line-height: 0;
}

.brand-row h1 {
  margin: 0;
  letter-spacing: 0.24em;
  font-size: 2rem;
}

.brand-row .mktv-logo-img {
  width: auto;
  height: auto;
  max-width: 82%;
  margin: 0 auto;
}

.profile-card {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
  padding: 7px;
  border-radius: 10px;
  background: #08203a;
  border: 1px solid #114266;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 600;
  color: #9fd5ff;
  background: linear-gradient(135deg, #0a2743, #0d3558);
  overflow: hidden;
  border: 1px solid #1a5b89;
}

.email,
.trial {
  margin: 0;
}

.email {
  font-size: 0.77rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.avatar-user-icon {
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.trial {
  margin-top: 2px;
  font-size: 0.78rem;
  color: #ffd86a;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-tabs {
  display: grid;
  gap: 8px;
}

.accordion-toggle {
  display: none;
  border: 1px solid #12486f;
  background: #0a2743;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 11px;
  font-family: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.accordion-panel {
  display: block;
}

.accordion-panel.is-collapsed {
  display: none;
}

.main-tab {
  border: 1px solid #12486f;
  background: #0a2743;
  color: var(--text);
  border-radius: 10px;
  padding: 9px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.main-tab.active {
  background: linear-gradient(120deg, #0c5f9e, #0a8d87);
  border-color: #1daec7;
}

.tab-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid #2d7da7;
  display: grid;
  place-items: center;
  font-size: 0.74rem;
  font-weight: 700;
  color: #b7e8ff;
  background: #0a3355;
}

.tab-icon svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.main-tab.active .tab-icon {
  color: #032436;
  border-color: #82f1d0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.avatar-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #061b30;
}

.sidebar-head {
  padding: 8px 6px 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.group-nav {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 420px);
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-item {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.group-item span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-item:hover {
  background: #09233e;
  color: #cde8ff;
}

.group-item.active {
  background: #0a3357;
  border-color: #1d78a9;
  color: #eff8ff;
}

.group-item .count {
  font-size: 0.74rem;
  border-radius: 999px;
  min-width: 28px;
  text-align: center;
  padding: 2px 6px;
  background: #0d3d63;
  color: #8cc7ff;
}

.main {
  padding: 12px;
}

.topbar {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #08213b, #081d34);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(760px, 72%);
}

.topbar h2,
.topbar h3 {
  margin: 0;
}

.title-wrap {
  display: grid;
  gap: 1px;
}

.topbar-logo {
  width: min(72px, 18vw);
  height: auto;
  object-fit: contain;
}

#pageTitle {
  display: none;
}

#listMeta {
  font-size: 0.7rem;
  line-height: 1.1;
  margin: 0;
}

.search-wrap {
  width: 100%;
}

#searchInput {
  width: 100%;
  border: 1px solid #194d77;
  border-radius: 11px;
  padding: 7px 9px;
  background: #061c31;
  color: var(--text);
  font-family: inherit;
}

#searchInput:focus {
  outline: none;
  border-color: #27b7d8;
}

.install-btn {
  border: 1px solid #1b7ba8;
  border-radius: 10px;
  padding: 7px 9px;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  color: #e9fbff;
  background: linear-gradient(120deg, #0a5e99, #0ba786);
  cursor: pointer;
}

.menu-glyph {
  position: relative;
  display: block;
  width: 18px;
  height: 12px;
}

.menu-glyph::before,
.menu-glyph::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  border-radius: 99px;
  background: currentColor;
}

.menu-glyph::before {
  top: 0;
  box-shadow: 0 5px 0 currentColor;
}

.menu-glyph::after {
  bottom: 0;
}

.section-panel {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #081f36, #071a2f);
  padding: 10px;
}

.player-shell {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #08213a, #071a30);
  padding: 10px;
  position: relative;
}

.player-shell.is-hidden {
  display: none;
}

.player-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

#player {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  border: 1px solid #1a4f7b;
  background: #000;
}

body.has-active-player #player {
  position: sticky;
  top: max(8px, env(safe-area-inset-top, 0px));
  z-index: 30;
  border: 0;
  border-radius: 0;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.42);
}

#playerStatus {
  margin: 0;
}

body.has-active-player .player-head {
  margin-bottom: 6px;
}

.player-loading {
  position: absolute;
  inset: auto 10px 10px 10px;
  aspect-ratio: 16 / 9;
  background:
    radial-gradient(circle at 18% 18%, rgba(15, 208, 255, 0.28), rgba(8, 24, 46, 0)),
    linear-gradient(145deg, rgba(3, 12, 24, 0.96), rgba(7, 22, 40, 0.92));
  border-radius: 10px;
  display: grid;
  place-items: center;
  gap: 10px;
  z-index: 35;
  overflow: hidden;
}

.player-loading::before {
  content: "";
  position: absolute;
  inset: -25% -10%;
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0),
    rgba(120, 224, 255, 0.2) 45%,
    rgba(255, 255, 255, 0) 65%
  );
  transform: translateX(-55%) rotate(4deg);
  animation: sweep 1.4s ease-in-out infinite;
}

.player-loading p {
  margin: 0;
  color: #dff5ff;
  font-size: 0.84rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  z-index: 1;
}

.player-loading-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.player-loading-logo {
  width: min(210px, 58vw);
  max-height: 68px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(255, 66, 66, 0.35));
}

.player-loading-skeleton {
  width: min(72%, 280px);
  display: grid;
  gap: 7px;
  z-index: 1;
}

.skeleton-line {
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, #0b2a46, #114369, #0b2a46);
  background-size: 220% 100%;
  animation: shimmer 1.1s linear infinite;
}

.skeleton-line.line-lg {
  width: 100%;
}

.skeleton-line.line-md {
  width: 72%;
}

.skeleton-line.line-sm {
  width: 46%;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

@keyframes sweep {
  to {
    transform: translateX(60%) rotate(4deg);
  }
}

.player-fullscreen-btn {
  border: 1px solid #1b7ba8;
  border-radius: 10px;
  padding: 6px 10px;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 600;
  color: #e9fbff;
  background: linear-gradient(120deg, #0a5e99, #0ba786);
  cursor: pointer;
}

.video-fullscreen #player {
  border-radius: 0;
  border: 0;
}

.channels-shell {
  margin-top: 10px;
}

#liveSection .topbar {
  margin-top: 10px;
}

body.has-active-player .player-shell {
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  padding-right: 3px;
}

body.has-active-player .channels-grid {
  max-height: calc(100vh - 320px);
}

.channel-item {
  border: 1px solid #14466f;
  background: linear-gradient(180deg, #092640, #081f35);
  border-radius: 13px;
  padding: 8px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  text-align: left;
}

.channel-item.active {
  border-color: #1de4a3;
}

.channel-logo {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: contain;
  background: #061a2f;
  border: 1px solid #163d62;
}

.channel-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
}

.channel-group {
  font-size: 0.76rem;
  color: var(--muted);
}

.channel-actions {
  display: flex;
  justify-content: flex-end;
}

.fav-btn {
  border: 1px solid #24557d;
  background: #0a2743;
  color: #9ab9d7;
  border-radius: 8px;
  min-width: 30px;
  padding: 4px 7px;
  cursor: pointer;
}

.fav-btn.active {
  color: #ff7ea7;
  border-color: #d05a87;
}

.load-btn {
  width: 100%;
  margin-top: 10px;
  border: 1px solid #155580;
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  background: linear-gradient(120deg, #0a5e99, #08807f);
  cursor: pointer;
}

.load-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.load-controls .load-btn {
  margin-top: 10px;
}

.load-btn.secondary {
  background: linear-gradient(120deg, #0a2e4d, #0a3f64);
  border-color: #184f78;
}

.load-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.settings-card {
  border: 1px solid #1a4f7b;
  border-radius: 12px;
  padding: 14px;
  background: #081f36;
  max-width: 520px;
}

.settings-card h3 {
  margin-top: 0;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .main {
    padding-bottom: 86px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    top: auto;
    z-index: 70;
    height: 72px;
    padding: 6px;
    border-right: 0;
    border-top: 1px solid #0f3557;
    border-bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    background: linear-gradient(180deg, rgba(4, 17, 31, 0.96), rgba(4, 17, 31, 0.98));
    overflow: visible;
  }

  .accordion-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    margin: 0;
  }

  .brand-row,
  .profile-card,
  .sidebar-head,
  #groupSelect {
    display: none !important;
  }

  #toggleGroupsBtn {
    grid-column: 1;
    grid-row: 1;
  }

  #mainTabsPanel {
    display: block !important;
    grid-column: 2 / 6;
    grid-row: 1;
  }

  #mainTabsPanel .main-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  #mainTabsPanel .main-tab {
    min-height: 52px;
    justify-content: center;
    padding: 6px;
  }

  #mainTabsPanel .main-tab .tab-label {
    display: none;
  }

  #groupsBlock {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 72px;
    max-height: 54vh;
    z-index: 75;
    border: 1px solid #12486f;
    border-radius: 12px;
    background: linear-gradient(180deg, #061a2e, #041424);
    padding: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    display: none;
  }

  #groupsBlock.is-open {
    display: block;
  }

  .group-nav {
    max-height: calc(54vh - 46px);
  }

  .search-wrap {
    width: 100%;
  }

  .topbar-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .player-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .player-meta {
    width: 100%;
    justify-content: space-between;
  }

  .channels-grid {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  }
}

@media (min-width: 981px) {
  .sidebar {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    gap: 8px;
    align-content: stretch;
    height: 100dvh;
    padding-bottom: 0;
  }

  #mainTabsPanel {
    margin-top: 0;
    align-self: end;
  }

  #groupsBlock {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #groupsBlock .group-nav {
    max-height: none;
    height: 100%;
    min-height: 0;
    padding-bottom: 0;
  }

  .main-tabs {
    position: static;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 0;
  }

  .main-tab {
    min-height: 56px;
    justify-content: center;
    padding: 6px;
  }

  .main-tab .tab-label {
    display: none;
  }

  body.has-active-player .player-shell {
    max-width: min(540px, 48vw);
    margin-inline: auto;
  }

  body.has-active-player #player {
    aspect-ratio: 16 / 9;
  }
}
