﻿/* ---------- Faraz Calendar (modern look) ----------
   رنگ‌ها فقط از این متغیرها خوانده می‌شوند؛ برای تغییر تم کافی است همین‌ها را override کنید. */
div.faraz-calendar {
    --fc-primary: #4f46e5;
    --fc-primary-soft: #eef2ff;
    --fc-text: #1f2937;
    --fc-muted: #6b7280;
    --fc-border: #e5e7eb;
    --fc-hover: #f3f4f6;
    --fc-off: #dc2626;

    position: absolute;
    z-index: 9999;
    display: grid;
    direction: rtl;
    width: 320px;
    box-sizing: border-box;
    background: #fff;
    color: var(--fc-text);
    font-size: 14px;
    line-height: 1.4;
    border: 1px solid var(--fc-border);
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 6px rgba(15, 23, 42, .08);
    animation: fc-pop .16s ease-out;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

div.faraz-calendar *,
div.faraz-calendar *::before,
div.faraz-calendar *::after {
    box-sizing: border-box;
}

div.faraz-calendar > content,
div.faraz-calendar > side {
    display: block;
}

/* ---------- Buttons / links ---------- */
div.faraz-calendar button {
    font: inherit;
    color: inherit;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
    transition: background-color .15s, color .15s, box-shadow .15s;
}

div.faraz-calendar a {
    cursor: pointer;
    transition: background-color .15s, color .15s, box-shadow .15s;
}

div.faraz-calendar button:focus-visible,
div.faraz-calendar a:focus-visible {
    outline: 2px solid var(--fc-primary);
    outline-offset: 2px;
}

div.faraz-calendar svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    display: block;
}

/* ---------- Header (month title + prev/next) ---------- */
div.faraz-calendar div.info,
div.faraz-calendar div.years {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 12px 4px;
}

div.faraz-calendar div.info > button.prev,
div.faraz-calendar div.info > button.next,
div.faraz-calendar div.years > button.prev,
div.faraz-calendar div.years > button.next {
    flex: 0 0 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fc-muted);
}

/* در RTL: «قبلی» سمت راست و رو به راست، «بعدی» سمت چپ و رو به چپ */
div.faraz-calendar button.next > svg {
    transform: rotate(180deg);
}

div.faraz-calendar div.info > button.title,
div.faraz-calendar div.years > button.toggle {
    flex: 1;
    height: 36px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 15px;
}

div.faraz-calendar div.info > button.title::after {
    content: "";
    display: inline-block;
    margin-inline-start: 8px;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--fc-muted);
    border-bottom: 2px solid var(--fc-muted);
    transform: translateY(-2px) rotate(45deg);
}

/* ---------- Days grid ---------- */
div.faraz-calendar table {
    width: calc(100% - 24px);
    margin: 0 12px;
    border-spacing: 0;
    table-layout: fixed;
}

div.faraz-calendar table th {
    padding: 8px 0;
    background: none;
    color: var(--fc-muted);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

div.faraz-calendar table th:last-child {
    color: var(--fc-off);
}

div.faraz-calendar table td {
    padding: 1px;
    height: 42px;
}

div.faraz-calendar table td > a {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    border-radius: 12px;
    text-align: center;
}

div.faraz-calendar table td > a.off {
    color: var(--fc-off);
}

div.faraz-calendar table td > a.today {
    box-shadow: inset 0 0 0 1.5px var(--fc-primary);
    color: var(--fc-primary);
    font-weight: 700;
}

div.faraz-calendar table td > a.current {
    background: var(--fc-primary);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(79, 70, 229, .35);
}

/* ---------- Footer ---------- */
div.faraz-calendar div.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    padding: 8px 12px 12px;
    border-top: 1px solid var(--fc-border);
}

div.faraz-calendar div.footer > button {
    height: 36px;
    padding: 0 16px;
    border-radius: 10px;
    font-weight: 600;
}

div.faraz-calendar div.footer > button.go-today {
    color: var(--fc-primary);
    background: var(--fc-primary-soft);
}

div.faraz-calendar div.footer > button.dismiss,
div.faraz-calendar div.footer > button.close {
    color: var(--fc-muted);
}

/* ---------- Month / year picker (overlay) ---------- */
div.faraz-calendar > side {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #fff;
    border-radius: inherit;
}

div.faraz-calendar.picking > side {
    display: flex;
    flex-direction: column;
}

div.faraz-calendar ul,
div.faraz-calendar ol {
    display: none;
    flex: 1;
    list-style: none;
    margin: 0;
    padding: 8px 12px 0;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
}

div.faraz-calendar > side.month ul,
div.faraz-calendar > side.year ol {
    display: grid;
}

div.faraz-calendar li > a {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 44px;
    border-radius: 12px;
    background: #f9fafb;
    text-align: center;
}

div.faraz-calendar li > a.active {
    background: var(--fc-primary-soft);
    color: var(--fc-primary);
    font-weight: 700;
}

/* ---------- Hover (فقط ماوس؛ روی لمس چسبنده نشود) ---------- */
@media (hover: hover) {
    div.faraz-calendar button:hover {
        background: var(--fc-hover);
    }

    div.faraz-calendar div.footer > button.go-today:hover {
        background: #e0e7ff;
    }

    div.faraz-calendar table td > a:hover,
    div.faraz-calendar li > a:hover {
        background: var(--fc-hover);
    }

    div.faraz-calendar table td > a.current:hover {
        background: var(--fc-primary);
        filter: brightness(1.1);
    }

    div.faraz-calendar li > a.active:hover {
        background: var(--fc-primary-soft);
    }
}

/* ---------- Backdrop ---------- */
div.faraz-calendar-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    background: rgba(15, 23, 42, .12);
}

/* ---------- Animation ---------- */
@keyframes fc-pop {
    from { opacity: 0; transform: translateY(-6px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

@keyframes fc-sheet {
    from { transform: translateY(100%); }
    to   { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    div.faraz-calendar { animation: none !important; }
}

/* ---------- Mobile: bottom sheet ---------- */
@media (max-width: 600px) {
    div.faraz-calendar {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: auto;
        max-width: 480px;
        margin: 0 auto;
        padding-bottom: env(safe-area-inset-bottom);
        border-radius: 20px 20px 0 0;
        border-width: 1px 0 0;
        font-size: 16px;
        animation: fc-sheet .24s cubic-bezier(.2, .8, .2, 1);
    }

    div.faraz-calendar::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        margin: 8px auto 0;
        border-radius: 2px;
        background: #d1d5db;
    }

    div.faraz-calendar div.info,
    div.faraz-calendar div.years {
        padding-top: 8px;
    }

    div.faraz-calendar div.info > button.prev,
    div.faraz-calendar div.info > button.next,
    div.faraz-calendar div.years > button.prev,
    div.faraz-calendar div.years > button.next {
        flex-basis: 44px;
        height: 44px;
    }

    div.faraz-calendar div.info > button.title,
    div.faraz-calendar div.years > button.toggle {
        height: 44px;
        font-size: 17px;
    }

    div.faraz-calendar table td {
        height: 48px;
    }

    div.faraz-calendar table td > a {
        height: 46px;
    }

    div.faraz-calendar li > a {
        min-height: 52px;
    }

    div.faraz-calendar div.footer > button {
        height: 44px;
    }

    div.faraz-calendar-bg {
        background: rgba(15, 23, 42, .4);
    }
}
