/* Group Modal Base Styles */
.group-modal {
    --modal-primary: #2563eb;
    --modal-primary-hover: #1d4ed8;
    --modal-success: #059669;
    --modal-error: #dc2626;
    --modal-surface: #ffffff;
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --modal-border: #e5e7eb;
    --modal-text: #111827;
    --modal-text-muted: #6b7280;
    --modal-radius: 16px;
    --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.group-modal.active {
    display: flex;
}

.group-modal.closing {
    pointer-events: none;
}

.group-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-overlay);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.group-modal-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.group-modal-content {
    background: var(--modal-surface);
    border-radius: var(--modal-radius);
    box-shadow: var(--modal-shadow);
    display: flex;
    flex-direction: column;
    max-height: 100%;
    overflow: hidden;
}

/* Modal Header */
.group-modal-header {
    padding: var(--space-md); /* 16px all around */
    border-bottom: 1px solid var(--modal-border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 56px; /* Consistent height */
}

.modal-handle {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--modal-border);
    border-radius: 2px;
}

.modal-title {
    font-family: var(--font-display);
    font-size: var(--fs-body); /* 16px */
    font-weight: var(--weight-semibold); /* 600 */
    color: var(--color-heading);
    margin: 0;
    line-height: var(--lh-body); /* 1.6 */
    text-align: center;
    /* Title is centered by the flex container */
}


.modal-close {
    position: absolute;
    left: var(--space-sm); /* 12px from left edge */
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: var(--space-xs); /* 8px padding */
    cursor: pointer;
    border-radius: 6px;
    color: var(--color-muted);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-body);
}

.modal-close:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: 2px;
}

/* Step Progress Indicator */
.step-progress {
    margin-bottom: var(--space-xs); /* 8px - reduced from 1rem */
    padding: 0 1rem;
}

.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    flex: none;
    position: relative;
}

.step-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--modal-border);
    color: var(--modal-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    transition: all 0.3s ease;
}

.step.active .step-number {
    background: var(--modal-primary);
    color: white;
}

.step.completed .step-number {
    background: var(--modal-success);
    color: white;
}

.step-label {
    font-size: 12px;
    color: var(--modal-text-muted);
}

.step-connector {
    width: calc(100% - 24px);
    height: 2px;
    background: var(--modal-border);
    margin: 0 8px;
    position: relative;
    top: -12px;
    max-width: 60px;
}

/* Modal Body */
.group-modal-body {
    padding: var(--space-md) var(--space-md) var(--space-sm); /* 16px top/sides, 12px bottom */
    overflow-y: auto;
    flex: 1;
}

.form-intro {
    margin-bottom: var(--space-sm); /* 12px - reduced from 1rem */
    padding: 0;
    display: block;
    background: none;
    border: none;
    text-align: center;
}

.form-intro::before {
    display: none; /* Remove old-school emoji icon */
}

.form-intro p {
    margin: 0;
    color: var(--modal-text-muted);
    line-height: 1.4; /* Tighter line height */
    font-size: var(--fs-small); /* 14px - using token */
}

/* Form Steps */
.form-step {
    display: none;
}

.form-step.active {
    display: block;
}

/* Form Sections */
.form-section {
    border: none;
    margin: 0 0 var(--space-md) 0; /* 16px - reduced from 1.25rem */
    padding: 0;
}

.section-title {
    font-size: var(--fs-body); /* 16px - reduced from 1.125rem */
    font-weight: var(--weight-semibold);
    color: var(--modal-text);
    margin: 0 0 var(--space-xs) 0; /* 8px - reduced from 0.75rem */
    padding-bottom: 0;
    border-bottom: none;
}

.form-grid {
    display: grid;
    gap: var(--space-xs); /* 8px - tighter spacing */
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-sm); /* 12px */
    }
    
    .form-field.full-width {
        grid-column: 1 / -1;
    }
}

/* Form Fields */
.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px; /* Very tight gap between label and input */
}

.field-label {
    font-weight: var(--weight-medium); /* 500 - less prominent */
    color: var(--modal-text);
    font-size: var(--fs-small); /* 14px */
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 2px; /* Minimal spacing */
}

.required {
    color: var(--modal-error);
    font-weight: 700;
}

.optional {
    color: var(--modal-text-muted);
    font-weight: 400;
    font-size: 0.8em;
}

.field-input,
.field-select {
    padding: var(--space-sm);
    border: 1px solid var(--modal-border);
    border-radius: var(--radius-md);
    font-size: 16px; /* Match tour component desktop */
    line-height: var(--lh-body);
    transition: all 0.2s ease;
    background: var(--modal-surface);
    color: var(--modal-text);
    min-height: 44px;
}

