/* Interactive Calibration Preview Edges */
.calibration-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    margin: 40px auto 40px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: visible;
}

#calibration-preview-canvas {
    position: absolute;
    top: -40px;
    left: -40px;
    width: calc(100% + 80px);
    height: calc(100% + 80px);
    pointer-events: none;
    z-index: 3;
}

.preview-screen {
    position: absolute;
    top: 37px;
    left: 57px;
    right: 57px;
    bottom: 37px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: white;
    font-size: 14px;
}

.preview-screen-border-width {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

.preview-screen-border-width label {
    white-space: nowrap;
}

.preview-screen-border-width input {
    width: 52px;
    padding: 2px 4px;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    text-align: center;
}

.preview-screen-border-width input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.25);
}

.preview-screen-total {
    font-size: 16px;
    font-weight: 600;
    opacity: 0.9;
    transition: color 0.2s;
    cursor: pointer;
    user-select: none;
}

.preview-screen-total:hover {
    opacity: 1;
}

.preview-screen-total.mismatch {
    color: #FFC107;
}


.inputs-dimmed .edge-led-input {
    opacity: 0.2;
    pointer-events: none;
}

.preview-screen-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-edge {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(128, 128, 128, 0.15);
    transition: background 0.2s;
    z-index: 2;
    user-select: none;
}

/* Edge test toggle zones — positioned outside the container border */
.edge-toggle {
    position: absolute;
    cursor: pointer;
    z-index: 1;
    background: rgba(128, 128, 128, 0.1);
    border: 1px solid rgba(128, 128, 128, 0.35);
    border-radius: 3px;
    transition: background 0.2s, box-shadow 0.2s;
}

.edge-toggle:hover {
    background: rgba(128, 128, 128, 0.25);
}

.preview-edge.edge-disabled {
    opacity: 0.25;
    pointer-events: none;
}

.preview-edge.edge-disabled .edge-led-input {
    pointer-events: auto;
    opacity: 1;
}

.edge-toggle.edge-disabled {
    opacity: 0.15;
    pointer-events: none;
    cursor: default;
}

.toggle-top {
    top: -16px;
    left: 56px;
    right: 56px;
    height: 16px;
}

.toggle-bottom {
    bottom: -16px;
    left: 56px;
    right: 56px;
    height: 16px;
}

.toggle-left {
    left: -16px;
    top: 36px;
    bottom: 36px;
    width: 16px;
}

.toggle-right {
    right: -16px;
    top: 36px;
    bottom: 36px;
    width: 16px;
}

.edge-top {
    top: 0;
    left: 56px;
    right: 56px;
    height: 36px;
    border-radius: 6px 6px 0 0;
    flex-direction: row;
    gap: 8px;
}

.edge-bottom {
    bottom: 0;
    left: 56px;
    right: 56px;
    height: 36px;
    border-radius: 0 0 6px 6px;
    flex-direction: row;
    gap: 8px;
}

.edge-left {
    left: 0;
    top: 36px;
    bottom: 36px;
    width: 56px;
    flex-direction: column;
    border-radius: 6px 0 0 6px;
    gap: 4px;
}

.edge-right {
    right: 0;
    top: 36px;
    bottom: 36px;
    width: 56px;
    flex-direction: column;
    border-radius: 0 6px 6px 0;
    gap: 4px;
}

.edge-led-input {
    width: 46px;
    padding: 2px 2px;
    font-size: 12px;
    box-sizing: border-box;
    max-height: 100%;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    color: inherit;
}

.edge-led-input:focus {
    border-color: var(--primary-color);
    outline: none;
}

.edge-top .edge-led-input,
.edge-bottom .edge-led-input {
    width: 56px;
}

/* Hide spinner arrows on edge inputs to save space */
.edge-led-input::-webkit-outer-spin-button,
.edge-led-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.edge-led-input[type=number] {
    -moz-appearance: textfield;
}

/* Edge span bars */
.edge-span-bar {
    position: absolute;
    background: rgba(76, 175, 80, 0.3);
    border: 1px solid rgba(76, 175, 80, 0.5);
    border-radius: 2px;
    cursor: grab;
    transition: background 0.15s;
}

.edge-span-bar:hover {
    background: rgba(76, 175, 80, 0.45);
}

.edge-span-bar:active {
    cursor: grabbing;
}

/* Horizontal edges: bar spans left-right */
.edge-top .edge-span-bar,
.edge-bottom .edge-span-bar {
    top: 0;
    bottom: 0;
}

/* Vertical edges: bar spans top-bottom */
.edge-left .edge-span-bar,
.edge-right .edge-span-bar {
    left: 0;
    right: 0;
}

/* Resize handles — large transparent hit area with narrow visible strip */
.edge-span-handle {
    position: absolute;
    background: transparent;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.15s;
}

.edge-span-handle::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(76, 175, 80, 0.7);
    border-radius: 2px;
}

.edge-span-bar:hover .edge-span-handle {
    opacity: 1;
}

/* Horizontal handles */
.edge-top .edge-span-handle,
.edge-bottom .edge-span-handle {
    top: 0;
    bottom: 0;
    width: 16px;
    cursor: ew-resize;
}

.edge-top .edge-span-handle::after,
.edge-bottom .edge-span-handle::after {
    top: 3px;
    bottom: 3px;
    left: 6px;
    width: 4px;
}

.edge-top .edge-span-handle-start,
.edge-bottom .edge-span-handle-start {
    left: -8px;
}

.edge-top .edge-span-handle-end,
.edge-bottom .edge-span-handle-end {
    right: -8px;
}

/* Vertical handles */
.edge-left .edge-span-handle,
.edge-right .edge-span-handle {
    left: 0;
    right: 0;
    height: 16px;
    cursor: ns-resize;
}

.edge-left .edge-span-handle::after,
.edge-right .edge-span-handle::after {
    left: 3px;
    right: 3px;
    top: 6px;
    height: 4px;
}

.edge-left .edge-span-handle-start,
.edge-right .edge-span-handle-start {
    top: -8px;
}

.edge-left .edge-span-handle-end,
.edge-right .edge-span-handle-end {
    bottom: -8px;
}

/* Ensure LED input is above span bar */
.edge-led-input {
    position: relative;
    z-index: 2;
}

/* Corner start-position buttons */
.preview-corner {
    position: absolute;
    width: 56px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    color: rgba(128, 128, 128, 0.4);
    cursor: pointer;
    z-index: 5;
    transition: color 0.2s, transform 0.2s, text-shadow 0.2s;
    user-select: none;
}

.preview-corner:hover {
    color: rgba(76, 175, 80, 0.6);
}

.preview-corner.active:hover {
    transform: none;
}

.preview-corner.active {
    color: #4CAF50;
    text-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
    font-size: 22px;
}

.corner-top-left { top: 0; left: 0; }
.corner-top-right { top: 0; right: 0; }
.corner-bottom-left { bottom: 0; left: 0; }
.corner-bottom-right { bottom: 0; right: 0; }

/* Direction toggle inside screen */
.direction-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-family: inherit;
    font-size: 12px;
    box-sizing: border-box;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
}

.direction-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
}

.direction-toggle #direction-icon {
    font-size: 14px;
}

/* Overlay toggle inside the preview screen */
.calibration-overlay-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-family: inherit;
    font-size: 12px;
    box-sizing: border-box;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    user-select: none;
}

.calibration-overlay-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
}

.calibration-overlay-toggle.active {
    background: rgba(76, 175, 80, 0.35);
    border-color: rgba(76, 175, 80, 0.7);
}

.preview-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

