/* Container ครอบ input และ popover */
.tdp-field-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* ช่อง Input แสดงผล */
.tdp-input {
    width: 100%;
    height: 44px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #1e293b;
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.tdp-input:hover {
    border-color: #94a3b8;
}

.tdp-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* กล่อง Popover ปฏิทิน — ใช้ fixed + วางบน body เพื่อไม่ล้นจอ/ถูกตัดโดย modal */
.tdp-popover {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 288px;
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14);
    padding: 12px;
    z-index: 2100;
    user-select: none;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.tdp-popover.tdp-show {
    display: block;
    animation: tdpFadeIn 0.15s ease-out;
}

@keyframes tdpFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Nav Header เดือน/ปี */
.tdp-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.tdp-nav-title {
    font-size: 13.5px;
    font-weight: 700;
    color: #0f172a;
}

.tdp-nav-btn {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11.5px;
    color: #475569;
}

.tdp-nav-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

/* Grid Days */
.tdp-grid-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 4px;
}

.tdp-grid-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    row-gap: 2px;
}

.tdp-cell {
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    border-radius: 5px;
    color: #1e293b;
}

.tdp-cell:hover:not(.empty):not(.is-start):not(.is-end) {
    background: #f1f5f9;
}

.tdp-cell.empty {
    cursor: default;
}

.tdp-cell.is-start {
    background: #003c71 !important;
    color: #ffffff !important;
    font-weight: 700;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.tdp-cell.is-end {
    background: #003c71 !important;
    color: #ffffff !important;
    font-weight: 700;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.tdp-cell.is-start.is-end,
.tdp-cell.is-selected {
    border-radius: 6px !important;
}

.tdp-cell.in-range,
.tdp-cell.in-preview {
    background: #eef5fc !important;
    color: #003c71 !important;
    border-radius: 0 !important;
}

/* ช่องเลือกเวลาแยกซ้าย-ขวา */
.tdp-time-section {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.tdp-time-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 6px;
}

.tdp-time-label {
    font-size: 10.5px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 3px;
    display: block;
}

.tdp-time-row {
    display: flex;
    align-items: center;
    gap: 3px;
}

.tdp-time-row > span {
    flex: 0 0 auto;
    color: #64748b;
    font-weight: 700;
    line-height: 1;
}

.tdp-time-row select {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: 28px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
    color: #1e293b;
    outline: none;
    padding: 0 2px;
}

/* แถบ Action ด้านล่าง */
.tdp-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tdp-btn-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #64748b;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 5px 11px;
    line-height: 1.2;
    transition: all 0.15s ease-in-out;
    text-decoration: none;
}

.tdp-btn-clear:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
    text-decoration: none;
}

.tdp-btn-clear:active {
    background: #fee2e2;
}

.tdp-btn-confirm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 13px;
    background: #003c71;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #003c71;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.2;
    transition: all 0.15s ease-in-out;
    box-shadow: 0 1px 2px rgba(0, 60, 113, 0.15);
}

.tdp-btn-confirm:hover {
    background: #00284d;
    border-color: #00284d;
}

/* โหมดไม่แสดงเวลา (showTime: false) */
.tdp-popover.tdp-no-time {
    width: 268px;
}

.tdp-popover.tdp-no-time .tdp-time-section {
    display: none !important;
}

/* รองรับจอมือถือขนาดเล็ก (< 480px) */
@media (max-width: 480px) {
    .tdp-popover {
        width: 265px;
        padding: 10px;
        max-width: calc(100vw - 16px);
        border-radius: 8px;
    }

    .tdp-popover.tdp-no-time {
        width: 252px;
    }

    .tdp-nav {
        margin-bottom: 6px;
    }

    .tdp-nav-title {
        font-size: 13px;
    }

    .tdp-nav-btn {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }

    .tdp-grid-weekdays {
        font-size: 10.5px;
        margin-bottom: 3px;
    }

    .tdp-cell {
        height: 27px;
        font-size: 11.5px;
    }

    .tdp-time-section {
        gap: 4px;
        padding-top: 6px;
        margin-top: 8px;
    }

    .tdp-time-box {
        padding: 4px;
    }

    .tdp-time-label {
        font-size: 10px;
    }

    .tdp-time-row select {
        height: 25px;
        font-size: 11px;
    }

    .tdp-footer {
        margin-top: 10px;
        padding-top: 6px;
    }

    .tdp-btn-clear {
        padding: 4px 9px;
        font-size: 11px;
    }

    .tdp-btn-confirm {
        padding: 4px 11px;
        font-size: 11.5px;
    }
}

/* รองรับกรณีใช้งานร่วมกับ Bootstrap .input-group */
.input-group > .tdp-field-wrapper {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

.input-group > .tdp-field-wrapper > .tdp-input {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.input-group > .tdp-field-wrapper:not(:last-child) > .tdp-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-sm > .tdp-field-wrapper > .tdp-input {
    height: 31px;
    padding: 4px 10px;
    font-size: 0.85rem;
    line-height: 1.5;
}