/* Thai Calendar Styles */
.calendar-popup {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    width: 300px;
    display: none;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.calendar-popup.show {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Calendar container positioning */
#calendar-container {
    position: relative;
    display: inline-block;
    width: 100%;
    min-height: 1px;
}

/* Calendar card styles */
.card {
    margin: 0;
    padding: 0;
    border: none;
    background: #fff;
    width: 100%;
    position: relative;
}

.card-body {
    padding: 1rem;
}

/* Calendar grid */
.calendar-grid {
    width: 100%;
}

/* Days header */
.days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 10px;
    text-align: center;
}

/* Calendar days */
.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day {
    height: 36px;
    width: 36px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #333 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.calendar-day:hover {
    background: #E5F1F8 !important;
    color: #333 !important;
    border-radius: 20px !important;
}

.calendar-day.btn-primary {
    background-color: #0072BC;
    border-color:#0072BC;
    color: white;
}

.calendar-day.text-muted {
    color: #bbb !important;
    opacity: 1 !important;
}

/* Month navigation */
.prev-month, .next-month {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
}

.prev-month:hover, .next-month:hover {
    background: #F3F4F6;
}

/* Calendar header */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.calendar-title {
    font-size: 1rem;
    font-weight: 500;
    margin: 0;
}

/* Responsive adjustments */
@media (max-width: 576px) {
    .calendar-day {
        height: 32px;
        width: 32px;
        font-size: 0.8rem;
    }
}

/* Selected day */
.calendar-day.btn-primary:hover {
    background-color:#0072BC;
    border-color:#0072BC;
}

/* Today highlight (optional) */
.calendar-day.today {
    font-weight: bold;
    border: 1px solid#0072BC;
}

/* Improve spacing */
.calendar-grid {
    margin-bottom: 0.5rem;
}

/* Calendar navigation buttons */
.calendar-nav {
    display: flex;
    gap: 8px;
}

.calendar-nav button {
    padding: 4px 8px;
    border: 1px solid #E5E7EB;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.calendar-nav button:hover {
    background: #F3F4F6;
}

.calendar-arrow-btn {
    display: flex;
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    background: #FFF;
    border: none;
    transition: background 0.2s, box-shadow 0.2s;
    cursor: pointer;
    box-shadow: none;
}

.calendar-arrow-btn:hover {
    background: #F4F8FB !important;
    border-radius: 8px !important;
    box-shadow: 0px 2px 10px 0px rgba(0,0,0,0.08) !important;
}

.calendar-arrow-btn img {
    width: 20px;
    height: 20px;
    pointer-events: none;
    filter: none;
    transition: filter 0.2s;
}

.calendar-arrow-btn:hover img {
    filter: none;
}

.calendar-day.btn-primary, .calendar-day.selected, .calendar-day:active {
    background: #0072BC !important;
    color: #fff !important;
    border-radius: 20px !important;
}

.calendar-day:hover {
    background: #E5F1F8 !important;
    color: #333 !important;
    border-radius: 20px !important;
}

.calendar-month-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.calendar-month-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.calendar-month-btn {
    width: 64px;
    height: 40px;
    border: none;
    background: transparent;
    color: #333;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, font-size 0.2s;
}

.calendar-month-btn.selected,
.calendar-month-btn:hover {
    background: #E5F1F8;
    color: #0072BC;
}

.calendar-month-btn.selected {
    font-size: 16px;
}

.calendar-year-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 0 8px 8px 8px;
}

.calendar-year-btn {
    min-width: 72px;
    height: 44px;
    margin: 2px 0;
    font-size: 14px;
    border: none;
    background: transparent;
    color: #333;
    border-radius: 8px;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, font-weight 0.2s, font-size 0.2s;
}

.calendar-year-btn.selected,
.calendar-year-btn:hover {
    background: #E5F1F8 !important;
    color: #0072BC !important;
    font-weight: 500;
    font-size: 16px;
}

.calendar-year-btn:disabled,
.calendar-year-btn.disabled {
    color: #bbb !important;
    background: transparent !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* ===========================
   Period Calendar (dual month)
   =========================== */
.period-calendar-popup {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.16);
    padding: 20px;
    display: none;
}

.period-calendar-popup.show {
    display: block;
}

