/*
*   Styles for AutomaticFFL Checkout
*/

.dealers-container {
  width: 70%;
  height: 70%;
  background-color: #ffffff;
  border-radius: 6px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  display: block;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

#automaticffl-map-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.automaticffl-dealer-layer {
  width: 100%;
  z-index: 1000;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #000;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease-out, visibility 200ms ease-out;
}

.automaticffl-dealer-layer.visible {
  opacity: 1;
  visibility: visible;
}

.automaticffl-dealer-selected {
  border: solid 2px #522a74;
  padding: 20px 20px 0px 20px;
  margin-bottom: 2.617924em;
  border-left: 0.6180469716em solid #522a74;
  color: #333333;
  border-radius: 2px;
}

.automaticffl-dealer-selected a {
  color: #333333;
}

/* Hide templates and hidden fields */
#automaticffl-dealer-card-template,
.hidden {
  display: none;
}

.dealer-phone {
  color: #512a74;
  margin: 0;
}
@media screen and (max-width: 800px) {
  .dealers-container {
    width: 96%;
    height: 90%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    border-radius: 6px;
  }
  .automaticffl-dealer-layer {
    z-index: 10000;
  }
}

#automaticffl-select-dealer {
  margin-bottom: 15px;
}

#automaticffl-select-dealer svg {
  display: inline-block;
  vertical-align: middle;
}

/* FFL-298 this prevents the scroll bar from taking up space inside the html */
body {
  margin-right: calc(-1 * (100vw - 100%)) !important;
}

/*
 * Block Checkout Styles - FFL Dealer Selection
 */

/*
 * FR-4: Hide non-name shipping fields whenever an FFL is required.
 *
 * The body class .automaticffl-ffl-required is added by the
 * dealer-selection child block whenever an FFL is required for the
 * cart (firearm present, or ammo bound for a restricted state).
 * Applied always — whether or not a dealer has been picked — so the
 * Edit-mode form behaves identically before and after selection.
 *
 * Pre-pick:  cart shipping is the customer's saved address. Edit
 *            shows only first/last name; other fields can't be
 *            changed because the FFL pick will overwrite them.
 * Post-pick: cart shipping is the dealer's address. Edit shows only
 *            first/last name so the customer can fix typos without
 *            losing the dealer-set fields.
 *
 * Selectors target stable HTML attributes (input name + element id)
 * — not WooCommerce's internal .wc-block-components-* class names —
 * to stay NFR-1 doc-clean. WC Blocks renders shipping fields with:
 *   - text inputs:  name="shipping_<field>", id="shipping-<field>"
 *   - state/country selects: id="shipping-<field>" (no name attr)
 *
 * The text-input wrapper is one div deep (input is a direct child),
 * so :has(> input[...]) matches the wrapper. The select wrapper is
 * two divs deep (select inside .wc-blocks-components-select__container
 * inside .wc-blocks-components-select), so :has(> div > select[...])
 * targets the outer wrapper.
 *
 * first_name and last_name are intentionally NOT in the list — those
 * stay editable so the customer can correct typos at any time.
 *
 * :has() browser support: Safari 15.4+ (Mar 2022), Chrome 105+
 * (Aug 2022), Firefox 121+ (Dec 2023). Within WC Blocks' modern
 * baseline.
 */
