/*
 * My Account -- Login / Register column layout and form rhythm.
 *
 * woocommerce-layout.css gives .col2-set a float clearfix:
 *   .woocommerce .col2-set::after, .woocommerce .col2-set::before { content:" "; display:table }
 * #customer_login carries that class, so as soon as it is display:grid those two
 * pseudo-elements are counted as grid items. The grid then holds four items and
 * lays out as ::before | Login  /  Register | ::after -- login top-right,
 * register below-left. Removing them is what actually fixes the alignment.
 */

.woocommerce #customer_login.col2-set::before,
.woocommerce #customer_login.col2-set::after,
.woocommerce-page #customer_login.col2-set::before,
.woocommerce-page #customer_login.col2-set::after {
  content: none !important;
  display: none !important;
}

/* Nothing between the panel and the grid may narrow it, or the columns end
   short and leave dead space on the right. */
.ahp-account-v2-shortcode,
.ahp-account-v2-shortcode > .woocommerce,
.woocommerce .woocommerce-notices-wrapper {
  width: 100% !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  float: none !important;
}

.woocommerce #customer_login,
.woocommerce-page #customer_login {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 24px !important;
  align-items: stretch;
  justify-items: stretch;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  box-sizing: border-box;
}

/* The floats are meaningless once the clearfix is gone, and they fight the grid. */
.woocommerce #customer_login > .u-column1,
.woocommerce #customer_login > .u-column2,
.woocommerce-page #customer_login > .u-column1,
.woocommerce-page #customer_login > .u-column2 {
  width: auto !important;
  max-width: none;
  min-width: 0;
  margin: 0 !important;
  float: none !important;
  clear: none;
  display: flex;
  flex-direction: column;
}

/* Pin each column so source order cannot drift if another rule adds an item. */
.woocommerce #customer_login > .u-column1 { grid-column: 1; grid-row: 1; }
.woocommerce #customer_login > .u-column2 { grid-column: 2; grid-row: 1; }

.woocommerce #customer_login > .u-column1 > h2,
.woocommerce #customer_login > .u-column2 > h2 {
  margin: 0 0 16px;
  line-height: 1.2;
}

/* Cards fill their column exactly and share one height, so both sides match
   edge to edge and bottom out together. */
.woocommerce #customer_login form.login,
.woocommerce #customer_login form.register {
  flex: 1;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* One gap value owns the vertical rhythm; per-row margins would double it. */
.woocommerce #customer_login form.login > p,
.woocommerce #customer_login form.register > p,
.woocommerce #customer_login form.register > .woocommerce-privacy-policy-text {
  margin: 0 !important;
  padding: 0;
}

.woocommerce #customer_login .woocommerce-form-row label {
  margin-bottom: 8px;
}

/* Login: submit and remember-me share one row. Reversed so the button leads
   while the checkbox stays after it in the tab order.
   WooCommerce puts .form-row on every row, so :not(.woocommerce-form-row)
   is what isolates the submit row from the username/password fields. */
.woocommerce #customer_login form.login > p.form-row:not(.woocommerce-form-row) {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* Field rows stay stacked: label above its input, full width. */
.woocommerce #customer_login form.login > p.woocommerce-form-row,
.woocommerce #customer_login form.register > p.woocommerce-form-row {
  display: block;
}

.woocommerce #customer_login .woocommerce-form-row > label {
  display: block;
  width: 100%;
}

.woocommerce #customer_login .woocommerce-form-row .password-input {
  display: block;
  width: 100%;
  position: relative;
}

.woocommerce #customer_login .woocommerce-form-login__rememberme {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 !important;
  padding: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.woocommerce #customer_login .woocommerce-form-login__rememberme input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  flex: none;
  accent-color: #9b4dff;
  cursor: pointer;
}

.woocommerce #customer_login .woocommerce-LostPassword {
  margin: 0 !important;
  font-size: 14px;
}

/* Register: the consent copy is fine print, not body text. */
.woocommerce #customer_login .woocommerce-privacy-policy-text p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  opacity: .72;
}

.woocommerce #customer_login .woocommerce-privacy-policy-text a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Buttons size to their label instead of stretching across the card. */
.woocommerce #customer_login form.login .woocommerce-form-login__submit,
.woocommerce #customer_login form.register .woocommerce-form-register__submit {
  width: auto;
  align-self: flex-start;
  flex: none;
}

/* Drop the register action to the card floor so both cards end evenly. */
.woocommerce #customer_login form.register > p.woocommerce-form-row:last-child {
  margin-top: auto !important;
}

/* ---- Sign in / Create account tabs ----
   Only one panel shows at a time, switched client-side so neither form
   reloads the page. Until the script runs the two columns render side by
   side as before, so the page is never broken with JS disabled. */
.ahpa-tabs {
  display: inline-flex;
  gap: 4px;
  margin: 0 0 20px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(255, 255, 255, .04);
}

