/**
 * Tree-Ripe Stop Calendar
 * Month grid (desktop) + agenda list (mobile) with crew colors.
 *
 * @package TreeRipeEcosystem
 * @since 7.2.0
 */

/* ─── VARIABLES ─── */
:root {
    --sc-green: #0F5E41;
    --sc-green-dk: #0A4730;
    --sc-green-md: #408469;
    --sc-green-lt: #E8F4EB;
    --sc-text: #333333;
    --sc-sub: #444444;
    --sc-border: #e0e5e8;
    --sc-crew-red: #D93B3B;
    --sc-crew-blue: #3B7DD9;
    --sc-crew-yellow: #F9E084;
    --sc-crew-purple: #7B3DD9;
    --sc-crew-tbd: #cccccc;
}

/* ─── CONTAINER ─── */
.tr-sc {
    max-width: 1100px;
    margin: 0 auto;
    padding: clamp(20px, 4vw, 48px) clamp(16px, 3vw, 32px);
    font-family: 'Avenir Next', 'Avenir', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--sc-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── HEADER ─── */
.tr-sc-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: clamp(16px, 2.5vw, 28px);
    flex-wrap: wrap;
    gap: 12px;
}

.tr-sc-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(24px, 4vw, 36px);
    color: var(--sc-green);
    line-height: 1.15;
    margin: 0;
    padding: 0;
}

.tr-sc-subtitle {
    font-size: 16px;
    color: var(--sc-sub);
    margin-top: 4px;
    font-weight: 500;
}

/* ─── CONTROLS ─── */
.tr-sc-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tr-sc-today-btn {
    border: 2px solid var(--sc-green);
    background: transparent;
    color: var(--sc-green);
    font-weight: 700;
    font-size: 14px;
    padding: 0 20px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: inherit;
    min-height: 44px;
}

.tr-sc-today-btn:hover {
    background: var(--sc-green);
    color: #ffffff;
}

.tr-sc-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tr-sc-month-label {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(18px, 2.5vw, 24px);
    color: var(--sc-green);
    min-width: 200px;
    text-align: center;
}

.tr-sc-nav-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: 2px solid var(--sc-green);
    background: transparent;
    border-radius: 999px;
    color: var(--sc-green);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.tr-sc-nav-btn:hover {
    background: var(--sc-green);
    color: #ffffff;
}

.tr-sc-nav-btn i {
    font-size: 14px;
    line-height: 1;
}

/* ─── CREW LEGEND ─── */
.tr-sc-legend {
    display: flex;
    align-items: center;
    gap: clamp(12px, 2vw, 20px);
    margin-bottom: clamp(12px, 2vw, 20px);
    flex-wrap: wrap;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid var(--sc-border);
}

.tr-sc-legend-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--sc-sub);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-right: 4px;
}

.tr-sc-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--sc-sub);
}

.tr-sc-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    flex-shrink: 0;
}

.tr-sc-legend-pill {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    line-height: 1.4;
}

.tr-sc-legend-pill--normal {
    background: var(--sc-green-lt);
    color: var(--sc-green);
}

.tr-sc-legend-pill--busy {
    background: var(--sc-green);
    color: #ffffff;
}

/* ─── CALENDAR GRID ─── */
.tr-sc-grid {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid var(--sc-border);
    overflow: hidden;
}

.tr-sc-dow {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--sc-green);
}

.tr-sc-dow-cell {
    padding: 14px 0;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #ffffff;
}

.tr-sc-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

/* ─── DAY CELL ─── */
.tr-sc-day {
    min-height: clamp(80px, 11vw, 110px);
    border-right: 1px solid #eef0f2;
    border-bottom: 1px solid #eef0f2;
    padding: 8px;
    position: relative;
    cursor: default;
    transition: background 0.15s;
}

.tr-sc-day:nth-child(7n) {
    border-right: none;
}

.tr-sc-day--empty {
    background: #f8f9fa;
}

.tr-sc-day--has-stops {
    cursor: pointer;
}

