/*
 * TVs dashboard (assets/js/views/tvs.js). Everything is scoped under .v-tvs and built on the
 * tokens / shared classes from app.css, so themes, accents and large-size mode carry over.
 */

/* ================================================================ header */
.v-tvs .tvs-header {
  margin-bottom: 4px;
}

.v-tvs .tvs-refresh .icon {
  transition: transform 0.3s var(--ease);
}

.v-tvs .tvs-refresh.is-spinning {
  opacity: 1;
}

.v-tvs .tvs-refresh.is-spinning .icon {
  animation: lc-spin 0.9s linear infinite;
}

.v-tvs .tvs-select-btn .icon {
  display: none;
}

.v-tvs.tvs-selecting .tvs-select-btn .icon {
  display: inline-block;
}

.v-tvs .tvs-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-height: 22px;
  margin: 0 4px 18px;
  color: var(--text-dim);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.v-tvs .tvs-meta-env {
  color: var(--text);
  font-weight: 650;
}

.v-tvs .tvs-meta-sep {
  color: var(--text-faint);
}

.v-tvs .tvs-meta-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.v-tvs .tvs-meta-stat .dot {
  width: 8px;
  height: 8px;
  box-shadow: none;
}

.v-tvs .tvs-meta-time {
  color: var(--text-faint);
}

/* Status refresh failed (server unreachable etc.). */
.v-tvs .tvs-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 10px 10px 10px 14px;
  border: 1px solid rgba(var(--danger-rgb), 0.35);
  border-radius: var(--radius);
  background: rgba(var(--danger-rgb), 0.1);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.4;
}

.v-tvs .tvs-alert > .icon {
  color: var(--danger);
}

.v-tvs .tvs-alert-text {
  flex: 1 1 auto;
  min-width: 0;
}

/* ================================================================= rooms */
/*
 * Room blocks share one column grid (1 / 2 / 3 columns). A room spans as many columns as it
 * has TVs (up to the grid width) and lays its cards out in that many columns with the same
 * gap, so cards line up across rooms and one-TV rooms sit side by side.
 */
.v-tvs .tvs-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 22px 14px;
}

.v-tvs .tvs-group {
  min-width: 0;
}

.v-tvs .tvs-room {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 0 4px 8px;
}

.v-tvs .tvs-room-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.v-tvs .tvs-room-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11.5px;
  letter-spacing: 0;
}

.v-tvs .tvs-room-select {
  display: none;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.v-tvs.tvs-selecting .tvs-room-select {
  display: inline-flex;
}

/* ================================================================== grid */
.v-tvs .tvs-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

/* iPad portrait and up: 2 columns. */
@media (min-width: 640px) {
  .v-tvs .tvs-content {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
  }

  .v-tvs .tvs-group {
    grid-column: span 2;
  }

  .v-tvs .tvs-group[data-n="1"] {
    grid-column: span 1;
  }

  .v-tvs .tvs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .v-tvs .tvs-group[data-n="1"] .tvs-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* iPad landscape: 3 columns. */
@media (min-width: 1000px) {
  .v-tvs .tvs-content {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: 18px;
  }

  .v-tvs .tvs-group {
    grid-column: span 3;
  }

  .v-tvs .tvs-group[data-n="1"] {
    grid-column: span 1;
  }

  .v-tvs .tvs-group[data-n="2"] {
    grid-column: span 2;
  }

  .v-tvs .tvs-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
  }

  .v-tvs .tvs-group[data-n="1"] .tvs-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .v-tvs .tvs-group[data-n="2"] .tvs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ================================================================== card */
.v-tvs .tvc {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.14s var(--ease), border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.v-tvs .tvc::before {
  /* Soft accent wash that fades in for the current / selected TV. */
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: inherit;
  background: radial-gradient(520px 200px at 0% 0%, rgba(var(--accent-rgb), 0.16), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.v-tvs .tvc.tvc-pressing {
  transform: scale(0.985);
}

.v-tvs .tvc.is-current {
  border-color: rgba(var(--accent-rgb), 0.5);
  box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.28), var(--shadow);
}

.v-tvs .tvc.is-current::before {
  opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
  .v-tvs .tvc:hover {
    border-color: var(--border-strong);
  }

  .v-tvs .tvc.is-current:hover {
    border-color: rgba(var(--accent-rgb), 0.65);
  }
}

.v-tvs .tvc-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 0;
}

.v-tvs .tvc-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  flex: none;
}

.v-tvs .tvc-open {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.v-tvs .tvc-open:focus-visible {
  border-radius: 6px;
  outline-offset: 4px;
}

.v-tvs .tvc-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 17.5px;
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.25;
}

.v-tvs .tvc-box {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
}

.v-tvs .tvc-box:empty {
  display: none;
}

.v-tvs .tvc-badges {
  display: flex;
  align-items: center;
  flex: none;
  gap: 6px;
}

.v-tvs .tvc-rec {
  gap: 5px;
}

.v-tvs .tvc-rec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: tvs-blink 1.6s ease-in-out infinite;
}

.v-tvs .tvc-check {
  display: none;
}

.v-tvs.tvs-selecting .tvc-check {
  display: flex;
}

/* ------------------------------------------------------------ card body */
.v-tvs .tvc-body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  justify-content: center;
  gap: 12px;
  min-height: 112px;
  padding: 14px 16px 16px;
  transition: opacity 0.25s;
}