.ahpa-tab {
  appearance: none;
  min-height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: .68;
  transition: background .16s ease, opacity .16s ease;
}

.ahpa-tab:hover { opacity: .9; }

.ahpa-tab.is-active {
  background: linear-gradient(135deg, #9b4dff, #6d28d9);
  color: #fff;
  opacity: 1;
  box-shadow: 0 8px 20px rgba(109, 40, 217, .28);
}

.ahpa-tab:focus-visible {
  outline: 2px solid #9b4dff;
  outline-offset: 2px;
}

/* One panel at a time, so the grid collapses to a single full-width column. */
.woocommerce #customer_login.ahpa-tabs-ready,
.woocommerce-page #customer_login.ahpa-tabs-ready {
  grid-template-columns: minmax(0, 1fr) !important;
}

.woocommerce #customer_login.ahpa-tabs-ready > .u-column1,
.woocommerce #customer_login.ahpa-tabs-ready > .u-column2 {
  grid-column: 1 !important;
  grid-row: 1 !important;
}

.woocommerce #customer_login.ahpa-tabs-ready > [hidden] {
  display: none !important;
}

/* ---- Register: qualified-researcher fields ----
   WooCommerce prints email + password first and fires woocommerce_register_form
   after them, so our fields would all land below the password. The register form
   is a flex column, so `order` restores the intended sequence without having to
   override the template. */
.woocommerce #customer_login form.register {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 14px;
  align-content: start;
}

.woocommerce #customer_login form.register > * {
  grid-column: 1 / -1;
}

.woocommerce #customer_login form.register .ahpa-field--first-name { order: 1; grid-column: 1; }
.woocommerce #customer_login form.register .ahpa-field--last-name  { order: 2; grid-column: 2; }
/* Email is the first p WooCommerce prints, password the second. */
.woocommerce #customer_login form.register > p.woocommerce-form-row:nth-of-type(1) { order: 3; }
.woocommerce #customer_login form.register .ahpa-field--business-type     { order: 4; }
.woocommerce #customer_login form.register .ahpa-field--research-category { order: 5; }
.woocommerce #customer_login form.register .ahpa-field--researcher-role   { order: 6; }
.woocommerce #customer_login form.register .ahpa-field--org-name          { order: 7; }
.woocommerce #customer_login form.register .ahpa-field--nmi               { order: 8; }
.woocommerce #customer_login form.register > p.woocommerce-form-row:nth-of-type(2) { order: 9; grid-column: 1; }
.woocommerce #customer_login form.register .ahpa-field--confirm-password { order: 10; grid-column: 2; }
.woocommerce #customer_login form.register .ahpa-field--consent    { order: 11; }
.woocommerce #customer_login form.register .woocommerce-privacy-policy-text { order: 12; }
.woocommerce #customer_login form.register > p.woocommerce-form-row:last-of-type { order: 13; }

.woocommerce #customer_login form.register .ahpa-field { margin: 0 !important; }

.woocommerce #customer_login .ahpa-field select {
  width: 100%;
  box-sizing: border-box;
  /* Explicit background required: without it Chrome paints the closed select
     using the selected option's colour, turning the field white. */
  background-color: #1b1a20;
  color: #ffffff;
}

/* The dropdown popup is drawn by the OS on a light background, so inheriting
   the theme's white text renders it white-on-white. Dark text on white is the
   one pairing that stays legible even where a browser ignores option colours. */
.woocommerce #customer_login .ahpa-field select option {
  color: #111827;
  background-color: #ffffff;
}

.woocommerce #customer_login .ahpa-hint {
  display: block;
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.5;
  opacity: .66;
}

/* The NMI field is conditional; [hidden] must beat the grid display. */
.woocommerce #customer_login .ahpa-field--nmi[hidden] {
  display: none !important;
}

.woocommerce #customer_login .ahpa-field--nmi {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(155, 77, 255, .32);
  background: rgba(155, 77, 255, .09);
}

.woocommerce #customer_login .ahpa-consent {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin: 0 !important;
  font-size: 13px;
  line-height: 1.55;
  cursor: pointer;
}

.woocommerce #customer_login .ahpa-consent input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: #9b4dff;
  cursor: pointer;
}

@media (max-width: 620px) {
  .woocommerce #customer_login form.register {
    grid-template-columns: minmax(0, 1fr);
  }

  .woocommerce #customer_login form.register .ahpa-field--first-name,
  .woocommerce #customer_login form.register .ahpa-field--last-name,
  .woocommerce #customer_login form.register > p.woocommerce-form-row:nth-of-type(2),
  .woocommerce #customer_login form.register .ahpa-field--confirm-password {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .woocommerce #customer_login,
  .woocommerce-page #customer_login {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 20px !important;
  }

  .woocommerce #customer_login > .u-column1 { grid-column: 1; grid-row: 1; }
  .woocommerce #customer_login > .u-column2 { grid-column: 1; grid-row: 2; }
}
