/* ============================================================
   Calendar Page
============================================================ */

.calendar-page {
    width: 100%;
    max-width: 1180px;
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    padding: 16px 20px 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

/* ============================================================
   Header
============================================================ */

.calendar-page__header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.calendar-page__navigation {
    display: flex;
    align-items: center;
    gap: 9px;
}

.calendar-page__nav-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: .2s ease;
}

.calendar-page__nav-btn:hover {
    border-color: var(--color-border-strong);
    background: var(--color-surface-hover);
    transform: translateY(-1px);
}

.calendar-page__current-date {
    min-width: 125px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.calendar-page__month {
    font-size: 17px;
    font-weight: 800;
    color: var(--color-text);
}

.calendar-page__year {
    font-size: 10px;
    color: var(--color-text-muted);
}

.calendar-page__today-btn {
    height: 34px;
    padding: 0 15px;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: 10px;
    font-weight: 650;
    cursor: pointer;
    transition: .2s ease;
}

.calendar-page__today-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ============================================================
   Calendar Container
============================================================ */

.calendar-page__calendar {
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: 17px;
    background: var(--color-surface);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    flex: 1;
}

/* ============================================================
   Weekdays Row
============================================================ */

.calendar-page__weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    min-height: 39px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-hover);
    flex-shrink: 0;
}

.calendar-page__weekdays span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: var(--color-text-muted);
}

/* ============================================================
   Days Grid
============================================================ */

.calendar-page__days {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-auto-rows: minmax(91px, 1fr);
    overflow-y: auto;
    scrollbar-width: none;
}

.calendar-page__days::-webkit-scrollbar {
    display: none;
}

/* ============================================================
   Day Cell
============================================================ */

.calendar-day {
    position: relative;
    min-width: 0;
    min-height: 91px;
    padding: 8px 9px;
    border-left: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    transition: background .2s ease, box-shadow .2s ease;
    overflow: hidden;
}

.calendar-day:nth-child(7n + 1) {
    border-left: 0;
}

.calendar-day:hover {
    background: var(--color-surface-hover);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-primary) 30%, transparent);
}

.calendar-day--today {
    background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface));
    box-shadow: inset 0 0 0 1.5px var(--color-primary), 0 3px 12px color-mix(in srgb, var(--color-primary) 12%, transparent);
    z-index: 2;
}

.calendar-day--today .calendar-day__number {
    color: var(--color-primary-light);
    font-weight: 850;
}

.calendar-day--selected {
    box-shadow: inset 0 0 0 2px var(--color-primary) !important;
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface));
}

/* ============================================================
   Date Display
============================================================ */

.calendar-day__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 5px;
}

.calendar-day__number {
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 750;
    color: var(--color-text);
}