.field-textarea {
    padding: var(--space-sm);
    border: 1px solid var(--modal-border);
    border-radius: var(--radius-md);
    font-size: 16px; /* Match tour component desktop */
    line-height: var(--lh-body);
    transition: all 0.2s ease;
    background: var(--modal-surface);
    color: var(--modal-text);
    min-height: 80px;
    resize: none;
}

@media (max-width: 640px) {
    .field-input,
    .field-select,
    .field-textarea {
        font-size: 15px; /* Match tour component mobile */
        line-height: 1.5;
    }
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: -1px; /* Inside border for tighter layout */
    border-color: var(--modal-primary);
    box-shadow: none;
}

.field-input.error,
.field-select.error,
.field-textarea.error {
    border-color: var(--modal-error);
}

.field-help {
    font-size: 0.8rem;
    color: var(--modal-text-muted);
    margin-top: -0.25rem;
}

/* Subtle pickup location help text */
#pickup_location_help {
    font-size: 12px; /* Small but readable */
    color: #6b7280; /* Slightly darker for better contrast */
    margin-top: 0.25rem;
    font-weight: var(--weight-regular); /* Normal weight */
}

/* Pickup location subtext below input */
.pickup-location-subtext {
    font-size: 12px; /* Small but readable */
    color: #6b7280; /* Subtle gray */
    margin-top: 4px; /* Right below input */
    margin-bottom: 0;
    font-weight: var(--weight-regular);
    line-height: 1.3;
}

.field-error {
    font-size: 0.8rem;
    color: var(--modal-error);
    font-weight: 500;
    display: none;
}

.field-error.active {
    display: block;
}

/* Date Input Group - Inline Layout */
.date-input-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

@media (max-width: 767px) {
    .date-input-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
}

.date-flexible {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: none;
    border-radius: 6px;
    white-space: nowrap;
    margin-inline-start: auto;
}

@media (max-width: 767px) {
    .date-flexible {
        margin-inline-start: 0;
        justify-self: start;
    }
}

.checkbox-input {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--modal-primary);
}

.checkbox-label {
    font-size: 0.875rem;
    color: var(--modal-text-muted);
    cursor: pointer;
}

.date-input-group.flexible .date-input {
    opacity: 0.5;
    pointer-events: none;
}

.date-input {
    flex: 1;
    min-width: 140px;
}

/* Contact Preference Section */
.contact-preference-section {
    margin-top: var(--space-md);
}

.contact-toggle-group {
    display: flex;
    gap: var(--space-xs); /* 8px */
    margin-bottom: var(--space-sm);
}

.toggle-button {
    flex: 1;
    padding: var(--space-xs) var(--space-sm); /* 8px vertical, 12px horizontal */
    background: var(--modal-surface);
    color: var(--modal-text);
    border: 1px solid var(--modal-border);
    border-radius: var(--radius-md); /* 8px */
    font-size: var(--fs-small); /* 14px */
    font-weight: var(--weight-regular);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 40px;
    white-space: nowrap;
}

.toggle-button:hover:not(.active) {
    background: rgba(0, 0, 0, 0.02);
    border-color: #9ca3af;
}

.toggle-button.active {
    background: var(--modal-primary);
    color: white;
    border-color: var(--modal-primary);
    font-weight: var(--weight-medium);
}

.toggle-button:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: 2px;
}

/* Contact Details Section */
.contact-details-section {
    margin-top: var(--space-sm);
    transition: all 0.3s ease;
}

.contact-details-inner {
    padding: var(--space-sm);
    background: #f9fafb; /* Light gray background */
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.time-toggle-group {
    display: flex;
    gap: var(--space-xs);
}

.time-button {
    padding: 6px var(--space-sm);
    background: white;
    color: #374151; /* Gray-700 for better contrast */
    border: 1px solid var(--modal-border);
    border-radius: 20px; /* Pill shape */
    font-size: 14px; /* clearer label size */
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.time-button:hover:not(.active) {
    background: #f3f4f6;
}

.time-button.active {
    background: #d1fae5; /* emerald-100 */
    color: #065f46;      /* emerald-900 */
    border-color: #34d399; /* emerald-400 */
}

.time-button:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: 2px;
}

/* Phone input in contact details */
.contact-details-section .field-input {
    height: 40px; /* Slightly smaller in this context */
    font-size: var(--fs-small); /* 14px */
}

/* Expandable Section - Keep for any other expandable content */
.expandable-section {
    margin: var(--space-md) 0 0 0;
    border: 1px solid var(--modal-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(0, 0, 0, 0.02);
}

.expandable-trigger {
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: var(--weight-medium);
    color: var(--modal-text);
    transition: all 0.2s ease;
    list-style: none;
    border-bottom: none;
    min-height: 44px;
}

.expandable-trigger:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--modal-primary);
}

