/* تقویم همیشه داخل کادر بماند و چیزی روش نیفتد */
.pwt-datepicker-container, .pdp-container, .pwt-date-picker { 
    z-index: 99999 !important; 
    overflow: hidden; 
    position: absolute;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    font-family: 'IRANSans', Tahoma, Arial, sans-serif;
    direction: rtl;
    text-align: right;
    max-width: 100vw;
    width: 320px;
    box-sizing: border-box;
}

/* CRITICAL FIX: جدول روزها همیشه 7 ستون مساوی */
.pwt-days, .pdp-days {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 0 !important;
    white-space: normal !important;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

.pwt-day, .pdp-day {
    text-align: center !important;
    padding: 8px 0 !important;
    box-sizing: border-box !important;
    cursor: pointer;
    font-size: 14px;
    color: #495057;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-width: 32px;
    height: 32px;
    line-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* نوار روزهای هفته هم گرید شود */
.pwt-weekdays, .pdp-weekdays {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    text-align: center !important;
    padding: 8px 0 !important;
    margin: 0;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    white-space: normal !important;
}

.pwt-weekdays > *, .pdp-weekdays > * {
    text-align: center !important;
    font-weight: bold;
    color: #495057;
    font-size: 13px;
    padding: 8px;
    box-sizing: border-box;
}

/* هدر بالا (جایی که دکمه ماه قبل/بعد است) همیشه روی بقیه باشد */
.pwt-datepicker-header, .pwt-header, .pdp-header { 
    position: relative; 
    z-index: 2; 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom: none;
    padding: 12px 15px;
    text-align: center;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pwt-datepicker-title {
    font-size: 16px;
    font-weight: bold;
    color: white;
    flex: 1;
    text-align: center;
}

.pwt-datepicker-nav,
.pwt-btn-prev,
.pwt-btn-next {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 8px;
    margin: 0 5px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 18px;
    width: 32px;
    height: 32px;
    transition: all 0.3s ease;
    pointer-events: auto !important;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.pwt-datepicker-nav:hover,
.pwt-btn-prev:hover,
.pwt-btn-next:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

.pwt-day:hover, .pdp-day:hover {
    background: #e3f2fd;
    color: #1976d2;
    transform: scale(1.05);
}

.pwt-day.selected, .pdp-day.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: bold;
}

.pwt-day.today, .pdp-day.today {
    background: #fff3e0;
    color: #f57c00;
    font-weight: bold;
    border: 2px solid #ff9800;
}

.pwt-day.disabled, .pdp-day.disabled {
    color: #ccc;
    cursor: not-allowed;
    background: transparent;
}

.pwt-day.disabled:hover, .pdp-day.disabled:hover {
    background: transparent;
    transform: none;
}

/* Footer styling */
.pwt-datepicker-footer {
    border-top: 1px solid #e9ecef;
    padding: 12px 15px;
    text-align: center;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.pwt-datepicker-footer button,
.pwt-btn-today {
    padding: 8px 16px;
    margin: 0 5px;
    border: 1px solid #dee2e6;
    background: white;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'IRANSans', Tahoma, Arial, sans-serif;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.pwt-datepicker-footer button:hover,
.pwt-btn-today:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}

.pwt-btn-today {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    font-weight: bold;
}

.pwt-btn-today:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

/* CRITICAL FIX: موبایل - تمام عرض پایین صفحه */
@media (max-width: 576px) {
    .pwt-datepicker-container, .pdp-container {
        position: fixed !important; 
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important; 
        max-width: 100vw !important;
        margin: 0 !important;
        border-radius: 12px 12px 0 0 !important;
        max-height: 80vh !important;
        overflow-y: auto !important;
        transform: none !important;
    }
    
    .pwt-datepicker-header, .pwt-header, .pdp-header {
        padding: 10px 12px;
        position: sticky;
        top: 0;
        z-index: 1;
        border-radius: 12px 12px 0 0;
    }
    
    .pwt-datepicker-title {
        font-size: 14px;
    }
    
    .pwt-datepicker-nav,
    .pwt-btn-prev,
    .pwt-btn-next {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }
    
    .pwt-days, .pdp-days {
        padding: 10px;
        grid-template-columns: repeat(7, 1fr) !important;
    }
    
    .pwt-day, .pdp-day { 
        min-width: 28px;
        height: 28px;
        line-height: 28px;
        padding: 4px; 
        font-size: 13px; 
    }
    
    .pwt-datepicker-footer {
        padding: 10px;
        position: sticky;
        bottom: 0;
        background: #f8f9fa;
        border-radius: 0;
    }
    
    .pwt-datepicker-footer button,
    .pwt-btn-today {
        padding: 10px 16px;
        font-size: 14px;
        min-width: 80px;
    }
}

@media (max-width: 400px) {
    .pwt-datepicker-container,
    .pdp-container {
        left: 5px !important;
        right: 5px !important;
        bottom: 10px !important;
        width: calc(100% - 10px) !important;
    }

    .pwt-day, .pdp-day {
        min-width: 24px;
        height: 24px;
        line-height: 24px;
        font-size: 12px;
    }
}

/* اگر والد input، overflow:hidden دارد، پاپاپ قطع نشود */
.form-group, 
.elementor-widget, 
.input-wrapper,
.cfm-form-group,
.wp-block-group,
.elementor-widget-container,
.cfm-form,
.cfm-tab,
.cfm-tab-content { 
    overflow: visible !important; 
}

/* ترجیحاً خود input تاریخ LTR باشد تا خواناتر */
input[name="from_date"], 
input[name="to_date"], 
input[name="request_date"], 
input[name="purchase_date"],
input[name="report_date_from"], 
input[name="report_date_to"], 
#from_date,
#to_date,
#request-date,
#purchase-date,
#report-date-from,
#report-date-to,
.persian-datepicker,
.ezpost-date { 
    direction: ltr !important; 
    text-align: left !important;
    font-family: 'IRANSans', Tahoma, Arial, sans-serif;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    transition: border-color 0.3s ease;
}

.persian-datepicker:focus,
.ezpost-date:focus,
input[name="from_date"]:focus, 
input[name="to_date"]:focus,
input[name="request_date"]:focus, 
input[name="purchase_date"]:focus,
input[name="report_date_from"]:focus, 
input[name="report_date_to"]:focus,
#from_date:focus,
#to_date:focus,
#request-date:focus,
#purchase-date:focus,
#report-date-from:focus,
#report-date-to:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .pwt-datepicker-container,
    .pdp-container,
    .pwt-date-picker {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .pwt-weekdays, .pdp-weekdays {
        background: #4a5568;
        color: #e2e8f0;
        border-color: #718096;
    }

    .pwt-weekdays > *, .pdp-weekdays > * {
        color: #e2e8f0;
    }

    .pwt-day, .pdp-day {
        color: #e2e8f0;
    }

    .pwt-datepicker-footer {
        background: #4a5568;
        border-color: #718096;
    }

    .pwt-datepicker-footer button {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #718096;
    }
}