/* Optimized for 2019 LG webOS Smart TV (Chromium 53/68) & Modern Browsers */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background-color: #07101d;
  color: #f1f5f9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  min-height: 46px;
  padding: 0 18px;
  background-color: #081322;
  border-bottom: 1px solid #162840;
}

.brand-left,
.brand-right {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #29a8ff;
  user-select: none;
}

.net-stats {
  font-size: 13.5px;
  font-weight: 600;
  color: #dbeafe;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}

/* Main Split Grid */
.main-grid {
  display: flex;
  flex: 1;
  min-height: 0;
  padding: 12px 14px;
  gap: 14px;
}

/* Left Player Column */
.player-pane {
  width: 49%;
  min-width: 49%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-frame {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 ratio compatible with Chromium 53 */
  background-color: #030811;
  border: 1px solid #182c46;
  border-radius: 8px;
  overflow: hidden;
}

.video-frame video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000000;
  object-fit: contain;
}

.player-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background-color: rgba(4, 10, 18, 0.72);
  z-index: 5;
  transition: opacity 0.2s ease;
}

.player-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(41, 168, 255, 0.25);
  border-top-color: #29a8ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.overlay-text {
  font-size: 13.5px;
  font-weight: 600;
  color: #e2e8f0;
  text-align: center;
  padding: 0 16px;
}

.player-toast {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 11px;
  background-color: rgba(8, 19, 34, 0.88);
  border: 1px solid #234066;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #93c5fd;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.player-toast.visible {
  opacity: 1;
}

/* Now Playing Card */
.now-playing-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background-color: #0d1c30;
  border: 1px solid #1b314e;
  border-radius: 8px;
}

.np-logo-box {
  position: relative;
  width: 42px;
  height: 42px;
  min-width: 42px;
  background-color: #ffffff;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 3px;
}

.np-logo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.np-logo-box img.hidden {
  display: none;
}

.np-fallback {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
}

.np-meta {
  min-width: 0;
  flex: 1;
}

.np-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-group {
  font-size: 13px;
  color: #8ba3c1;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Controls Row */
.controls-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.ctrl-btn,
.ctrl-select,
.mini-btn,
.cat-arrow {
  height: 34px;
  padding: 0 11px;
  background-color: #102036;
  border: 1px solid #1f3858;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
}

.ctrl-btn:hover,
.ctrl-select:hover,
.mini-btn:hover,
.cat-arrow:hover {
  background-color: #172d4b;
  border-color: #2d517d;
}

.ctrl-btn:focus,
.ctrl-select:focus,
.mini-btn:focus,
.cat-arrow:focus,
.search-input:focus,
.cat-pill:focus,
.channel-card:focus,
.fav-star:focus {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

.ctrl-btn.active {
  background-color: #2997ff;
  border-color: #2997ff;
  color: #ffffff;
}

.ctrl-select {
  padding-right: 8px;
}

.status-pill {
  height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  background-color: #0b2926;
  border: 1px solid #165b4f;
  color: #34d399;
  white-space: nowrap;
}

.status-pill.is-warn {
  background-color: #2b210b;
  border-color: #6b4f13;
  color: #fbbf24;
}

.status-pill.is-err {
  background-color: #2c1016;
  border-color: #6e1f2d;
  color: #f87171;
}

/* Right Browser Column */
.browser-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  background-color: #0b1728;
  border: 1px solid #1c324f;
  border-radius: 7px;
  color: #f8fafc;
  font-size: 14px;
}

.search-input::placeholder {
  color: #64748b;
}

/* Category Tabs Bar */
.cat-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cat-arrow {
  width: 30px;
  min-width: 30px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.cat-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.cat-scroll::-webkit-scrollbar {
  display: none;
}

.cat-pill {
  height: 32px;
  padding: 0 13px;
  background-color: #102036;
  border: 1px solid #1f3858;
  border-radius: 7px;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

.cat-pill:hover {
  background-color: #162b47;
  color: #ffffff;
}

.cat-pill.active {
  background-color: #2997ff;
  border-color: #2997ff;
  color: #061426;
  font-weight: 700;
}

/* List Subheader */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px;
}

.list-title {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.channel-count {
  font-size: 13px;
  color: #8ba3c1;
  margin-right: 4px;
}

.mini-btn {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

/* Channel Grid */
.channel-grid-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.channel-grid-wrap::-webkit-scrollbar {
  width: 6px;
}

.channel-grid-wrap::-webkit-scrollbar-track {
  background: #081322;
}

.channel-grid-wrap::-webkit-scrollbar-thumb {
  background: #1f3858;
  border-radius: 3px;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  padding-bottom: 12px;
}

.channel-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background-color: #0e1d31;
  border: 1px solid #1b314e;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.channel-card:hover {
  background-color: #142842;
  border-color: #2b4d78;
}

.channel-card.active {
  background-color: #132b4a;
  border-color: #2997ff;
}

.ch-logo-box {
  width: 42px;
  height: 42px;
  min-width: 42px;
  background-color: #ffffff;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 3px;
}

.ch-logo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ch-logo-fallback {
  font-size: 12px;
  font-weight: 800;
  color: #0f172a;
}

.ch-info {
  flex: 1;
  min-width: 0;
}

.ch-name {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-group {
  font-size: 12px;
  color: #88a0be;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-star {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}

.fav-star:hover {
  color: #fbbf24;
  background-color: rgba(255, 255, 255, 0.06);
}

.fav-star.is-fav {
  color: #fbbf24;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 36px 16px;
  text-align: center;
  color: #8ba3c1;
  font-size: 14px;
  background-color: #0d1c30;
  border: 1px solid #1b314e;
  border-radius: 8px;
}

/* Responsive Layout for Narrow Screens */
@media (max-width: 860px) {
  html,
  body {
    overflow: auto;
  }
  .main-grid {
    flex-direction: column;
    overflow: visible;
  }
  .player-pane {
    width: 100%;
    min-width: 100%;
  }
  .channel-grid-wrap {
    max-height: 60vh;
  }
}

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