.calendar-day__dates {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.calendar-day__gregorian {
    direction: ltr;
    font-size: 8px;
    color: var(--color-text-muted);
}

.calendar-day__hijri {
    direction: rtl;
    font-size: 7px;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.calendar-day__today-label {
    padding: 2px 6px;
    border-radius: 5px;
    background: color-mix(in srgb, var(--color-primary) 12%, transparent);
    color: var(--color-primary-light);
    font-size: 7px;
    font-weight: 750;
}

/* ============================================================
   Activity Progress
============================================================ */

.calendar-day__activity-progress {
    margin-top: 6px;
    font-size: 8px;
    font-weight: 700;
    color: var(--color-text-secondary);
    direction: rtl;
}

/* ============================================================
   Session Colors
============================================================ */

.calendar-day__sessions {
    min-height: 17px;
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.calendar-day__sessions::-webkit-scrollbar {
    display: none;
}

.calendar-day__session {
    flex: 0 0 auto;
    width: 17px;
    height: 5px;
    border-radius: 10px;
    background: var(--activity-color);
}

/* ============================================================
   Duration
============================================================ */

.calendar-day__duration {
    position: absolute;
    right: 9px;
    bottom: 7px;
    direction: ltr;
    font-size: 9px;
    font-weight: 750;
    color: var(--color-text-secondary);
}

.calendar-day__empty {
    display: block;
    margin-top: 7px;
    font-size: 8px;
    color: var(--color-text-muted);
}

/* ============================================================
   Placeholder
============================================================ */

.calendar-day--placeholder {
    background: transparent;
    border-color: transparent !important;
    box-shadow: none !important;
    cursor: default;
    pointer-events: none;
}

/* ============================================================
   Holiday
============================================================ */

.calendar-day--holiday {
    background: color-mix(in srgb, #c0392b 5%, var(--color-surface));
}

.calendar-day--holiday .calendar-day__number {
    color: #e74c3c;
}

.calendar-day--today.calendar-day--holiday {
    box-shadow: inset 0 0 0 1.5px var(--color-primary), inset 3px 0 0 #c0392b, 0 3px 12px color-mix(in srgb, var(--color-primary) 12%, transparent);
}

/* ============================================================
   Day Detail Modal
============================================================ */

.day-detail-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    direction: rtl;
}

.day-detail-modal.is-open {
    display: flex;
}

.day-detail-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.day-detail-modal__box {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 860px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.day-detail-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.day-detail-modal__eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--color-primary-light);
    font-size: 10px;
    font-weight: 600;
}

.day-detail-modal__title {
    margin: 0 0 4px;
    color: var(--color-text);
    font-size: 19px;
    font-weight: 750;
}

.day-detail-modal__subtitle {
    display: block;
    color: var(--color-text-muted);
    font-size: 10px;
}

.day-detail-modal__close {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: transparent;
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: 21px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.day-detail-modal__close:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    transform: rotate(90deg);
}

/* ============================================================
   Modal Columns
============================================================ */

.day-detail-modal__columns {
    min-height: 0;
    flex: 1;
    display: flex;
    gap: 1px;
    background: var(--color-border);
    overflow: hidden;
}

.day-detail-modal__column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    padding: 16px 18px 18px;
    overflow-y: auto;
}

.day-detail-modal__column-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 12px;
    color: var(--color-text);
    font-size: 12px;
    font-weight: 750;
}

.day-detail-modal__column-count {
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: 400;
}

/* ============================================================
   Session Card
============================================================ */

.day-session-card {
    position: relative;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 11px 10px 11px 8px;
    border-radius: 10px;
    border: 1px solid var(--activity-color, var(--color-primary));
    background-color: color-mix(in srgb, var(--activity-color, var(--color-primary)) 15%, var(--color-surface));
    box-shadow: var(--shadow-xs);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    margin-bottom: 8px;
}

.day-session-card:hover {
    border-color: color-mix(in srgb, var(--activity-color, var(--color-primary)) 55%, var(--color-border));
    background-color: color-mix(in srgb, var(--activity-color, var(--color-primary)) 22%, var(--color-surface));
    transform: scale(1.01);
}

.day-session-card__color {
    width: 4px;
    flex-shrink: 0;
    align-self: stretch;
    border-radius: 4px;
    background-color: var(--activity-color, var(--color-primary));
}

.day-session-card__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.day-session-card__title {
    margin: 0;
    overflow: hidden;
    color: var(--color-text);
    font-size: 11px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.day-session-card__time {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--color-text-muted);
    font-size: 9px;
}

.day-session-card__time-separator {
    opacity: 0.55;
    font-size: 8px;
}

.day-session-card__duration {
    flex-shrink: 0;
    align-self: center;
    color: var(--color-text-muted);
    font-size: 9px;
}

.day-session-card__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.day-session-card__edit,
.day-session-card__delete {
    width: 27px;
    height: 27px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 7px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.day-session-card__edit:hover {
    color: var(--color-primary-light);
    border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
    background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
    transform: translateY(-1px);
}

.day-session-card__delete:hover {
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.3);
    background-color: rgba(231, 76, 60, 0.08);
    transform: translateY(-1px);
}

/* ============================================================
   Untimed Card
============================================================ */

.day-untimed-card {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface-elevated);
    transition: border-color 0.2s ease, background-color 0.2s ease;
    margin-bottom: 8px;
}

.day-untimed-card:hover {
    border-color: var(--color-border-strong);
    background: var(--color-surface-hover);
}

