/* Checkout layout */
.checkout-layout {
  align-items: start;
  display: grid;
  gap: var(--space-10);
  grid-template-columns: 1fr;
}

@media (width >= 900px) {
  .checkout-layout {
    grid-template-columns: 1fr 360px;
  }
}

/* Error summary — GDS-style
 *
 * role="alert" causes screen readers to announce the contents immediately
 * when the element is un-hidden. This is the correct mechanism for
 * surfacing form errors — the user doesn't need to search for them.
 *
 * The summary is also given tabindex="-1" so focus can be programmatically
 * moved to it after validation fires. Keyboard users land at the top of
 * the error list and can Tab through the links to each invalid field.
 *
 * Discussed in:
 *   Section 6, Chapter 8 — Forms and validation (error summary pattern)
 *   Section 6, Chapter 12 — Live regions and error announcement (role="alert")
 *   Section 6, Chapter 9 — Keyboard navigation and focus (tabindex="-1", programmatic focus)
 */
.error-summary {
  background: var(--color-error-bg);
  border: 2px solid var(--color-error);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-8);
  padding: var(--space-5) var(--space-6);
}

.error-summary:focus {
  /* Inset (negative) offset, not outside the box — see base.css's
     :focus-visible rule for why. */
  outline: 3px solid var(--color-error);
  outline-offset: -3px;
}

.error-summary h2 {
  color: var(--color-error);
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.error-summary > p {
  color: var(--color-text);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}

.error-summary ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.error-summary li {
  margin-bottom: var(--space-1);
}

.error-summary a {
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: 600;
}

.error-summary a:focus-visible {
  outline-color: var(--color-error);
}

/* Form sections */
.checkout-form fieldset {
  border: none;
  margin: 0 0 var(--space-8);
  padding: 0;
}

.checkout-form legend {
  border-bottom: 2px solid var(--color-border);
  color: var(--color-brand-text);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--space-5);
  padding: 0;
  padding-bottom: var(--space-3);
  width: 100%;
}

/* Two-column field rows */
.field-row {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr 1fr;
}

@media (width <= 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

/* Error state on form group */
.form-group.has-error label {
  color: var(--color-error);
}

.form-group.has-error input,
.form-group.has-error select {
  border-color: var(--color-error);
  border-width: 2px;
}

.form-group.has-error input:focus,
.form-group.has-error select:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-error) 20%, transparent);
}

/* Optional label suffix */
.field-optional {
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 400;
  margin-left: var(--space-2);
}

/* Card number input group */
.card-input-wrapper {
  position: relative;
}

.card-input-wrapper input {
  padding-right: 5.5rem;
}

.card-brands {
  align-items: center;
  display: flex;
  gap: var(--space-2);
  pointer-events: none;
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
}

.card-brand {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 1px 4px;
}

/* Submit section */
.checkout-submit {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.checkout-submit .btn {
  font-size: var(--text-lg);
  justify-content: center;
  padding: var(--space-4) var(--space-6);
  width: 100%;
}

.checkout-security {
  align-items: center;
  color: var(--color-muted);
  display: flex;
  font-size: var(--text-xs);
  gap: var(--space-2);
  justify-content: center;
}

/* Order summary card */
.order-summary {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.order-summary-header {
  background: var(--color-brand);
  color: var(--color-white);
  padding: var(--space-5) var(--space-6);
}

.order-summary-header h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.order-summary-header p {
  color: rgb(255 255 255 / 70%);
  font-size: var(--text-sm);
  font-style: italic;
}

.order-summary-body {
  padding: var(--space-5) var(--space-6);
}

.order-line {
  align-items: baseline;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  font-size: var(--text-sm);
  gap: var(--space-4);
  justify-content: space-between;
  padding: var(--space-3) 0;
}

.order-line:last-of-type {
  border-bottom: none;
}

.order-line-label {
  color: var(--color-muted);
}

.order-line-value {
  font-weight: 600;
}

.order-line-promo .order-line-label {
  color: var(--color-success);
}

.order-line-promo .order-line-value {
  color: var(--color-success);
  font-weight: 700;
}

.order-total {
  align-items: baseline;
  display: flex;
  font-size: var(--text-lg);
  font-weight: 800;
  gap: var(--space-4);
  justify-content: space-between;
  padding: var(--space-4) 0 0;
}

.order-total-label {
  color: var(--color-text);
}

.order-total-value {
  color: var(--color-brand-text);
  font-size: var(--text-2xl);
}

.order-summary-footer {
  padding: 0 var(--space-6) var(--space-5);
}

.order-summary-footer p {
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
  margin-top: var(--space-2);
}

/* Success state */
.checkout-success {
  margin: 0 auto;
  max-width: 500px;
  padding: var(--space-16) var(--space-8);
  text-align: center;
}

.success-icon {
  align-items: center;
  background: var(--color-success-bg);
  border-radius: 50%;
  color: var(--color-success);
  display: flex;
  height: 64px;
  justify-content: center;
  margin: 0 auto var(--space-6);
  width: 64px;
}

.checkout-success h1 {
  color: var(--color-brand-text);
  margin-bottom: var(--space-4);
}

.checkout-success p {
  color: var(--color-muted);
  margin-bottom: var(--space-6);
}

.success-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: center;
}
