:root {
  --portal-bg: #020d1b;
  --portal-panel: #07182b;
  --portal-panel-2: #0b2038;
  --portal-line: #173a60;
  --portal-blue: #0787ff;
  --portal-blue-2: #0064e8;
  --portal-gold: #f6be3d;
  --portal-text: #f5f8ff;
  --portal-muted: #a9bad0;
}

body:has(.portal:not([hidden])) {
  background:
    radial-gradient(circle at 83% 25%, rgba(10, 82, 157, .18), transparent 34rem),
    linear-gradient(135deg, #020b16 0%, #041324 55%, #020b16 100%);
  color: var(--portal-text);
}

.portal { min-height: 100vh; background: transparent; }
.portal .wrap { width: min(100%, 1920px); max-width: none; margin: 0; }
.portalhead {
  height: 108px;
  padding: 0 46px;
  border-bottom: 1px solid #142c49;
  background: linear-gradient(90deg, rgba(3,15,30,.98), rgba(4,24,47,.96));
}
.portalhead .brand { gap: 13px; font-size: 29px; letter-spacing: .075em; font-weight: 800; }
.portalhead .brand img { width: 54px; height: 54px; object-fit: contain; }
.portalhead .brand span { color: #f6f8fc; }
.portalhead .brand span::first-letter { color: var(--portal-gold); }
.portal-account { display: flex; align-items: center; gap: 26px; font-weight: 700; }
.account-divider { width: 1px; height: 34px; background: #718095; }
.portal .portal-logout {
  width: auto;
  min-width: 124px;
  margin: 0;
  border-color: var(--portal-blue);
  background: rgba(3, 16, 31, .45);
  color: #eef7ff;
}

.portalgrid { min-height: calc(100vh - 108px); display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 0; padding: 0; }
.portalnav {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 50px 20px 138px;
  border-right: 1px solid #142d4a;
  background: linear-gradient(160deg, rgba(3, 17, 33, .98), rgba(4, 27, 51, .94));
}
.portalnav button {
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  min-height: 70px;
  padding: 0 26px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #c0d0e5;
  font-size: 20px;
  font-weight: 600;
  text-align: left;
}
.portalnav button:hover { border-color: #205486; background: rgba(8, 49, 86, .45); color: #fff; }
.portalnav button.active {
  border-color: #1f8fff;
  background: linear-gradient(135deg, #058dff, #086ee7);
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 117, 255, .2);
}
.picon {
  display: inline-block;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  background-color: currentColor;
  mask: var(--icon) center / contain no-repeat;
  -webkit-mask: var(--icon) center / contain no-repeat;
}
.picon-home { --icon: url('/portal-icons/home.svg'); }
.picon-devices { --icon: url('/portal-icons/devices.svg'); }
.picon-playlists { --icon: url('/portal-icons/playlists.svg'); }
.picon-orders { --icon: url('/portal-icons/orders.svg'); }
.picon-support { --icon: url('/portal-icons/support.svg'); }
.picon-add { --icon: url('/portal-icons/add.svg'); }
.picon-link { --icon: url('/portal-icons/link.svg'); }
.picon-info { --icon: url('/portal-icons/info.svg'); }
.picon-active { --icon: url('/portal-icons/active.svg'); }
.picon-trial { --icon: url('/portal-icons/trial.svg'); }
.picon-revoked { --icon: url('/portal-icons/revoked.svg'); }
.picon-sync { --icon: url('/portal-icons/sync.svg'); }
.picon-shield { --icon: url('/portal-icons/shield.svg'); }
.picon-edit { --icon: url('/portal-icons/edit.svg'); }
.picon-remove { --icon: url('/portal-icons/remove.svg'); }
.picon-logout { --icon: url('/portal-icons/logout.svg'); width: 19px; height: 19px; margin-right: 8px; }
.portal-motto { position: absolute; left: 50px; bottom: 58px; display: grid; gap: 4px; color: #86a7ce; font-size: 12px; letter-spacing: .31em; }
.portal-motto i { display: block; width: 52px; height: 3px; margin-top: 10px; background: var(--portal-gold); }

.portalmain { min-width: 0; padding: 49px 54px 70px; }
.portal-titlebar { display: flex; align-items: end; gap: 20px; margin-bottom: 34px; }
.portal-titlebar > div:first-child { min-width: 0; }
.portal-kicker { margin: 0 0 12px; color: var(--portal-gold); font-size: 14px; font-weight: 800; letter-spacing: .28em; text-transform: uppercase; }
.portalmain .portal-titlebar h1 { margin: 0; font-size: clamp(38px, 3vw, 56px); line-height: 1; letter-spacing: -.025em; }
.portal-titlebar .toolbar-actions { display: flex; gap: 14px; margin-left: auto; }
.portal .toolbar-actions .btn { width: auto; min-width: 178px; min-height: 58px; margin: 0; font-size: 17px; font-weight: 750; }
.portal .toolbar-actions .picon { width: 24px; height: 24px; margin-right: 10px; }

.portal-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; margin-bottom: 26px; }
.portal-summary.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.portal-stat {
  min-height: 128px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 22px;
  border: 1px solid #24507a;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(7, 27, 49, .96), rgba(5, 19, 35, .96));
  box-shadow: inset 0 1px rgba(255,255,255,.02);
}
.portal-stat-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: #21a4ff;
  background: rgba(3, 112, 220, .08);
}
.portal-stat-icon .picon { width: 38px; height: 38px; }
.portal-stat.tone-green .portal-stat-icon { color: #21d49a; }
.portal-stat.tone-gold .portal-stat-icon { color: var(--portal-gold); }
.portal-stat.tone-blue .portal-stat-icon { color: #2d9cff; }
.portal-stat-copy { min-width: 0; display: grid; }
.portal-stat strong { color: #fff; font-size: 44px; line-height: 1; }
.portal-stat strong.word { font-size: clamp(25px, 2.1vw, 38px); }
.portal-stat span:last-child { margin-top: 6px; color: #bed0e5; font-size: 16px; }

.portal .notice.approved-notice {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0 0 28px;
  padding: 17px 24px;
  border-color: #e6a900;
  background: linear-gradient(90deg, rgba(70, 48, 4, .55), rgba(27, 28, 25, .74));
  color: #ffd75d;
  font-size: 16px;
}
.approved-notice .picon { width: 28px; height: 28px; }

.portal .tablewrap { border-color: #163c63; border-radius: 12px; background: rgba(3, 15, 28, .78); }
.portal table { min-width: 940px; }
.portal thead { background: linear-gradient(90deg, #0d2745, #0b213c); }
.portal th { padding: 19px 24px; color: #c7d8ed; font-size: 14px; font-weight: 750; text-transform: none; letter-spacing: 0; }
.portal td { padding: 18px 24px; color: #eef4fb; border-top: 1px solid #183753; font-size: 15px; }
.portal tbody tr:hover { background: rgba(12, 51, 86, .3); }
.portal td:first-child { font-weight: 700; }
.portal .badge { border: 0; font-weight: 700; white-space: nowrap; }
.portal .playlist-type { min-width: 70px; padding: 6px 13px; border-radius: 20px; background: linear-gradient(135deg, #128dfb, #0759eb); color: #fff; text-align: center; }
.portal .status-active::before, .portal .status-trial::before, .portal .status-revoked::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.portal .action-cluster { display: flex; gap: 10px; }
.portal .action-cluster .btn, .portal .transfer-button { width: auto; min-height: 42px; margin: 0; background: transparent; font-weight: 700; white-space: nowrap; }
.portal .action-cluster .btn { color: #5cb5ff; border-color: #0788ff; }
.portal .action-cluster .btn.danger { color: #ff5c70; border-color: #ff405c; }
.portal .action-cluster .picon { width: 17px; height: 17px; margin-right: 7px; }
.portal .transfer-button { border-color: #f4bd2f; color: #ffd24e; }
.portal .transfer-used { color: #f2b62c; border: 1px solid #9b7018; background: rgba(96, 68, 5, .28); }
.portal .empty-state { padding: 54px 24px; text-align: center; color: var(--portal-muted); }

@media (max-width: 1260px) {
  .portalgrid { grid-template-columns: 260px minmax(0, 1fr); }
  .portalnav button { gap: 15px; padding: 0 18px; font-size: 17px; }
  .portalmain { padding: 42px 30px 60px; }
  .portal-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portal-summary.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .portalhead { height: 82px; padding: 0 18px; }
  .portalhead .brand { font-size: 20px; }
  .portalhead .brand img { width: 42px; height: 42px; }
  .portal-account { gap: 12px; }
  .account-divider { display: none; }
  .portal .portal-logout { min-width: 46px; padding: 0 12px; font-size: 0; }
  .portal .portal-logout .picon { margin: 0; }
  .portalgrid { min-height: calc(100vh - 82px); grid-template-columns: 1fr; }
  .portalnav { position: sticky; top: 0; z-index: 10; flex-direction: row; gap: 6px; overflow-x: auto; padding: 10px 14px; border-right: 0; border-bottom: 1px solid #173653; }
  .portalnav button { width: auto; min-width: max-content; min-height: 50px; gap: 9px; padding: 0 14px; font-size: 14px; }
  .portalnav .picon { width: 20px; height: 20px; }
  .portal-motto { display: none; }
  .portalmain { padding: 30px 18px 50px; }
  .portal-titlebar { align-items: flex-start; flex-direction: column; }
  .portal-titlebar .toolbar-actions { width: 100%; margin-left: 0; }
  .portal .toolbar-actions .btn { min-width: 0; flex: 1; }
  .portal-summary, .portal-summary.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .portalhead .brand span { display: none; }
  .portal-account #userName { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .portal-kicker { font-size: 11px; letter-spacing: .2em; }
  .portal-summary, .portal-summary.cols-3 { grid-template-columns: 1fr; gap: 12px; }
  .portal-stat { min-height: 96px; }
  .portal-stat-icon { width: 58px; height: 58px; }
  .portal-stat-icon .picon { width: 30px; height: 30px; }
  .portal-stat strong { font-size: 34px; }
  .portal .toolbar-actions { flex-direction: column; }
  .portal .toolbar-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .portalnav button, .portal .btn, .portal tbody tr { transition: border-color .18s ease, background .18s ease, color .18s ease, transform .18s ease; }
  .portal .toolbar-actions .btn:hover, .portal .action-cluster .btn:hover, .portal .transfer-button:hover { transform: translateY(-1px); }
}

/* Account settings and narrow-screen content */
.portalgrid, .portalmain, .portalnav, .portalhead, .portal-account { min-width:0; }
.portal .tablewrap { max-width:100%; overflow-x:auto; }
.account-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:24px; }
.account-form { min-width:0; margin:0; }
.account-form label { display:grid; gap:8px; margin:16px 0; }
.account-form input { width:100%; min-width:0; box-sizing:border-box; }
.account-form p { overflow-wrap:anywhere; }
#modalRoot .authpage { overflow:auto; padding:20px; z-index:100; }
#modalRoot .authbox { max-height:calc(100dvh - 40px); overflow:auto; width:min(100%,560px); }
@media(max-width:860px) {
 .account-grid { grid-template-columns:1fr; }
 .portalnav { max-width:100%; }
 .portal-titlebar h1 { overflow-wrap:anywhere; }
}
@media(max-width:600px) {
 .portal table { min-width:0; width:100%; }
 .portal table thead { display:none; }
 .portal table, .portal tbody, .portal tr, .portal td { display:block; width:100%; box-sizing:border-box; }
 .portal tbody tr { border-bottom:2px solid var(--portal-line); padding:12px 0; }
 .portal td { padding:9px 14px; border:0; overflow-wrap:anywhere; white-space:normal; }
 .portal td::before { content:attr(data-label); display:block; color:var(--portal-muted); font-size:12px; margin-bottom:4px; }
 .portal .action-cluster { flex-wrap:wrap; }
 .portalhead { gap:10px; }
 .portal .notice.approved-notice { padding:16px; align-items:flex-start; }
 .portal .portal-stat { min-width:0; }
}
