* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #111316;
  --panel: #181c22;
  --panel-soft: #20252d;
  --field: #12161c;
  --border: #303741;
  --border-strong: #465260;
  --text: #eef1f4;
  --muted: #9aa8b5;
  --accent: #4f7cff;
  --accent-strong: #6f91ff;
  --success: #63d297;
  --danger: #b9414f;
  --danger-panel: #421b24;
  --warning: #e0b85b;
  --radius: 8px;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  max-width: 1060px;
  margin: 20px auto;
  padding: 0 16px;
  line-height: 1.45;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h2,
h3 {
  line-height: 1.2;
}

.card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.card > h2:first-child,
.card > h3:first-child {
  margin-top: 0;
}

.card > p:last-child {
  margin-bottom: 0;
}

.login-shell {
  min-height: calc(100vh - 96px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 32px;
}

.login-card {
  width: min(420px, 100%);
  margin: 0;
}

.login-card button {
  width: 100%;
}

button,
input,
select {
  min-height: 40px;
  padding: 9px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  font: inherit;
}

button {
  background: var(--accent);
  border: 0;
  cursor: pointer;
  font-weight: 650;
  line-height: 1.2;
  transition: background 140ms ease, border-color 140ms ease, filter 140ms ease, opacity 140ms ease;
}

button.secondary {
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 11px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
}

.button-link.secondary {
  background: var(--panel-soft);
  border: 1px solid var(--border);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:hover:not(:disabled),
.button-link:hover {
  filter: brightness(1.08);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.muted {
  color: var(--muted);
}

.ok {
  color: var(--success);
}

.bad {
  color: #ff8f9a;
}

.hidden {
  display: none !important;
}

.danger {
  background: var(--danger);
}

.subtle-danger {
  background: var(--danger-panel);
  border: 1px solid #7c3944;
}

.pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
}

ul {
  padding-left: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.playlist-table {
  width: 100%;
  border-collapse: collapse;
}

.playlist-table th,
.playlist-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.playlist-table tbody tr:last-child td {
  border-bottom: 0;
}

.playlist-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.playlist-table th {
  color: var(--muted);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.025);
}

.playlist-table td button + button {
  margin-left: 6px;
}

.btn-sm {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 8px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  line-height: 1;
}

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  max-width: min(860px, calc(100vw - 24px));
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-weight: 600;
}

.toast-error {
  background: #561923;
  border: 1px solid #f06b7a;
}

.toast-ok {
  background: #173f2b;
  border: 1px solid var(--success);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.topbar h1 {
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-menu {
  position: relative;
}

.account-chip {
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  color: var(--text);
  display: inline-block;
}

.account-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: none;
  z-index: 20;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.32);
}

.account-menu:hover .account-dropdown,
.account-menu:focus-within .account-dropdown,
.account-dropdown:hover {
  display: block;
}

.account-dropdown button {
  width: 100%;
}

.account-dropdown button + button {
  margin-top: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}

.modal {
  width: min(560px, calc(100vw - 24px));
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

.modal-compact {
  width: min(420px, calc(100vw - 24px));
}

.modal h3 {
  margin: 0 0 10px 0;
}

.modal p {
  margin-top: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.field input {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.error-text {
  color: #ff8f9a;
  font-size: 14px;
  min-height: 18px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px 0;
}

.empty-state-error {
  color: #ffb0b8;
}

.empty-state-error .muted {
  color: #ffb0b8;
}

.mb-8 {
  margin-bottom: 8px;
}

.mt-12 {
  margin-top: 12px;
}

.vod-col-add {
  width: 92px;
}

.vod-col-date {
  width: 170px;
}

.vod-col-duration {
  width: 110px;
}

.admin-heading {
  justify-content: space-between;
}

.admin-heading h2 {
  margin: 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.admin-grid h3 {
  margin: 0 0 8px 0;
}

.admin-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-user-btn {
  width: 100%;
  text-align: left;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  min-height: 38px;
}

.admin-user-btn.active {
  background: var(--accent);
}

.admin-entitlement-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.admin-entitlement-form input[type="number"] {
  width: 110px;
}

.admin-entitlement-form select {
  min-width: 110px;
}

.admin-entitlement-name {
  min-width: 220px;
}

.source-override {
  color: var(--warning);
}

.source-plan {
  color: var(--success);
}

.source-missing {
  color: #ff8f9a;
}

.log-list,
.stats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.log-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--field);
}

.log-entry code {
  display: block;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 6px 0;
}

.admin-page {
  max-width: 1180px;
  background: var(--bg);
}

.admin-page .card,
.admin-page .account-chip,
.admin-page .account-dropdown,
.admin-page .metric-card {
  background: var(--panel);
  border-color: var(--border);
  border-radius: var(--radius);
}

.admin-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 4px;
}

.admin-page-heading h2 {
  margin: 0;
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric-value {
  display: block;
  font-size: 22px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.admin-layout-equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-layout-wide {
  grid-template-columns: 1fr;
}

.admin-panel {
  margin: 0;
}

.admin-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.admin-panel-heading h3,
.admin-panel-heading p {
  margin: 0;
}

.admin-users-panel {
  position: sticky;
  top: 12px;
}

.admin-entitlements-table th,
.admin-entitlements-table td {
  padding: 10px 8px;
}

.admin-channel-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-channel-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--field);
}

.admin-channel-row b,
.admin-channel-row code {
  overflow-wrap: anywhere;
}

.admin-channel-actions,
.admin-prep-issue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.admin-prep-issues {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.admin-prep-issue {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.playlist-card {
  width: 100%;
  padding: 18px 18px 16px;
}

.playlist-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.playlist-header h2,
.playlist-header p {
  margin: 0;
}

.playlist-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.playlist-list {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  border-top: 1px solid var(--border);
}

.playlist-item {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) minmax(150px, auto) auto;
  column-gap: 28px;
  row-gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 14px 10px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius);
}

.playlist-item.active {
  background: rgba(99, 210, 151, 0.06);
}

.playlist-order {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: center;
}

.playlist-order-number {
  color: var(--muted);
  font-weight: 700;
}

.playlist-order-buttons {
  display: flex;
  gap: 4px;
}

.playlist-main {
  max-width: 100%;
  min-width: 0;
}

.playlist-title {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.playlist-meta-chip {
  color: var(--muted);
  font-size: 13px;
}

.playlist-meta-chip + .playlist-meta-chip::before {
  content: "/";
  margin-right: 6px;
  color: #66717e;
}

.playlist-status {
  min-width: 0;
}

.status-badge {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
  font-weight: 700;
}

.status-ready {
  color: var(--success);
}

.status-processing {
  color: #cfd7df;
}

.status-issue {
  color: #ff9aa5;
}

.status-detail {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.playlist-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  body {
    margin-top: 14px;
    padding: 0 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .playlist-header,
  .playlist-header-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .playlist-item {
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
  }

  .admin-channel-row,
  .admin-prep-issue {
    grid-template-columns: 1fr;
  }

  .admin-channel-actions,
  .admin-prep-issue-actions {
    justify-content: flex-start;
  }

  .playlist-order {
    grid-template-columns: 28px auto;
    justify-content: start;
  }

  .playlist-title {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
    word-break: break-word;
  }

  .playlist-main,
  .playlist-status,
  .playlist-actions {
    width: 100%;
  }

  .playlist-actions {
    justify-content: flex-start;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-metrics,
  .admin-layout,
  .admin-layout-equal {
    grid-template-columns: 1fr;
  }

  .admin-users-panel {
    position: static;
  }

  .admin-entitlement-name {
    min-width: 180px;
  }
}
