:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #2f3136;
  --muted: #6b7280;
  --accent: #0078d4;
  --accent-strong: #106ebe;
  --accent-soft: #e9f3fe;
  --line: #e5e9f0;
  --line-strong: #d8dde8;
  --success: #107c10;
  --error: #a4262c;
  --shadow: 0 10px 26px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f7f8fb 0%, #f2f5fa 100%);
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button,
.button-like {
  border: 0;
  border-radius: 12px;
  padding: 0.8rem 1.15rem;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 600;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:not(.channel-card) {
  width: min(170px, 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
  box-shadow: 0 8px 18px rgba(0, 120, 212, 0.18);
}

.ghost-button {
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  box-shadow: none;
}

.danger-button {
  background: var(--error);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 600;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 2rem;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.topbar h1,
.section-heading h2,
.login-card h2,
.player-toolbar h3,
.empty-panel h3 {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  letter-spacing: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.topnav a {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
}

.topnav a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.topnav a.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(0, 120, 212, 0.14);
}

.user-chip,
.badge {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 0.9rem;
}

.page-shell {
  padding: 1.5rem 2rem 2rem;
}

.legal-page {
  width: min(840px, 100%);
  margin: 2rem auto;
  padding: clamp(1.5rem, 4vw, 3rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  line-height: 1.65;
}

.legal-page h2,
.legal-page h3 {
  color: var(--ink);
}

.legal-page h2 {
  margin: 0;
}

.legal-page h3 {
  margin: 2rem 0 0.5rem;
}

.legal-page p,
.legal-page ul {
  margin: 0.75rem 0;
}

.legal-page li + li {
  margin-top: 0.45rem;
}

.legal-updated {
  color: var(--muted);
  font-size: 0.9rem;
}

.flash-stack {
  padding: 0 2rem;
  display: grid;
  gap: 0.75rem;
}

.flash {
  padding: 1rem 1.15rem;
  border-radius: 14px;
  border: 1px solid var(--line);
}

.flash-error {
  background: #fff3f2;
  color: var(--error);
}

.flash-success,
.flash-info {
  background: #f2fbf2;
  color: var(--success);
}

.login-page .page-shell {
  min-height: calc(100vh - 1rem);
  display: grid;
  place-items: center;
}

.login-card,
.admin-card,
.stat-card,
.empty-panel,
.status-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(500px, 100%);
  padding: 1.75rem;
  border-radius: 20px;
  display: grid;
  justify-items: center;
}

.login-brand {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: center;
  justify-items: center;
  text-align: center;
  width: 100%;
}

.stack-form,
.grid-form,
.inline-form {
  display: grid;
  gap: 1rem;
}

.login-card .stack-form {
  justify-items: center;
  width: 100%;
}

.login-card .stack-form label,
.login-card .stack-form button {
  width: min(352px, 100%);
}

.login-card .stack-form button {
  display: block;
}

.icon-button {
  width: 40px !important;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  display: block;
}

.logo-tile {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.logo-tile--small {
  min-height: 56px;
  width: 56px;
  padding: 0.35rem;
  border-radius: 14px;
}

.logo-tile--header {
  min-height: 64px;
  width: 64px;
  padding: 0.4rem;
  border-radius: 14px;
  flex-shrink: 0;
}

.login-card .logo-tile {
  min-height: 96px;
  width: 176px;
}

label span {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

input,
select {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #ffffff;
  color: var(--ink);
}

select[multiple] {
  min-height: 132px;
  padding: 0.5rem;
}

.player-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.channel-list,
.player-stage,
.admin-page,
.admin-grid {
  display: grid;
  gap: 1rem;
}

.channel-list {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  align-content: start;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100vh - 150px);
  overflow: hidden;
  position: sticky;
  top: 1.5rem;
}

.channel-list__items {
  display: grid;
  align-content: start;
  gap: 1rem;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.player-stage {
  align-self: start;
}

.channel-card,
.channel-admin-card,
.user-card {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: left;
}

.channel-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 1rem;
  padding: 0.95rem;
  align-items: center;
  border-radius: 16px;
}

.channel-card.is-active {
  border-color: rgba(0, 120, 212, 0.55);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(0, 120, 212, 0.3);
  background: #fbfdff;
}

.channel-card__icon {
  display: grid;
  place-items: center;
}

.channel-card__icon img,
.channel-admin-card__header img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 0;
}

.channel-card__body {
  display: grid;
  gap: 0.25rem;
}

.channel-card__body strong {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.channel-card__body small {
  color: var(--muted);
}

.player-shell {
  position: relative;
  min-height: 540px;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(180deg, #eef3f8 0%, #dae4ef 100%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.player-shell video {
  width: 100%;
  height: 100%;
  min-height: 540px;
  object-fit: contain;
  background: transparent;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  color: var(--ink);
  background: linear-gradient(rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.7));
  z-index: 1;
}

.player-overlay h2 {
  margin: 0 0 0.5rem;
  font-size: 1.8rem;
  font-weight: 600;
}

.player-overlay p:last-child {
  margin: 0;
  color: var(--muted);
}

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

.player-toolbar,
.admin-card,
.status-panel,
.stat-card {
  padding: 1.3rem 1.4rem;
  border-radius: var(--radius);
}

.player-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.toolbar-actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.status-panel {
  color: var(--muted);
  background: #ffffff;
}

.admin-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

.stat-card strong {
  font-size: 2.25rem;
  display: block;
  margin-top: 0.35rem;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
}

.data-table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border-radius: 16px;
  overflow: hidden;
}

th,
td {
  padding: 0.95rem 0.7rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

th {
  background: #f5f7fa;
  color: var(--muted);
  font-weight: 600;
}

.user-grid,
.channel-admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.user-card,
.channel-admin-card {
  padding: 1rem;
  border-radius: 18px;
  display: grid;
  gap: 0.9rem;
}

.channel-admin-card__header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.card-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.actions-cell {
  text-align: right;
}

.users-table input,
.users-table select,
.channels-table input,
.channels-table select {
  min-width: 150px;
}

.group-summary-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 260px;
}

.group-summary-text {
  color: var(--ink);
  font-size: 0.95rem;
}

.edit-groups-button {
  width: auto !important;
  min-width: 0;
  padding: 0.55rem 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.edit-groups-button svg {
  width: 14px;
  height: 14px;
}

.groups-dialog {
  width: min(420px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

.groups-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
}

.groups-dialog__form {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.groups-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.groups-dialog__header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.groups-dialog__subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.groups-dialog__close {
  background: #ffffff;
  color: var(--muted);
  border: 1px solid var(--line);
}

.groups-dialog__options {
  display: grid;
  gap: 0.65rem;
  max-height: 280px;
  overflow-y: auto;
}

.groups-dialog__option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.groups-dialog__option input {
  width: auto;
}

.groups-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.import-dialog {
  width: min(620px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.import-dialog::backdrop {
  background: rgba(20, 28, 45, 0.48);
}

.import-dialog h3 {
  margin: 0 0 0.65rem;
}

.import-dialog p,
.import-dialog li {
  color: var(--muted);
}

.import-dialog ul {
  margin: 0.85rem 0;
  padding-left: 1.4rem;
}

.dialog-close-row {
  display: flex;
  justify-content: flex-end;
  margin: -0.45rem -0.45rem 0.25rem;
}

.channels-table input[type="url"] {
  min-width: 280px;
}

.table-icon-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-icon-cell img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 0;
}

.table-checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  width: 100%;
}

.table-checkbox input {
  width: auto;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: center;
}

.channel-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.channel-list-header h3 {
  margin: 0;
}

.selection-cell {
  width: 42px;
  text-align: center;
}

.selection-cell input {
  width: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.checkbox-row input {
  width: auto;
}

.server-config-toggle {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: fit-content;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafcff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
}

.server-config-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.server-config-toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-help {
  max-width: 760px;
  margin: -0.2rem 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

@media (max-width: 960px) {
  .player-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .player-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .login-brand {
    grid-template-columns: 1fr;
  }

  .channel-list {
    max-height: none;
    position: static;
  }

  .channel-list__items {
    overflow: visible;
  }
}
