/**
 * Turnaround Variations - Frontend Styles
 * Uses CSS logical properties for automatic RTL support
 */

/* ============================================
   CSS Variables for Theming
   ============================================ */
:root {
    --tav-primary-color: #0073aa;
    --tav-primary-hover: #005a87;
    --tav-border-color: #ddd;
    --tav-border-hover: #999;
    --tav-background: #fff;
    --tav-background-hover: #f9f9f9;
    --tav-background-selected: #e3f2fd;
    --tav-text-primary: #333;
    --tav-text-secondary: #666;
    --tav-text-muted: #999;
    --tav-focus-color: #4a90e2;
    --tav-success-color: #46b450;
    --tav-info-background: #f0f6fc;
    --tav-info-border: #0073aa;
    --tav-border-radius: 6px;
    --tav-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --tav-transition: all 0.3s ease;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --tav-primary-color: #4a90e2;
        --tav-primary-hover: #357abd;
        --tav-border-color: #444;
        --tav-border-hover: #666;
        --tav-background: #1e1e1e;
        --tav-background-hover: #2a2a2a;
        --tav-background-selected: #1a3a52;
        --tav-text-primary: #e0e0e0;
        --tav-text-secondary: #b0b0b0;
        --tav-text-muted: #888;
        --tav-focus-color: #4a90e2;
        --tav-info-background: #1a2a3a;
        --tav-info-border: #4a90e2;
    }
}

/* ============================================
   Hide Original Turnaround Dropdown
   ============================================ */