.day-untimed-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.day-untimed-card__title {
    overflow: hidden;
    color: var(--color-text);
    font-size: 11px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.day-untimed-card__progress {
    flex-shrink: 0;
    direction: ltr;
    color: var(--color-primary-light);
    font-size: 11px;
    font-weight: 700;
}

.day-untimed-card__checks {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.day-untimed-card__check {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border-strong);
    border-radius: 5px;
    background: var(--color-surface);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.day-untimed-card__check:hover {
    border-color: var(--color-primary-light);
    transform: scale(1.05);
}

.day-untimed-card__check--done {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.day-untimed-card__check--done::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
}

/* ============================================================
   Empty State
============================================================ */

.day-detail-modal__empty {
    margin: 6px 0 0;
    color: var(--color-text-muted);
    font-size: 11px;
    line-height: 1.7;
}

/* ============================================================
   Occasion
============================================================ */

.day-detail-modal__occasion {
    flex-shrink: 0;
    padding: 14px 22px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-elevated);
    color: var(--color-text-secondary);
    font-size: 12px;
    line-height: 1.8;
}

.day-detail-modal__occasion--holiday {
    background: color-mix(in srgb, #c0392b 6%, var(--color-surface));
    color: #e74c3c;
    font-weight: 600;
}

/* ============================================================
   Scrollbar
============================================================ */

.day-detail-modal__column::-webkit-scrollbar {
    width: 3px;
}

.day-detail-modal__column::-webkit-scrollbar-track {
    background: transparent;
}

.day-detail-modal__column::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 10px;
}

.day-detail-modal__column::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

.day-detail-modal__column {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
}

/* ============================================================
   Add Session Button
============================================================ */

.day-detail-modal__column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.day-detail-modal__add-session {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.day-detail-modal__add-session:hover {
    background: var(--color-primary-dark);
    transform: scale(1.1);
}

.day-detail-modal__add-session--disabled {
    background: var(--color-border-strong);
    cursor: not-allowed;
    opacity: 0.5;
}

.day-detail-modal__add-session--disabled:hover {
    background: var(--color-border-strong);
    transform: none;
}

/* ============================================================
   Note Button
============================================================ */

.day-session-card__note {
    width: 27px;
    height: 27px;
    border-radius: 7px;
    border: 1px solid var(--color-border);
    background: transparent;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    align-self: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--color-text-secondary);
}

.day-session-card__note:hover {
    background: var(--color-surface-hover);
}

.day-session-card__note--has-note {
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
    border-color: var(--color-primary);
    color: var(--color-primary-light);
}

/* ============================================================
   Disabled States
============================================================ */

.day-untimed-card__check--disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.day-untimed-card--future {
    opacity: 0.7;
}

/* ============================================================
   Responsive Design
============================================================ */

@media (max-width: 900px) {
    .calendar-page {
        padding: 14px;
    }

    .calendar-page__days {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .calendar-page__weekdays {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .calendar-page__weekdays span:nth-child(n + 6) {
        display: none;
    }

    .calendar-day:nth-child(7n + 1) {
        border-left: 1px solid var(--color-border);
    }

    .calendar-day:nth-child(5n + 1) {
        border-left: 0;
    }

    .day-detail-modal__box {
        max-width: 95%;
        max-height: 95vh;
        border-radius: 16px;
    }

    .day-detail-modal__header {
        padding: 14px 16px 10px;
    }

    .day-detail-modal__columns {
        flex-direction: column;
        overflow-y: auto;
    }

    .day-detail-modal__column {
        padding: 12px 14px;
    }
}

@media (max-width: 650px) {
    .calendar-page {
        padding: 12px;
    }

    .calendar-page__days {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .calendar-page__weekdays {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .calendar-page__weekdays span:nth-child(n + 4) {
        display: none;
    }

    .calendar-day:nth-child(5n + 1) {
        border-left: 1px solid var(--color-border);
    }

    .calendar-day:nth-child(3n + 1) {
        border-left: 0;
    }

    .day-detail-modal {
        padding: 12px;
    }

    .day-detail-modal__box {
        max-width: 98%;
        max-height: 98vh;
        border-radius: 14px;
    }

    .day-detail-modal__header {
        padding: 12px 14px 8px;
    }

    .day-detail-modal__title {
        font-size: 16px;
    }

    .day-detail-modal__column {
        padding: 10px 12px;
    }

    .day-detail-modal__occasion {
        padding: 10px 14px;
        font-size: 11px;
    }
}