.v-tvs .tvc.is-changing .tvc-body {
  opacity: 0.45;
}

.v-tvs .tvc-now {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.v-tvs .tvc-prog {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  gap: 1px;
}

.v-tvs .tvc-title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.v-tvs .tvc-ep {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 14px;
}

.v-tvs .tvc-time {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.v-tvs .tvc-pbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.v-tvs .tvc-pbar .progress {
  flex: 1 1 auto;
}

.v-tvs .tvc-left {
  flex: none;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.v-tvs .tvc-loading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.v-tvs .tvc-loading .skeleton-group {
  flex: 1 1 auto;
  gap: 8px;
}

.v-tvs .tvc-loading-tile {
  flex: none;
  width: 64px;
  height: 44px;
  border-radius: 11px;
}

/* Standby / offline / error */
.v-tvs .tvc-state {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.v-tvs .tvc-state-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-dim);
}

.v-tvs .tvc-state-text {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.v-tvs .tvc-state-title {
  font-size: 16px;
  font-weight: 700;
}

.v-tvs .tvc-state-sub {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.v-tvs .tvc-state .btn {
  flex: none;
}

.v-tvs .tvc.st-standby .tvc-state-ic {
  background: rgba(var(--warning-rgb), 0.14);
  color: var(--warning);
}

.v-tvs .tvc.st-offline .tvc-state-ic {
  background: rgba(var(--danger-rgb), 0.14);
  color: var(--danger);
}

.v-tvs .tvc.st-error .tvc-state-ic {
  background: rgba(var(--warning-rgb), 0.14);
  color: var(--warning);
}

.v-tvs .tvc.st-standby .tvc-name,
.v-tvs .tvc.st-offline .tvc-name {
  color: var(--text-dim);
}

.v-tvs .tvc.st-offline {
  border-style: dashed;
  border-color: rgba(var(--danger-rgb), 0.3);
}

.v-tvs .tvc.st-standby .tvc-body,
.v-tvs .tvc.st-offline .tvc-body {
  background: repeating-linear-gradient(135deg, transparent 0 14px, var(--surface) 14px 28px);
}

/* ------------------------------------------------------------ TV sets */
/* A TV set that is off (or not on the Wi-Fi) is normal, not an error. */
.v-tvs .tvc.is-tvset.st-offline {
  border-style: solid;
  border-color: var(--border);
}

.v-tvs .tvc.is-tvset.st-offline .tvc-state-ic,
.v-tvs .tvc.is-tvset.st-standby .tvc-state-ic {
  background: var(--surface-2);
  color: var(--text-dim);
}

/* The app on screen as an initials tile (same size as a channel badge). */
.v-tvs .tvc-app {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 64px;
  height: 44px;
  border-radius: 11px;
  background: var(--app-color, var(--accent));
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.v-tvs .tvc-app-none {
  background: var(--surface-2);
  color: var(--text-dim);
  box-shadow: inset 0 0 0 1px var(--border);
  text-shadow: none;
}

/* Volume meter in place of the program progress bar. */
.v-tvs .tvc-volbar > .icon {
  flex: none;
  color: var(--text-dim);
}

.v-tvs .tvc-volbar.is-muted,
.v-tvs .tvc-volbar.is-muted > .icon,
.v-tvs .tvc-volbar.is-muted .tvc-left {
  color: var(--warning);
}

/* Linked receiver TV: "Bar TV · Netflix · Vol 12" under the program. */
.v-tvs .tvc-tvset {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-top: -4px;
  color: var(--text-faint);
  font-size: 12.5px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.v-tvs .tvc-tvset > .icon {
  flex: none;
}

.v-tvs .tvc-tvset-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.v-tvs .tvc-tvset.is-muted {
  color: var(--warning);
}

/* ----------------------------------------------------------- quick keys */
/* --n = number of quick keys (4 for receiver TVs, 6 with a linked TV set's volume). */
.v-tvs .tvc-actions {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr));
  border-top: 1px solid var(--border);
  cursor: default;
}

/* Six keys: icon over label so each fits its narrower column. */
.v-tvs .tvc-actions[data-n="6"] .tvc-act {
  flex-direction: column;
  gap: 2px;
  font-size: 11.5px;
}

.v-tvs .tvc-act {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: calc(var(--btn-h) + 2px);
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.v-tvs .tvc-act + .tvc-act {
  border-left: 1px solid var(--border);
}

.v-tvs .tvc-act-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.v-tvs .tvc-act.pressed {
  transform: none;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.v-tvs .tvc-act.pressed .icon {
  transform: scale(0.9);
}

.v-tvs .tvc-act .icon {
  transition: transform 0.12s var(--ease);
}

.v-tvs .tvc-act.is-wake {
  color: var(--success);
}

/* Mute is on. */
.v-tvs .tvc-act.is-on {
  color: var(--warning);
}

/* A TV set's Power while the TV is off: only explains (TVs can't be turned on over Wi-Fi). */
.v-tvs .tvc-act.is-off {
  color: var(--text-faint);
}

.v-tvs .tvc-act:disabled {
  cursor: default;
}

@media (hover: hover) and (pointer: fine) {
  .v-tvs .tvc-act:hover {
    background: var(--surface-2);
    color: var(--text);
  }
}

/* Busy buttons (power / tune / retry in flight): icon + text fade, a spinner takes their place. */
.v-tvs .tvc-act.is-busy > *,
.v-tvs .btn.is-busy > * {
  opacity: 0;
}

.v-tvs .tvc-act.is-busy::after,
.v-tvs .btn.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2.5px solid rgba(127, 140, 170, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: lc-spin 0.8s linear infinite;
}

.v-tvs .btn.is-busy {
  opacity: 1;
}

.v-tvs .btn-primary.is-busy::after {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
}

/* ------------------------------------------------------------ select mode */
.v-tvs.tvs-selecting {
  padding-bottom: calc(150px + var(--safe-bottom));
}

.v-tvs.tvs-selecting .tvc-actions {
  display: none;
}

.v-tvs.tvs-selecting .tvc {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.v-tvs.tvs-selecting .tvc::before {
  opacity: 0;
}

.v-tvs.tvs-selecting .tvc.selected {
  border-color: rgba(var(--accent-rgb), 0.7);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.45), var(--shadow);
}

.v-tvs.tvs-selecting .tvc.selected::before {
  opacity: 1;
}

.v-tvs .tvc.selected .check-circle {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  transform: scale(1.06);
}

/* Floating action bar for the selection. */
.v-tvs .tvs-bar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 12px);
  z-index: 30;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  width: calc(100% - 24px - var(--safe-left) - var(--safe-right));
  max-width: 860px;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--toast-bg);
  -webkit-backdrop-filter: saturate(170%) blur(22px);
  backdrop-filter: saturate(170%) blur(22px);
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
}

.v-tvs.tvs-selecting .tvs-bar {
  display: flex;
  animation: tvs-bar-in 0.28s var(--ease) both;
}

.v-tvs .tvs-bar-info {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 8px;
  min-width: 0;
  padding-left: 8px;
}

.v-tvs .tvs-bar-count {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.v-tvs .tvs-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.v-tvs .tvs-bar-on .icon {
  color: var(--success);
}

.v-tvs .tvs-bar-off .icon {
  color: var(--danger);
}

.v-tvs .tvs-bar .btn:disabled .icon {
  color: inherit;
}

@media (max-width: 699px) {
  .v-tvs .tvs-bar {
    padding: 8px;
  }

  .v-tvs .tvs-bar-info {
    order: 1;
  }

  .v-tvs .tvs-bar-done {
    order: 2;
  }

  .v-tvs .tvs-bar-actions {
    order: 3;
    flex: 1 1 100%;
  }

  .v-tvs .tvs-bar-actions > .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 10px;
  }
}

@media (max-width: 400px) {
  .v-tvs .tvs-bar-actions > .btn {
    gap: 5px;
    font-size: 14px;
  }

  .v-tvs .tvs-bar-actions > .btn .icon {
    display: none;
  }
}

/* ================================================================= empty */
.v-tvs .tvs-empty {
  max-width: 620px;
  margin: 12px auto 0;
  width: 100%;
}

.v-tvs .tvs-welcome {
  overflow: hidden;
  background:
    radial-gradient(420px 220px at 50% 0%, rgba(var(--accent-rgb), 0.16), transparent 70%),
    var(--card-bg);
}

.v-tvs .tvs-welcome .empty {
  padding: 56px 24px 48px;
}

/* ================================================================ phones */
@media (max-width: 420px) {
  .v-tvs .tvc-act {
    flex-direction: column;
    gap: 2px;
    font-size: 11.5px;
  }

  .v-tvs .tvc-body {
    min-height: 100px;
  }

  .v-tvs .tvc-state {
    flex-wrap: wrap;
  }

  .v-tvs .tvc-state .btn {
    margin-left: 58px;
  }
}

/* Large buttons: a touch more room for the quick keys. */
html[data-size="large"] .v-tvs .tvc-act {
  font-size: 14.5px;
}

/* ============================================================= animation */
@keyframes tvs-bar-in {
  from {
    opacity: 0;
    transform: translate(-50%, 18px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes tvs-blink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.25;
  }
}