.tr-sc-day--has-stops:hover {
    background: #f4f9f6;
}

.tr-sc-day--today {
    background: #f0faf4;
}

.tr-sc-day--today .tr-sc-day-num {
    background: var(--sc-green);
    color: #ffffff;
    border-radius: 999px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tr-sc-day--selected {
    background: #edf7f1 !important;
    box-shadow: inset 0 0 0 2px var(--sc-green);
}

.tr-sc-day-num {
    font-size: 14px;
    font-weight: 600;
    color: var(--sc-sub);
    display: inline-flex;
    line-height: 1;
    margin-bottom: 6px;
}

.tr-sc-day--empty .tr-sc-day-num {
    color: #cccccc;
}

/* Stop count pill */
.tr-sc-day-indicator {
    margin-top: 4px;
}

.tr-sc-day-pill {
    display: inline-flex;
    align-items: center;
    background: var(--sc-green-lt);
    color: var(--sc-green);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    line-height: 1.4;
    white-space: nowrap;
}

.tr-sc-day-pill--busy {
    background: var(--sc-green);
    color: #ffffff;
}

/* ─── EXPANDED PANEL ─── */
.tr-sc-expand {
    display: none;
    grid-column: 1 / -1;
    background: #ffffff;
    border-bottom: 2px solid var(--sc-green);
    border-top: 2px solid var(--sc-green);
    padding: clamp(16px, 3vw, 28px);
    animation: trScSlide 0.2s ease;
}

.tr-sc-expand--open {
    display: block;
}

@keyframes trScSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.tr-sc-expand-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.tr-sc-expand-date {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(20px, 3vw, 26px);
    color: var(--sc-green);
}

.tr-sc-expand-count {
    font-size: 16px;
    font-weight: 600;
    color: var(--sc-sub);
    margin-left: 8px;
}

.tr-sc-expand-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: 2px solid var(--sc-border);
    background: #ffffff;
    color: var(--sc-sub);
    border-radius: 999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.tr-sc-expand-close:hover {
    border-color: var(--sc-green);
    color: var(--sc-green);
}

/* Stop cards in expanded panel */
.tr-sc-expand-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.tr-sc-stop-card {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
    background: #ffffff;
    border-radius: 10px;
    text-decoration: none;
    color: var(--sc-text);
    border: 1.5px solid var(--sc-border);
    transition: border-color 0.18s, transform 0.12s;
}

.tr-sc-stop-card:hover {
    border-color: var(--sc-green);
    transform: translateY(-1px);
    color: var(--sc-text);
}

.tr-sc-stop-crew-bar {
    width: 4px;
    height: 36px;
    border-radius: 2px;
    flex-shrink: 0;
}

.tr-sc-stop-info {
    flex: 1;
    min-width: 0;
}

.tr-sc-stop-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--sc-text);
    line-height: 1.3;
    display: block;
}

.tr-sc-stop-meta {
    font-size: 16px;
    color: var(--sc-sub);
    font-weight: 500;
    margin-top: 2px;
    display: block;
}

.tr-sc-stop-crew-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: auto;
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.tr-sc-stop-thumbs {
    display: flex;
    gap: 4px;
    align-items: center;
    width: 100%;
    margin-left: 16px;
    order: 10;
}

.tr-sc-stop-thumb {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--sc-border);
}

