:root {
  --turquoise-top: #eef9f8;
  --turquoise-mid: #ccefeb;
  --turquoise-bottom: #8dd5d0;
  --turquoise: #6fcac5;
  --turquoise-dark: #238f91;
  --pink: #f0529f;
  --pink-dark: #bd2478;
  --ink: #111827;
  --muted: #637083;
  --line: #cbd8e5;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 22px 55px rgba(25, 103, 113, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #ffffff 0%, #ffffff 7%, var(--turquoise-top) 18%, var(--turquoise-mid) 48%, var(--turquoise-bottom) 100%);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.billing-page {
  width: min(1120px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-items: center;
  padding: 26px 0 44px;
}

.billing-shell {
  width: 100%;
  display: grid;
  gap: 18px;
}

.billing-help-footer {
  margin-top: 18px;
  color: var(--ink);
  font-size: clamp(0.95rem, 2.2vw, 1.08rem);
  font-weight: 700;
  text-align: center;
  line-height: 1.35;
}

.billing-help-footer a {
  color: var(--pink-dark);
  text-decoration: none;
  white-space: nowrap;
}

.billing-help-footer a:hover {
  text-decoration: underline;
}

.billing-hero {
  position: relative;
  display: grid;
  justify-items: center;
  text-align: center;
  animation: billingRise 420ms ease-out both;
}

.billing-logo {
  width: min(420px, 82vw);
  height: auto;
  display: block;
  filter: drop-shadow(0 12px 22px rgba(28, 115, 118, 0.14));
}

.billing-subtitle {
  margin: 4px 0 0;
  color: var(--pink-dark);
  font-size: clamp(1.1rem, 2.5vw, 1.45rem);
  font-weight: 800;
  text-transform: uppercase;
}

.back-button {
  position: absolute;
  left: 18px;
  top: 18px;
  width: 46px;
  height: 46px;
  border: 2px solid rgba(240, 82, 159, 0.45);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--pink-dark);
  font-size: 1.8rem;
  font-weight: 900;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 24px rgba(25, 103, 113, 0.12);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.back-button[hidden] {
  display: none;
}

.back-button:hover {
  transform: translateX(-2px) scale(1.04);
  border-color: var(--pink);
}

.back-button:active {
  transform: translateX(-2px) scale(0.96);
}

.billing-panel {
  position: relative;
  width: min(940px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 34px);
  border: 2px solid rgba(240, 82, 159, 0.18);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.billing-panel .back-button + .form-heading {
  padding: 0 56px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: billingRise 280ms ease-out both;
}

.intro-copy,
.form-heading {
  text-align: center;
}

.intro-copy h1,
.form-heading h1 {
  margin: 0;
  color: var(--turquoise-dark);
  font-size: clamp(1.75rem, 4vw, 2.55rem);
  line-height: 1.05;
}

.intro-copy p,
.form-heading p {
  margin: 8px auto 0;
  max-width: 560px;
  color: var(--muted);
  font-size: clamp(0.98rem, 2vw, 1.12rem);
  font-weight: 650;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 26px;
}

.choice-button {
  min-height: 150px;
  padding: 22px;
  border: 3px solid rgba(111, 202, 197, 0.45);
  border-radius: 24px;
  background: #ffffff;
  color: var(--turquoise-dark);
  box-shadow: 0 16px 30px rgba(22, 117, 121, 0.13);
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.choice-button span {
  display: block;
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  font-weight: 900;
  line-height: 1.04;
}

.choice-button small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 750;
}

.choice-button.accent {
  border-color: rgba(240, 82, 159, 0.55);
  color: var(--pink-dark);
}

.choice-button:hover {
  transform: translateY(-4px) scale(1.015);
  border-color: var(--turquoise);
  box-shadow: 0 20px 38px rgba(22, 117, 121, 0.18);
}

.choice-button.accent:hover {
  border-color: var(--pink);
}

.choice-button:active,
.primary-button:active,
.secondary-button:active {
  transform: scale(0.98);
}

.billing-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.existing-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field[hidden] {
  display: none;
}

.field span {
  color: #50637c;
  font-size: 0.92rem;
  font-weight: 850;
}

.field-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.help-button {
  width: 18px;
  height: 18px;
  border: 2px solid var(--pink);
  border-radius: 50%;
  background: #ffffff;
  color: var(--pink-dark);
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-size: 0.78rem;
  font-weight: 950;
  line-height: 1;
}

.help-button:hover {
  transform: scale(1.08);
}

.folio-help-tooltip {
  position: absolute;
  z-index: 30;
  top: 27px;
  right: 0;
  width: min(730px, calc(100vw - 44px));
  display: grid;
  grid-template-columns: minmax(300px, 420px) 86px minmax(170px, 1fr);
  align-items: center;
  gap: 0;
  border: 2px solid rgba(240, 82, 159, 0.34);
  border-radius: 18px;
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 18px 42px rgba(18, 70, 78, 0.22);
  animation: modalPop 160ms ease-out both;
}

.folio-help-tooltip[hidden] {
  display: none;
}

.folio-help-ticket {
  border: 2px solid #111827;
  background: #ffffff;
  padding: 16px 20px;
  color: #111827;
  text-align: center;
  font-size: 1rem;
  line-height: 1.16;
}

.folio-help-logo {
  width: 120px;
  height: auto;
  display: block;
  margin: 0 auto 10px;
  filter: contrast(1.35) grayscale(1);
}

.folio-help-ticket strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 500;
  line-height: 1.02;
}

.folio-help-ticket span,
.folio-help-line {
  display: block;
  margin-top: 3px;
  font-weight: 700;
}

.folio-help-line {
  text-align: left;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 900;
}

.folio-help-folio {
  position: relative;
}

.folio-help-line mark {
  border: 2px solid #ef1d1d;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  padding: 0 3px;
}

.folio-help-total {
  margin-top: 8px;
  text-align: right;
  font-size: 1.05rem;
  font-weight: 950;
}

.folio-help-thanks {
  margin-top: 10px;
  font-size: 1.05rem;
  line-height: 1.18;
}

.folio-help-arrow {
  height: 2px;
  background: #ef1d1d;
  position: relative;
  transform: translateX(-3px);
}

.folio-help-arrow::after {
  content: "";
  position: absolute;
  left: -1px;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 10px solid #ef1d1d;
  transform: translateY(-50%);
}

.folio-help-note {
  border: 1px solid #111827;
  border-radius: 14px;
  padding: 14px 16px;
  color: #111827;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 500;
  line-height: 1.22;
  text-align: center;
}

.field input,
.field select {
  width: 100%;
  min-height: 50px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 14px;
  font-size: 1rem;
  font-weight: 760;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.field input:focus,
.field select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(240, 82, 159, 0.13);
}

.field input[readonly] {
  color: #395067;
  background: #f3f8fb;
}

.email-field,
.fiscal-regime-field,
[data-new-email-field] {
  grid-column: span 2;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  padding: 0 22px;
  color: #ffffff;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  box-shadow: 0 14px 28px rgba(189, 36, 120, 0.24);
}

.primary-button:hover {
  box-shadow: 0 17px 32px rgba(189, 36, 120, 0.31);
}

.primary-button:disabled,
.primary-button[aria-disabled="true"],
.secondary-button:disabled,
.secondary-button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.52;
  box-shadow: none;
}

