/* ===== v24 calendar page ===== */

.crm-calendar-shell {
    overflow: hidden;
}

.crm-calendar-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}

.crm-calendar-head h2 {
    margin: 0;
    font-size: clamp(26px, 3vw, 38px);
    line-height: 1.05;
    letter-spacing: -.02em;
}

.crm-calendar-head p {
    margin: 8px 0 0;
    color: var(--crm-soft);
}

.crm-calendar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.crm-calendar-switch,
.crm-calendar-nav {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid var(--crm-border);
    border-radius: 16px;
    background: var(--crm-panel-2);
}

.crm-calendar-switch button,
.crm-calendar-nav button {
    min-height: 36px;
    border: 0;
    border-radius: 12px;
    padding: 0 13px;
    background: transparent;
    color: var(--crm-soft);
    font-weight: 850;
}

.crm-calendar-switch button.active {
    color: #ffffff;
    background: linear-gradient(135deg, #0f46d9, #0b2f9f);
    box-shadow: 0 10px 22px rgba(37, 99, 235, .26);
}

.crm-calendar-nav button:hover {
    color: var(--crm-text);
    background: color-mix(in srgb, var(--crm-primary) 10%, transparent);
}

.crm-calendar-view {
    display: none;
}

.crm-calendar-view.active {
    display: block;
}

.crm-month-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.crm-month-weekdays span {
    color: var(--crm-soft);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 0 10px;
}

.crm-month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.crm-month-cell {
    min-height: 132px;
    border: 1px solid var(--crm-border);
    border-radius: 18px;
    background: var(--crm-panel-2);
    padding: 10px;
    min-width: 0;
    transition: .16s ease;
}

.crm-month-cell:hover {
    border-color: color-mix(in srgb, var(--crm-primary) 45%, var(--crm-border) 55%);
    background: color-mix(in srgb, var(--crm-primary) 5%, var(--crm-panel-2) 95%);
}

.crm-month-cell.muted {
    opacity: .42;
}

.crm-month-cell.today {
    border-color: color-mix(in srgb, var(--crm-primary) 60%, var(--crm-border) 40%);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--crm-primary) 42%, transparent);
}

.crm-month-cell-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.crm-month-cell-top strong {
    font-size: 15px;
}

.crm-month-cell-top span {
    min-height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    background: rgba(59, 130, 246, .14);
    color: var(--crm-primary-2);
    font-size: 11px;
    font-weight: 900;
}

.crm-month-events {
    display: grid;
    gap: 6px;
}

.crm-calendar-event {
    min-width: 0;
    border-radius: 12px;
    padding: 7px 8px;
    display: grid;
    gap: 3px;
    border: 1px solid transparent;
    transition: .16s ease;
}

.crm-calendar-event:hover {
    transform: translateY(-1px);
}

.crm-calendar-event span {
    font-size: 11px;
    font-weight: 900;
    opacity: .88;
}

