/* ─── Wochenkalender Graphical Grid Overlay ─── */
/* Visual style mirrors the legacy EK.JS canvas implementation:
   light background, EKH-magenta (#C31D64) for Tagbetrieb,
   EKH-blue (#1F94B9) for Nachtbetrieb, and red weekend day labels.
   See screenshot/hk.PNG. */

:root {
    --wk-on:        #C31D64;   /* EKH magenta — Tagbetrieb (heating ON) */
    --wk-off:       #1F94B9;   /* EKH blue    — Nachtbetrieb (heating OFF) */
    --wk-bg:        #ffffff;
    --wk-border:    #d0d0d0;
    --wk-grid:      #e0e0e0;
    --wk-text:      #1a1a1a;
    --wk-muted:     #6a6a6a;
    --wk-weekend:   #C31D64;
    --wk-cursor:    #1a1a1a;
}

/* Overlay container — covers the canvas/grid host. Fully opaque white so
   it visually replaces the underlying 46-col grid (the legacy canvas
   implementation drew the same way: it filled the canvas with #E0E0E0
   and drew the schedule on top). */
.wk-overlay {
    position: absolute;
    inset: 0;
    z-index: 40;
    background: var(--wk-bg);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    font-family: 'Segoe UI', 'Arial', system-ui, sans-serif;
    color: var(--wk-text);
    overflow: auto;
    border: 1px solid var(--wk-border);
}

.wk-overlay.wk-hidden {
    display: none;
}

/* ─── Header ─── */
.wk-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.wk-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--wk-text);
    line-height: 1.3;
}

.wk-info {
    font-size: 13px;
    color: var(--wk-muted);
    line-height: 1.3;
    text-align: right;
}

/* The right-side header info string carries "<day> <time>  Tag/Nachtbetrieb" —
   the legacy canvas drew "Tagbetrieb" / "Nachtbetrieb" in EKH-magenta to flag
   the current state. We mirror that with a generated highlight rule below. */
.wk-info .wk-info-state {
    color: var(--wk-on);
    font-weight: 600;
    margin-left: 8px;
}

/* Back arrow at top-left — mirrors EK.JS line 666-672 cyan exit button.
   Click sends maus=1101 (back to previous menu). */
