/* Timeline-Ansicht: Raum-Event-Gantt-Chart */
/* Nutzt CSS-Variablen aus style.css für automatisches Dark-Mode-Handling */

/* ==========================================================================
   Timeline-spezifische Variablen (erben von style.css, überschreiben bei Bedarf)
   ========================================================================== */
:root {
    /* Timeline Header - Fixed colors (identical in light/dark mode) */
    --tl-header-row1-bg: hsl(211, 45%, 26%);
    --tl-header-row2-bg: hsl(211, 40%, 35%);
    --tl-header-text: hsl(0, 0%, 100%);
    --tl-header-text-muted: hsla(0, 0%, 100%, 0.7);
    --tl-header-input-bg: hsl(0, 0%, 100%);
    --tl-header-input-border: hsla(0, 0%, 100%, 0.3);
    --tl-header-chip-bg: hsl(211, 60%, 45%);
    --tl-header-group-bg: hsla(0, 0%, 100%, 0.1);

    /* Timeline Dimensionen - zentral definiert */
    --timeline-days: 60;
    --timeline-day-width: 200px;
    --timeline-label-width: 130px;
    --timeline-total-width: calc(var(--timeline-label-width) + var(--timeline-day-width) * var(--timeline-days));

    /* Timeline Farben */
    --timeline-event-bg: var(--action);
    --timeline-event-inactive: var(--c-140);
    --timeline-grid-line: var(--line-default);
    --timeline-row-line: hsla(0, 0%, 100%, 0.5);
    --timeline-wochenende-bg: hsla(0, 41%, 57%, 0.2);
    --timeline-heute-bg: var(--focus-ring);
    --timeline-main-bg: hsl(0, 0%, 88%);
    --timeline-count-bar: hsla(0, 70%, 50%, 0.3);
    --timeline-building-alt: hsla(0, 0%, 0%, 0.04);
}

/* Dark Mode: dunklere Rasterlinien */
html[data-theme="dark"] {
    --timeline-row-line: hsla(0, 0%, 100%, 0.08);
    --timeline-main-bg: hsl(0, 0%, 33%);
    --timeline-building-alt: hsla(0, 0%, 100%, 0.04);
}

/* Layout: Vollbild unter fixem Header */
.timeline-page {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    /* Recalculate total width based on local --timeline-days */
    --timeline-total-width: calc(var(--timeline-label-width) + var(--timeline-day-width) * var(--timeline-days));
}

.timeline-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

/* Two-Row Header Layout (Desktop) */
.tl-header-row1 {
    width: 100%;
}

.tl-header-row2 {
    background: var(--tl-header-row2-bg);
    width: 100%;
}

/* ==========================================================================
   ROW 1: CSS Grid Layout (Search | Filter | Auto | Nav | Theme)
   ========================================================================== */
.tl-header-row1 .tl-header-content {
    display: grid;
    grid-template-columns: auto auto auto auto auto auto;
    /* Columns: Search | Lstg-Filter | Checkbox | AutoBtn | NavLink | ThemeToggle */
    align-items: center;
    gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.5rem 1rem;
}

/* ==========================================================================
   ROW 2: CSS Grid Layout (Info | Chip | Zoom)
   ========================================================================== */
.tl-header-row2 .tl-header-content {
    display: grid;
    grid-template-columns: auto 1fr auto;
    /* Columns: Info | Chip (left-aligned) | Zoom */
    align-items: center;
    gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.35rem 1rem;
    font-size: 0.8rem;
}

/* Filter Chip alignment */
.tl-filter-chip {
    justify-self: start;
}

/* Nav Link in Timeline Header */
.tl-nav-link {
    color: var(--tl-header-text);
    text-decoration: none;
    text-align: center;
    font-size: 0.875rem;
    padding: 4px 10px;
    border-radius: var(--radius-md);
    background: hsla(0, 0%, 0%, 0.15);
    transition: background 0.2s;
}

.tl-nav-link:hover {
    background: hsla(0, 0%, 0%, 0.25);
}

.tl-header-row1 .search-container {
    margin: 0
}

#leistungSelect {
    background: var(--tl-header-group-bg);
    border: 1px solid var(--tl-header-input-border);
    border-radius: var(--radius-md);
    color: var(--tl-header-text);
    font-size: 0.8rem;
    padding: 4px 6px;
    min-width: 180px;
    max-width: 400px;
    cursor: pointer;
}

#leistungSelect option {
    background: var(--tl-header-row1-bg);
    color: var(--tl-header-text);
}

.tl-filter-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--tl-header-text);
    cursor: pointer;
    white-space: nowrap;
    padding-left: 8px;
}

