/* WATCH tab — live SC2 Twitch streams + custom chat.
   Desktop: [streams sidebar | big player | chat]. Tablet: streams strip on
   top, player + chat below. Mobile: player always on top, a segmented
   control swaps the lower panel between the live list and chat. */

#page-watch { padding: 0; }

.watch-disabled {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-dim);
}

.watch-root {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 340px;
  grid-template-areas: "streams main chat";
  gap: 12px;
  padding: 12px;
  height: calc(100dvh - 132px);
  min-height: 460px;
  box-sizing: border-box;
}

/* ---- Streams sidebar ---- */
.watch-streams {
  grid-area: streams;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
/* The game filter toggle IS the header row; the collapse button sits at its
   right edge. (No separate "Live now" title — the toggle labels the panel.) */
.watch-streams-head {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

/* Game filter toggle (All / SC2 / SC1) */
.watch-game-toggle {
  flex: 1;
  display: flex;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.watch-game-btn {
  flex: 1;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 5px 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.watch-game-btn:hover { color: var(--text); }
.watch-game-btn.is-active { background: var(--accent-dim); color: var(--text); }

.watch-streams-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.watch-empty { padding: 18px 14px; color: var(--text-muted); font-size: 13px; }

.watch-stream-card {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 7px;
  margin-bottom: 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}
.watch-stream-card:hover { background: var(--surface-alt); }
.watch-stream-card.is-active {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.watch-thumb {
  position: relative;
  flex: 0 0 96px;
  width: 96px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}
.watch-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.watch-live-dot {
  position: absolute; top: 4px; left: 4px;
  background: #e0245e; color: #fff;
  font-size: 9px; font-weight: 700; letter-spacing: .04em;
  padding: 1px 5px; border-radius: 3px;
}
.watch-viewers {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(0,0,0,.7); color: #fff;
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
}
.watch-card-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.watch-card-name {
  font-weight: 600; font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.watch-pill-curated { color: var(--accent); margin-right: 3px; }
.watch-card-title {
  font-size: 12px; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Player ---- */
.watch-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.watch-player-pool {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.watch-player {
  position: absolute;
  inset: 0;
  visibility: hidden;     /* hidden players stay alive (muted) for instant switch */
  opacity: 0;
}
.watch-player.is-visible { visibility: visible; opacity: 1; }
.watch-player iframe { width: 100%; height: 100%; border: 0; display: block; }

.watch-now {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px 2px;
  flex: 0 0 auto;
}
.watch-now-name { font-weight: 700; font-size: 15px; color: var(--text); }
.watch-now-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.watch-now-link:hover { text-decoration: underline; }
.watch-now-note { font-size: 12px; color: var(--text-muted); }

/* ---- Chat ---- */
.watch-chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.watch-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.watch-chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
}
.watch-msg { padding: 2px 0; word-wrap: break-word; overflow-wrap: anywhere; }
.watch-msg-name { font-weight: 700; }
.watch-msg-colon { color: var(--text-muted); }
.watch-msg-text { color: var(--text); }
.watch-msg-system { color: var(--text-muted); font-style: italic; }
.watch-emote { height: 22px; vertical-align: middle; margin: -2px 1px; }

.watch-chat-composer { border-top: 1px solid var(--border); padding: 10px; }
.watch-chat-form { display: flex; gap: 8px; }
.watch-chat-input {
  flex: 1; min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}
.watch-chat-input:focus { outline: none; border-color: var(--accent); }
.watch-chat-send, .watch-link-btn {
  background: var(--accent);
  color: #04121d;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}
.watch-chat-send:hover, .watch-link-btn:hover { filter: brightness(1.08); }
.watch-link-prompt {
  display: flex; flex-direction: column; gap: 8px;
  font-size: 13px; color: var(--text-dim);
}

/* ---- Mobile segmented control (hidden on desktop) ---- */
.watch-mobile-tabs { display: none; }

/* ---- Collapse / expand the side panels (desktop) ---- */
.watch-collapse-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  flex: 0 0 auto;
}
.watch-collapse-btn:hover { background: var(--surface-alt); color: var(--text); }

.watch-expand-rail {
  display: none;            /* shown only when its panel is collapsed (desktop) */
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--text-dim);
  padding: 12px 0;
}
.watch-expand-rail:hover { color: var(--text); background: var(--surface-alt); }
.watch-expand-icon { font-size: 16px; font-weight: 700; }
.watch-expand-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}

/* Per-card game badge (shown only in the mixed "All" view) */
.watch-game-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .03em;
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.watch-game-badge-sc2 { background: rgba(86, 194, 255, .18); color: #8fd2ff; }
.watch-game-badge-bw  { background: rgba(255, 180, 84, .18); color: #ffc879; }

@media (min-width: 1024px) {
  .watch-root { transition: grid-template-columns .15s ease; }
  .watch-root[data-streams-collapsed="true"] { grid-template-columns: 40px minmax(0, 1fr) 340px; }
  .watch-root[data-chat-collapsed="true"]    { grid-template-columns: 264px minmax(0, 1fr) 40px; }
  .watch-root[data-streams-collapsed="true"][data-chat-collapsed="true"] {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }
  /* Collapsed: hide the panel body, show the vertical expand rail. */
  .watch-root[data-streams-collapsed="true"] .watch-streams-head,
  .watch-root[data-streams-collapsed="true"] .watch-streams-list { display: none; }
  .watch-root[data-streams-collapsed="true"] .watch-streams > .watch-expand-rail { display: flex; }
  .watch-root[data-chat-collapsed="true"] .watch-chat-head,
  .watch-root[data-chat-collapsed="true"] .watch-chat-msgs,
  .watch-root[data-chat-collapsed="true"] .watch-chat-composer { display: none; }
  .watch-root[data-chat-collapsed="true"] .watch-chat > .watch-expand-rail { display: flex; }
}

/* Collapse affordances are desktop-only (tablet uses a top strip, mobile tabs). */
@media (max-width: 1023px) {
  .watch-collapse-btn, .watch-expand-rail { display: none !important; }
}

/* ---- Tablet: streams strip on top, player + chat below ---- */
@media (max-width: 1023px) {
  .watch-root {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "streams streams"
      "main chat";
  }
  /* Head (title + game toggle) on top, cards as a horizontal strip below. */
  .watch-streams { flex-direction: column; }
  .watch-streams-head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .watch-game-toggle { flex: 0 0 auto; }
  .watch-streams-list {
    display: flex; flex-direction: row; gap: 8px;
    overflow-x: auto; overflow-y: hidden; padding: 8px;
  }
  .watch-stream-card { flex: 0 0 220px; margin-bottom: 0; }
}

/* ---- Mobile: player on top, segmented lower panel ---- */
@media (max-width: 767px) {
  .watch-root {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    height: calc(100dvh - 108px);
  }
  .watch-main { flex: 0 0 auto; }
  .watch-player-pool { aspect-ratio: 16 / 9; flex: none; }
  .watch-streams, .watch-chat { display: none; flex: 1 1 auto; min-height: 0; }
  .watch-streams { flex-direction: column; }
  .watch-streams-list { flex-direction: column; overflow-y: auto; }
  .watch-stream-card { flex: 0 0 auto; }
  .watch-root[data-mobile-view="streams"] .watch-streams { display: flex; }
  .watch-root[data-mobile-view="chat"] .watch-chat { display: flex; }

  .watch-mobile-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  .watch-mtab {
    flex: 1;
    background: transparent;
    border: 0;
    border-radius: 7px;
    padding: 9px;
    color: var(--text-dim);
    font-weight: 600;
    cursor: pointer;
  }
  .watch-mtab.is-active { background: var(--accent-dim); color: var(--text); }
}

/* ---- Admin dashboard: curated streamer manager (#admin-watch-curated) ---- */
.admin-watch-list { list-style: none; margin: 10px 0 0; padding: 0; }
.admin-watch-empty { color: var(--text-muted); font-size: 13px; padding: 6px 0; }
.admin-watch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 6px;
  background: var(--surface);
}
.admin-watch-dot {
  flex: 0 0 auto;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}
.admin-watch-dot.is-live { background: #2ecc71; box-shadow: 0 0 6px rgba(46,204,113,.7); }
.admin-watch-name { flex: 1; color: var(--text); text-decoration: none; font-weight: 600; }
.admin-watch-name:hover { text-decoration: underline; }
.admin-watch-actions { display: flex; gap: 4px; }
.admin-watch-actions button {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  width: 28px; height: 28px;
  cursor: pointer;
  line-height: 1;
}
.admin-watch-actions button:hover:not(:disabled) { background: var(--surface-hi); }
.admin-watch-actions button:disabled { opacity: .35; cursor: default; }
.admin-watch-actions .admin-watch-remove { color: #e0245e; }

/* Viewer-count adjustments (#admin-watch-modifiers) */
.admin-vmod-badge {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #ffb454;
}
.admin-vmod-live { margin-top: 12px; }
.admin-vmod-live-head { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.admin-vmod-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  border-bottom: 1px solid var(--border);
}
.admin-vmod-name {
  flex: 1 1 auto; min-width: 0;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.admin-vmod-counts {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.admin-vmod-counts b { color: var(--text); }
.admin-vmod-input {
  flex: 0 0 auto;
  width: 64px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 6px;
  text-align: right;
}
.admin-vmod-input:focus { outline: none; border-color: var(--accent); }
.admin-vmod-unit { color: var(--text-muted); font-size: 12px; }