.tr-sc-stop-thumb-more {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #f5f5f5;
    border: 1px solid var(--sc-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #666;
}

/* ─── MOBILE: AGENDA VIEW ─── */
.tr-sc-agenda {
    display: none;
}

/* ─── FOCUS STATES ─── */
.tr-sc-nav-btn:focus-visible,
.tr-sc-today-btn:focus-visible,
.tr-sc-expand-close:focus-visible,
.tr-sc-stop-card:focus-visible {
    outline: 3px solid var(--sc-green);
    outline-offset: 2px;
}

/* ─── TABLET (<=900px) ─── */
@media (max-width: 900px) {
    .tr-sc-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tr-sc-controls {
        width: 100%;
        justify-content: space-between;
    }

    .tr-sc-expand-list {
        grid-template-columns: 1fr;
    }
}

/* ─── MOBILE (<=640px): SWITCH TO AGENDA ─── */
@media (max-width: 640px) {
    .tr-sc-grid {
        display: none;
    }

    .tr-sc-agenda {
        display: block;
    }

    .tr-sc-agenda-day {
        margin-bottom: 2px;
    }

    .tr-sc-agenda-date {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        background: #f8f9fa;
        border: 1px solid #eef0f2;
        border-radius: 10px;
        cursor: pointer;
        transition: background 0.15s;
    }

    .tr-sc-agenda-date:hover {
        background: #f0faf4;
    }

    .tr-sc-agenda-date--today {
        background: #edf7f1;
        border-color: var(--sc-green-md);
    }

    .tr-sc-agenda-date--open {
        border-radius: 10px 10px 0 0;
        border-bottom: none;
    }

    .tr-sc-agenda-dow {
        font-size: 14px;
        font-weight: 700;
        color: var(--sc-green);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        width: 40px;
        flex-shrink: 0;
    }

    .tr-sc-agenda-daynum {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 22px;
        font-weight: 700;
        color: var(--sc-text);
        width: 36px;
        flex-shrink: 0;
    }

    .tr-sc-agenda-summary {
        flex: 1;
        min-width: 0;
    }

    .tr-sc-agenda-stop-count {
        font-size: 16px;
        font-weight: 600;
        color: var(--sc-sub);
        display: block;
    }

    .tr-sc-agenda-crews {
        display: flex;
        gap: 4px;
        margin-top: 4px;
    }

    .tr-sc-agenda-crew-pip {
        width: 10px;
        height: 10px;
        border-radius: 999px;
    }

    .tr-sc-agenda-chevron {
        font-size: 16px;
        color: var(--sc-sub);
        flex-shrink: 0;
        transition: transform 0.2s;
    }

    .tr-sc-agenda-date--open .tr-sc-agenda-chevron {
        transform: rotate(180deg);
    }

    .tr-sc-agenda-stops {
        display: none;
        border: 1px solid #eef0f2;
        border-top: none;
        border-radius: 0 0 10px 10px;
        overflow: hidden;
    }

    .tr-sc-agenda-stops--open {
        display: block;
    }

    .tr-sc-agenda-stop {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        border-bottom: 1px solid #eef0f2;
        text-decoration: none;
        color: var(--sc-text);
        transition: background 0.12s;
        min-height: 44px;
    }

    .tr-sc-agenda-stop:last-child {
        border-bottom: none;
    }

    .tr-sc-agenda-stop:hover {
        background: #f4f9f6;
    }

    .tr-sc-agenda-stop-bar {
        width: 4px;
        height: 32px;
        border-radius: 2px;
        flex-shrink: 0;
    }

    .tr-sc-agenda-stop-info {
        flex: 1;
        min-width: 0;
    }

    .tr-sc-agenda-stop-name {
        font-size: 16px;
        font-weight: 700;
        color: var(--sc-text);
        display: block;
    }

    .tr-sc-agenda-stop-time {
        font-size: 16px;
        color: var(--sc-sub);
        font-weight: 500;
        display: block;
    }

    .tr-sc-agenda-stop-crew {
        font-size: 13px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
    }

    .tr-sc-month-label {
        min-width: 160px;
        font-size: 18px;
    }
}

/* ─── EMPTY STATE ─── */
.tr-sc-empty-month {
    text-align: center;
    padding: clamp(40px, 6vw, 80px) 20px;
    color: var(--sc-sub);
}

.tr-sc-empty-month-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--sc-text);
    margin-bottom: 8px;
}

.tr-sc-empty-month-sub {
    font-size: 16px;
    max-width: 360px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ─── PRINT ─── */
@media print {
    .tr-sc-nav-btn,
    .tr-sc-today-btn,
    .tr-sc-expand-close { display: none; }

    .tr-sc-grid {
        border: 1px solid #dddddd;
    }
}