.wk-back-btn {
    pointer-events: auto;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    background: linear-gradient(180deg, #23A6D1 0%, #1F94B9 100%);
    border: 0;
    color: #fff;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    border-radius: var(--radius-xs);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 1px 2px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    transition: filter 0.1s ease, transform 0.05s ease;
}

.wk-back-btn:hover { filter: brightness(1.1); }
.wk-back-btn:active { filter: brightness(0.85); transform: translateY(1px); }
.wk-back-btn:focus-visible { outline: 2px solid var(--wk-on); outline-offset: 1px; }

.wk-close-btn {
    pointer-events: auto;
    background: transparent;
    border: 1px solid var(--wk-border);
    color: var(--wk-muted);
    font-size: 16px;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.wk-close-btn:hover {
    background: #f3f3f3;
    color: var(--wk-text);
    border-color: #b0b0b0;
}


/* ─── Time Axis ─── */
.wk-time-axis {
    position: relative;
    height: 18px;
    margin-left: 38px;
    margin-right: 4px;
    margin-bottom: 2px;
    flex-shrink: 0;
}

.wk-time-label {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--wk-text);
    font-variant-numeric: tabular-nums;
}

/* ─── Day Grid ─── */
.wk-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.wk-row {
    display: flex;
    align-items: center;
    height: 26px;
    flex-shrink: 0;
}

/* No special "today" highlight — the legacy implementation didn't have one. */
.wk-row-today { }
.wk-row-today .wk-day-label { }
.wk-row-today .wk-bar-track { }

.wk-day-label {
    width: 34px;
    font-size: 14px;
    font-weight: 700;
    color: var(--wk-text);
    text-align: left;
    margin-right: 4px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Saturday + Sunday day labels in EKH-magenta, matching the legacy canvas. */
.wk-row:nth-last-child(-n+2) .wk-day-label {
    color: var(--wk-weekend);
}

.wk-bar-track {
    position: relative;
    flex: 1;
    height: 100%;
    background: transparent;
    border-radius: 0;
    overflow: visible;
}

/* Gridlines at 6h intervals — light, like the legacy canvas */
.wk-gridline {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--wk-grid);
    pointer-events: none;
    z-index: 0;
}

/* Bar segment base — step-chart visual: ON sits high (full bar), OFF sits low. */
.wk-bar-segment {
    position: absolute;
    border-radius: 0;
    min-width: 1px;
    pointer-events: auto;
    z-index: 1;
}

.wk-bar-segment:hover {
    filter: brightness(0.9);
}

/* ON segment (Tagbetrieb) — full-height EKH-magenta bar */
.wk-bar-on {
    top: 4px;
    bottom: 4px;
    background: var(--wk-on);
}

/* OFF segment (Nachtbetrieb) — thin EKH-blue bar at the bottom (step-chart). */
.wk-bar-off {
    top: 60%;
    bottom: 4px;
    background: var(--wk-off);
}

/* Tooltip on hover */
.wk-bar-segment::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: #2a2a2a;
    color: #ffffff;
    font-size: 11px;
    padding: 3px 7px;
    border-radius: var(--radius-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 50;
}

.wk-bar-segment:hover::after {
    opacity: 1;
}

/* ─── Cursor Marker (edit modes) ─── */
/* Vertical black dashed line, like the legacy canvas (ctx.setLineDash([3,2])). */
.wk-cursor {
    position: absolute;
    top: -2px;
    bottom: -2px;
    background: transparent;
    border-left: 2px dashed var(--wk-cursor);
    z-index: 5;
    pointer-events: none;
}

.wk-cursor-night {
    border-left-color: var(--wk-off);
}

.wk-cursor-scan {
    border-left-color: #2aa452;
    opacity: 0.85;
}

/* ─── Aktion Line (below grid) ─── */
.wk-aktion {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    margin-left: 38px;
    flex-shrink: 0;
}

.wk-aktion-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--wk-text);
    white-space: nowrap;
}

.wk-aktion-item {
    font-size: 14px;
    color: var(--wk-muted);
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    white-space: nowrap;
}

.wk-aktion-active {
    font-weight: 700;
}

.wk-aktion-active.wk-aktion-view {
    background: transparent;
    color: var(--wk-text);
}

.wk-aktion-active.wk-aktion-setday {
    background: rgba(195, 29, 100, 0.12);
    color: var(--wk-on);
}

.wk-aktion-active.wk-aktion-setnight {
    background: rgba(31, 148, 185, 0.12);
    color: var(--wk-off);
}

/* ─── Cursor Info (edit modes, below Aktion) ─── */
.wk-cursorinfo {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 4px;
    margin-left: 38px;
    flex-shrink: 0;
}

.wk-cursorinfo-pos {
    font-size: 14px;
    font-weight: 700;
    color: var(--wk-text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.wk-cursorinfo-value {
    font-size: 14px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: var(--radius-xs);
    white-space: nowrap;
}

.wk-status-tag {
    background: rgba(195, 29, 100, 0.12);
    color: var(--wk-on);
}

.wk-status-nacht {
    background: rgba(31, 148, 185, 0.12);
    color: var(--wk-off);
}

/* Verification message */
.wk-verify-msg {
    font-size: 14px;
    font-weight: 600;
    color: #2aa452;
    white-space: nowrap;
}

.wk-verify-dots::after {
    content: '';
    animation: wk-dots 1.5s steps(4, end) infinite;
}

@keyframes wk-dots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* ─── Action Panels (Bedienung + HK-Zustand) ─── */
/* The 6 quick-action buttons mirror EK.JS lines 627-657: hardcoded click
   hotspots whose visuals are synthesised here, not in the controller's data. */
.wk-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 24px;
    margin-top: 14px;
    margin-left: 38px;
    margin-right: 8px;
    flex-shrink: 0;
}

.wk-actions-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wk-actions-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--wk-text);
    margin-bottom: 2px;
}