body.automaticffl-ffl-required div:has(> input[name="shipping_address_1"]),
body.automaticffl-ffl-required div:has(> input[name="shipping_address_2"]),
body.automaticffl-ffl-required div:has(> input[name="shipping_city"]),
body.automaticffl-ffl-required div:has(> input[name="shipping_postcode"]),
body.automaticffl-ffl-required div:has(> input[name="shipping_phone"]),
body.automaticffl-ffl-required div:has(> input[name="shipping_company"]),
body.automaticffl-ffl-required div:has(> div > select#shipping-state),
body.automaticffl-ffl-required div:has(> div > select#shipping-country),
body.automaticffl-ffl-required div:has(> div > input#shipping-state),
body.automaticffl-ffl-required div:has(> div > input#shipping-country) {
  display: none !important;
}

/*
 * FR-4: hide the "Use same address for billing" toggle when an FFL
 * is required. Billing CAN'T equal shipping when shipping goes to a
 * licensed dealer — the dealer isn't the customer's billing party.
 * Our handleDealerSelect flips the toggle state off programmatically;
 * this rule hides it from the UI so the customer can't re-enable a
 * setting that no longer makes sense.
 *
 * Targets the toggle wrapper structurally: the only <input
 * type="checkbox"> inside the shipping-fields fieldset is this one
 * (verified live 2026-04). NFR-1 doc-clean — uses the fieldset id +
 * native HTML <input type="checkbox">, no .wc-block-components-* or
 * .wp-block-woocommerce-* class names. As of 2026-04 WooCommerce
 * Blocks ships no documented filter, slot fill, or block attribute
 * for hiding this toggle per-cart-context.
 */
body.automaticffl-ffl-required #shipping-fields div:has(> label > input[type="checkbox"]) {
  display: none !important;
}

/*
 * FR-4 (backup): visually-disabled state for non-name shipping fields
 * when an FFL is required. Acts as a safety net if the :has() hide
 * rules above ever miss — e.g. browser predates :has() support, or a
 * WC Blocks DOM change breaks the wrapper selector. The fields stay
 * rendered but become non-interactive and clearly read-only.
 *
 * Cannot set the actual `disabled` attribute from CSS, so we use
 * pointer-events + visual cues. The hide rules above take precedence
 * when they match (display:none beats this).
 */
body.automaticffl-ffl-required input[name^="shipping_"]:not([name="shipping_first_name"]):not([name="shipping_last_name"]),
body.automaticffl-ffl-required select[id^="shipping-"]:not([id="shipping-first_name"]):not([id="shipping-last_name"]) {
  pointer-events: none !important;
  background-color: #f5f5f5 !important;
  color: #999 !important;
  cursor: not-allowed !important;
  opacity: 0.6 !important;
}

/* FFL Dealer Selection component styling for blocks checkout */
.automaticffl-dealer-selection {
  margin-bottom: 1.5em;
}

/* Find/Change Dealer button styling */
.automaticffl-dealer-selection .ffl-search-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background-color: #333333;
  color: #ffffff;
  padding: 12px 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 200ms ease;
}

.automaticffl-dealer-selection .ffl-search-button:hover {
  background-color: #444444;
}

.automaticffl-dealer-selection .ffl-search-button svg {
  flex-shrink: 0;
}

/* Selected dealer card for blocks checkout */
.automaticffl-dealer-selection .automaticffl-dealer-selected {
  margin-bottom: 1em;
}

/*
 * State Selector Styles - Ammo Checkout
 */

/* Classic checkout state selector */
#automaticffl-ammo-checkout {
  margin-bottom: 2em;
}

#automaticffl-ammo-checkout h3 {
  margin-bottom: 1em;
}

#automaticffl-state-selector {
  width: 100%;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background-color: #fff;
}

#automaticffl-state-selector:focus {
  border-color: #522a74;
  outline: none;
  box-shadow: 0 0 0 2px rgba(82, 42, 116, 0.2);
}

#automaticffl-state-message {
  margin-top: 15px;
  margin-bottom: 15px;
}

.automaticffl-state-restricted .woocommerce-error,
.automaticffl-state-allowed .woocommerce-message {
  margin-bottom: 0;
}

#automaticffl-ffl-container {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

/* Block checkout state selector */
.automaticffl-state-selector {
  margin-bottom: 1.5em;
}

.automaticffl-state-selector h3 {
  margin-bottom: 0.75em;
  font-size: 1.1em;
}

.automaticffl-state-select-wrapper {
  margin: 1em 0;
}

.automaticffl-state-select-wrapper label {
  display: block;
  margin-bottom: 0.5em;
  font-weight: 500;
}

