:root {
  color-scheme: dark;
  --bg: #070a10;
  --bg-deep: #030508;
  --surface: #0e141d;
  --surface-raised: #141c27;
  --surface-soft: #1a2330;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f7fa;
  --muted: #9aa5b3;
  --gold: #f6c945;
  --gold-bright: #ffe47b;
  --green: #38d4a5;
  --red: #ff6f7d;
  --blue: #5b91ff;
  --radius: 18px;
  --font: "Segoe UI Variable", "Aptos", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 10%, rgba(246, 201, 69, 0.08), transparent 26rem),
    radial-gradient(circle at 88% 82%, rgba(46, 100, 195, 0.13), transparent 30rem),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--gold);
  color: #07090c;
  font-weight: 800;
  transform: translateY(-160%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  width: min(calc(100% - 40px), 1260px);
  min-height: 78px;
  margin-inline: auto;
  padding-top: max(12px, env(safe-area-inset-top));
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(246, 201, 69, 0.24);
}

.brand span span {
  color: var(--gold);
}

.home-link {
  display: inline-flex;
  min-height: 44px;
  padding: 0 14px;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  transition: color 160ms ease, background 160ms ease;
}

.home-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.portal-shell {
  width: min(calc(100% - 40px), 1260px);
  min-height: calc(100dvh - 78px);
  margin-inline: auto;
  padding: clamp(28px, 5vw, 72px) 0 max(36px, env(safe-area-inset-bottom));
}

.login-view {
  display: grid;
  width: min(100%, 1040px);
  min-height: min(680px, calc(100dvh - 130px));
  margin-inline: auto;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 440px);
  align-items: center;
  gap: clamp(44px, 8vw, 112px);
}

.login-intro h1,
.dashboard-heading h1 {
  max-width: 720px;
  margin: 10px 0 18px;
  font-size: clamp(38px, 5vw, 70px);
  line-height: 1.02;
  letter-spacing: 0;
}

.login-intro > p:not(.eyebrow) {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.6;
}

.eyebrow,
.panel-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.security-note {
  display: inline-flex;
  margin-top: 30px;
  padding: 12px 16px;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(56, 212, 165, 0.22);
  border-radius: 12px;
  background: rgba(56, 212, 165, 0.06);
  color: #bcefdc;
  font-size: 13px;
  font-weight: 700;
}

.security-note span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: rgba(56, 212, 165, 0.18);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(20, 28, 39, 0.96), rgba(11, 16, 23, 0.96));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

.login-panel {
  padding: clamp(26px, 4vw, 40px);
}

.panel-heading {
  display: flex;
  margin-bottom: 34px;
  align-items: center;
  gap: 16px;
}

.panel-heading img {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  object-fit: cover;
}

.panel-heading h2,
.playlist-toolbar h2,
.device-title-row h2,
.dialog-header h2 {
  margin: 4px 0 0;
  font-size: 23px;
  letter-spacing: 0;
}

.field {
  display: grid;
  margin-top: 20px;
  gap: 9px;
}

.field > span,
.type-fieldset legend {
  color: #dfe4eb;
  font-size: 13px;
  font-weight: 750;
}

.field input {
  width: 100%;
  height: 52px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  outline: none;
  background: #070b12;
  color: var(--text);
  font-size: 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input::placeholder {
  color: #647080;
}

.field input:focus {
  border-color: rgba(246, 201, 69, 0.7);
  box-shadow: 0 0 0 3px rgba(246, 201, 69, 0.1);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 54px;
}

.icon-button {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 52px;
  padding: 0 20px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.primary-button {
  background: var(--gold);
  color: #080a0d;
}

.primary-button:hover {
  background: var(--gold-bright);
  transform: translateY(-1px);
}

.secondary-button {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
}

.secondary-button:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.07);
}

.danger-button {
  background: var(--red);
  color: #170509;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.login-panel > .primary-button {
  width: 100%;
  margin-top: 26px;
}

.form-message {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid rgba(91, 145, 255, 0.2);
  border-radius: 10px;
  background: rgba(91, 145, 255, 0.08);
  color: #c9d9ff;
  font-size: 13px;
  line-height: 1.45;
}

.error-message {
  border-color: rgba(255, 111, 125, 0.28);
  background: rgba(255, 111, 125, 0.1);
  color: #ffc2c8;
}