.period-calendar-popup.period-only .period-toggle-label {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

.period-calendar-card {
    width: 585px;
}

/* Single mode: ปิด toggle แล้วซ่อน panel ขวา แสดง calendar ตัวเดียว */
.period-calendar-card.period-calendar-single {
    width: 302px; /* 262 month + 20*2 padding */
}

.period-calendar-months.period-calendar-single .period-calendar-month-right {
    display: none;
}

.period-calendar-months.period-calendar-single {
    justify-content: center;
}


.period-calendar-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.period-calendar-months {
    display: flex;
    gap: 24px;
}

.period-calendar-month {
    width: 262px;
}

.period-month-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px;
    margin-bottom: 8px;
}

.period-month-title {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    line-height: 1.4;
}

.period-nav-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 8px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    color: #4B5563;
    cursor: pointer;
}

.period-nav-btn:hover {
    background: #F3F4F6;
}

.period-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.period-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    text-align: center;
    font-size: 10px;
    color: #9CA3AF;
    margin-bottom: 8px;
}

.period-weekday {
    padding: 4px 0;
    line-height: 1.2;
}

.period-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
}

.period-day-cell {
    position: relative;
    height: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.period-range-bg {
    position: absolute;
    left: 0;
    right: 0;
    height: 20px;
    background: #E5F1F8; /* ฟ้าอ่อนของโปรเจกต์ */
    border-radius: 0;
    transform: translateY(1px);
}

.period-range-bg.start {
    border-top-left-radius: 9999px;
    border-bottom-left-radius: 9999px;
}

.period-range-bg.end {
    border-top-right-radius: 9999px;
    border-bottom-right-radius: 9999px;
}

.period-day-btn {
    position: relative;
    z-index: 1;
    width: 28px;
    height: 28px;
    border-radius: 9999px;
    border: none;
    background: transparent;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
}

.period-day-btn:hover:not(.period-day-empty) {
    background: #F3F4F6;
}

.period-day-btn.period-day-selected {
    background: #0072BC; /* น้ำเงินหลักของโปรเจกต์ */
    color: #fff;
}

.period-day-btn.period-day-inrange {
    color: #0072BC;
}

.period-day-btn.period-day-empty {
    cursor: default;
}

.period-calendar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0;
}

.period-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: #374151;
    cursor: pointer;
    min-height: 40px;
}

.period-toggle-track {
    position: relative;
    width: 40px;
    height: 20px;
    border-radius: 9999px;
    background: #E5E7EB;
    transition: background 0.2s;
}

.period-toggle-track.on {
    background: #0072BC;
}

.period-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 9999px;
    background: #fff;
    transition: transform 0.2s;
}

.period-toggle-track.on .period-toggle-thumb {
    transform: translateX(20px);
}

.period-calendar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.period-calendar-actions .period-btn-cancel,
.period-calendar-actions .period-btn-confirm {
    padding: 8px 20px;
    font-size: 14px;
    border-radius: 12px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
}

/* Input appearance (เหมือน filter input อื่นๆ) */
.period-calendar-wrapper {
    display: inline-block;
    position: relative;
}

/* ใน form-group ให้ input อยู่ใต้ label และเต็มความกว้าง */
.form-group .period-calendar-wrapper {
    display: block;
    width: 100%;
}

.period-calendar-input-wrapper {
    border: 1px solid #D6D6D6;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 10px;
    background: #fff;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    color: #858585;
}

.period-calendar-input {
    flex: 1;
    border: none;
    background: transparent;
    color: #c2c2c2;
    font-size: 16px;
    font-weight: 500;
    padding: 0;
    cursor: pointer;
    outline: none;
    min-width: 0;
}

.period-calendar-input::placeholder {
    color: #C2C2C2;
    font-size: 16px;
    font-weight: 500;
}

.period-calendar-icon {
    font-size: 24px;
    color: #6B7280;
    flex-shrink: 0;
}

.period-calendar-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    cursor: pointer;
    color: #0072BC;
    flex-shrink: 0;
}

/* Active state (เมื่อมีค่า) */
.period-calendar-wrapper.has-value .period-calendar-input-wrapper {
    border: 1px solid #0072BC !important;
    background: #E5F1F8 !important;
    color: #0072BC;
}

.period-calendar-wrapper.has-value .period-calendar-input {
    color: #0072BC;
}

.period-calendar-wrapper.has-value .period-calendar-icon {
    display: none;
}

.period-calendar-wrapper.has-value .period-calendar-remove {
    display: inline-flex !important;
}