.automaticffl-state-select-wrapper select {
  width: 100%;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background-color: #fff;
}

.automaticffl-state-select-wrapper select:focus {
  border-color: #522a74;
  outline: none;
  box-shadow: 0 0 0 2px rgba(82, 42, 116, 0.2);
}

.automaticffl-state-message {
  margin-top: 1em;
}

/* Ammo checkout container in block checkout */
.automaticffl-dealer-selection .automaticffl-state-selector {
  margin-bottom: 1.5em;
  padding-bottom: 1em;
  border-bottom: 1px solid #e0e0e0;
}

/*
 * API Unavailable Notice Styles
 */

.automaticffl-unavailable-notice {
  margin-bottom: 1.5em;
}

.automaticffl-unavailable-message {
  text-align: center;
}

.automaticffl-unavailable-message p {
  margin: 0 0 0.5em 0;
}

.automaticffl-unavailable-message p:last-of-type {
  margin-bottom: 1em;
}

.automaticffl-unavailable-message button {
  margin-top: 0.5em;
}

/* Classic checkout unavailable notice */
#automaticffl-unavailable-notice .woocommerce-info {
  text-align: center;
  padding: 20px;
}

#automaticffl-unavailable-notice .woocommerce-info p {
  margin: 0 0 0.5em 0;
}

#automaticffl-unavailable-notice .woocommerce-info button {
  margin-top: 10px;
}

/*
 * Ammo-Only Checkout - Shipping Form Visibility Transitions
 *
 * Classic-checkout transitions only. The block checkout transitions
 * targeted private WC classes (.wp-block-woocommerce-* and
 * .wc-block-checkout__*) and were removed for NFR-1 compliance —
 * the FFL child block now manages its own visibility within the
 * shipping address area.
 */
.woocommerce-shipping-fields,
#ship-to-different-address,
.woocommerce-shipping-fields__field-wrapper {
  transition: opacity 0.15s ease-in-out;
}

/*
 * Standardized Notice Banners - Cart Page
 * Used for both firearms and ammo mixed cart notices
 */

/* Base notice styles */
.automaticffl-notice {
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start !important;
  gap: 12px !important;
  margin-bottom: 2em;
  padding: 1em 1.5em;
  border-radius: 4px;
  background: #f9f9f9;
  color: #515151;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Checkout ammo+regular notice: hidden by default, shown via JS class toggle */
#automaticffl-ammo-regular-message {
  display: none !important;
}

#automaticffl-ammo-regular-message.is-visible {
  display: flex !important;
}

/* Notice icon */
.automaticffl-notice-icon {
  flex-shrink: 0 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-top: 2px;
}

.automaticffl-notice-icon svg {
  display: block;
  width: 24px;
  height: 24px;
}

/* Notice content */
.automaticffl-notice-content {
  flex: 1 1 auto !important;
  min-width: 0;
}

/* Notice message */
.automaticffl-notice-message {
  margin: 0 0 0.5em 0;
  padding: 0;
  font-weight: 600;
  color: #515151;
}

/* Error state */
.automaticffl-notice-error {
  border-top: 3px solid #b81c23;
}

.automaticffl-notice-error .automaticffl-notice-icon {
  color: #b81c23;
}

/* Success state */
.automaticffl-notice-success {
  border-top: 3px solid #4a7c0f;
}

.automaticffl-notice-success .automaticffl-notice-icon {
  color: #4a7c0f;
}

/* Info state */
.automaticffl-notice-info {
  border-top: 3px solid #1e85be;
}

.automaticffl-notice-info .automaticffl-notice-icon {
  color: #1e85be;
}

.automaticffl-state-row {
  margin-bottom: 15px;
}

.automaticffl-state-row label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.automaticffl-state-row abbr.required {
  text-decoration: none;
  border: none;
  color: #b81c23;
  cursor: default;
}

#automaticffl-cart-state-select {
  width: 100%;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background-color: #fff;
}

