/**
 * Styles for the in-house Calendar component (Scripts/Calendar/*.js), replacing FullCalendar.
 * Class prefix "cal-" throughout - deliberately distinct from FullCalendar's "fc-" classes
 * (Scheduler-Calendar-Design.md: clean-break DOM/CSS). Loaded after Modern.css so its --totm-*
 * tokens are already defined; the Schedule app has no dark-mode system, so this follows
 * Scheduler.css/Modern.css's convention of a single light theme rather than defining one.
 */

.cal-root {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    font-family: var(--totm-font);
    font-size: var(--totm-fs-sm);
    color: var(--totm-text);
    background: #fff;
    overflow: hidden;
    box-sizing: border-box;
}

.cal-root * {
    box-sizing: border-box;
}

/* --- Toolbar --- */

/* Matches the app-wide lighter header blue - the same rgba(25,118,210,.8) used by .SectionHeading
   (Jobs List, Job Details, every dialog title) and the old FullCalendar engine's own
   .fc-toolbar/.fc-button (measured live). The .8 alpha over the white panel behind it is what
   makes it read lighter than a solid #1976D2 - "the Date Heading" is this whole bar, not just the
   title text. */
.cal-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(25, 118, 210, .8);
    border-bottom: 1px solid rgba(0, 0, 0, .15);
}

.cal-toolbar-left,
.cal-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.cal-title {
    flex: 1 1 auto;
    text-align: center;
    font-weight: 700;
    font-size: var(--totm-fs-lg);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 4px;
    background: transparent;
    color: #fff;
    font-size: var(--totm-fs-sm);
    cursor: pointer;
}

.cal-btn:hover {
    background: rgba(255, 255, 255, .15);
}

.cal-btn:disabled {
    opacity: .5;
    cursor: default;
    background: transparent;
}

.cal-toolbar-icon-button {
    padding: 0 8px;
}

.cal-toolbar-nav-group {
    display: flex;
    gap: 2px;
}

.cal-body {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

/* --- Resource area (left column) --- */

.cal-resource-area {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
    border-right: 1px solid var(--totm-border-strong);
    background: #fff;
}

/* Drag handle for the resource/name column's width (Calendar.js's attach logic). Straddles the
   column's right border so it's easy to grab without needing pixel-perfect aim. */
.cal-resource-area-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 3;
}

.cal-resource-area-resizer:hover {
    background: var(--totm-brand-tint);
}

/* Applied to <body> for the duration of a drag - keeps the resize cursor and blocks text
   selection even when the pointer briefly outruns the (only 6px wide) handle. */
body.cal-resizing-columns {
    cursor: col-resize;
    user-select: none;
}

.cal-resource-area-header {
    flex: 0 0 auto;
    border-bottom: 1px solid var(--totm-border-strong);
    background: #F5F6F8;
}

.cal-resource-rows-viewport {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}

.cal-resource-rows {
    position: relative;
}

.cal-group-row {
    position: absolute;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: var(--totm-fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--totm-text-muted);
    background: #F5F6F8;
    border-bottom: 1px solid var(--totm-border);
}

.cal-resource-row {
    position: absolute;
    left: 0;
    right: 0;
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--totm-border);
    cursor: pointer;
}

.cal-resource-row--highlighted {
    background: #dcdcdc;
}

.cal-resource-cell {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* --- Timeline (single scroller for the axis + grid + events, section 3.2) --- */

.cal-timeline {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    overflow: auto;
    background: #fff;
}

.cal-time-axis {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 2;
    overflow: hidden;
    background: #F5F6F8;
    border-bottom: 1px solid var(--totm-border-strong);
}

.cal-slot-label {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding-left: 4px;
    font-size: var(--totm-fs-xs);
    color: var(--totm-text-muted);
    border-left: 1px solid var(--totm-border);
    white-space: nowrap;
}

.cal-day-column-label {
    justify-content: center;
    padding-left: 0;
    font-weight: 600;
}

.cal-today-column {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--totm-brand-tint);
    opacity: .6;
    pointer-events: none;
}

.cal-grid {
    position: relative;
    background: #fff;
}

.cal-slot-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--totm-border);
}

.cal-slot-line--hour {
    background: var(--totm-border-strong);
}

/* Shades OUTSIDE business hours (inverted on request from the original "shade business hours"
   design - see Calendar.Geometry.js's outOfHoursSpans). */
.cal-out-of-hours {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--totm-brand-tint);
    opacity: .6;
    pointer-events: none;
}

.cal-lane {
    position: absolute;
    left: 0;
    right: 0;
    border-bottom: 1px solid var(--totm-border);
}

.cal-lane--group {
    background: #F5F6F8;
}

.cal-now-indicator {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #E53935;
    pointer-events: none;
    z-index: 1;
}

.cal-event-layer {
    position: absolute;
    left: 0;
}

/* Drop-target outline shown while a job list tile is being dragged over the grid
   (Calendar.ExternalDragAdapter.js) - a plain sibling of the event chips, sized/positioned via
   Calendar.js's resolveHighlightRect so it lands exactly where the drop would land. */
.cal-drop-highlight {
    position: absolute;
    background: var(--totm-brand-tint);
    border: 2px dashed var(--totm-brand);
    border-radius: 2px;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 2;
}

