:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --sidebar: #0f1c2e;
  --sidebar-2: #15263d;
  --text: #152033;
  --muted: #627084;
  --line: #e4e9f0;
  --accent: #0e7c86;
  --accent-2: #0a5f67;
  --danger: #c0392b;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --live: #d62828;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(15, 28, 46, 0.06);
  --font: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: linear-gradient(160deg, #eef3f7 0%, #f7f4ef 55%, #eef6f7 100%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

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

.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: #dce6f2;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 8px 12px 28px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1aa6b2, #0e7c86);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  margin-bottom: 10px;
}
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  color: #fff;
  letter-spacing: 0.02em;
}
.brand p {
  margin: 4px 0 0;
  color: #8ea0b8;
  font-size: 0.8rem;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  color: #b7c5d8;
  margin-bottom: 4px;
  font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active {
  background: rgba(26, 166, 178, 0.18);
  color: #fff;
  box-shadow: inset 3px 0 0 #1aa6b2;
}
.nav .ico {
  width: 18px;
  text-align: center;
  opacity: 0.9;
}

.sidebar-foot {
  margin-top: 32px;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.82rem;
  color: #8ea0b8;
}
.sidebar-foot a { color: #9fd9df; }

.main {
  padding: 28px 32px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  gap: 16px;
}
.topbar h2 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 650;
}
.topbar .meta { color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card h3 {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat {
  padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-live { background: #fde8e8; color: var(--live); }
.badge-idle { background: #eef2f6; color: var(--muted); }
.badge-error { background: #fdecea; color: var(--danger); }
.badge-ok { background: #e8f7ee; color: var(--ok); }
.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn:hover { background: var(--accent-2); }
.btn-secondary {
  background: #eef2f6;
  color: var(--text);
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a93226; }
.btn-live {
  background: var(--live);
  min-width: 140px;
  font-size: 1rem;
  padding: 12px 20px;
}
.btn-sm { padding: 7px 11px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.flash {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-weight: 500;
}
.flash-success { background: #e8f7ee; color: #146c38; }
.flash-error { background: #fdecea; color: #922b21; }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tr:last-child td { border-bottom: none; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.form-row { margin-bottom: 14px; }
input[type=text],
input[type=password],
input[type=file],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(14,124,134,0.25);
  border-color: var(--accent);
}
.help { color: var(--muted); font-size: 0.82rem; margin-top: 6px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(26,166,178,0.18), transparent 35%),
    radial-gradient(circle at 85% 75%, rgba(15,28,46,0.12), transparent 40%),
    linear-gradient(160deg, #eef3f7, #f7f4ef);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.login-card h1 { margin: 0 0 6px; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; }

.stream-hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}
.now-playing {
  background: linear-gradient(135deg, #102033, #163147);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px;
  min-height: 180px;
}
.now-playing .label { color: #93a7bd; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.now-playing h3 { margin: 8px 0 4px; font-size: 1.35rem; }
.now-playing .meta { color: #a9bdd4; }

.orient-picks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.orient-pick {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  background: #fff;
}
.orient-pick input { margin-right: 8px; }
.orient-pick.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,124,134,0.12);
}
.orient-icon {
  width: 42px;
  height: 28px;
  border: 2px solid currentColor;
  border-radius: 4px;
  margin-bottom: 8px;
  opacity: 0.7;
}
.orient-icon.portrait {
  width: 22px;
  height: 36px;
}

.empty {
  color: var(--muted);
  padding: 18px 0;
  text-align: center;
}

.btn-youtube {
  background: #ff0000;
  color: #fff;
}
.btn-youtube:hover { background: #d40000; color: #fff; }
.btn-youtube-lg {
  padding: 14px 22px;
  font-size: 1.05rem;
  gap: 10px;
}
.yt-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 4px 4px;
}
.yt-logo-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: #ff0000;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  box-shadow: 0 10px 24px rgba(255, 0, 0, 0.25);
}
.yt-connected-row {
  display: flex;
  gap: 16px;
  align-items: center;
}
.yt-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
}
.yt-avatar-fallback {
  display: grid;
  place-items: center;
  background: #ff0000;
  color: #fff;
  font-weight: 700;
}
.channel-grid {
  display: grid;
  gap: 10px;
}
.channel-card {
  display: grid;
  grid-template-columns: 18px 64px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: #fff;
}
.channel-card:has(input:checked) {
  border-color: #ff0000;
  box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.12);
}
.channel-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
}

.studio {
  display: grid;
  gap: 16px;
}
.studio-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.studio-bar-left,
.studio-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.studio-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #ff3b3b, #c81e1e);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.studio-title {
  margin: 0;
  font-size: 1.05rem;
}
.studio-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}
.studio-grid {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.studio-monitor-col {
  position: sticky;
  top: 16px;
}
.monitor {
  background: #12161d;
  border: 1px solid #2a3340;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(15, 28, 46, 0.12);
}
.monitor-label {
  display: flex;
  justify-content: space-between;
  color: #8b98ab;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.monitor-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05070b;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #313b4a;
}
.monitor.orient-portrait .monitor-screen {
  aspect-ratio: 9 / 16;
  max-width: 140px;
  margin: 0 auto;
}
.tv-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
  position: relative;
  z-index: 1;
}
.monitor-caption {
  margin-top: 8px;
  color: #d7dee8;
}
.monitor-caption-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: #8b98ab;
  margin-bottom: 2px;
}
.monitor-caption strong {
  font-size: 0.86rem;
  font-weight: 650;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tv-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fde8e8;
  color: var(--live);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 0.78rem;
}
.tv-idle-pill {
  display: inline-flex;
  align-items: center;
  background: #eef2f6;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 700;
  font-size: 0.78rem;
}
.tv-nosignal {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: #070a10;
}
.tv-nosignal.hidden { display: none; }
.tv-noise {
  position: absolute;
  inset: 0;
  opacity: 0.16;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 4px);
  animation: noiseShift 1.2s steps(4) infinite;
}
@keyframes noiseShift {
  0% { transform: translate(0,0); }
  25% { transform: translate(-1%, 1%); }
  50% { transform: translate(1%, -1%); }
  75% { transform: translate(-1%, -1%); }
  100% { transform: translate(0,0); }
}
.tv-nosignal-text {
  position: relative;
  z-index: 1;
  text-align: center;
  color: #d5deea;
  padding: 8px;
}
.tv-nosignal-text strong {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}
.tv-nosignal-text span {
  color: #8b98ab;
  font-size: 0.7rem;
}
.studio-playlist { margin-bottom: 0; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
  }
  .grid-3, .grid-2, .stream-hero, .control-room, .studio-grid { grid-template-columns: 1fr; }
  .studio-monitor-col { position: static; max-width: 240px; }
  .main { padding: 18px; }
}