.tl-filter-checkbox input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--tl-header-chip-bg);
}

/* Timeline Info in Row 2 */
.tl-info {
    font-size: 0.75rem;
    color: var(--tl-header-text-muted);
    white-space: nowrap;
}

/* Filter Chip in Row 2 */
.tl-filter-chip {
    background: var(--tl-header-chip-bg);
    color: var(--tl-header-text);
    border: none;
    border-radius: var(--radius-pill);
    padding: 4px 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.tl-filter-chip:hover {
    opacity: 0.85;
}

/* Zoom Select in Row 2 */
.tl-zoom-select {
    margin-left: auto;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--tl-header-text);
    font-size: 0.75rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.tl-zoom-select:hover {
    border-color: hsla(0, 0%, 100%, 0.4);
    background: hsla(0, 0%, 100%, 0.05);
}

.tl-zoom-select option {
    background: var(--tl-header-row1-bg);
    color: var(--tl-header-text);
}

/* Search Input in Timeline Header - uses same vars as filter-group */
.timeline-search .search-input {
    background: var(--tl-header-group-bg);
    border: 1px solid var(--tl-header-input-border);
    border-radius: var(--radius-md);
    color: var(--tl-header-text);
    font-size: 0.9rem;
    padding: 4px 8px;
}

.timeline-search .search-input::placeholder {
    color: var(--tl-header-text-muted);
}

/* Auto-Scroll Button in Header */
.tl-header-row1 .auto-scroll-btn {
    color: var(--tl-header-text);
    background: hsla(0, 0%, 0%, 0.15);
    border: none;
    padding: 4px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.tl-header-row1 .theme-toggle:hover,
.tl-header-row1 .auto-scroll-btn:hover {
    background: hsla(0, 0%, 0%, 0.25);
}

.tl-header-row1 .auto-scroll-btn.active {
    background: var(--tl-header-chip-bg);
}

/* Legacy compatibility */
.timeline-info {
    font-size: 12px;
    color: var(--text-inverse);
    margin-right: 1rem;
}

.timeline-filter-select,
.timeline-zoom-select {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-default);
    background: var(--surface-panel);
    color: var(--text-default);
    cursor: pointer;
}

.timeline-filter-select {
    max-width: 200px;
}

.timeline-main {
    position: fixed;
    top: 85px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    background: var(--timeline-main-bg);
    -webkit-overflow-scrolling: touch;
    /* Firefox Scrollbar */
    scrollbar-width: auto;
    scrollbar-color: var(--action) var(--surface-panel);
}

/* Custom Scrollbars für Timeline */
.timeline-main::-webkit-scrollbar {
    width: 14px;
    height: 14px;
}

.timeline-main::-webkit-scrollbar-track {
    background: var(--surface-panel);
    border-radius: 7px;
}

.timeline-main::-webkit-scrollbar-thumb {
    background: var(--action);
    border-radius: 7px;
    border: 2px solid var(--surface-panel);
}

.timeline-main::-webkit-scrollbar-thumb:hover {
    background: var(--action-hover);
}

.timeline-main::-webkit-scrollbar-corner {
    background: var(--surface-panel);
}

/* Auto-Scroll Button im Header */
.auto-scroll-btn {
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.auto-scroll-btn.active {
    background: var(--action);
    color: var(--text-inverse);
}

/* Filter-Checkbox */
.timeline-filter-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-inverse);
    cursor: pointer;
    white-space: nowrap;
}

.timeline-filter-checkbox input[type="checkbox"] {
    cursor: pointer;
}

.timeline-container {
    display: flex;
    flex-direction: column;
}

/* GPU-Optimierung für Auto-Scroll (Transform-basiert) */
.timeline-container.auto-scrolling {
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
    /* Force GPU layer */
}

/* Header-Zeile mit Tagen */
.timeline-header-row {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface-panel);
    border-bottom: 2px solid var(--timeline-grid-line);
    min-width: var(--timeline-total-width);
}

.timeline-raum-label-header {
    width: var(--timeline-label-width);
    min-width: var(--timeline-label-width);
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-panel);
    border-right: 1px solid var(--timeline-grid-line);
}

.timeline-days-header {
    display: grid;
    grid-template-columns: repeat(var(--timeline-days), var(--timeline-day-width));
}

.timeline-day-header {
    padding: 2px 1px;
    text-align: center;
    font-size: 9px;
    border-right: 1px solid var(--timeline-grid-line);
    background: var(--surface-panel);
}

.timeline-day-header.heute {
    background: var(--timeline-heute-bg);
    font-weight: 600;
}

