/* ===== Calendar View Styles ===== */

/* Container */
.calendar-container {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    min-height: 0;
}

/* ===== Toolbar ===== */
.calendar-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}

.calendar-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.calendar-toolbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.calendar-toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    flex-wrap: wrap;
}

.calendar-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.calendar-nav-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--copper-light);
    color: var(--copper);
}

.calendar-nav-btn svg {
    width: 16px;
    height: 16px;
}

.calendar-today-btn {
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.calendar-today-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--copper-light);
    color: var(--copper);
}

.calendar-title {
    font-family: 'Sora', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* Filter selects */
.calendar-filter-select {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b73' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.calendar-filter-select:hover,
.calendar-filter-select:focus {
    border-color: var(--copper-light);
    color: var(--text-primary);
}

/* View toggle */
.calendar-view-toggle {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.calendar-view-btn {
    height: 34px;
    padding: 0 14px;
    border: none;
    background: var(--bg-white);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-right: 1px solid var(--border-color);
    white-space: nowrap;
}

.calendar-view-btn:last-child {
    border-right: none;
}

.calendar-view-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.calendar-view-btn.active {
    background: var(--copper);
    color: #fff;
    font-weight: 600;
}

/* ===== Month Grid ===== */
.calendar-month-grid {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.calendar-month-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 2px solid var(--border-light);
}

.calendar-day-header {
    padding: 10px 0;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}

.calendar-month-body {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    flex: 1;
    min-height: 0;
}

/* Day cell */
.calendar-day-cell {
    min-height: 100px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: 6px;
    cursor: pointer;
    transition: background var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: relative;
    overflow: hidden;
}

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

.calendar-day-cell:hover {
    background: var(--bg-secondary);
}

.calendar-day-cell.other-month {
    background: var(--bg-primary);
    opacity: 0.55;
}

.calendar-day-cell.other-month:hover {
    opacity: 0.75;
    background: var(--bg-secondary);
}

.calendar-day-cell.today {
    background: #fff9f6;
}

.calendar-day-cell.today:hover {
    background: #fff4ef;
}

/* Day number */
.calendar-day-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
    margin-bottom: 2px;
}

.calendar-day-cell.today .calendar-day-number {
    background: var(--copper);
    color: #fff;
    font-weight: 700;
}

/* Job bars */
.calendar-job-bar {
    display: flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    min-width: 0;
}

.calendar-job-bar:hover {
    opacity: 0.85;
    transform: translateX(1px);
}

/* Time block striped pattern */
.calendar-job-bar.time-block {
    background-image: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 3px,
        rgba(255, 255, 255, 0.25) 3px,
        rgba(255, 255, 255, 0.25) 6px
    ) !important;
    border: 1px solid rgba(255,255,255,0.3);
}

/* More jobs overflow */
.calendar-more-jobs {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--copper);
    cursor: pointer;
    padding: 1px 6px;
    border-radius: 4px;
    transition: background var(--transition-fast);
    display: inline-block;
    text-decoration: none;
}

.calendar-more-jobs:hover {
    background: rgba(193, 127, 89, 0.1);
    color: var(--copper-dark);
}

/* ===== Week Grid ===== */
.calendar-week-grid {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.calendar-week-table {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    min-width: 600px;
    position: relative;
}

.calendar-week-col-header {
    padding: 12px 8px 10px;
    text-align: center;
    border-bottom: 2px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--bg-white);
    position: sticky;
    top: 0;
    z-index: 2;
}

.calendar-week-col-header:first-child {
    border-right: 1px solid var(--border-light);
}

.calendar-week-col-header:last-child {
    border-right: none;
}

.calendar-week-col-dayname {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}

.calendar-week-col-daynum {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.calendar-week-col-header.today .calendar-week-col-daynum {
    background: var(--copper);
    color: #fff;
}

.calendar-week-time-col {
    background: var(--bg-primary);
    border-right: 1px solid var(--border-light);
    position: sticky;
    left: 0;
    z-index: 1;
}

/* Time label */
.calendar-time-label {
    height: 48px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 4px 8px 0 0;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-light);
}

/* Week cell */
.calendar-week-cell {
    height: 48px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    position: relative;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.calendar-week-cell:last-child {
    border-right: none;
}

.calendar-week-cell:hover {
    background: var(--bg-secondary);
}

.calendar-week-cell.today-col {
    background: #fff9f6;
}

.calendar-week-cell.today-col:hover {
    background: #fff4ef;
}

/* Week view job blocks */
.calendar-week-job {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 0.71rem;
    font-weight: 500;
    color: #fff;
    overflow: hidden;
    cursor: pointer;
    z-index: 2;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    min-height: 20px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 1px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.calendar-week-job:hover {
    opacity: 0.88;
    transform: scale(1.01);
}

.calendar-week-job.time-block {
    background-image: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 3px,
        rgba(255, 255, 255, 0.2) 3px,
        rgba(255, 255, 255, 0.2) 6px
    ) !important;
    border: 1px solid rgba(255,255,255,0.3);
}

.calendar-week-job-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    line-height: 1.3;
}

.calendar-week-job-sub {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
    font-size: 0.66rem;
    line-height: 1.2;
}

