/**
 * Appointment Calendar Styles
 * Supports week and month views with dark mode
 */

/* ===== Day View ===== */
.calendar-day-view {
    display: flex;
    flex-direction: column;
    min-height: 600px;
}

.calendar-day-view-header {
    border: 1px solid var(--bs-border-color);
    border-bottom: none;
}

.calendar-day-header-single {
    background: var(--bs-body-bg);
    padding: 1rem 1.5rem;
    border-bottom: 2px solid var(--bs-border-color);
}

.calendar-day-header-single.today {
    background: rgba(13, 110, 253, 0.08);
    border-bottom-color: var(--bs-primary);
}

.calendar-day-header-single .day-header-top {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.calendar-day-header-single .day-name-long {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--bs-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.calendar-day-header-single .day-number-large {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--bs-body-color);
    line-height: 1;
}

.calendar-day-header-single.today .day-number-large {
    color: var(--bs-primary);
}

.calendar-day-header-single .day-month-year {
    font-size: 1rem;
    color: var(--bs-secondary);
}

.calendar-day-header-single .day-event-count {
    margin-left: auto;
}

.calendar-day-header-single .day-header-events {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--bs-border-color);
}

.calendar-day-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bs-border-color);
    border: 1px solid var(--bs-border-color);
}

.calendar-day-time-row {
    display: grid;
    grid-template-columns: minmax(50px, 70px) 1fr;
    gap: 1px;
    min-height: 70px;
}

.calendar-day-time-row.has-events {
    min-height: 80px;
}

.calendar-day-time-cell {
    background: var(--bs-body-bg);
    padding: 0.5rem 0.75rem;
    cursor: default;
    position: relative;
}

.calendar-day-time-cell:hover {
    background: var(--bs-tertiary-bg);
}

/* Day view event cards — wider with more detail */
.calendar-event-day {
    margin-bottom: 0.375rem;
}

.calendar-event-day .event-location {
    font-size: 0.688rem;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 0.125rem;
}

/* Clickable day numbers in month and week views */
.day-drill {
    cursor: pointer;
}

.calendar-month-cell .cell-date.day-drill:hover {
    color: var(--bs-primary);
    text-decoration: underline;
}

.calendar-day-header .day-number.day-drill:hover {
    color: var(--bs-primary);
    text-decoration: underline;
}

/* ===== Week View ===== */
.calendar-week-view {
    display: flex;
    flex-direction: column;
    min-height: 600px;
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
}

/* Smooth container transitions */
#calendarContainer {
    transition: all 0.2s ease-in-out;
}

.calendar-week-header {
    display: grid;
    grid-template-columns: minmax(50px, 70px) repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--bs-border-color);
    border: 1px solid var(--bs-border-color);
    border-bottom: none;
    min-width: 100%;
}

/* Spacer in week header that aligns with the time-label column below */
.calendar-week-header-spacer {
    background: var(--bs-light);
    border-bottom: 2px solid var(--bs-border-color);
}

.calendar-day-header {
    background: var(--bs-body-bg);
    padding: 0.75rem;
    text-align: center;
    border-bottom: 2px solid var(--bs-border-color);
}

.calendar-day-header.today {
    background: rgba(13, 110, 253, 0.1);
    border-bottom-color: var(--bs-primary);
}

.calendar-day-header .day-header-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0.5rem;
}

.calendar-day-header .day-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--bs-secondary);
    text-transform: uppercase;
}

.calendar-day-header .day-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--bs-body-color);
    margin-top: 0.25rem;
}

.calendar-day-header.today .day-number {
    color: var(--bs-primary);
}

.calendar-day-header .day-header-events {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.5rem;
    width: 100%;
}

.calendar-week-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bs-border-color);
    border: 1px solid var(--bs-border-color);
}

.calendar-time-row {
    display: grid;
    grid-template-columns: minmax(50px, 70px) repeat(7, minmax(0, 1fr));
    gap: 1px;
    min-height: 60px;
}

.time-label {
    background: var(--bs-light);
    padding: 0.5rem 0.25rem;
    text-align: right;
    font-size: 0.75rem;
    color: var(--bs-secondary);
    font-weight: 500;
    word-break: keep-all;
    white-space: nowrap;
    overflow: hidden;
}

.calendar-time-cell {
    background: var(--bs-body-bg);
    padding: 0.25rem;
    cursor: pointer;
    position: relative;
    min-height: 60px;
}