.billing-top-message {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 10000;
  min-width: min(92vw, 540px);
  transform: translate(-50%, -18px);
  padding: 12px 18px;
  color: #ffffff;
  background: #b71f67;
  border: 2px solid #f7a5cd;
  border-radius: 15px;
  box-shadow: 0 16px 34px rgba(40, 104, 103, 0.24);
  font-weight: 950;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.billing-top-message.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.secondary-button {
  background: linear-gradient(135deg, #7a8da5, #4c5e76);
  box-shadow: 0 12px 24px rgba(42, 57, 74, 0.18);
}

.preview-grid {
  display: grid;
  grid-template-columns: 0.82fr 1.18fr;
  gap: 18px;
  margin-top: 24px;
}

.preview-card {
  min-width: 0;
  border: 2px solid rgba(111, 202, 197, 0.36);
  border-radius: 22px;
  background: #ffffff;
  padding: 18px;
  box-shadow: 0 13px 28px rgba(22, 117, 121, 0.11);
}

.preview-card h2 {
  margin: 0 0 14px;
  color: var(--pink-dark);
  font-size: 1.25rem;
}

.preview-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.preview-list div {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
}

.preview-list dt {
  color: #60738b;
  font-weight: 850;
}

.preview-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 780;
}

.ticket-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.94rem;
}

.ticket-table th,
.ticket-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #dbe5ee;
  text-align: right;
}

.ticket-table th:first-child,
.ticket-table td:first-child {
  text-align: left;
}

.ticket-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px solid rgba(240, 82, 159, 0.3);
  color: var(--pink-dark);
  font-size: 1.18rem;
  font-weight: 950;
}

.billing-screen-ticket {
  border-radius: 24px;
  background: #f5f8fb;
  padding: 14px;
}

