/**
 * TT Datepicker — Custom calendar component styles
 * Design tokens use CSS variables from TatilTour theme
 *
 * @package TatilTour
 * @version 1.0.0
 */

/* ── Variables ── */
:root {
    --dp-primary: var(--tt-primary, #fd5c02);
    --dp-primary-light: #fff5ef;
    --dp-holiday-dot: #e74c3c;
    --dp-text: #333;
    --dp-text-muted: #999;
    --dp-border: #e8e8e8;
    --dp-bg: #fff;
    --dp-cell-size: 40px;
    --dp-radius: 12px;
}

/* ── Overlay (mobile backdrop) ── */
.tt-dp-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.25s;
}
.tt-dp-overlay--active {
    display: block;
    opacity: 1;
}

/* ── Body lock when picker open on mobile ── */
body.tt-dp-open {
    overflow: hidden;
}

/* ── Main Container ── */
.tt-dp {
    display: none;
    position: absolute;
    z-index: 9999;
    background: var(--dp-bg);
    border-radius: var(--dp-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    width: 320px;
    font-family: inherit;
    font-size: 14px;
    color: var(--dp-text);
    -webkit-user-select: none;
    user-select: none;
    animation: ttDpFadeIn 0.2s ease;
}
.tt-dp--open {
    display: block;
}
.tt-dp--dual {
    width: 640px;
}

@keyframes ttDpFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Header ── */
.tt-dp__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px;
    position: relative;
}

.tt-dp__nav {
    width: 32px;
    height: 32px;
    border: 1px solid var(--dp-border);
    border-radius: 8px;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dp-text);
    font-size: 12px;
    transition: all 0.15s;
    flex-shrink: 0;
}
.tt-dp__nav:hover {
    border-color: var(--dp-primary);
    color: var(--dp-primary);
    background: var(--dp-primary-light);
}

.tt-dp__title {
    font-weight: 600;
    font-size: 15px;
    text-align: center;
    flex: 1;
    display: flex;
    justify-content: center;
    gap: 40px;
}
.tt-dp__title span {
    min-width: 140px;
}

/* ── Night count badge ── */
.tt-dp__night-badge {
    position: absolute;
    top: 14px;
    right: 56px;
    background: var(--dp-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
    line-height: 1.4;
}

/* ── Body ── */
.tt-dp__body {
    display: flex;
    gap: 0;
    padding: 0 12px;
}
.tt-dp__month {
    flex: 1;
    padding: 0 4px;
}

/* ── Dual month separator ── */
.tt-dp--dual .tt-dp__body {
    gap: 8px;
}
.tt-dp--dual .tt-dp__month:first-child {
    border-right: 1px solid var(--dp-border);
    padding-right: 12px;
}

/* ── Weekday header ── */
.tt-dp__weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--dp-text-muted);
    padding: 8px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Day Grid ── */
.tt-dp__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    padding-bottom: 4px;
}

/* ── Day Cell ── */
.tt-dp__day {
    position: relative;
    height: var(--dp-cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.tt-dp__day:hover:not(.tt-dp__day--disabled):not(.tt-dp__day--empty) {
    background: var(--dp-primary-light);
    color: var(--dp-primary);
}

.tt-dp__day--empty {
    cursor: default;
}

.tt-dp__day--disabled {
    color: #ddd;
    cursor: not-allowed;
}

/* ── Weekend subtle color ── */
.tt-dp__day--weekend:not(.tt-dp__day--disabled):not(.tt-dp__day--start):not(.tt-dp__day--end):not(.tt-dp__day--in-range) {
    color: #888;
}

/* ── Today marker ── */
.tt-dp__day--today {
    font-weight: 700;
    color: var(--dp-primary);
}
.tt-dp__day--today::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--dp-primary);
}

/* ── Selected: start ── */
.tt-dp__day--start {
    background: var(--dp-primary) !important;
    color: #fff !important;
    border-radius: 8px 0 0 8px;
    font-weight: 600;
}
.tt-dp--single .tt-dp__day--start {
    border-radius: 8px;
}
/* When start = end (1 day), full round */
.tt-dp__day--start.tt-dp__day--end {
    border-radius: 8px;
}