.calendar-time-cell:hover {
    background: var(--bs-light);
}

/* ===== Month View ===== */
.calendar-month-view {
    display: flex;
    flex-direction: column;
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
}

.calendar-month-header {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--bs-border-color);
    border: 1px solid var(--bs-border-color);
    border-bottom: none;
    min-width: 100%;
}

.calendar-day-name {
    background: var(--bs-light);
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--bs-secondary);
    text-transform: uppercase;
}

.calendar-month-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--bs-border-color);
    border: 1px solid var(--bs-border-color);
}

.calendar-week-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
}

.calendar-month-cell {
    background: var(--bs-body-bg);
    min-height: 100px;
    padding: 0.5rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.calendar-month-cell.other-month {
    background: var(--bs-light);
    opacity: 0.6;
}

.calendar-month-cell.other-month .cell-date {
    color: var(--bs-secondary);
}

.calendar-month-cell.today {
    background: rgba(13, 110, 253, 0.05);
    border: 2px solid var(--bs-primary);
}

.calendar-month-cell:hover {
    background: var(--bs-tertiary-bg);
}

.calendar-month-cell .cell-date {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--bs-body-color);
    margin-bottom: 0.5rem;
}

.calendar-month-cell.today .cell-date {
    color: var(--bs-primary);
    font-size: 1rem;
}

.cell-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ===== Event Cards ===== */
.calendar-event {
    background: var(--bs-primary);
    color: white;
    padding: 0.375rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1.2;
    transition: transform 0.2s, box-shadow 0.2s;
}

.calendar-event:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* All-day event modifier - black border */
.all-day-event {
    border: 2px solid #000;
}

[data-bs-theme="dark"] .all-day-event {
    border-color: #fff;
}

