:root {
  --brand-main: #0a0420;
  --brand-blue: #223180;
  --brand-accent: #bebfdc;
  --brand-background: #f2f2f8;
  --brand-coral: #ff7070;
  --primary: var(--brand-blue);
  --primary-dark: var(--brand-main);
  --primary-light: #eeeefa;
  --primary-ring: rgba(34, 49, 128, 0.16);
  --text: var(--brand-main);
  --muted: #626581;
  --border: #d9daea;
  --bg: var(--brand-background);
  --panel: #ffffff;
  --danger: #d94f59;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #15803d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Header ── */
.page-header {
  background: var(--brand-main);
  height: 60px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-brand-logo {
  display: block;
  width: 150px;
  height: auto;
}

.header-sep {
  color: rgba(255, 255, 255, 0.25);
  font-size: 18px;
  font-weight: 300;
}

.header-sub {
  color: var(--brand-accent);
  font-size: 14px;
  font-weight: 500;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.portal-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}

.portal-link {
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--brand-accent);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.portal-link:hover,
.portal-link:focus-visible {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.session-loading-screen {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.session-loading-screen h1 {
  margin: 18px 0 4px;
  font-size: 22px;
}

.session-loading-screen p {
  margin: 0;
  color: var(--muted);
}

.session-spinner {
  width: 38px;
  height: 38px;
  border: 4px solid var(--brand-accent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: session-spin 0.8s linear infinite;
}

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

/* ── Wrapper ── */
.form-wrapper {
  max-width: 780px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.page-intro {
  text-align: center;
  margin-bottom: 36px;
}

.page-intro h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 8px;
  line-height: 1.2;
}

.page-intro p {
  color: var(--muted);
  margin: 0;
  font-size: 15px;
}

/* ── Section card ── */
.form-section {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-num {
  width: 26px;
  height: 26px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--brand-coral);
}

.section-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ── Fields ── */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.req-star { color: var(--danger); }

.request-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.request-mode-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  display: grid;
  gap: 4px;
  user-select: none;
}

.request-mode-card:hover {
  border-color: var(--brand-accent);
  background: #f7f7fb;
}

.request-mode-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.request-mode-card input[type="radio"] {
  display: none;
}

.request-mode-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.request-mode-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="search"]:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

input:-webkit-autofill,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #fff inset !important;
  -webkit-text-fill-color: var(--text) !important;
}

/* ── Product cards ── */
.request-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.request-choice-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  background: #fff;
  cursor: pointer;
  display: grid;
  gap: 6px;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.request-choice-card:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.request-choice-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
}

.request-choice-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.flow-back {
  margin-bottom: 16px;
}

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.product-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  user-select: none;
  position: relative;
}

.product-card:hover {
  border-color: var(--brand-accent);
  background: #f7f7fb;
}

.product-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.product-card.current-license {
  cursor: pointer;
}

.product-check {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: transparent;
  transition: all 0.15s;
}

.product-card.selected .product-check {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.product-icon {
  font-size: 30px;
  margin-bottom: 10px;
  line-height: 1;
}

.product-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.product-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Packages section ── */
#packages-section,
#new-packages-section,
#existing-package-block {
  display: none;
}

#packages-section.visible,
#new-packages-section.visible,
#existing-package-block.visible {
  display: block;
}

.packages-loading {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}

.packages-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
}

.package-section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 8px;
}

.package-section-head .subsection-label {
  margin: 0;
}

.package-section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.package-section-actions input {
  width: min(260px, 34vw);
  min-height: 34px;
}

.package-clear-btn {
  min-height: 28px;
  padding: 0 12px;
  font-size: 12px;
}

.package-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.package-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  cursor: pointer;
  text-align: center;
  user-select: none;
  background: #fff;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  position: relative;
}

.package-card:hover {
  border-color: var(--brand-accent);
  background: #f7f7fb;
}

.package-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.package-card.current-license {
  cursor: pointer;
}

