/**
 * DeliveryTimeSlot Plugin - 配送日時指定カスタムスタイル
 * 完全テーマ非依存設計 (CSS Reset & Self-contained Scoped Styles)
 */

/* 1. 安全なネイティブ要素非表示 (注文手続き画面 /shopping でのみ非表示・確認画面では正常表示) */
#page_shopping .ec-select__delivery,
#page_shopping .ec-select__time,
form[action*="shopping_confirm"] .ec-select__delivery,
form[action*="shopping_confirm"] .ec-select__time,
#page_shopping .ec-dts-hidden-native,
form[action*="shopping_confirm"] .ec-dts-hidden-native {
    display: none;
    visibility: hidden;
    height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* ご注文内容確認画面 (/shopping/confirm) では確実に正常表示を維持 */
#page_shopping_confirm .ec-select__delivery,
#page_shopping_confirm .ec-select__time,
form[action*="shopping_checkout"] .ec-select__delivery,
form[action*="shopping_checkout"] .ec-select__time {
    display: block;
    visibility: visible;
    height: auto;
    overflow: visible;
    margin-bottom: 16px;
    padding: 0;
}

/* 2. メインコンテナ (テーマのグローバルスタイル干渉を遮断) */
.ec-dts-container {
    all: revert;
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin-top: 16px;
    margin-bottom: 24px;
    padding: 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1e293b;
    text-align: left;
    letter-spacing: normal;
}

.ec-dts-container *,
.ec-dts-container *::before,
.ec-dts-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* 3. ヘッダー */
.ec-dts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.ec-dts-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.3;
}

.ec-dts-title-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #e0f2fe;
    color: #0284c7;
}

/* 4. 最短お届けボタン (テーマのボタンリセット適用) */
button.ec-dts-fastest-btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1;
    color: #0369a1;
    background: #f0f9ff;
    border: 1px dashed #7dd3fc;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    box-shadow: none;
}

button.ec-dts-fastest-btn:hover {
    background: #e0f2fe;
    border-color: #0284c7;
    color: #0284c7;
}

button.ec-dts-fastest-btn.active {
    background: #0284c7;
    color: #ffffff;
    border-style: solid;
    border-color: #0284c7;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}

/* 5. セクション見出し & 日付選択エリア */
.ec-dts-section {
    margin-top: 18px;
}

.ec-dts-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.ec-dts-step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #0284c7;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

.ec-dts-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.4;
}

.ec-dts-section-hint {
    font-size: 0.8rem;
    font-weight: 400;
    color: #64748b;
}

.ec-dts-section-subtitle {
    font-size: 0.88rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 8px;
    display: block;
}

.ec-dts-date-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 12px 2px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f8fafc;
    -webkit-overflow-scrolling: touch;
}

.ec-dts-date-scroll::-webkit-scrollbar {
    height: 6px;
}

.ec-dts-date-scroll::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 3px;
}

.ec-dts-date-scroll::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* 日付選択ボタン (Buttonタグリセット) */
button.ec-dts-date-btn {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 auto;
    padding: 8px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    min-width: 82px;
    user-select: none;
    outline: none;
    font-family: inherit;
    box-shadow: none;
}

button.ec-dts-date-btn:hover:not(.disabled) {
    border-color: #0284c7;
    background: #f0f9ff;
    transform: translateY(-1px);
}

button.ec-dts-date-btn.active {
    border-color: #0284c7;
    background: #0284c7;
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.35);
}

button.ec-dts-date-btn.active .ec-dts-weekday,
button.ec-dts-date-btn.active .ec-dts-day,
button.ec-dts-date-btn.active .ec-dts-date-status {
    color: #ffffff;
}

button.ec-dts-date-btn.disabled {
    opacity: 0.45;
    background: #f8fafc;
    cursor: not-allowed;
    border-color: #e2e8f0;
}

.ec-dts-weekday {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    display: block;
    margin-bottom: 2px;
}

.ec-dts-weekday.is-saturday {
    color: #2563eb;
}