/* Week view header events (compact style) */
.calendar-event-header {
    background: var(--bs-primary);
    color: white;
    padding: 0.25rem 0.375rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.688rem;
    line-height: 1.2;
    transition: transform 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event-header:hover {
    transform: translateX(2px);
}

.calendar-event-header .event-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event .event-time {
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.calendar-event .event-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event .event-customer {
    font-size: 0.688rem;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Event color classes - Appointments (all 20 colors) */
.calendar-event-purple,
.calendar-event-month.calendar-event-purple,
.calendar-event-header.calendar-event-purple {
    background: #6f42c1;
    color: white;
}

.calendar-event-green,
.calendar-event-month.calendar-event-green,
.calendar-event-header.calendar-event-green {
    background: #198754;
    color: white;
}

.calendar-event-blue,
.calendar-event-month.calendar-event-blue,
.calendar-event-header.calendar-event-blue {
    background: #0d6efd;
    color: white;
}

.calendar-event-orange,
.calendar-event-month.calendar-event-orange,
.calendar-event-header.calendar-event-orange {
    background: #fd7e14;
    color: white;
}

.calendar-event-red,
.calendar-event-month.calendar-event-red,
.calendar-event-header.calendar-event-red {
    background: #dc3545;
    color: white;
}

.calendar-event-yellow,
.calendar-event-month.calendar-event-yellow,
.calendar-event-header.calendar-event-yellow {
    background: #ffc107;
    color: #000 !important; /* Dark text for better contrast on yellow */
}

.calendar-event-pink,
.calendar-event-month.calendar-event-pink,
.calendar-event-header.calendar-event-pink {
    background: #d63384;
    color: white;
}

.calendar-event-cyan,
.calendar-event-month.calendar-event-cyan,
.calendar-event-header.calendar-event-cyan {
    background: #0dcaf0;
    color: #000 !important;
}

.calendar-event-teal,
.calendar-event-month.calendar-event-teal,
.calendar-event-header.calendar-event-teal {
    background: #20c997;
    color: white;
}

.calendar-event-indigo,
.calendar-event-month.calendar-event-indigo,
.calendar-event-header.calendar-event-indigo {
    background: #6610f2;
    color: white;
}

.calendar-event-lime,
.calendar-event-month.calendar-event-lime,
.calendar-event-header.calendar-event-lime {
    background: #84cc16;
    color: #000 !important;
}

.calendar-event-brown,
.calendar-event-month.calendar-event-brown,
.calendar-event-header.calendar-event-brown {
    background: #795548;
    color: white;
}

.calendar-event-gray,
.calendar-event-month.calendar-event-gray,
.calendar-event-header.calendar-event-gray {
    background: #6c757d;
    color: white;
}

/* Bootstrap utility color variants */
.calendar-event-success,
.calendar-event-month.calendar-event-success,
.calendar-event-header.calendar-event-success {
    background: #198754;
    color: white;
}

.calendar-event-danger,
.calendar-event-month.calendar-event-danger,
.calendar-event-header.calendar-event-danger {
    background: #dc3545;
    color: white;
}

.calendar-event-warning,
.calendar-event-month.calendar-event-warning,
.calendar-event-header.calendar-event-warning {
    background: #ffc107;
    color: #000 !important;
}

.calendar-event-info,
.calendar-event-month.calendar-event-info,
.calendar-event-header.calendar-event-info {
    background: #0dcaf0;
    color: #000 !important;
}

.calendar-event-primary,
.calendar-event-month.calendar-event-primary,
.calendar-event-header.calendar-event-primary {
    background: #0d6efd;
    color: white;
}

.calendar-event-secondary,
.calendar-event-month.calendar-event-secondary,
.calendar-event-header.calendar-event-secondary {
    background: #6c757d;
    color: white;
}

.calendar-event-dark,
.calendar-event-month.calendar-event-dark,
.calendar-event-header.calendar-event-dark {
    background: #212529;
    color: white;
}

/* Month view event compact style */
.calendar-event-month {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.375rem;
    border-radius: 3px;
    margin-bottom: 2px;
    cursor: pointer;
    font-size: 0.688rem;
    color: white;
    transition: transform 0.2s;
}

.calendar-event-month:hover {
    transform: translateX(2px);
}

.calendar-event-month .event-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
    flex-shrink: 0;
}

.calendar-event-month .event-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-more {
    font-size: 0.688rem;
    color: var(--bs-secondary);
    font-weight: 500;
    padding: 0.125rem 0.25rem;
    cursor: pointer;
}

.event-more:hover {
    color: var(--bs-primary);
}

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

/* Large Desktop - Show everything with plenty of space */
@media (min-width: 1400px) {
    .calendar-month-cell {
        min-height: 130px;
    }

    .calendar-time-cell {
        min-height: 70px;
    }
}

/* Standard Desktop - Default styles work well */
@media (min-width: 992px) and (max-width: 1399px) {
    .calendar-month-cell {
        min-height: 110px;
    }

    .calendar-day-header .day-number {
        font-size: 1.25rem;
    }
}

/* Tablet - Start compacting */
@media (min-width: 768px) and (max-width: 991px) {
    .calendar-month-cell {
        min-height: 90px;
    }

    .calendar-time-cell {
        min-height: 50px;
    }

    .calendar-day-header .day-number {
        font-size: 1.125rem;
    }

    .calendar-day-header .day-name {
        font-size: 0.75rem;
    }

    .calendar-event {
        font-size: 0.688rem;
        padding: 0.25rem 0.375rem;
    }

    .calendar-event .event-customer {
        font-size: 0.625rem;
    }

    .time-label {
        font-size: 0.688rem;
        padding: 0.375rem 0.125rem;
    }
}

/* Mobile - Compact view with horizontal scroll */
@media (max-width: 767px) {
    .calendar-week-view,
    .calendar-month-view {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .calendar-week-header,
    .calendar-month-header,
    .calendar-week-row {
        min-width: 650px;
    }

    .calendar-time-row {
        min-width: 650px;
    }

    .calendar-week-header {
        grid-template-columns: 45px repeat(7, minmax(80px, 1fr));
    }

    .calendar-time-row {
        grid-template-columns: 45px repeat(7, minmax(80px, 1fr));
    }

    .calendar-month-cell {
        min-height: 75px;
        padding: 0.375rem;
    }

    .calendar-time-cell {
        min-height: 45px;
    }

    .calendar-day-header {
        padding: 0.5rem 0.25rem;
    }

    .calendar-day-header .day-number {
        font-size: 1rem;
    }

    .calendar-day-header .day-name {
        font-size: 0.688rem;
    }

    .calendar-event {
        font-size: 0.625rem;
        padding: 0.25rem 0.375rem;
    }

    .calendar-event .event-customer {
        display: none;
    }

    .calendar-event-header {
        font-size: 0.625rem;
        padding: 0.1875rem 0.25rem;
    }

    .time-label {
        font-size: 0.625rem;
        padding: 0.25rem 0.125rem;
    }

    .calendar-month-cell .cell-date {
        font-size: 0.75rem;
    }
}

/* ===== Dark Mode Support ===== */
[data-bs-theme="dark"] .calendar-day-header-single.today {
    background: rgba(13, 110, 253, 0.15);
}

[data-bs-theme="dark"] .calendar-day-time-cell {
    background: var(--bs-body-bg);
}

[data-bs-theme="dark"] .calendar-day-header.today {
    background: rgba(13, 110, 253, 0.2);
}

[data-bs-theme="dark"] .calendar-month-cell.today {
    background: rgba(13, 110, 253, 0.1);
}

[data-bs-theme="dark"] .calendar-month-cell.other-month {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .time-label {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .calendar-week-header-spacer {
    background: var(--bs-secondary-bg);
}

[data-bs-theme="dark"] .calendar-day-name {
    background: var(--bs-secondary-bg);
}

/* ===== Loading State ===== */
#calendarContainer .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* ===== Print Styles ===== */
@media print {
    .calendar-time-cell:hover,
    .calendar-month-cell:hover {
        background: transparent;
    }

    .calendar-event:hover,
    .calendar-event-month:hover {
        transform: none;
        box-shadow: none;
    }
}

/* ===== Schedule Sidebar ===== */
.schedule-sidebar {
    width: 210px;
    flex-shrink: 0;
    transition: width 0.2s ease;
}

.schedule-sidebar.sidebar-collapsed {
    width: 42px;
}

.schedule-sidebar-header {
    padding: 0.4rem 0.6rem;
    background: var(--bs-tertiary-bg);
}

.schedule-sidebar-body {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
}

/* Sidebar job cards */
.sj-card {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.4rem;
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.15s, opacity 0.15s;
}

.sj-card:hover {
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
}

.sj-card.sj-dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.sj-number {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--bs-body-color);
}

.sj-customer {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sj-status {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sj-due {
    font-size: 0.68rem;
}

/* Sidebar drop zone highlight */
.sidebar-drag-over .card {
    border-color: var(--bs-primary) !important;
    box-shadow: 0 0 0 2px rgba(13,110,253,.25);
}

/* ===== Drag-over highlight for calendar cells ===== */
.calendar-drag-over {
    background: rgba(13, 110, 253, 0.08) !important;
    outline: 2px dashed var(--bs-primary);
    outline-offset: -2px;
}

/* ===== Dragging job event on calendar ===== */
.event-dragging {
    opacity: 0.4;
    cursor: grabbing;
}

/* Ensure calendar takes full remaining width */
.min-width-0 {
    min-width: 0;
}

/* ===== Collapsed sidebar — center the chevron button ===== */
.schedule-sidebar.sidebar-collapsed .schedule-sidebar-header {
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
}

.schedule-sidebar.sidebar-collapsed .schedule-sidebar-header > div {
    flex-direction: column;
    align-items: center;
}

/* ===== Job hover preview card ===== */
.sjp-card {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    overflow: hidden;
    width: 260px;
    font-size: 0.8rem;
}

.sjp-status-bar {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fff;
    padding: 0.2rem 0.6rem;
}

.sjp-header {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.6rem 0.1rem 0.5rem;
}

.sjp-job {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--bs-body-color);
}

.sjp-customer {
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
    padding: 0 0.6rem 0.3rem 0.6rem;
}

.sjp-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--bs-secondary-color);
    font-size: 0.75rem;
    margin-bottom: 0.15rem;
    padding: 0 0.6rem;
}

.sjp-overdue {
    color: #dc3545 !important;
    font-weight: 600;
}

.sjp-notes {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
    font-style: italic;
    margin: 0.25rem 0.6rem;
    border-top: 1px solid var(--bs-border-color);
    padding-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sjp-items {
    border-top: 1px solid var(--bs-border-color);
    margin-top: 0.3rem;
    padding: 0.3rem 0.6rem 0.4rem;
}

.sjp-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--bs-body-color);
    padding: 0.05rem 0;
    min-width: 0;
}

.sjp-item-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.sjp-qty {
    font-weight: 700;
    color: var(--bs-primary);
    flex-shrink: 0;
}

.sjp-color-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bs-secondary);
    flex-shrink: 0;
}

.sjp-color {
    font-size: 0.68rem;
    color: var(--bs-secondary-color);
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sjp-more {
    color: var(--bs-secondary-color);
    font-style: italic;
    font-size: 0.72rem;
}
