:root {
  --portal-bg-1: #050814;
  --portal-bg-2: #0a1228;
  --portal-bg-3: #0f1a39;
  --portal-surface: rgba(8, 13, 29, 0.94);
  --portal-card: rgba(11, 18, 40, 0.96);
  --portal-card-soft: rgba(10, 16, 34, 0.86);
  --portal-border: rgba(148, 163, 184, 0.16);
  --portal-text: #eef4ff;
  --portal-muted: #97abca;
  --portal-accent: #f2be55;
  --portal-cyan: #36d6ff;
  --portal-success: #35ddb1;
  --portal-danger: #ff7e7e;
  --portal-shadow: 0 28px 72px rgba(2, 6, 23, 0.48);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Tajawal', sans-serif;
  color: var(--portal-text);
  background:
    radial-gradient(circle at 16% 18%, rgba(54, 214, 255, 0.11), transparent 26%),
    radial-gradient(circle at 84% 16%, rgba(242, 190, 85, 0.08), transparent 24%),
    radial-gradient(circle at 74% 82%, rgba(90, 162, 255, 0.14), transparent 28%),
    linear-gradient(145deg, var(--portal-bg-1), var(--portal-bg-2) 48%, var(--portal-bg-3));
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black 32%, transparent 100%);
}

.portal-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(18px, calc(12px + env(safe-area-inset-top))) 16px max(20px, calc(16px + env(safe-area-inset-bottom)));
  position: relative;
  z-index: 1;
}

.portal-shell {
  width: min(560px, 100%);
  margin: 0 auto;
}

.portal-panel,
.portal-modal-card {
  border-radius: 32px;
  border: 1px solid var(--portal-border);
  background: linear-gradient(180deg, rgba(8, 13, 29, 0.97), rgba(8, 13, 28, 0.92));
  box-shadow: var(--portal-shadow);
  backdrop-filter: blur(16px);
}

.portal-main-card {
  overflow: hidden;
  position: relative;
}

.portal-main-card::before,
.portal-main-card::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(16px);
}

.portal-main-card::before {
  width: 220px;
  height: 220px;
  top: -110px;
  left: -80px;
  background: radial-gradient(circle, rgba(54, 214, 255, 0.14), transparent 72%);
}

.portal-main-card::after {
  width: 260px;
  height: 260px;
  bottom: -140px;
  right: -120px;
  background: radial-gradient(circle, rgba(242, 190, 85, 0.11), transparent 72%);
}

.portal-panel-head,
.portal-systems-head,
.portal-modal-head,
.portal-step-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.portal-panel-head {
  padding: 22px 22px 0;
  position: relative;
  z-index: 1;
}

.portal-brandline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-icon,
.portal-step-icon {
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--portal-border);
  background: linear-gradient(165deg, rgba(13, 21, 45, 0.96), rgba(8, 13, 29, 0.84));
}

.portal-icon {
  width: 56px;
  height: 56px;
  padding: 4px;
  border-radius: 18px;
}

.portal-step-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
}

.portal-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.portal-step-icon img,
.portal-step-icon svg {
  width: 28px;
  height: 28px;
  object-fit: contain;
  color: #eaf6ff;
}

.portal-brandline small {
  display: block;
  color: var(--portal-muted);
  font-size: 0.72rem;
  margin-bottom: 2px;
}

.portal-brandline strong {
  display: block;
  font-family: 'Tajawal', sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
}

.portal-status,
.portal-step-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--portal-border);
  background: rgba(255, 255, 255, 0.04);
  color: #dbe7ff;
  font-size: 0.78rem;
}

.portal-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--portal-success);
  box-shadow: 0 0 0 5px rgba(53, 221, 177, 0.12);
}

.portal-stage {
  position: relative;
  z-index: 1;
}

.portal-loading-stage {
  min-height: 360px;
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 36px 30px;
  text-align: center;
  color: var(--portal-muted);
}

.portal-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(148, 163, 184, 0.18);
  border-top-color: var(--portal-cyan);
  animation: portalSpin 0.85s linear infinite;
}

.portal-login-intro {
  padding: 30px 30px 0;
  text-align: center;
}

.portal-login-intro h1,
.portal-systems-head h2,
.portal-modal-head h3,
.portal-step-card h4 {
  margin: 0;
  font-family: 'Tajawal', sans-serif;
  font-weight: 800;
}

.portal-login-intro h1 {
  font-size: 1.55rem;
  margin-bottom: 8px;
}

.portal-login-intro p,
.portal-modal-head p,
.portal-step-card p {
  margin: 0;
  color: var(--portal-muted);
  line-height: 1.8;
  font-size: 0.94rem;
}

.portal-form {
  padding: 22px 30px 30px;
}

.portal-field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.portal-field label {
  color: #d8e4f9;
  font-size: 0.88rem;
  font-weight: 700;
}

.portal-field-shell {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(4, 9, 22, 0.9);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.portal-field-shell:focus-within {
  border-color: rgba(54, 214, 255, 0.56);
  box-shadow: 0 0 0 4px rgba(54, 214, 255, 0.12);
  transform: translateY(-1px);
}

.portal-field-shell svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: #7ea8d9;
}

