@layer tokens, base, components, utilities;

/* --------------------------------------
   PRICING TEXT REFINEMENTS

   More subtle, refined typography for pricing
   Using existing design tokens for consistency
-------------------------------------- */
@layer components {

  /* Primary pricing display refinements */
  .st-price-origin .price .item {
    font-family: var(--font-body, system-ui, -apple-system, "Segoe UI", Arial);
    font-size: var(--fs-body, 16px);
    font-weight: var(--weight-medium, 500);
    line-height: var(--lh-snug, 1.2);
    color: var(--color-heading, #111827);
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
  }

  /* Header price context - slightly larger but still refined */
  .widget-section .st-price-origin .price .item {
    font-size: var(--fs-h4, 16px);
    font-weight: var(--weight-semibold, 600);
  }

  /* Total section - keep readable but not heavy */
  .total-section .st-price-origin .price .item {
    font-size: var(--fs-body, 16px);
    font-weight: var(--weight-medium, 500);
    color: var(--color-heading, #111827);
  }

  /* Sticky mobile CTA - smaller, more integrated */
  .sticky-mobile-cta .st-price-origin .price .item {
    font-size: var(--fs-sm, 14px);
    font-weight: var(--weight-semibold, 600);
    color: var(--color-surface, #ffffff);
  }

  /* Override utility classes to use design tokens - scoped to price context */
  .st-price-origin .price .text-lg {
    font-size: var(--fs-body, 16px);
    font-weight: var(--weight-medium, 500);
  }

  /* Responsive refinements - keep sizes smaller across breakpoints */
  @media (max-width: 768px) {
    .st-price-origin .price .item {
      font-size: var(--fs-sm, 14px);
    }

    .widget-section .st-price-origin .price .item {
      font-size: var(--fs-body, 16px);
    }

    .total-section .st-price-origin .price .item {
      font-size: var(--fs-sm, 14px);
    }
  }

  /* Tabular nums now included in main .st-price-origin .price .item rule above */


  /* Centered help link directly below Book Now button */
  .booking-help-link-centered {
    display: inline-block;
    font-size: var(--fs-sm, 14px);
    font-weight: var(--weight-regular, 400);
    color: var(--color-heading, #111827);
    text-decoration: underline;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
  }

  .booking-help-link-centered:hover,
  .booking-help-link-centered:focus {
    color: var(--color-heading, #111827);
    text-decoration: underline;
    opacity: 0.7;
  }

  .booking-help-link-centered:visited {
    color: var(--color-heading, #111827);
  }


  /* Enhanced focus state for accessibility */
  .booking-help-link-centered:focus-visible {
    outline: 2px solid var(--color-info); /* Blue focus ring */
    outline-offset: 2px;
    border-radius: 2px;
  }

  /* State-based CTA improvements */
  .btn-primary-cta {
    min-height: 48px; /* Better tapability */
    transition: all 0.2s ease;
    position: relative;
  }

  /* Disabled state styling */
  .btn-primary-cta:disabled,
  .btn-primary-cta[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: var(--color-border, #e5e7eb);
    border-color: var(--color-border, #e5e7eb);
    color: var(--color-muted, #6b7280);
  }

  /* Enabled state - full color and contrast */
  .btn-primary-cta:not(:disabled):not([aria-disabled="true"]) {
    opacity: 1;
    cursor: pointer;
  }

  /* Loading state styling */
  .btn-primary-cta[aria-busy="true"] {
    cursor: wait;
    position: relative;
  }

  /* Muted disabled state for Book Now button (keep brand hue, de-emphasized) */
  #book-now-btn:disabled,
  #book-now-btn[aria-disabled="true"] {
    background-color: var(--brand-primary-disabled, #8495d8);
    border-color: var(--brand-primary-disabled-border, #788ad2);
    color: var(--color-surface, #ffffff);
    opacity: 1; /* intentional override of global disabled opacity */
    cursor: not-allowed;
  }

  /* Microcopy under CTA */
  .cta-microcopy {
    margin-top: var(--space-xs); /* 8px from tokens */
    text-align: center;
  }

  .trust-signal {
    font-size: var(--fs-xs); /* 12px */
    font-weight: var(--weight-regular); /* 400 */
    color: var(--color-muted); /* #6b7280 - muted text */
    line-height: var(--lh-snug); /* 1.2 */
  }

  /* Ensure proper spacing between microcopy and trust bullets */
  .cta-microcopy + .checkout-trust {
    margin-top: var(--space-sm) !important; /* 12px gap */
  }

  /* Button ready state animation */
  .btn-primary-cta.btn-ready {
    animation: buttonReady 0.6s ease-out;
  }

  @media (prefers-reduced-motion: reduce) {
    .btn-primary-cta.btn-ready {
      animation: none;
    }
  }

  @keyframes buttonReady {
    0% {
      transform: scale(1);
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    50% {
      transform: scale(1.02);
      box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    }
    100% {
      transform: scale(1);
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
  }

  /* Booking actions section styling */
  .booking-actions {
    padding: 15px;
    background-color: var(--color-surface, #ffffff);
  }

  /* Ensure booking actions section background is white */
  #booking-actions {
    background: var(--color-surface, #ffffff);
  }

  /* Guest selection now uses .date-picker-button class from flatpickr-modern.css */

  /* Two-line hierarchy for guest display - prevents orphaned text wrapping */
  .guest-display-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    width: 100%;
  }

  .guest-primary {
    font-weight: var(--weight-semibold, 600);
    line-height: 1.1;
    color: var(--color-heading, #111827);
  }

  .guest-secondary {
    font-size: var(--fs-sm, 14px);
    color: var(--color-muted, #6b7280);
    line-height: 1.2;
    margin-top: 2px;
  }

  /* Mobile optimization */
  @media (max-width: 420px) {
    .guest-secondary {
      font-size: 0.8125rem; /* 13px on mobile */
    }
  }

  /* When no guests selected, keep left alignment to match date field */
  .guest-display-container:has(.guest-secondary.d-none) {
    align-items: flex-start;
    justify-content: center;
  }

  .guest-display-container:has(.guest-secondary.d-none) .guest-primary {
    color: var(--color-muted, #6b7280);
    font-weight: var(--weight-regular, 400);
  }

  /* CSS class fallback for :has() selector compatibility */
  .guest-display-container.guest-single-line {
    align-items: flex-start;
    justify-content: center;
  }

  .guest-display-container.guest-single-line .guest-primary {
    color: var(--color-muted, #6b7280);
    font-weight: var(--weight-regular, 400);
  }

  /* Guest counters in popover - match trigger button width exactly */
  .guest-counters {
    width: 100%;
    max-width: 100%;
    padding: 12px;
    box-sizing: border-box;
  }

  /* Use CSS custom property to match exact trigger width */
  .booking-widget-instant .popover.guest-popover {
    width: var(--trigger-width, auto);
    min-width: var(--trigger-width, 280px);
    max-width: var(--trigger-width, none);
    border: 1px solid var(--color-border, #e5e7eb);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    z-index: 1060;
  }

  .booking-widget-instant .popover.guest-popover .popover-body {
    padding: 0.5rem;
    color: #212529;
  }

  .guest-counters .counter-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
  }

  .guest-counters .counter-row:first-child {
    padding-top: 4px; /* Less space at top */
  }

  .guest-counters .counter-row:last-child {
    border-bottom: none;
    padding-bottom: 4px; /* Less space at bottom */
  }

  .guest-counters .counter-info {
    flex: 1;
  }

  .guest-counters .counter-label {
    font-size: var(--fs-body); /* 16px */
    font-weight: var(--weight-medium); /* 500 */
    color: var(--color-heading);
    margin-bottom: 2px;
  }

  .guest-counters .counter-sublabel {
    font-size: var(--fs-sm); /* 14px */
    color: var(--color-muted);
  }

  .guest-counters .counter-controls {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .guest-counters .counter-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 50%;
    background: var(--color-surface, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--color-muted, #6b7280);
  }

  .guest-counters .counter-btn:hover {
    border-color: #007cba;
    color: #007cba;
  }

  .guest-counters .counter-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background-color: #f9fafb;
    border-color: #f0f0f0;
    color: #d1d5db;
  }

  /* Show disabled minus buttons but make them visually inactive */
  .guest-counters .counter-btn.counter-minus:disabled {
    visibility: visible; /* Ensure minus buttons are always visible */
  }

  .guest-counters .counter-display {
    font-size: var(--fs-body);
    font-weight: var(--weight-medium);
    color: var(--color-heading);
    min-width: 24px;
    text-align: center;
  }

  /* Popover styling consolidated above */

  /* Guest popover footer */
  .guest-popover-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-top: 1px solid #f0f0f0;
    background: #fff;
  }

  .guest-popover-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs, 8px);
    background: transparent;
    border: none;
    color: #2563eb;
    font-size: var(--fs-sm, 14px);
    font-weight: var(--weight-medium, 500);
    text-decoration: underline;
    cursor: pointer;
    padding: 4px 8px;
    margin: 0;
    transition: color 0.2s ease, transform 0.2s ease;
  }

  .guest-popover-close:hover,
  .guest-popover-close:focus {
    color: #1d4ed8;
    outline: none;
    text-decoration: underline;
  }

  .guest-popover-close:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
  }

  /* Force bottom arrow styling for guest popover */
  .booking-widget-instant .popover.bs-popover-bottom .popover-arrow::before {
    border-bottom-color: var(--color-border, #e5e7eb);
  }

  .booking-widget-instant .popover.bs-popover-bottom .popover-arrow::after {
    border-bottom-color: var(--color-surface, #ffffff);
  }

  /* Ensure popover appears below trigger */
  /* Removed forced fixed positioning; let Popper manage placement */

  /* Widget container overflow fix for popover */
  .booking-widget-instant {
    overflow: visible !important;
  }

  .booking-widget-instant .widget-card {
    overflow: visible !important;
    position: relative;
    z-index: 1;
  }

  /* Z-index now handled in consolidated popover rule above */

  /* Screen reader only content */
  .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  /* Focus management for popover counters */
  .guest-counters .counter-btn:focus {
    outline: 2px solid var(--color-info);
    outline-offset: 2px;
    z-index: 1;
  }

  /* Keyboard navigation improvements */
  .popover[role="dialog"] {
    outline: none;
  }

  .popover[role="dialog"]:focus-within {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  /* Mobile specific adjustments */
  @media (max-width: 767px) {
    .guest-counters {
      width: 100%;
      max-width: 100%;
      min-width: 0;
    }

    /* On mobile, use full-width placement */
    .guest-selector-trigger ~ .popover {
      max-width: calc(100vw - 16px) !important;
    }
  }
}