.timeline-day-header.wochenende {
    background: var(--timeline-wochenende-bg);
}

.day-wochentag {
    display: block;
    color: var(--text-muted);
}

.day-datum {
    display: block;
    color: var(--text-default);
}

/* Body mit Raum-Zeilen */
.timeline-body {
    flex: 1;
}

/* Einzelne Raum-Zeile */
.timeline-row {
    display: flex;
    height: 18px;
    min-width: var(--timeline-total-width);
    border-bottom: 1px solid var(--timeline-row-line);
}

.timeline-row.hidden-row {
    display: none;
}

.timeline-row.building-alt {
    background: var(--timeline-building-alt);
}

.timeline-row:hover {
    background: var(--tint-hover);
}

/* Raum-Label (links, sticky) */
.timeline-raum-label {
    width: var(--timeline-label-width);
    min-width: var(--timeline-label-width);
    padding: 0 4px;
    font-size: 9px;
    line-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-default);
    background: var(--surface-panel);
    border-right: 1px solid var(--timeline-grid-line);
    position: sticky;
    left: 0;
    z-index: 5;
}

/* Balkengrafik für Leistungs-Anzahl */
.timeline-raum-label::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: var(--count-width, 0%);
    background: var(--timeline-count-bar);
    pointer-events: none;
}

/* Events-Container (rechts) - Hybrid: Grid-Layout + Absolute Events */
.timeline-events-container {
    position: relative;
    min-height: 18px;
    width: calc(var(--timeline-day-width) * var(--timeline-days));
    /* Rasterlinien: 1px Linie am rechten Rand jeder Tages-Spalte */
    background-image: linear-gradient(to right, transparent calc(100% - 1px), var(--timeline-row-line) 0);
    background-size: var(--timeline-day-width) 100%;
}

/* Event-Balken */
.timeline-event {
    position: absolute;
    top: 2px;
    height: 14px;
    background: var(--timeline-event-bg);
    border-radius: 2px;
    overflow: hidden;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s;
    z-index: 1;
}

.timeline-event.no-leistungen {
    background: var(--timeline-event-inactive);
}

.timeline-event.has-selected-leistung {
    box-shadow: 0 0 0 3px var(--danger);
    z-index: 3;
}

/* Highlighted events (from EPOS search) - uses outline only */
.timeline-event.highlighted {
    outline: 3px solid hsl(45, 100%, 50%);
    outline-offset: -1px;
    z-index: 4;
}

.timeline-event:hover {
    opacity: 0.85;
    z-index: 2;
}