.dashboard-view {
  padding-top: 18px;
}

.dashboard-heading {
  display: flex;
  margin-bottom: clamp(28px, 4vw, 46px);
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.dashboard-heading h1 {
  margin-bottom: 0;
  font-size: clamp(38px, 5vw, 62px);
}

.heading-actions {
  display: flex;
  gap: 10px;
}

.compact-button {
  min-height: 44px;
  padding-inline: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
}

.device-panel {
  position: sticky;
  top: 22px;
  overflow: hidden;
  padding: 26px;
}

.device-panel::before {
  position: absolute;
  top: -140px;
  right: -120px;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: rgba(246, 201, 69, 0.08);
  content: "";
  filter: blur(30px);
  pointer-events: none;
}

.device-logo-wrap {
  position: relative;
  width: 74px;
  height: 74px;
  margin-bottom: 26px;
}

.device-logo-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 19px;
  object-fit: cover;
}

.device-title-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  padding: 0 10px;
  align-items: center;
  border: 1px solid rgba(154, 165, 179, 0.2);
  border-radius: 999px;
  background: rgba(154, 165, 179, 0.08);
  color: #c3cad3;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.status-badge.active,
.status-badge.trial {
  border-color: rgba(56, 212, 165, 0.3);
  background: rgba(56, 212, 165, 0.1);
  color: #a9efd8;
}

.status-badge.expired,
.status-badge.blocked,
.status-badge.suspended {
  border-color: rgba(255, 111, 125, 0.3);
  background: rgba(255, 111, 125, 0.1);
  color: #ffc2c8;
}

.device-details {
  position: relative;
  display: grid;
  margin: 28px 0 0;
  gap: 0;
}

.device-details > div {
  display: grid;
  min-height: 58px;
  padding: 14px 0;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.device-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.device-details dd {
  display: flex;
  min-width: 0;
  margin: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: #e9edf2;
  font-size: 13px;
  font-weight: 750;
  text-align: right;
  overflow-wrap: anywhere;
}

.device-details code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.copy-button {
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  flex: 0 0 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
}

.playlist-column {
  min-width: 0;
}

.playlist-toolbar {
  display: flex;
  min-height: 78px;
  margin-bottom: 18px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.playlist-toolbar h2 span {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  margin-left: 7px;
  padding-inline: 8px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--gold);
  font-size: 12px;
  vertical-align: 3px;
}

.playlist-loading {
  display: flex;
  min-height: 180px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  display: grid;
  min-height: 310px;
  padding: 44px 24px;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 18px;
  place-items: center;
  border: 1px solid rgba(246, 201, 69, 0.25);
  border-radius: 16px;
  background: rgba(246, 201, 69, 0.08);
  color: var(--gold);
  font-size: 28px;
}

.empty-state h3 {
  margin: 0;
  font-size: 21px;
}

.empty-state p {
  max-width: 420px;
  margin: 10px 0 22px;
  color: var(--muted);
  line-height: 1.55;
}

.playlist-list {
  display: grid;
  gap: 12px;
}

.playlist-card {
  display: grid;
  min-height: 112px;
  padding: 20px;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(20, 28, 39, 0.92), rgba(12, 17, 24, 0.92));
  transition: border-color 160ms ease, transform 160ms ease;
}

.playlist-card:hover {
  border-color: rgba(246, 201, 69, 0.25);
  transform: translateY(-1px);
}

.playlist-type-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(246, 201, 69, 0.2);
  border-radius: 13px;
  background: rgba(246, 201, 69, 0.07);
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
}

.playlist-copy {
  min-width: 0;
}