.billing-ticket-paper {
  max-width: 420px;
  margin: 0 auto;
  border-radius: 24px;
  background: #ffffff;
  padding: 24px 28px;
  color: #111827;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  font-family: Arial, sans-serif;
  line-height: 1.18;
}

.billing-ticket-header {
  text-align: center;
}

.billing-ticket-header img {
  width: 120px;
  max-width: 100%;
  height: auto;
  margin-bottom: 10px;
  filter: contrast(1.4) grayscale(1);
  image-rendering: crisp-edges;
}

.billing-ticket-header h2 {
  margin: 0;
  color: #111827;
  font-size: clamp(1.8rem, 3vw, 2.15rem);
  font-weight: 400;
  line-height: 1.05;
}

.billing-ticket-header div {
  margin-top: 3px;
  color: #111827;
  font-size: clamp(1rem, 1.7vw, 1.24rem);
}

.billing-ticket-meta {
  margin-top: 12px;
  color: #111827;
  font-size: clamp(1rem, 1.8vw, 1.24rem);
  line-height: 1.22;
}

.billing-ticket-meta strong {
  font-size: clamp(1.08rem, 1.9vw, 1.34rem);
}

.billing-ticket-items {
  margin-top: 5px;
}

.billing-ticket-item {
  color: #111827;
  font-size: clamp(1rem, 1.8vw, 1.22rem);
}

.billing-ticket-item strong {
  display: block;
  font-size: clamp(1.05rem, 1.9vw, 1.28rem);
}

.billing-ticket-item div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.billing-ticket-total-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  color: #111827;
  font-size: clamp(1.1rem, 2vw, 1.38rem);
}

.billing-ticket-payments {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 3px 8px;
  margin-top: 8px;
  color: #111827;
  font-size: clamp(1rem, 1.7vw, 1.16rem);
}

.billing-ticket-payments div {
  min-width: 0;
}

.billing-ticket-payments strong,
.billing-ticket-payments span {
  display: block;
}

.billing-ticket-footer {
  margin-top: 12px;
  color: #111827;
  text-align: center;
  font-size: clamp(1rem, 1.8vw, 1.18rem);
  line-height: 1.2;
}

.preview-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 15, 25, 0.45);
}

.modal-backdrop[hidden] {
  display: none;
}

.app-modal {
  width: min(460px, 100%);
  border: 2px solid rgba(240, 82, 159, 0.38);
  border-radius: 24px;
  background: #ffffff;
  padding: 24px;
  box-shadow: 0 26px 60px rgba(7, 15, 25, 0.28);
  animation: modalPop 190ms ease-out both;
}

.app-modal h2 {
  margin: 0 0 10px;
  color: var(--turquoise-dark);
  font-size: 1.35rem;
}

.app-modal p {
  margin: 0;
  color: var(--ink);
  font-size: 1.02rem;
  font-weight: 720;
  line-height: 1.4;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  color: #ffffff;
  background: var(--pink);
  font-weight: 900;
}

.modal-actions button.secondary {
  background: #61748c;
}

@keyframes billingRise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  .existing-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 640px) {
  .billing-page {
    width: min(100% - 20px, 520px);
    align-items: start;
    padding-top: 16px;
  }

  .billing-logo {
    width: min(305px, 78vw);
  }

  .back-button {
    left: 14px;
    top: 14px;
    width: 42px;
    height: 42px;
  }

  .billing-panel {
    padding: 18px;
    border-radius: 22px;
  }

  .choice-grid,
  .billing-form,
  .existing-form,
  .preview-actions {
    grid-template-columns: 1fr;
  }

  .choice-button {
    min-height: 118px;
  }

  .email-field,
  .fiscal-regime-field,
  [data-new-email-field] {
    grid-column: auto;
  }

  .folio-help-tooltip {
    position: static;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 4px;
  }

  .folio-help-arrow {
    width: 2px;
    height: 28px;
    justify-self: center;
    transform: none;
  }

  .folio-help-arrow::after {
    left: 50%;
    top: 100%;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 10px solid #ef1d1d;
    border-bottom: 0;
    transform: translateX(-50%);
  }

  .billing-panel .back-button + .form-heading {
    padding: 0 46px;
  }

  .preview-list div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .ticket-table {
    font-size: 0.86rem;
  }

  .ticket-table th,
  .ticket-table td {
    padding: 9px 5px;
  }

  .billing-screen-ticket {
    padding: 8px;
  }

  .billing-ticket-paper {
    padding: 20px 18px;
    border-radius: 20px;
  }
}