/* ── Selected: end ── */
.tt-dp__day--end {
    background: var(--dp-primary) !important;
    color: #fff !important;
    border-radius: 0 8px 8px 0;
    font-weight: 600;
}

/* ── In range (confirmed) ── */
.tt-dp__day--in-range {
    background: var(--dp-primary-light);
    border-radius: 0;
    color: var(--dp-primary);
}

/* ── Hover range (during selection) ── */
.tt-dp__day--hover-range {
    background: var(--dp-primary-light);
    border-radius: 0;
    color: var(--dp-primary);
}

/* ── Holiday dot ── */
.tt-dp__dot {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--dp-holiday-dot);
    display: block;
    font-style: normal;
    pointer-events: none;
}

/* Shift today dot when holiday dot also present */
.tt-dp__day--today.tt-dp__day--holiday::after {
    left: calc(50% - 5px);
}
.tt-dp__day--today.tt-dp__day--holiday .tt-dp__dot {
    left: calc(50% + 5px);
}

/* ── Holiday tooltip ── */
.tt-dp__day--holiday[title] {
    cursor: help;
}
.tt-dp__day--holiday[title]:hover::before {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
    line-height: 1.4;
}
/* Arrow for tooltip */
.tt-dp__day--holiday[title]:hover::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #333;
    z-index: 10;
    pointer-events: none;
}
/* Avoid conflict with today dot — override only when holiday+today */
.tt-dp__day--today.tt-dp__day--holiday[title]:hover::after {
    content: '';
    border: 4px solid transparent;
    border-top-color: #333;
}

/* Selected day overrides holiday dot color */
.tt-dp__day--start .tt-dp__dot,
.tt-dp__day--end .tt-dp__dot {
    background: rgba(255, 255, 255, 0.7);
}
.tt-dp__day--start::after,
.tt-dp__day--end::after {
    display: none;
}

/* ── Footer ── */
.tt-dp__footer {
    display: flex;
    justify-content: space-between;
    padding: 8px 16px 14px;
    border-top: 1px solid var(--dp-border);
    margin-top: 4px;
}

.tt-dp__btn {
    background: none;
    border: 1px solid var(--dp-border);
    border-radius: 8px;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--dp-text);
    transition: all 0.15s;
    line-height: 1.4;
}
.tt-dp__btn:hover {
    border-color: var(--dp-primary);
    color: var(--dp-primary);
    background: var(--dp-primary-light);
}

/* ── Mobile: Bottom Sheet ── */
@media (max-width: 768px) {
    :root {
        --dp-cell-size: calc((100vw - 56px) / 7);
    }

    .tt-dp--sheet {
        position: fixed !important;
        bottom: 0;
        left: 0 !important;
        right: 0;
        top: auto !important;
        width: 100% !important;
        max-height: 75vh;
        border-radius: 20px 20px 0 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        animation: ttDpSlideUp 0.3s ease;
    }

    .tt-dp--sheet .tt-dp__body {
        flex-direction: column;
    }

    .tt-dp--sheet .tt-dp__header {
        padding: 16px 16px 10px;
        position: sticky;
        top: 0;
        background: var(--dp-bg);
        z-index: 2;
        border-bottom: 1px solid var(--dp-border);
    }

    .tt-dp--sheet .tt-dp__footer {
        position: sticky;
        bottom: 0;
        background: var(--dp-bg);
        z-index: 2;
        padding: 10px 16px 16px;
    }

    /* Sheet handle */
    .tt-dp--sheet::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: #ddd;
        margin: 10px auto 0;
    }

    @keyframes ttDpSlideUp {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .tt-dp__day {
        font-size: 14px;
    }

    .tt-dp__title {
        font-size: 14px;
        gap: 20px;
    }

    .tt-dp__night-badge {
        position: static;
        display: inline-block;
        margin-left: 8px;
        font-size: 10px;
        padding: 2px 8px;
    }
}

/* ── Very small screens ── */
@media (max-width: 380px) {
    :root {
        --dp-cell-size: calc((100vw - 40px) / 7);
    }

    .tt-dp__day {
        font-size: 13px;
    }

    .tt-dp__weekdays {
        font-size: 10px;
    }
}