.playlist-copy h3 {
  margin: 0 0 7px;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.playlist-source {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-pill {
  display: inline-flex;
  padding: 4px 7px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(91, 145, 255, 0.1);
  color: #b8cdff;
  font-size: 10px;
  font-weight: 850;
}

.playlist-actions {
  display: flex;
  gap: 8px;
}

.card-action {
  display: inline-flex;
  min-height: 40px;
  padding: 0 13px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  color: #dce2e9;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.card-action:hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
}

.card-action.delete:hover {
  border-color: rgba(255, 111, 125, 0.35);
  color: #ffb1ba;
}

dialog {
  width: min(calc(100% - 32px), 660px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.dialog-card {
  max-height: calc(100dvh - 32px);
  padding: clamp(22px, 4vw, 34px);
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 19px;
  background: #101721;
  box-shadow: 0 38px 100px rgba(0, 0, 0, 0.5);
}

.dialog-header {
  display: flex;
  margin-bottom: 20px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.dialog-close {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 27px;
  cursor: pointer;
}

.type-fieldset {
  margin: 22px 0 0;
  padding: 0;
  border: 0;
}

.segmented-control {
  display: grid;
  margin-top: 9px;
  padding: 4px;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #080c12;
}

.segmented-control label {
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  min-height: 42px;
  padding: 0 10px;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented-control input:checked + span {
  background: var(--surface-soft);
  color: var(--gold);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid var(--gold);
}

.xtream-grid,
.pin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

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

.field-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.switch-row {
  position: relative;
  display: flex;
  min-height: 72px;
  margin-top: 24px;
  padding: 14px 14px 14px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
}

.switch-row span {
  display: grid;
  gap: 4px;
}

.switch-row strong {
  font-size: 13px;
}

.switch-row small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.switch-row input {
  position: absolute;
  opacity: 0;
}

.switch-row i {
  position: relative;
  width: 44px;
  height: 25px;
  flex: 0 0 44px;
  border-radius: 999px;
  background: #313b48;
  transition: background 160ms ease;
}

.switch-row i::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #f4f7fa;
  content: "";
  transition: transform 160ms ease;
}

.switch-row input:checked + i {
  background: var(--gold);
}

.switch-row input:checked + i::after {
  transform: translateX(19px);
}

.dialog-actions {
  display: grid;
  margin-top: 26px;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.confirm-dialog {
  width: min(calc(100% - 32px), 440px);
}

.confirm-card {
  text-align: center;
}

.confirm-icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 111, 125, 0.12);
  color: var(--red);
  font-size: 25px;
  font-weight: 900;
}

.confirm-card h2 {
  margin: 0;
}

.confirm-card p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  z-index: 120;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: min(420px, calc(100% - 40px));
  padding: 14px 17px;
  border: 1px solid rgba(56, 212, 165, 0.28);
  border-radius: 12px;
  background: #14241f;
  color: #c5f1e2;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  font-weight: 750;
}

.toast.error {
  border-color: rgba(255, 111, 125, 0.3);
  background: #2a151a;
  color: #ffc6cc;
}

.portal-legal {
  width: min(calc(100% - 40px), 1260px);
  margin: 0 auto;
  padding: 10px 0 28px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  line-height: 1.65;
}

.portal-legal p {
  margin: 0;
}

@media (max-width: 880px) {
  .login-view {
    min-height: auto;
    padding: 30px 0 50px;
    grid-template-columns: 1fr;
    gap: 38px;
  }

  .login-intro {
    text-align: center;
  }

  .login-intro h1,
  .login-intro > p:not(.eyebrow) {
    margin-inline: auto;
  }

  .login-panel {
    width: min(100%, 480px);
    margin-inline: auto;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .device-panel {
    position: relative;
    top: auto;
  }

  .device-details {
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
  }
}

@media (max-width: 620px) {
  .topbar,
  .portal-shell {
    width: min(calc(100% - 24px), 1260px);
  }

  .brand span {
    display: none;
  }

  .portal-shell {
    padding-top: 24px;
  }

  .login-view {
    padding-top: 10px;
  }

  .login-intro h1,
  .dashboard-heading h1 {
    font-size: 38px;
  }

  .security-note {
    margin-top: 22px;
  }

  .dashboard-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .heading-actions {
    width: 100%;
  }

  .heading-actions > button {
    flex: 1;
  }

  .device-details {
    grid-template-columns: 1fr;
  }

  .playlist-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .playlist-card {
    min-height: 0;
    padding: 17px;
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .playlist-type-icon {
    width: 42px;
    height: 42px;
  }

  .playlist-actions {
    grid-column: 1 / -1;
  }

  .card-action {
    flex: 1;
  }

  .xtream-grid,
  .pin-grid,
  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .dialog-actions .primary-button,
  .dialog-actions .danger-button {
    grid-row: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