.ec-dts-weekday.is-sunday,
.ec-dts-weekday.is-holiday {
    color: #dc2626;
}

.ec-dts-day {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    display: block;
}

.ec-dts-date-status {
    font-size: 0.68rem;
    font-weight: 600;
    display: block;
    margin-top: 2px;
}

.ec-dts-status-available {
    color: #16a34a;
}

.ec-dts-status-muted {
    color: #64748b;
}

/* 6. スロット時間帯選択グリッド & カード */
.ec-dts-slot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
    margin-top: 4px;
}

.ec-dts-slot-card {
    position: relative;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 11px 14px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 58px;
    user-select: none;
    outline: none;
}

.ec-dts-slot-card:hover:not(.disabled) {
    border-color: #38bdf8;
    background: #f0f9ff;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(2, 132, 199, 0.08);
}

.ec-dts-slot-card.active {
    border-color: #0284c7;
    background: #f0f9ff;
    box-shadow: 0 0 0 1px #0284c7, 0 3px 10px rgba(2, 132, 199, 0.12);
}

.ec-dts-slot-card.disabled {
    opacity: 0.55;
    background: #f8fafc;
    cursor: not-allowed;
    border-color: #e2e8f0;
}

/* ラジオボタン風インジケーター */
.ec-dts-radio-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    background: #ffffff;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.ec-dts-radio-dot {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
    transition: all 0.15s ease;
}

.ec-dts-slot-card.active .ec-dts-radio-indicator {
    border-color: #0284c7;
}

.ec-dts-slot-card.active .ec-dts-radio-dot {
    background: #0284c7;
}

.ec-dts-slot-card.disabled .ec-dts-radio-indicator {
    border-color: #e2e8f0;
    background: #f1f5f9;
}

/* スロット情報エリア */
.ec-dts-slot-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.ec-dts-slot-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ec-dts-slot-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ec-dts-slot-name {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.3;
}

.ec-dts-slot-card.active .ec-dts-slot-name {
    color: #0369a1;
}

.ec-dts-slot-time-range {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: #64748b;
    font-weight: 500;
}

.ec-dts-slot-time-range svg {
    color: #94a3b8;
    flex-shrink: 0;
}

/* 手数料表示 */
.ec-dts-surcharge {
    font-size: 0.72rem;
    color: #b91c1c;
    font-weight: 700;
    background: #fee2e2;
    padding: 1px 6px;
    border-radius: 4px;
    line-height: 1.4;
    white-space: nowrap;
}

/* スロット状態バッジ */
.ec-dts-slot-badge-wrap {
    flex-shrink: 0;
}

.ec-dts-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 3px 9px;
    border-radius: 9999px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.3;
}

.ec-dts-badge-available {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.ec-dts-badge-few {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
}

.ec-dts-badge-full {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.ec-dts-badge-expired {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* 7. 未選択案内・注意書き・ローディング表示 */
.ec-dts-empty-state {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    color: #64748b;
    font-size: 0.85rem;
    width: 100%;
}

.ec-dts-empty-state svg {
    color: #94a3b8;
    flex-shrink: 0;
}

.ec-dts-notice {
    margin-top: 16px;
    padding: 10px 14px;
    background: #f8fafc;
    border-left: 3px solid #0284c7;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.6;
}

.ec-dts-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #64748b;
    font-size: 0.9rem;
    gap: 8px;
}

.ec-dts-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-top-color: #0284c7;
    border-radius: 50%;
    animation: ec-dts-spin 0.8s linear infinite;
}

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

/* 8. モバイル対応 */
@media (max-width: 640px) {
    .ec-dts-container {
        padding: 14px;
        margin-top: 12px;
        margin-bottom: 16px;
    }

    .ec-dts-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    button.ec-dts-fastest-btn {
        width: 100%;
        justify-content: center;
    }

    .ec-dts-slot-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .ec-dts-slot-card {
        padding: 10px 12px;
        min-height: 54px;
    }

    .ec-dts-section-hint {
        display: none;
    }
}