.package-check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: transparent;
  transition: all 0.12s;
}

.package-card.selected .package-check {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.package-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.package-card.selected .package-name {
  color: var(--primary-dark);
}

/* ── Tier ── */
.license-list-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.license-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.license-list-row {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(140px, auto) minmax(120px, auto);
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.license-list-row:hover {
  border-color: var(--brand-accent);
  background: #f7f7fb;
}

.license-list-row.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.license-row-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.license-row-main strong,
.license-row-main span,
.license-list-row > span {
  overflow-wrap: anywhere;
}

.license-row-main span,
.license-list-row > span {
  color: var(--muted);
  font-size: 12px;
}

.selected-license-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f7f7fb;
}

.selected-license-summary > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.selected-license-summary > .wide {
  grid-column: 1 / -1;
}

.selected-license-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.selected-license-summary strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.existing-package-block {
  margin-top: 20px;
}

.subsection-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.tier-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  user-select: none;
  text-align: center;
  display: block;
}

.tier-card:hover {
  border-color: var(--brand-accent);
}

.tier-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.tier-card input[type="radio"] { display: none; }

.tier-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  text-transform: capitalize;
}

.tier-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Quantity stepper ── */
.qty-stepper {
  display: flex;
  align-items: stretch;
  width: fit-content;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.qty-btn {
  width: 46px;
  height: 46px;
  border: none;
  background: #f7f7fb;
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.qty-btn:hover { background: var(--primary-light); }
.qty-btn:active { background: var(--brand-accent); }
.qty-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.qty-value {
  width: 68px;
  height: 46px;
  border: none;
  border-left: 1.5px solid var(--border);
  border-right: 1.5px solid var(--border);
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  background: #fff;
  font-family: inherit;
  outline: none;
  -moz-appearance: textfield;
}

.qty-value::-webkit-inner-spin-button,
.qty-value::-webkit-outer-spin-button { -webkit-appearance: none; }

.qty-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.qty-exp-row {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

.qty-exp-col {
  display: flex;
  flex-direction: column;
}

.qty-exp-col input[type="date"] {
  width: 180px;
}

/* ── Submit section ── */
.submit-section {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.btn-submit {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 48px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  font-family: inherit;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(34, 49, 128, 0.3);
}

.btn-submit:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(10, 4, 32, 0.3);
}

.btn-submit:active { transform: translateY(1px); }

.btn-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.submit-note {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.form-status {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

.form-status.hidden { display: none; }

/* ── Success screen ── */
#success-screen {
  display: none;
  text-align: center;
  padding: 60px 24px;
  animation: fade-in 0.3s ease;
}

#success-screen.visible { display: block; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.success-icon {
  width: 80px;
  height: 80px;
  background: var(--success-bg);
  border: 2px solid var(--success-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto 24px;
}

.success-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 10px;
}

.success-sub {
  color: var(--muted);
  font-size: 15px;
  max-width: 420px;
  margin: 0 auto 28px;
  line-height: 1.6;
}

.success-email {
  font-weight: 700;
  color: var(--text);
}

.btn-another {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 26px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-another:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.hidden { display: none !important; }

/* ── Sign-in screen ── */
#signin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 24px 20px;
}

#signin-screen.hidden { display: none; }

.gate-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 8px;
}

.gate-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 24px;
  line-height: 1.5;
}

.gate-card .field {
  text-align: left;
}

#success-screen { display: none; }
#success-screen.visible { display: block; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .form-wrapper { padding: 24px 16px 60px; }
  .request-choice-grid { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: 1fr; }
  .request-mode-grid { grid-template-columns: 1fr; }
  .tier-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .license-list-toolbar { grid-template-columns: 1fr; }
  .license-list-row { grid-template-columns: 1fr; }
  .selected-license-summary { grid-template-columns: 1fr; }
  .page-intro h1 { font-size: 22px; }
}