.crm-calendar-event strong {
    font-size: 12px;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-calendar-event.blue,
.crm-week-event.blue {
    color: #93c5fd;
    background: rgba(59, 130, 246, .14);
    border-color: rgba(59, 130, 246, .22);
}

.crm-calendar-event.cyan,
.crm-week-event.cyan {
    color: #67e8f9;
    background: rgba(6, 182, 212, .13);
    border-color: rgba(6, 182, 212, .22);
}

.crm-calendar-event.violet,
.crm-week-event.violet {
    color: #c4b5fd;
    background: rgba(124, 58, 237, .14);
    border-color: rgba(124, 58, 237, .22);
}

.crm-calendar-event.green,
.crm-week-event.green {
    color: #86efac;
    background: rgba(34, 197, 94, .13);
    border-color: rgba(34, 197, 94, .22);
}

.crm-calendar-event.orange,
.crm-week-event.orange {
    color: #fdba74;
    background: rgba(249, 115, 22, .14);
    border-color: rgba(249, 115, 22, .22);
}

.crm-calendar-event.red,
.crm-week-event.red {
    color: #fca5a5;
    background: rgba(239, 68, 68, .14);
    border-color: rgba(239, 68, 68, .22);
}

html[data-theme="light"] .crm-calendar-event.blue,
html[data-theme="light"] .crm-week-event.blue { color: #1d4ed8; }

html[data-theme="light"] .crm-calendar-event.cyan,
html[data-theme="light"] .crm-week-event.cyan { color: #0e7490; }

html[data-theme="light"] .crm-calendar-event.violet,
html[data-theme="light"] .crm-week-event.violet { color: #6d28d9; }

html[data-theme="light"] .crm-calendar-event.green,
html[data-theme="light"] .crm-week-event.green { color: #166534; }

html[data-theme="light"] .crm-calendar-event.orange,
html[data-theme="light"] .crm-week-event.orange { color: #c2410c; }

html[data-theme="light"] .crm-calendar-event.red,
html[data-theme="light"] .crm-week-event.red { color: #991b1b; }

.crm-week-calendar {
    border: 1px solid var(--crm-border);
    border-radius: 20px;
    overflow: hidden;
    background: var(--crm-panel-solid);
}

.crm-week-header {
    display: grid;
    grid-template-columns: 72px repeat(7, minmax(0, 1fr));
    border-bottom: 1px solid var(--crm-border);
    background: var(--crm-panel-2);
}

.crm-week-corner {
    border-right: 1px solid var(--crm-border);
}

.crm-week-day-head {
    min-height: 66px;
    border-right: 1px solid var(--crm-border);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 4px;
}

.crm-week-day-head:last-child {
    border-right: 0;
}

.crm-week-day-head span {
    color: var(--crm-soft);
    font-size: 12px;
    font-weight: 900;
}

.crm-week-day-head strong {
    font-size: 15px;
}

.crm-week-day-head.today {
    color: var(--crm-primary-2);
    background: rgba(59, 130, 246, .08);
}

.crm-week-body {
    display: grid;
    grid-template-columns: 72px 1fr;
}

.crm-week-time-col {
    border-right: 1px solid var(--crm-border);
    background: var(--crm-panel-2);
}

.crm-week-time-col div {
    height: 72px;
    padding: 8px 8px 0;
    color: var(--crm-soft);
    font-size: 12px;
    font-weight: 800;
    text-align: right;
}

.crm-week-grid {
    position: relative;
    height: 864px;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.crm-week-day-col {
    border-right: 1px solid var(--crm-border);
    min-width: 0;
}

.crm-week-day-col:last-child {
    border-right: 0;
}

.crm-week-day-col.today {
    background: rgba(59, 130, 246, .045);
}

.crm-week-hour-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--crm-border);
    pointer-events: none;
}

.crm-current-time-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: #ef4444;
    z-index: 6;
    box-shadow: 0 0 14px rgba(239, 68, 68, .42);
}

.crm-current-time-line::before {
    content: "";
    position: absolute;
    left: -5px;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
}

.crm-current-time-line span {
    position: absolute;
    left: 8px;
    top: -13px;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 900;
}

.crm-week-event {
    position: absolute;
    z-index: 5;
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 9px 10px;
    overflow: hidden;
    display: grid;
    align-content: start;
    gap: 4px;
    transition: .16s ease;
}

.crm-week-event:hover {
    transform: translateY(-1px);
    z-index: 7;
}

.crm-week-event strong {
    font-size: 13px;
    line-height: 1.12;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-week-event span {
    font-size: 11px;
    font-weight: 850;
    opacity: .85;
}

@media (max-width: 1180px) {
    .crm-calendar-head {
        flex-direction: column;
    }

    .crm-calendar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .crm-month-grid,
    .crm-month-weekdays {
        min-width: 900px;
    }

    .crm-calendar-view[data-calendar-view="month"] {
        overflow-x: auto;
    }

    .crm-week-calendar {
        min-width: 980px;
    }

    .crm-calendar-view[data-calendar-view="week"] {
        overflow-x: auto;
    }
}

@media (max-width: 680px) {
    .crm-calendar-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .crm-calendar-switch,
    .crm-calendar-nav {
        width: 100%;
        justify-content: center;
    }

    .crm-calendar-actions .crm-btn {
        width: 100%;
    }
}

/* ===== v25 calendar: overlaps, day view, mobile month ===== */

.crm-calendar-switch {
    grid-template-columns: repeat(3, 1fr);
}

.crm-day-calendar {
    border: 1px solid var(--crm-border);
    border-radius: 20px;
    overflow: hidden;
    background: var(--crm-panel-solid);
}

.crm-day-header {
    min-height: 72px;
    border-bottom: 1px solid var(--crm-border);
    background: var(--crm-panel-2);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.crm-day-header span {
    display: block;
    color: var(--crm-soft);
    font-size: 12px;
    font-weight: 900;
    margin-bottom: 5px;
}

.crm-day-header strong {
    display: block;
    font-size: 20px;
}

.crm-day-header b {
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    background: rgba(59, 130, 246, .14);
    color: var(--crm-primary-2);
    font-size: 12px;
    font-weight: 900;
}

.crm-day-body {
    display: grid;
    grid-template-columns: 72px 1fr;
}

.crm-day-grid {
    position: relative;
    height: 864px;
    min-width: 0;
    background: color-mix(in srgb, var(--crm-panel-solid) 94%, var(--crm-primary) 6%);
}

.crm-week-event {
    min-width: 0;
}

.crm-week-event strong,
.crm-week-event span {
    max-width: 100%;
}

/* Мобильная версия календаря */
@media (max-width: 680px) {
    .crm-calendar-shell {
        margin-left: -12px;
        margin-right: -12px;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        padding-left: 10px;
        padding-right: 10px;
    }

    .crm-calendar-head {
        padding: 0 2px;
    }

    .crm-month-grid,
    .crm-month-weekdays {
        min-width: 0 !important;
        width: 100%;
        gap: 4px;
    }

    .crm-calendar-view[data-calendar-view="month"] {
        overflow-x: visible !important;
        width: 100%;
    }

    .crm-month-cell {
        min-height: 62px;
        border-radius: 12px;
        padding: 7px 5px;
    }

    .crm-month-cell-top {
        margin-bottom: 4px;
    }

    .crm-month-cell-top strong {
        font-size: 13px;
    }

    .crm-month-cell-top span {
        display: none;
    }

    .crm-month-events {
        display: flex;
        gap: 3px;
        align-items: center;
        min-height: 7px;
    }

    .crm-calendar-event {
        width: 100%;
        min-height: 5px;
        height: 5px;
        padding: 0;
        border-radius: 999px;
        overflow: hidden;
    }

    .crm-calendar-event span,
    .crm-calendar-event strong {
        display: none;
    }

    .crm-week-calendar,
    .crm-day-calendar {
        min-width: 0 !important;
        width: 100%;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .crm-calendar-view[data-calendar-view="week"],
    .crm-calendar-view[data-calendar-view="day"] {
        overflow-x: auto;
        margin-left: -10px;
        margin-right: -10px;
        padding-left: 0;
        padding-right: 0;
    }

    .crm-week-calendar {
        min-width: 840px !important;
    }

    .crm-day-calendar {
        min-width: 0 !important;
    }

    .crm-day-body {
        grid-template-columns: 56px 1fr;
    }

    .crm-week-time-col div {
        padding-right: 5px;
        font-size: 11px;
    }

    .crm-day-grid {
        min-width: 0;
    }

    .crm-week-event {
        padding: 7px 8px;
        border-radius: 12px;
    }

    .crm-week-event strong {
        font-size: 12px;
    }

    .crm-week-event span {
        font-size: 10px;
    }
}

/* ===== v26 calendar file split + mobile right offset + timing alignment ===== */

/* Страница календаря управляет шириной сама */
.crm-calendar-shell {
    max-width: 100%;
}

/* Более точное поведение недельной/дневной сетки */
.crm-week-grid,
.crm-day-grid {
    height: 864px; /* 12 часов × 72px, с 08:00 до 20:00 */
}

.crm-week-time-col div {
    height: 72px;
}

/* Линии часов ровно через 72px */
.crm-week-hour-line {
    height: 1px;
}

/* Мобильная версия: убираем странный правый отступ */
@media (max-width: 680px) {
    .crm-main:has(.crm-calendar-shell) {
        padding-left: 0 !important;
        padding-right: 0 !important;
        overflow-x: hidden !important;
    }

    .crm-main:has(.crm-calendar-shell) .crm-page-head {
        padding-left: 12px;
        padding-right: 12px;
    }

    .crm-calendar-shell {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-left: calc(50% - 50vw) !important;
        margin-right: calc(50% - 50vw) !important;
        border-left: 0 !important;
        border-right: 0 !important;
        border-radius: 0 !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .crm-calendar-head {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }

    .crm-month-grid,
    .crm-month-weekdays {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
    }

    .crm-month-cell {
        min-width: 0 !important;
    }

    .crm-calendar-view[data-calendar-view="month"] {
        overflow-x: hidden !important;
    }
}