.event-titel {
    display: block;
    padding: 0 3px;
    font-size: 12px;
    line-height: 12px;
    color: var(--text-inverse);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Responsive: Schmalere Labels und Tage auf kleinen Screens */
@media (max-width: 768px) {
    :root {
        --timeline-label-width: 100px;
        --timeline-day-width: 60px;
    }

    .timeline-raum-label-header,
    .timeline-raum-label {
        font-size: 8px;
    }

    .timeline-day-header {
        font-size: 8px;
    }

    .event-titel {
        font-size: 8px;
    }

    .timeline-container {
        min-width: max-content;
    }

    /* ==========================================================================
       MOBILE: Unified Grid Layout using display: contents
       All elements become direct children of timeline-header grid
       Grid: 3 columns, 3 rows
       ========================================================================== */
    .timeline-header {
        display: grid;
        grid-template-columns: 1fr auto auto;
        grid-template-rows: auto auto auto;
        gap: 0.25rem 0.5rem;
        padding: 0.5rem;
        position: relative;
        /* Apply single background for all rows */
        background: var(--tl-header-row1-bg);
    }

    /* Ensure all grid items are above the pseudo-element */
    .timeline-header>*,
    .timeline-search,
    .tl-filter-group,
    .tl-nav-link,
    .theme-toggle,
    .tl-zoom-select,
    .tl-info,
    .tl-filter-chip {
        position: relative;
        z-index: 1;
    }

    /* Dissolve row containers so children become grid items */
    .tl-header-row1,
    .tl-header-row2,
    .tl-header-row1 .tl-header-content,
    .tl-header-row2 .tl-header-content {
        display: contents;
    }

    /* ROW 1: Search | Nav | Theme */
    .timeline-search {
        grid-column: 1;
        grid-row: 1;
        z-index: 10;
        /* Higher than other grid items so search-results appears on top */
    }

    .tl-nav-link {
        grid-column: 2;
        grid-row: 1;
        padding: 4px 10px;
    }

    .theme-toggle {
        grid-column: 3;
        grid-row: 1;
        font-size: 0.8rem;
        padding: 4px 8px;
        max-width: 40px;
        justify-self: end;
    }

    /* ROW 2: Filter | Zoom */
    .tl-filter-group {
        grid-column: 1 / 3;
        grid-row: 2;
        font-size: 0.75rem;
        padding: 4px 8px 4px 4px;
    }

    .tl-filter-group select {
        font-size: 0.75rem;
        padding: 3px 4px;
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tl-filter-checkbox {
        font-size: 0.7rem;
        padding-left: 6px;
    }

    .tl-zoom-select {
        grid-column: 3;
        grid-row: 2;
        font-size: 0.7rem;
        padding: 3px 8px;
    }

    /* ROW 3: Info | Chip */
    .tl-info {
        grid-column: 1;
        grid-row: 3;
        font-size: 0.7rem;
    }

    .tl-filter-chip {
        grid-column: 2 / 4;
        grid-row: 3;
        font-size: 0.7rem;
        padding: 3px 10px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        justify-self: start;
    }

    /* Hide Auto-Scroll on mobile */
    .auto-scroll-btn {
        display: none;
    }

    /* Adjust main content top offset for mobile header */
    .timeline-main {
        top: 95px;
    }
}

/* ==========================================================================
   Buchungsdetail-Modal
   ========================================================================== */
.buchung-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.buchung-modal.active {
    display: block;
}

.buchung-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.buchung-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    background: var(--surface-panel);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.buchung-modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 10;
    line-height: 1;
    padding: 4px 8px;
}

.buchung-modal-close:hover {
    color: var(--text-default);
}

.buchung-modal-body {
    padding: var(--spacing-md);
    overflow-y: auto;
    max-height: calc(90vh - 20px);
}

.buchung-modal-body .loading-text {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

.buchung-modal-body .modal-footer {
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--line-default);
    text-align: center;
}

/* Modal-spezifische Anpassungen für Buchungsdetails */
.buchung-modal-body .raum-details,
.buchung-modal-body .leistungen-section,
.buchung-modal-body .tech-leistungen-section {
    margin-bottom: var(--spacing-md);
}

@media (max-width: 768px) {
    .buchung-modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .buchung-modal-body {
        padding: var(--spacing-sm);
    }
}

/* ==========================================================================
   Event-Tooltip (Hover-Popup mit Leistungen)
   ========================================================================== */
.event-tooltip {
    position: fixed;
    background: var(--surface-panel);
    border-radius: var(--radius-md);
    padding: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 500;
    min-width: 240px;
    max-width: 320px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    border: 1px solid var(--line-default);
    overflow: hidden;
}

.event-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Tooltip Header */
.event-tooltip-header {
    background-color: var(--header-bg);
    color: var(--text-inverse);
    padding: 8px 12px;
    border-bottom: 1px solid var(--line-default);
}

.event-tooltip-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
    line-height: 1.3;
}

.event-tooltip-meta {
    font-size: 11px;
    color: var(--text-inverse);
    opacity: 0.85;
}

/* Leistungen Liste */
.event-tooltip-leistungen {
    padding: 8px 12px;
    max-height: 180px;
    overflow-y: auto;
}

.event-tooltip-section-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.event-tooltip-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.event-tooltip-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--line-quiet);
    font-size: 12px;
}

.event-tooltip-item:last-child {
    border-bottom: none;
}

.event-tooltip-name {
    color: var(--text-default);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 8px;
}

.event-tooltip-count {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    flex-shrink: 0;
    min-width: 28px;
}

.event-tooltip-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 4px;
    font-size: 11px;
}

/* Footer mit Link zum Modal */
.event-tooltip-footer {
    padding: 6px 12px;
    border-top: 1px solid var(--line-default);
    background: var(--surface-raised);
}

.event-tooltip-link {
    display: block;
    color: var(--action);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
}

.event-tooltip-link:hover {
    text-decoration: underline;
}

/* Close Button (Mobile) */
.event-tooltip-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-inverse);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
}

.event-tooltip-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Loading State */
.event-tooltip-loading {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.event-tooltip-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--line-default);
    border-top-color: var(--action);
    border-radius: 50%;
    animation: tooltip-spin 0.8s linear infinite;
    margin: 0 auto 8px;
}

@keyframes tooltip-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile Tooltip: zentriert und größer */
@media (max-width: 768px) {
    .event-tooltip.visible {
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 90%;
        max-height: 80vh;
    }

    .event-tooltip.visible .event-tooltip-close {
        display: flex;
    }

    .event-tooltip-leistungen {
        max-height: 40vh;
    }
}