.wk-action-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-xs);
    user-select: none;
    pointer-events: auto;
}

.wk-action-row:hover {
    background: rgba(31, 148, 185, 0.08);
}

.wk-action-row:focus-visible {
    outline: 2px solid var(--wk-off);
    outline-offset: 1px;
}

/* The cyan/blue rectangular button — matches the legacy canvas
   ctx.fillRect(xpos+1, ypos-20, 20, 23) light-blue + ctx.fillRect(xpos+4,
   ypos-17, 14, 17) darker-blue inset look. */
.wk-action-btn {
    flex-shrink: 0;
    display: inline-block;
    width: 20px;
    height: 23px;
    background:
        linear-gradient(180deg, #1F94B9 0%, #1F94B9 100%);
    border-radius: var(--radius-xs);
    box-shadow:
        inset 0 0 0 3px #23A6D1,
        0 1px 1px rgba(0, 0, 0, 0.2);
    position: relative;
}

.wk-action-row:hover .wk-action-btn {
    filter: brightness(1.08);
}

.wk-action-row:active .wk-action-btn {
    filter: brightness(0.85);
    transform: translateY(1px);
}

.wk-action-mark {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    font-size: 16px;
    font-weight: 800;
    line-height: 1;
}

.wk-action-mark-check {
    color: var(--wk-text);
}

.wk-action-mark-x {
    color: var(--wk-on);
}

.wk-action-label {
    font-size: 13px;
    color: var(--wk-text);
    line-height: 1.25;
}

.wk-action-active .wk-action-label {
    font-weight: 600;
}

/* Tighter responsive layout */
@media (max-width: 768px) {
    .wk-actions-grid {
        margin-left: 32px;
        gap: 12px 16px;
        margin-top: 10px;
    }

    .wk-actions-title {
        font-size: 13px;
    }

    .wk-action-label {
        font-size: 12px;
    }

    .wk-action-btn {
        width: 18px;
        height: 21px;
    }
}

@media (max-width: 480px) {
    .wk-actions-grid {
        grid-template-columns: 1fr;
        margin-left: 26px;
    }
}

/* ─── Toggle Button (visible when overlay is hidden) ─── */
.wk-toggle-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 41;
    pointer-events: auto;
    background: var(--wk-bg);
    border: 1px solid var(--wk-on);
    color: var(--wk-on);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-family: 'Segoe UI', system-ui, sans-serif;
    transition: all 0.15s ease;
}

.wk-toggle-btn:hover {
    background: var(--wk-on);
    color: #fff;
}

.wk-toggle-btn.wk-hidden {
    display: none;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .wk-overlay {
        padding: 8px 10px;
    }

    .wk-title {
        font-size: 14px;
    }

    .wk-info {
        font-size: 12px;
    }

    .wk-day-label {
        width: 28px;
        font-size: 12px;
    }

    .wk-time-axis {
        margin-left: 32px;
    }

    .wk-aktion, .wk-cursorinfo {
        margin-left: 32px;
    }

    .wk-row {
        height: 22px;
    }

    .wk-time-label {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .wk-overlay {
        padding: 6px 8px;
    }

    .wk-title {
        font-size: 13px;
    }

    .wk-day-label {
        width: 24px;
        font-size: 11px;
    }

    .wk-time-axis {
        margin-left: 26px;
    }

    .wk-aktion, .wk-cursorinfo {
        margin-left: 26px;
        gap: 8px;
    }

    .wk-aktion-label, .wk-aktion-item {
        font-size: 12px;
    }

    .wk-row {
        height: 20px;
    }
}