.expandable-trigger::after {
    content: '+';
    font-size: 1.2em;
    font-weight: var(--weight-regular);
    transition: transform 0.2s ease;
    color: var(--modal-text-muted);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.expandable-section[open] .expandable-trigger::after {
    content: '−';
    transform: none;
}

.expandable-content {
    padding: 0 var(--space-md) var(--space-md);
    border-top: 1px solid var(--modal-border);
    margin: 0;
    background: transparent;
}

/* Modal Footer with Step Navigation */
.group-modal-footer {
    padding: var(--space-md); /* 16px all around */
    border-top: 1px solid var(--modal-border);
    background: var(--modal-surface);
}

.step-navigation {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    align-items: stretch;
}

.nav-button {
    background: transparent;
    color: #6b7280; /* Subtle gray text */
    border: none;
    border-radius: 0;
    padding: 0;
    font-size: var(--fs-small); /* 14px */
    font-weight: var(--weight-regular);
    cursor: pointer;
    transition: color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: auto;
    text-decoration: none;
}

.nav-button svg {
    width: 16px;
    height: 16px;
}

.nav-button:hover:not(:disabled) {
    color: var(--modal-text);
    text-decoration: none;
}

.nav-button:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

.nav-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Navigation footer layout */
.footer-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    min-height: 24px; /* Maintain height even when previous button is hidden */
}

.prev-button {
    order: 1;
}

.prev-button svg {
    margin-right: 4px;
}

.footer-note {
    order: 2;
    margin-inline-start: auto;
    text-align: right;
}

.submit-button,
.primary-button {
    width: 100%;
    background: var(--modal-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg); /* 12px */
    padding: 0 var(--space-lg); /* Horizontal padding only */
    font-size: var(--fs-small); /* 14px to match mock */
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    height: 48px; /* Fixed height */
    position: relative;
}

.submit-button:hover:not(:disabled),
.primary-button:hover:not(:disabled) {
    background: var(--modal-primary-hover);
    transform: none;
}

.submit-button:focus,
.primary-button:focus {
    outline: 2px solid var(--modal-primary);
    outline-offset: 2px;
}

.submit-button:disabled,
.primary-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.submit-button.loading .button-text,
.primary-button.loading .button-text {
    opacity: 0;
}

.button-spinner {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    display: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.submit-button.loading .button-spinner,
.primary-button.loading .button-spinner {
    display: block;
}

.button-arrow {
    transition: transform 0.2s ease;
}

.submit-button.loading .button-arrow,
.primary-button.loading .button-arrow {
    display: none;
}

/* RTL icon mirroring */
:dir(rtl) .prev-button svg,
:dir(rtl) .next-button svg,
:dir(rtl) .button-arrow {
    transform: rotate(180deg);
}

.form-note,
.footer-note {
    margin: 0;
    font-size: 11px; /* Smaller for secondary info */
    color: #6b7280;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* Success Message */
.success-message {
    text-align: center;
    padding: 2rem 2rem;
}

.success-icon {
    color: var(--modal-success);
    margin-bottom: 1.5rem;
}

.success-message h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--modal-text);
    margin: 0 0 1rem 0;
}

.success-message p {
    color: var(--modal-text-muted);
    line-height: 1.6;
    margin: 0;
}