/* Hide any turnaround select dropdowns - keep them in DOM but invisible */
select[name*="turnaround"],
select[id*="turnaround"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ============================================
   Main Container
   ============================================ */
.tav-custom-interface {
    margin-block: 15px 20px;
    padding-block: 0;
    clear: both;
    transition: opacity 0.15s ease-in-out;
}

.tav-custom-interface.updating {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================
   Date Boxes Layout
   ============================================ */
.tav-date-boxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-block: 15px;
    padding: 0;
    list-style: none;
}

/* Tablet - 3 columns */
@media (min-width: 768px) and (max-width: 1024px) {
    .tav-date-boxes {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Desktop - 4 columns */
@media (min-width: 1025px) {
    .tav-date-boxes {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Mobile - 2 columns */
@media (max-width: 767px) {
    .tav-date-boxes {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

/* Small mobile - 1 column */
@media (max-width: 480px) {
    .tav-date-boxes {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Date Box Styles
   ============================================ */
.tav-date-box {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
    background: var(--tav-background);
    border: 2px solid var(--tav-border-color);
    border-radius: var(--tav-border-radius);
    cursor: pointer;
    transition: var(--tav-transition);
    text-align: center;
    min-height: 90px;
    user-select: none;
}

.tav-date-box:hover {
    border-color: var(--tav-border-hover);
    background: var(--tav-background-hover);
    transform: translateY(-2px);
    box-shadow: var(--tav-box-shadow);
}

.tav-date-box:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.tav-date-box.selected {
    border-color: var(--tav-primary-color);
    background: var(--tav-background-selected);
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.tav-date-box.selected::before {
    content: '✓';
    position: absolute;
    top: 6px;
    inset-inline-end: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--tav-primary-color);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
}

/* Focus state for accessibility */
.tav-date-box:focus,
.tav-date-box:focus-visible {
    outline: 2px solid var(--tav-focus-color);
    outline-offset: 2px;
    border-color: var(--tav-focus-color);
}

/* Disabled state */
.tav-date-box-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background: var(--tav-background);
}

.tav-date-box-disabled:hover {
    border-color: var(--tav-border-color);
    background: var(--tav-background);
    transform: none;
    box-shadow: none;
}

.tav-date-box-disabled .tav-date-box-date,
.tav-date-box-disabled .tav-date-box-label {
    color: var(--tav-text-muted);
    text-decoration: line-through;
}

/* Date text */
.tav-date-box-date {
    font-size: 16px;
    font-weight: 700;
    color: var(--tav-text-primary);
    margin-block-end: 6px;
    line-height: 1.2;
}

/* Label text */
.tav-date-box-label {
    font-size: 13px;
    color: var(--tav-text-secondary);
    line-height: 1.3;
}

.tav-date-box.selected .tav-date-box-date {
    color: var(--tav-primary-color);
}

/* Mobile adjustments */
@media (max-width: 767px) {
    .tav-date-box {
        padding: 14px 10px;
        min-height: 80px;
    }

    .tav-date-box-date {
        font-size: 15px;
    }

    .tav-date-box-label {
        font-size: 12px;
    }
}

/* ============================================
   Calendar Mode
   ============================================ */
.tav-calendar-wrapper {
    margin-block: 15px;
    max-width: 400px;
}

.tav-calendar-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid var(--tav-border-color);
    border-radius: var(--tav-border-radius);
    background: var(--tav-background);
    color: var(--tav-text-primary);
    transition: var(--tav-transition);
    cursor: pointer;
}

.tav-calendar-input:hover {
    border-color: var(--tav-border-hover);
}

.tav-calendar-input:focus {
    outline: none;
    border-color: var(--tav-focus-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/* Flatpickr overrides */
.flatpickr-calendar {
    font-family: inherit;
    border-radius: var(--tav-border-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.flatpickr-day.selected {
    background: var(--tav-primary-color);
    border-color: var(--tav-primary-color);
}

.flatpickr-day.selected:hover {
    background: var(--tav-primary-hover);
    border-color: var(--tav-primary-hover);
}

/* ============================================
   Delivery Info
   ============================================ */
.tav-delivery-info {
    margin-block: 15px;
    padding: 14px 16px;
    background: var(--tav-info-background);
    border-inline-start: 4px solid var(--tav-info-border);
    border-radius: var(--tav-border-radius);
    color: var(--tav-text-primary);
    animation: tav-slide-down 0.3s ease;
}

/* ============================================
   Disclaimer
   ============================================ */
.tav-disclaimer {
    margin-block-start: 15px;
    padding: 10px 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--tav-text-muted);
    text-align: center;
    font-style: italic;
    border-top: 1px solid #e0e0e0;
}

.tav-delivery-info strong {
    display: inline-block;
    margin-inline-end: 8px;
    color: var(--tav-primary-color);
    font-weight: 600;
}

.tav-days-count {
    color: var(--tav-text-secondary);
    font-size: 14px;
}

@keyframes tav-slide-down {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile adjustments */
@media (max-width: 767px) {
    .tav-delivery-info {
        padding: 12px 14px;
        font-size: 14px;
    }
}

/* ============================================
   Initial Page Load Overlay
   ============================================ */
.tav-initial-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    min-height: 300px;
    backdrop-filter: blur(2px);
}

@media (prefers-color-scheme: dark) {
    .tav-initial-overlay {
        background: rgba(30, 30, 30, 0.95);
    }
}

.tav-initial-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(0, 115, 170, 0.1);
    border-top-color: var(--tav-primary-color);
    border-right-color: var(--tav-primary-color);
    border-radius: 50%;
    animation: tav-spin 0.8s linear infinite;
    margin-bottom: 20px;
}

.tav-initial-loading-text {
    color: var(--tav-text-primary);
    font-size: 16px;
    font-weight: 600;
    animation: tav-pulse 1.5s ease-in-out infinite;
}

/* ============================================
   Loading State
   ============================================ */
.tav-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px 20px;
    min-height: 150px;
}

.tav-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 115, 170, 0.1);
    border-top-color: var(--tav-primary-color);
    border-right-color: var(--tav-primary-color);
    border-radius: 50%;
    animation: tav-spin 0.8s linear infinite;
    margin-bottom: 15px;
}

.tav-loading-text {
    color: var(--tav-text-secondary);
    font-size: 14px;
    font-weight: 500;
    animation: tav-pulse 1.5s ease-in-out infinite;
}

@keyframes tav-pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

@keyframes tav-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   RTL Support
   ============================================ */
.tav-rtl {
    direction: rtl;
}

.tav-rtl .tav-date-boxes {
    direction: rtl;
}

.tav-rtl .tav-date-box {
    text-align: center;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .tav-custom-interface {
        display: none;
    }
}

/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .tav-date-box,
    .tav-calendar-input,
    .tav-delivery-info {
        transition: none;
        animation: none;
    }

    .tav-date-box:hover {
        transform: none;
    }

    .tav-loading::before {
        animation: none;
        border-top-color: var(--tav-border-color);
    }
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
    .tav-date-box {
        border-width: 3px;
    }

    .tav-date-box.selected {
        border-width: 4px;
    }

    .tav-date-box:focus {
        outline-width: 3px;
    }
}

/* ============================================
   Disabled State
   ============================================ */
.tav-date-box[aria-disabled="true"],
.tav-date-box.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================
   Error State
   ============================================ */
.tav-error {
    padding: 12px 16px;
    margin-block: 15px;
    background: #fee;
    border-inline-start: 4px solid #c00;
    border-radius: var(--tav-border-radius);
    color: #c00;
    font-size: 14px;
}

/* ============================================
   Utilities
   ============================================ */
.tav-hidden {
    display: none !important;
}

.tav-screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