/* Week grid column days */
.calendar-week-day-col {
    display: flex;
    flex-direction: column;
    position: relative;
    border-right: 1px solid var(--border-light);
}

.calendar-week-day-col:last-child {
    border-right: none;
}

/* ===== Event Creation Modal ===== */
.calendar-event-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 31, 0.45);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.calendar-event-modal-overlay.open {
    display: flex;
}

.calendar-event-modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 420px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    animation: calModalIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes calModalIn {
    from { opacity: 0; transform: scale(0.94) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.calendar-event-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.calendar-event-modal-title {
    font-family: 'Sora', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.calendar-event-modal-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: rgba(193, 127, 89, 0.12);
    color: var(--copper);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.calendar-event-modal-close {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    font-size: 1rem;
    line-height: 1;
}

.calendar-event-modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.calendar-event-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.calendar-event-type-toggle {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.calendar-event-type-btn {
    flex: 1;
    height: 36px;
    border: none;
    background: var(--bg-white);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-right: 1px solid var(--border-color);
}

.calendar-event-type-btn:last-child {
    border-right: none;
}

.calendar-event-type-btn:hover {
    background: var(--bg-secondary);
}

.calendar-event-type-btn.active {
    background: var(--copper);
    color: #fff;
    font-weight: 600;
}

.calendar-modal-form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.calendar-modal-form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.calendar-modal-input {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    transition: border-color var(--transition-fast);
    width: 100%;
}

.calendar-modal-input:focus {
    border-color: var(--copper);
    box-shadow: 0 0 0 3px rgba(193, 127, 89, 0.1);
}

.calendar-modal-select {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    transition: border-color var(--transition-fast);
    width: 100%;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b73' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.calendar-modal-select:focus {
    border-color: var(--copper);
    box-shadow: 0 0 0 3px rgba(193, 127, 89, 0.1);
}

.calendar-modal-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.calendar-event-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-primary);
}

.calendar-modal-btn {
    height: 36px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}

.calendar-modal-btn.secondary {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.calendar-modal-btn.secondary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.calendar-modal-btn.primary {
    background: var(--copper);
    color: #fff;
}

.calendar-modal-btn.primary:hover {
    background: var(--copper-dark);
}

/* ===== Legend ===== */
.calendar-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 0 4px;
}

.calendar-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.calendar-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.calendar-legend-stripe {
    width: 16px;
    height: 10px;
    border-radius: 3px;
    background-image: repeating-linear-gradient(
        -45deg,
        #9b9ba3,
        #9b9ba3 2px,
        #d0d0d5 2px,
        #d0d0d5 5px
    );
    flex-shrink: 0;
}

/* ===== Empty state ===== */
.calendar-empty-week {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 0.85rem;
    text-align: center;
    grid-column: 2 / -1;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .calendar-container {
        padding: 12px;
        gap: 12px;
    }

    .calendar-toolbar {
        padding: 10px 12px;
        gap: 8px;
    }

    .calendar-toolbar-right {
        gap: 6px;
    }

    .calendar-title {
        font-size: 0.95rem;
    }

    .calendar-filter-select {
        font-size: 0.78rem;
        height: 32px;
    }

    .calendar-view-btn,
    .calendar-today-btn {
        height: 32px;
        padding: 0 10px;
        font-size: 0.78rem;
    }

    .calendar-nav-btn {
        width: 32px;
        height: 32px;
    }

    .calendar-day-cell {
        min-height: 72px;
        padding: 4px;
    }

    .calendar-job-bar {
        font-size: 0.65rem;
        padding: 1px 4px;
    }

    .calendar-week-table {
        min-width: 480px;
    }
}

/* ===== Map View ===== */
.map-container { padding: 24px; height: calc(100vh - 80px); display: flex; flex-direction: column; }
.map-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.map-filters { display: flex; gap: 12px; align-items: center; }
#mapLeaflet { flex: 1; border-radius: 12px; border: 1px solid var(--border-light, #e5e2dd); overflow: hidden; min-height: 400px; z-index: 1; }

.map-popup-title { font-family: 'Sora', sans-serif; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.map-popup-customer { font-size: 0.85rem; color: #6b7280; margin-bottom: 8px; }
.map-popup-detail { font-size: 0.8rem; display: flex; align-items: center; gap: 4px; margin-bottom: 3px; }
.map-popup-status {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 0.7rem; font-weight: 600; text-transform: capitalize;
}
.map-popup-link {
    display: inline-block; margin-top: 8px; color: #c17f59;
    font-weight: 500; font-size: 0.8rem; cursor: pointer;
}
.map-popup-link:hover { text-decoration: underline; }

.map-optimize-btn {
    display: flex; align-items: center; gap: 6px; padding: 8px 16px;
    background: linear-gradient(135deg, #c17f59, #a66b47);
    color: white; border: none; border-radius: 8px;
    font-family: 'DM Sans', sans-serif; font-size: 0.85rem; font-weight: 500;
    cursor: pointer; transition: all 0.15s ease;
}
.map-optimize-btn:hover { opacity: 0.9; transform: translateY(-1px); }