/* Small Screen Optimizations */
@media (max-width: 480px) {
    .group-modal {
        padding: 0.75rem;
        align-items: center;
        justify-content: center;
    }
    
    .group-modal-container {
        max-height: calc(100dvh - 24px);
        border-radius: var(--modal-radius);
    }
    
    .group-modal-content {
        border-radius: var(--modal-radius);
        max-height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .group-modal-body {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }
    
    .group-modal-header,
    .group-modal-footer {
        flex-shrink: 0;
    }
}

/* ===== Compact mode to reduce height without redesign ===== */
.group-modal.compact .group-modal-container {
    max-width: 568px;                /* slimmer look */
    max-height: 86vh;                /* leaves breathing room; helps avoid viewport scroll */
}

/* Header + stepper */
.group-modal.compact .group-modal-header { 
    padding: 10px 14px 6px; 
}
.group-modal.compact .modal-title {
    font-size: var(--fs-body); /* 16px - consistent with tokens */
    line-height: var(--lh-body); /* 1.6 - better readability */
}
.group-modal.compact .step-progress { 
    margin-bottom: 6px; 
    padding: 0 12px; 
}
.group-modal.compact .step-number { 
    width: 22px; 
    height: 22px; 
    font-size: 11px; 
}
.group-modal.compact .step-connector { 
    max-width: 48px; 
    height: 2px; 
    margin: 0 6px; 
    top: -11px; 
}

/* Intro line: smaller, lighter, tighter */
.group-modal.compact .form-intro {
    margin-bottom: var(--space-xs);
}
.group-modal.compact .form-intro p {
    font-size: 13px; /* Slightly smaller for compact mode */
    line-height: 1.4;
}

/* Body padding and section headers */
.group-modal.compact .group-modal-body { 
    padding: 12px 16px; 
}
.group-modal.compact .section-title { 
    margin: 4px 0 6px; 
    padding-bottom: 6px; 
    font-size: 15px;
}

/* Grid + fields */
.group-modal.compact .form-grid { 
    gap: 8px; 
}
.group-modal.compact .form-field { 
    gap: 6px; 
}
.group-modal.compact .field-label { 
    font-size: 13px; 
}
.group-modal.compact .field-input,
.group-modal.compact .field-select,
.group-modal.compact .field-textarea {
    padding: 10px 12px;              /* ~44px control height */
    border-width: 1px;               /* was 2px */
    font-size: 14px;
}
.group-modal.compact .field-help { 
    display: none; /* we moved min-6 into the label */
}

/* Date + "flexible" inline */
.group-modal.compact .date-input-group { 
    gap: 10px; 
}
.group-modal.compact .date-flexible { 
    padding: 0; 
}

/* Footer + buttons */
.group-modal.compact .group-modal-footer { 
    padding: 12px 16px 14px; 
}
.group-modal.compact .nav-button { 
    min-height: 44px; 
    padding: 10px 14px; 
    border-radius: 10px; 
    font-size: 14px;
}
.group-modal.compact .submit-button { 
    height: 44px; 
    border-radius: 10px; 
}
.group-modal.compact .form-note { 
    font-size: 12px; 
    margin-top: 6px; 
}

/* Mobile viewport safety: avoid OS UI collisions */
@supports (height: 1dvh) {
    .group-modal.compact .group-modal-container { 
        max-height: calc(100dvh - 16px); 
    }
}

/* Tom Select Overrides */
.ts-wrapper {
    position: relative;
    margin-bottom: 0 !important;
}

.ts-wrapper .ts-control {
    padding: var(--space-sm) !important;
    border: 1px solid var(--modal-border) !important;
    border-radius: var(--radius-md) !important;
    font-size: 16px !important;
    line-height: var(--lh-body) !important;
    background: var(--modal-surface) !important;
    color: var(--modal-text) !important;
    min-height: 44px !important;
    box-shadow: none !important;
    cursor: pointer !important;
}

.ts-wrapper.single .ts-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    padding-right: 40px !important;
}

.ts-wrapper.focus .ts-control {
    border-color: var(--modal-primary) !important;
    outline: 2px solid var(--modal-primary) !important;
    outline-offset: -1px !important;
}

/* Style the search input that appears inside */
.ts-wrapper .ts-control > input {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    outline: none !important;
    font-size: 16px !important;
}

/* Style the dropdown */
.ts-wrapper .ts-dropdown {
    border: 1px solid var(--modal-border) !important;
    border-radius: var(--radius-md) !important;
    margin-top: 4px !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
    background: white !important;
    z-index: 10000 !important;
}

.ts-wrapper .ts-dropdown-content {
    max-height: 200px !important;
    overflow-y: auto !important;
    padding: 4px !important;
}

/* Style the dropdown options */
.ts-wrapper .option {
    padding: 8px 12px !important;
    cursor: pointer !important;
    border-radius: 4px !important;
    margin: 2px 0 !important;
}

.ts-wrapper .option:hover,
.ts-wrapper .option.active {
    background: #f3f4f6 !important;
}

.ts-wrapper .option.selected {
    background: var(--modal-primary) !important;
    color: white !important;
}

/* Fix the odd spacing below the input */
.ts-wrapper.dropdown-active .ts-control {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.ts-wrapper.dropdown-active .ts-dropdown {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
    margin-top: -1px !important;
}

/* Ensure no extra space is added */
.tom-select-pickup-location {
    margin-bottom: 0 !important;
}

.tom-select-pickup-location + .pickup-location-subtext {
    margin-top: 4px !important;
}

/* Mobile adjustments */
@media (max-width: 640px) {
    .ts-wrapper .ts-control {
        font-size: 15px !important;
    }
}

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

/* High Contrast */
@media (prefers-contrast: high) {
    .field-input,
    .field-select,
    .field-textarea {
        border-width: 3px;
    }

    .submit-button:focus {
        outline-width: 3px;
    }
}