/**
 * Calendar Timeline View
 * Google Calendar-style continuous timeline for appointment scheduling.
 * All classes prefixed with .ct- to avoid conflicts with .appt- grid classes.
 * Uses design-system.css variables for automatic dark mode support.
 */

/* ── Container ─────────────────────────────────────────── */
.ct-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    font-size: 0.8rem;
    user-select: none;
    position: relative;
}

/* ── Header row (tech names) ──────────────────────────── */
.ct-header {
    display: flex;
    border-bottom: 2px solid var(--border, #ddd);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-card, #fff);
}

.ct-header-gutter {
    width: 50px;
    min-width: 50px;
    flex-shrink: 0;
}

.ct-header-columns {
    display: flex;
    flex: 1;
    min-width: 0;
}

.ct-header-col {
    flex: 1;
    min-width: 0;
    text-align: center;
    padding: 0.4rem 0.25rem;
    font-weight: 600;
    font-size: 0.8rem;
    border-left: 1px solid var(--border, #ddd);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text, #333);
}

/* ── Scrollable body ──────────────────────────────────── */
.ct-body {
    display: flex;
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding-top: 8px;
}

/* ── Time gutter (left column) ────────────────────────── */
.ct-gutter {
    width: 50px;
    min-width: 50px;
    flex-shrink: 0;
    position: relative;
}

.ct-gutter-label {
    position: absolute;
    right: 6px;
    font-size: 0.7rem;
    color: var(--text-muted, #888);
    transform: translateY(-50%);
    white-space: nowrap;
    line-height: 1;
}

/* ── Columns area ─────────────────────────────────────── */
.ct-columns {
    display: flex;
    flex: 1;
    min-width: 0;
    position: relative;
}

.ct-column {
    flex: 1;
    min-width: 0;
    position: relative;
    border-left: 1px solid var(--border, #ddd);
}

/* ── Gridlines ────────────────────────────────────────── */
.ct-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid color-mix(in srgb, var(--border, #ddd) 50%, transparent);
    pointer-events: none;
    z-index: 0;
}

.ct-gridline--hour {
    border-top: 1px solid var(--border, #ddd);
}

/* ── Business hours overlay ───────────────────────────── */
.ct-non-business {
    position: absolute;
    left: 0;
    right: 0;
    background: var(--bg-card, #f5f5f5);
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}

.ct-business-hours {
    position: absolute;
    left: 0;
    right: 0;
    background: var(--bg-card, #fff);
    pointer-events: none;
    z-index: 0;
}

/* ── Current time indicator ───────────────────────────── */
.ct-now-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--error, #ef4444);
    z-index: 8;
    pointer-events: none;
}

.ct-now-line::before {
    content: '';
    position: absolute;
    left: -4px;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error, #ef4444);
}

/* ── Appointment event blocks ─────────────────────────── */
.ct-event {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 4px;
    padding: 2px 5px;
    overflow: hidden;
    cursor: pointer;
    z-index: 3;
    font-size: 0.72rem;
    line-height: 1.3;
    border-left: 3px solid;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.15s, transform 0.15s;
}

.ct-event:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    z-index: 6;
    transform: scale(1.01);
}

/* Type colors */
.ct-event--service {
    background: var(--info-bg, #dbeafe);
    border-left-color: var(--info, #3b82f6);
    color: var(--info-text, #1e40af);
}

.ct-event--drop_off {
    background: var(--success-bg, #d1fae5);
    border-left-color: var(--success, #22c55e);
    color: var(--success-text, #166534);
}

.ct-event--pickup {
    background: var(--warning-bg, #fef3c7);
    border-left-color: var(--warning, #f59e0b);
    color: var(--warning-text, #92400e);
}

.ct-event--remote {
    background: #ede9fe;
    border-left-color: #8b5cf6;
    color: #5b21b6;
}

.ct-event--call {
    background: #ccfbf1;
    border-left-color: #14b8a6;
    color: #115e59;
    z-index: 5;
}

/* This ticket highlight */
.ct-event--this-ticket {
    outline: 2px solid var(--info, #3b82f6);
    outline-offset: 1px;
    z-index: 5;
}

/* This customer's call highlight */
.ct-event--this-customer {
    outline: 2px solid #14b8a6;
    outline-offset: 1px;
    font-weight: 600;
    z-index: 5;
}

.ct-event--cancelled {
    opacity: 0.4;
    text-decoration: line-through;
}

/* Event content layout */
.ct-event-time {
    font-weight: 600;
    font-size: 0.7rem;
    white-space: nowrap;
}

.ct-event-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ct-event-ticket {
    font-size: 0.65rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ct-event-badge {
    float: right;
    font-size: 0.6rem;
    line-height: 1;
    margin-left: 2px;
}

/* ── Drag-to-move & resize ───────────────────────────── */
.ct-event-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
    border-radius: 0 0 4px 4px;
}

.ct-event-resize-handle:hover {
    background: rgba(0, 0, 0, 0.12);
}

.ct-event.ct-dragging {
    opacity: 0.35;
    pointer-events: none;
}

.ct-move-ghost {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 4px;
    border: 2px dashed var(--info, #3b82f6);
    background: var(--info-bg, #dbeafe);
    opacity: 0.7;
    z-index: 9;
    pointer-events: none;
    padding: 2px 5px;
    font-size: 0.72rem;
    line-height: 1.3;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ── Ghost preview (click-to-schedule) ────────────────── */
.ct-ghost {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 4px;
    background: var(--info-bg, #dbeafe);
    border: 2px dashed var(--info, #3b82f6);
    opacity: 0.6;
    z-index: 5;
    pointer-events: auto;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--info-text, #1e40af);
}

.ct-ghost:hover {
    opacity: 0.8;
}

.ct-ghost.ct-ghost-dragging {
    cursor: grabbing;
    opacity: 0.5;
}

/* ── Hover time indicator ─────────────────────────────── */
.ct-hover-time {
    position: absolute;
    left: -50px;
    width: 48px;
    text-align: right;
    font-size: 0.65rem;
    color: var(--info, #3b82f6);
    font-weight: 600;
    pointer-events: none;
    transform: translateY(-50%);
    z-index: 7;
    white-space: nowrap;
}

/* ── View toggle buttons ──────────────────────────────── */
.ct-view-toggle {
    display: inline-flex;
    border: 1px solid var(--border, #ddd);
    border-radius: 0.375rem;
    overflow: hidden;
    font-size: 0.8rem;
}

.ct-view-btn {
    padding: 0.25rem 0.6rem;
    border: none;
    background: var(--bg-card, #fff);
    color: var(--text-muted, #888);
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s, color 0.15s;
}

.ct-view-btn:not(:last-child) {
    border-right: 1px solid var(--border, #ddd);
}

.ct-view-btn:hover {
    background: var(--info-bg, #dbeafe);
}

.ct-view-btn.active {
    background: var(--info, #3b82f6);
    color: #fff;
    font-weight: 500;
}

/* ── Dark mode overrides ──────────────────────────────── */
html.theme-dark .ct-event--remote {
    background: #2e1065;
    border-left-color: #a78bfa;
    color: #c4b5fd;
}

html.theme-dark .ct-event--call {
    background: #042f2e;
    border-left-color: #2dd4bf;
    color: #99f6e4;
}

html.theme-dark .ct-event--this-customer {
    outline-color: #2dd4bf;
}

html.theme-dark .ct-non-business {
    background: rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
    html:not(.theme-light) .ct-event--remote {
        background: #2e1065;
        border-left-color: #a78bfa;
        color: #c4b5fd;
    }

    html:not(.theme-light) .ct-event--call {
        background: #042f2e;
        border-left-color: #2dd4bf;
        color: #99f6e4;
    }

    html:not(.theme-light) .ct-event--this-customer {
        outline-color: #2dd4bf;
    }

    html:not(.theme-light) .ct-non-business {
        background: rgba(0, 0, 0, 0.3);
    }

    html:not(.theme-light) .ct-overtime-btn {
        background: rgba(30, 30, 30, 0.85);
        color: #aaa;
    }
    html:not(.theme-light) .ct-overtime-btn:hover {
        background: rgba(50, 50, 50, 0.95);
        color: #ddd;
    }
}

/* ── Body inner (used when overtime arrows present) ───── */
.ct-body-inner {
    display: flex;
    position: relative;
}

/* ── Overtime toggle arrows ────────────────────────────── */
.ct-overtime-btn {
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    margin-left: 50px; /* skip gutter */
    color: var(--text-muted, #888);
    background: rgba(245, 245, 245, 0.85);
    transition: background 0.15s, color 0.15s;
    opacity: 0.7;
}
.ct-overtime-btn:hover {
    background: rgba(230, 230, 230, 0.95);
    color: var(--text, #333);
    opacity: 1;
}
.ct-overtime-btn--top {
    border-bottom: 1px dashed var(--border, #ccc);
}
.ct-overtime-btn--bottom {
    border-top: 1px dashed var(--border, #ccc);
}