.portal-field-shell input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--portal-text);
  outline: none;
  font: inherit;
  text-align: left;
}

.portal-field-shell input::placeholder {
  color: #6f82a3;
}

.portal-error {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--portal-danger);
  font-size: 0.9rem;
}

.portal-login-btn,
.portal-primary-btn,
.portal-secondary-btn {
  min-height: 54px;
  border-radius: 18px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.portal-login-btn,
.portal-primary-btn {
  border: 0;
  color: #08101e;
  background: linear-gradient(120deg, #f8cb58, #f2be55 34%, #41cfff 100%);
  box-shadow: 0 18px 36px rgba(54, 195, 255, 0.14), 0 14px 24px rgba(242, 190, 85, 0.12);
}

.portal-login-btn {
  width: 100%;
  margin-top: 8px;
  font-family: 'Tajawal', sans-serif;
  font-size: 1rem;
}

.portal-secondary-btn {
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #dce9ff;
  background: rgba(255, 255, 255, 0.04);
  padding: 0 16px;
}

.portal-systems {
  padding: 22px;
}

.portal-systems-head {
  margin-bottom: 18px;
}

.portal-systems-head h2 {
  font-size: 1.3rem;
}

.portal-systems-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.portal-system-tile,
.portal-step-card {
  border-radius: 22px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(165deg, rgba(13, 21, 45, 0.94), rgba(8, 13, 29, 0.82));
}

.portal-system-tile {
  min-height: 152px;
  padding: 18px;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.portal-system-tile:hover {
  transform: translateY(-3px);
  border-color: rgba(54, 214, 255, 0.32);
  box-shadow: 0 20px 36px rgba(2, 6, 23, 0.34);
}

.portal-system-tile::after {
  content: '';
  position: absolute;
  inset: auto -34px -42px auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(54, 214, 255, 0.18), transparent 72%);
}

.portal-tile-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(54, 214, 255, 0.12);
  border: 1px solid rgba(54, 214, 255, 0.18);
  color: #e7f8ff;
  font-weight: 800;
  font-size: 0.96rem;
}

.portal-system-name {
  margin: 0 0 8px;
  font-size: 1.02rem;
  font-weight: 800;
}

.portal-system-tag {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  width: fit-content;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #dbe7ff;
  font-size: 0.76rem;
}

.portal-system-tag--warn {
  border-color: rgba(245, 158, 11, 0.28);
  background: rgba(245, 158, 11, 0.14);
  color: #fde68a;
}

.portal-system-tag--danger {
  border-color: rgba(248, 113, 113, 0.28);
  background: rgba(127, 29, 29, 0.22);
  color: #fecaca;
}

.portal-empty-tile {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--portal-muted);
}

.hidden {
  display: none !important;
}

.portal-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 6, 23, 0.64);
  backdrop-filter: blur(10px);
}

.portal-modal.open {
  display: flex;
}

.portal-modal-card {
  width: min(980px, 100%);
}

.portal-modal-head {
  padding: 22px 22px 0;
  align-items: flex-start;
}

.portal-modal-close {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #dce9ff;
  cursor: pointer;
  font-size: 1.2rem;
}

.portal-onboarding-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 20px 22px 22px;
}

.portal-step-card {
  min-height: 252px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.portal-step-state[data-kind="done"] {
  color: #defcf1;
  border-color: rgba(53, 221, 177, 0.22);
  background: rgba(53, 221, 177, 0.1);
}

.portal-step-state[data-kind="warn"] {
  color: #fff2cf;
  border-color: rgba(242, 190, 85, 0.24);
  background: rgba(242, 190, 85, 0.1);
}

.portal-step-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #dce7fb;
  font-size: 0.85rem;
}

.portal-step-list li {
  position: relative;
  padding-right: 16px;
  line-height: 1.7;
}

.portal-step-list li::before {
  content: '';
  position: absolute;
  right: 0;
  top: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--portal-accent), var(--portal-cyan));
}

.portal-step-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.portal-primary-btn[disabled],
.portal-secondary-btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.portal-step-note {
  font-size: 0.82rem;
  color: var(--portal-muted);
  line-height: 1.75;
}

@keyframes portalSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .portal-page {
    align-items: flex-start;
    padding-inline: 12px;
  }

  .portal-panel,
  .portal-modal-card {
    border-radius: 24px;
  }

  .portal-panel-head {
    padding: 18px 18px 0;
    flex-direction: column;
    align-items: stretch;
  }

  .portal-brandline,
  .portal-status {
    align-self: flex-start;
  }

  .portal-login-intro {
    padding: 24px 20px 0;
  }

  .portal-form,
  .portal-systems {
    padding: 20px;
  }

  .portal-login-intro h1 {
    font-size: 1.68rem;
  }

  .portal-systems-head,
  .portal-modal-head,
  .portal-step-top {
    flex-direction: column;
    align-items: stretch;
  }

  .portal-onboarding-grid,
  .portal-systems-grid {
    grid-template-columns: 1fr;
  }

  .portal-modal {
    padding: 12px;
  }
}