/* Day view only - matches the old engine's eventOverlap:false, a drop that would land on an
   already-booked slot is refused (Calendar.ExternalDragAdapter.js withholds onDrop entirely). */
.cal-drop-highlight--invalid {
    background: rgba(229, 57, 53, .15);
    border-color: #E53935;
}

.cal-event {
    position: absolute;
    cursor: pointer;
}

/* renderEvent (the facade's colour/icon/title hook) targets this element, not the outer .cal-event -
   see Calendar.EventLayer.js's own comment on why the resize handles are kept as separate siblings. */
.cal-event-content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    gap: 3px;
    border-radius: 2px;
    overflow: hidden;
    padding: 2px 4px;
    font-size: var(--totm-fs-xs);
    line-height: 1.3;
    color: #fff;
    background: var(--totm-brand);
    border: 1px solid rgba(0, 0, 0, .15);
    white-space: nowrap;
}

/* Week/Month chips (Calendar.EventLayer.js's layoutChip) get real row height via lane division,
   so their title can wrap onto multiple lines instead of being clipped to one. pre-line (not
   normal) so the "JobCode - Customer\r\nJobName" break View.Calendar.js's renderNewEngineEvent
   builds into the title renders as an actual line, rather than collapsing to a space and only
   wrapping if the combined text happens to overflow the chip's width. */
.cal-event--wrap .cal-event-content {
    align-items: flex-start;
    white-space: pre-line;
}

.cal-event-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-event--wrap .cal-event-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    white-space: pre-line;
}

/* Status icon strip (time promise, fromMobile, H&S, vaccination, text-reminder-pending) - anchored
   to .cal-event-content's own top-right corner rather than flowing inline with the title, so a
   long title doesn't push icons out of view and icons don't eat into the title's own space.
   pointer-events:none so drag/resize/click still hit the chip underneath, not the icons. */
.cal-event-icons {
    position: absolute;
    top: 2px;
    right: 4px;
    display: flex;
    gap: 4px;
    pointer-events: none;
}

.cal-event-icon {
    font-size: 10px;
    text-shadow: 0 0 2px rgba(0, 0, 0, .6);
}

.cal-resize-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 6px;
    z-index: 2;
    cursor: ew-resize;
}

.cal-resize-handle--start {
    left: 0;
}

.cal-resize-handle--end {
    right: 0;
}

/* Only editable events show resize handles - fromMobile/editable:false events render none (Calendar.EventLayer.js). */
.cal-event:not(.cal-event--editable) .cal-resize-handle {
    display: none;
}

/* View.Calendar.js's job-selected highlight (addClockIconToJobsNewEngine) - transform-only so it
   never touches top/left/position, unlike jQuery UI's .effect("shake") which saves/restores
   those around a temporary DOM-wrapping animation and can stomp on Calendar.EventLayer's own
   absolute positioning if a render lands on this chip mid-shake. */
@keyframes cal-event-shake {
    0%, 100% { transform: translateX(0); }
    16.66%, 50%, 83.33% { transform: translateX(-10px); }
    33.33%, 66.66% { transform: translateX(10px); }
}

.cal-event--shaking {
    animation: cal-event-shake .6s ease-in-out;
}

.cal-event--dragging {
    z-index: 3;
}

.cal-event--dragging .cal-event-content {
    opacity: .75;
}

.cal-event--invalid .cal-event-content {
    outline: 2px solid #E53935;
    outline-offset: -2px;
}

/* Day view only (Calendar.EventLayer.js's layoutChip) - a chevron at whichever edge the booking's
   real start/end runs past the calendar's visible time range, pointing toward the hidden portion.
   currentColor so it matches the event's own text colour (set inline per-status by renderEvent)
   rather than a fixed shade. CSS-triangle trick: a zero-size transparent border box with one side
   coloured; colouring the side opposite the pointed-to edge is what makes the tip point that way.
   The matching padding-left/right reservation keeps the title/icons (renderEvent's innerHTML,
   flowed by .cal-event-content's flex layout) from running underneath it. */
.cal-event--continues-before .cal-event-content {
    padding-left: 10px;
}

.cal-event--continues-after .cal-event-content {
    padding-right: 10px;
}

.cal-event--continues-before .cal-event-content::before,
.cal-event--continues-after .cal-event-content::after {
    content: "";
    position: absolute;
    top: 50%;
    margin-top: -4px;
    border: 4px solid transparent;
    pointer-events: none;
}

.cal-event--continues-before .cal-event-content::before {
    left: 1px;
    border-right-color: currentColor;
}

.cal-event--continues-after .cal-event-content::after {
    right: 1px;
    border-left-color: currentColor;
}

/* --- Scrollbars, matching Modern.css's --totm-scrollbar tokens used elsewhere in Schedule --- */

.cal-timeline::-webkit-scrollbar,
.cal-resource-rows-viewport::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.cal-timeline::-webkit-scrollbar-thumb,
.cal-resource-rows-viewport::-webkit-scrollbar-thumb {
    background: var(--totm-scrollbar);
    border-radius: 5px;
}

.cal-timeline::-webkit-scrollbar-thumb:hover,
.cal-resource-rows-viewport::-webkit-scrollbar-thumb:hover {
    background: var(--totm-scrollbar-hover);
}

.cal-timeline::-webkit-scrollbar-track,
.cal-resource-rows-viewport::-webkit-scrollbar-track {
    background: transparent;
}