#automaticffl-cart-state-select:focus {
  border-color: #522a74;
  outline: none;
  box-shadow: 0 0 0 2px rgba(82, 42, 116, 0.2);
}

/* Ammo + Regular allowed state styling for blocks */
.automaticffl-ammo-regular-allowed {
  margin-bottom: 1.5em;
}

/*
 * Save for Later - Mixed Cart Feature
 */

/* Save for later section within notice */
.automaticffl-notice .automaticffl-save-prompt {
  margin: 0.75em 0 0.5em 0;
  padding-top: 0.75em;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 500;
  font-size: 14px;
  color: #515151;
}

.automaticffl-save-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 0;
}

/* Primary button (FFL items) */
.automaticffl-notice .automaticffl-save-btn {
  flex: 1;
  max-width: 220px;
  min-width: auto;
  padding: 10px 20px;
  background-color: #b81c23;
  color: #ffffff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  text-align: center;
  transition: background-color 150ms ease;
}

.automaticffl-notice .automaticffl-save-btn:hover {
  background-color: #961720;
  color: #ffffff;
}

.automaticffl-notice .automaticffl-save-btn:focus {
  outline: 2px solid #522a74;
  outline-offset: 2px;
}

/* Secondary button (Regular items) */
.automaticffl-notice .automaticffl-save-btn[data-item-type="regular"] {
  background-color: #f7f6f7;
  color: #515151;
  border: 1px solid #ccc;
}

.automaticffl-notice .automaticffl-save-btn[data-item-type="regular"]:hover {
  background-color: #eee;
  border-color: #999;
  color: #515151;
}

.automaticffl-notice .automaticffl-save-btn:disabled,
.automaticffl-notice .automaticffl-save-btn.loading {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Helper text for save for later */
.automaticffl-notice .automaticffl-save-help {
  margin: 0.75em 0 0 0;
  padding: 0;
  font-size: 13px;
  color: #666;
  font-style: italic;
}

/* Error message for save failures */
#automaticffl-save-error {
  margin-bottom: 10px;
}

/* Thank you page redirect notice */
.automaticffl-redirect-notice.automaticffl-notice {
  margin-bottom: 2em;
}

.automaticffl-countdown {
  font-weight: bold;
  font-size: 1.1em;
  color: #1e85be;
  margin: 0 3px;
}

.automaticffl-redirect-action {
  margin: 0.75em 0 0 0;
}

.automaticffl-redirect-action .button {
  display: inline-block;
  background-color: #333333;
  color: #ffffff;
  padding: 10px 20px;
  border: none;
  border-radius: 3px;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}

.automaticffl-redirect-action .button:hover {
  background-color: #444444;
  color: #ffffff;
}

/* Responsive adjustments */
@media screen and (max-width: 600px) {
  .automaticffl-save-buttons {
    flex-direction: column;
    align-items: flex-start;
  }

  .automaticffl-save-btn {
    width: 100%;
  }
}

/*
 * Blocks Checkout - Save for Later
 */

.automaticffl-blocks-save-for-later {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.automaticffl-blocks-save-prompt {
  margin-bottom: 12px;
  font-weight: 500;
}

.automaticffl-blocks-save-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.automaticffl-blocks-save-btn {
  flex: 1;
  min-width: 180px;
}

/* Primary button (FFL items) - uses default dark style */
.automaticffl-blocks-save-btn--primary {
  background-color: #333333;
  color: #ffffff;
}

.automaticffl-blocks-save-btn--primary:hover {
  background-color: #444444;
  color: #ffffff;
}

/* Secondary button (Regular items) - lighter style */
.automaticffl-blocks-save-btn--secondary {
  background-color: #f7f6f7;
  color: #515151;
  border: 1px solid #ccc;
}

.automaticffl-blocks-save-btn--secondary:hover {
  background-color: #eee;
  border-color: #999;
  color: #515151;
}

.automaticffl-blocks-save-help {
  margin: 0;
  font-size: 13px;
  color: #666;
  font-style: italic;
}

