/*
 * Rulers.css - Professional-grade ruler styling for Layout Optimizer
 * Self-contained styling for Photoshop-style rulers with minimal footprint
 *
 * Features:
 * - 30px ruler width/height constraint
 * - Overlay positioning to minimize layout disruption
 * - Professional visual styling
 * - Responsive crosshair system
 * - Draggable zero markers
 * - Clean integration with existing design system
 */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

:root {
    --ruler-size: 36px;
    --ruler-border: var(--color-border, #3f3f3f);
    --ruler-text: var(--color-foreground-darker);
    --ruler-text-primary: var(--color-foreground-darker);
    --ruler-accent: var(--color-accent, #007AFF);
    --ruler-tick-color: var(--color-foreground);
    --ruler-major-tick: var(--color-foreground);
    --ruler-crosshair: var(--color-foreground-brighter);
    --ruler-font-family: var(--font-family-02);

    /* Crosshair customization properties */
    --crosshair-vertical-width: 1px;
    --crosshair-horizontal-height: 1px;
    --crosshair-vertical-height: 9px; /* Can be set to specific px values */
    --crosshair-horizontal-width: 9px; /* Can be set to specific px values */
}

/* ==========================================================================
   Main Ruler Container
   ========================================================================== */

.rulers-container {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 0;
    bottom: 0;
    pointer-events: none;
    /* Allow clicks to pass through to underlying elements */
    z-index: 1000;
    /* Above base material, below drag operations */
    font-family: var(--ruler-font-family);
    font-size: 9px;
    line-height: 1;
}

/* Enable pointer events only on interactive elements */
.rulers-container .coordinate-display {
    pointer-events: auto;
}

/* ==========================================================================
   Corner Element (Unit Display)
   ========================================================================== */

.ruler-corner {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--ruler-size);
    height: var(--ruler-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 200;
    color: var(--ruler-text);
    z-index: 1002;
}


/* ==========================================================================
   Horizontal Ruler (Width/X-axis)
   ========================================================================== */

.ruler-horizontal {
    position: absolute;
    top: 0;
    left: 0;
    /* Start from left edge of rulers container */
    right: 0;
    /* Extend to canvas edge */
    height: var(--ruler-size);
    border-bottom: 0px solid var(--ruler-border);
    overflow: visible;
}

.ruler-horizontal .ruler-track {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Vertical Ruler (Length/Y-axis)
   ========================================================================== */

.ruler-vertical {
    position: absolute;
    top: 0;
    /* Start from top edge of rulers container */
    left: 0;
    bottom: 0;
    /* Extend to canvas bottom */
    width: var(--ruler-size);
    border-right: 0px solid var(--ruler-border);
    overflow: hidden;
}

.ruler-vertical .ruler-track {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Ruler Marks (Ticks and Labels)
   ========================================================================== */

.ruler-marks {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Horizontal ruler marks */
.ruler-mark.horizontal {
    position: absolute;
    bottom: 0;
    width: 1px;
    background: var(--ruler-tick-color);
    pointer-events: none;
}

.ruler-mark.horizontal.major {
    color: var(--ruler-tick-color);
    opacity: 0.8;
}

.ruler-mark.horizontal.medium {
    color: var(--ruler-tick-color);
    opacity: 0.6;
}

.ruler-mark.horizontal.semi {
    color: var(--ruler-tick-color);
    opacity: 0.4;
}

.ruler-mark.horizontal.minor {
    color: var(--ruler-tick-color);
    opacity: 0.3;
}


/* Hide minor marks in scale-to-fit: LENGTH mode */
.rulers-container.scale-to-fit-length .ruler-mark.minor {
    opacity: 0;
}



/* Vertical ruler marks */
.ruler-mark.vertical {
    position: absolute;
    right: 0;
    height: 1px;
    background: var(--ruler-tick-color);
    pointer-events: none;
}

.ruler-mark.vertical.major {
    color: var(--ruler-tick-color);
    opacity: 0.8;
}

.ruler-mark.vertical.medium {
    color: var(--ruler-tick-color);
    opacity: 0.6;
}

.ruler-mark.vertical.semi {
    color: var(--ruler-tick-color);
    opacity: 0.4;
}

.ruler-mark.vertical.minor {
    color: var(--ruler-tick-color);
    opacity: 0.3;
}

/* ==========================================================================
   Ruler Labels
   ========================================================================== */

.ruler-label {
    position: absolute;
    font-size: 10px;
    color: var(--ruler-text);
    font-weight: 400;
    white-space: nowrap;
    user-select: none;
    pointer-events: none;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* Horizontal ruler labels */
.ruler-horizontal .ruler-label {
    bottom: 12px;
    transform: translateX(-50%);
}

/* Vertical ruler labels */
.ruler-vertical .ruler-label {
    right: 9px;
    transform: translateY(-4px);
    transform-origin: center;
}


/* ==========================================================================
   Crosshairs (Cursor Position Indicators)
   ========================================================================== */

.ruler-crosshair-vertical {
    position: absolute;
    top: auto;
    bottom: 0;
    width: var(--crosshair-vertical-width);
    height: var(--crosshair-vertical-height);
    background: var(--color-foreground-brighter);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s ease;
    z-index: 999;
}

.ruler-crosshair-horizontal {
    position: absolute;
    left: auto;
    right: 0;
    width: var(--crosshair-horizontal-width);
    height: var(--crosshair-horizontal-height);
    background: var(--color-foreground-brighter);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.1s ease;
    z-index: 999;
}

/* ==========================================================================
   Crosshair Coordinate Labels
   ========================================================================== */

.crosshair-coord {
    position: absolute;
    background: var(--color-background);
    color: var(--color-foreground-brighter);
    border-radius: 0px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 10px;
    font-weight: 400;
    white-space: nowrap;
    user-select: none;
    backdrop-filter: blur(10px);
    z-index: 1004;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}


/* Add gradient fade effect using pseudo-elements */
.crosshair-coord::before {
    content: '';
    position: absolute;
    top: 0;
    left: -20px;
    right: -20px;
    bottom: 0;
    background: linear-gradient(to right,
            transparent 0%,
            var(--color-background) 30%,
            var(--color-background) 70%,
            transparent 100%);
    z-index: -1;
    pointer-events: none;
}

/* Horizontal coordinate (Y value) on vertical crosshair */
.crosshair-coord.horizontal-coord {
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 3px 6px 21px;
}

/* Horizontal fade gradient for vertical ruler (Y coordinate label) */
.crosshair-coord.horizontal-coord::before {
    background: linear-gradient(to bottom,
            transparent 0%,
            var(--color-background) 30%,
            var(--color-background) 70%,
            transparent 100%);
    left: 0;
    right: 0;
    top: -36px;
    bottom: -36px;
}

/* Vertical coordinate (X value) on horizontal crosshair */
.crosshair-coord.vertical-coord {
    bottom: 9px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 14px 6px 3px 6px;
}

/* Vertical fade gradient for horizontal ruler (X coordinate label) */
.crosshair-coord.vertical-coord::before {
    background: linear-gradient(to right,
            transparent 0%,
            var(--color-background) 25%,
            var(--color-background) 75%,
            transparent 100%);
    left: -36px;
    right: -36px;
    top: 0;
    bottom: 0;
}

/* Hide on smaller screens */
@media screen and (max-width: 1019px) {
    .crosshair-coord {
        display: none;
    }
}

.coord-separator {
    opacity: 0.6;
    margin: 0 2px;
}

.coord-unit {
    opacity: 0.8;
    margin-left: 2px;
    font-size: 9px;
}

/* ==========================================================================
   Base Material Layout Adjustments
   ========================================================================== */

/* When rulers are enabled, adjust layout visualization positioning */
#layout_canvas .layout-visualization {
    transition: margin 0.2s ease;
}


/* Force top alignment for scale-to-fit LENGTH mode when rulers are enabled */
#layout_canvas.rulers-enabled .rulers-container.scale-to-fit-length ~ .layout-visualization .base-material {
    margin-top: 1px !important;
    margin-bottom: auto !important;
}

/* Alternative selector for scale-to-fit LENGTH mode - ONLY for single canvas, NOT multi-sheet */
.rulers-container.scale-to-fit-length + * .base-material,
#layout_canvas.rulers-enabled .layout-visualization:not(.multi-sheet) .base-material.scale-to-length {
    margin-top: 1px !important;
    margin-bottom: auto !important;
}

/* Desktop width and margin styling when rulers are visible - ONLY for fixed dimension materials */
@media screen and (min-width: 900px) {
    #layout_canvas.rulers-enabled .layout-visualization.multi-sheet .sheet-visualization .base-material.scale-to-length {
        width: auto;
        margin: 0px auto auto 0px;
    }

    /* 42px margins for rulers - DESKTOP ONLY */
    #layout_canvas.rulers-enabled .layout-visualization.multi-sheet .sheet-visualization .base-material {
        margin-left: 42px !important;
        margin-top: 42px !important;
    }
}

/* ==========================================================================
   Multi-Sheet Rulers (Fixed Dimension Materials)
   ========================================================================== */

/* Sheet rulers container positioned within each sheet-container */
.sheet-rulers-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1000;
    font-family: var(--ruler-font-family);
    font-size: 9px;
    line-height: 1;
}

/* Enable pointer events only on interactive elements within sheets */
.sheet-rulers-container .crosshair-coord {
    pointer-events: auto;
}

#layout_canvas.rulers-enabled .layout-visualization.multi-sheet .sheet-visualization .rulers-container {
    position: absolute;
    left: 0px;
    top: 0px;
}

/* This rule moved to desktop media query below */


/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Mobile considerations (width < 900px) */
@media screen and (max-width: 899px) {
    .rulers-container {
        /* Hide rulers by default on mobile */
        display: none;
    }

    /* Show rulers on mobile when parent has rulers-enabled class */
    #layout_canvas.rulers-enabled .rulers-container,
    .rulers-enabled .rulers-container {
        display: block;
    }

    /* Override if explicitly enabled on mobile */
    .rulers-container.mobile-enabled {
        display: block;
    }

    /* Smaller coordinate display on mobile */
    .coordinate-display {
        top: 32px;
        right: 5px;
        font-size: 10px;
        padding: 3px 6px;
    }

    /* Override desktop ruler margins for mobile multi-sheet */
    #layout_canvas.rulers-enabled .layout-visualization.multi-sheet .sheet-visualization .base-material {
        margin-left: 24px !important;
        margin-top: 42px !important;
    }

    #layout_canvas.rulers-enabled .layout-visualization.multi-sheet .sheet-visualization .rulers-container {
    position: absolute;
    left: -18px;
    top: -42px;
    pointer-events: none; /* Prevent touch event interference on mobile */
}

    /* Stack vertical ruler digits vertically on mobile only */
    .ruler-vertical .ruler-label {
        writing-mode: vertical-lr;
        text-orientation: upright;
        transform: translateY(-50%);
        right: 6px;
        line-height: 0.3;
        text-align: center;
        width: 12px;
        font-size: 10px;
    }

    /* Show crosshair coordinate labels on mobile when rulers are enabled */
    #layout_canvas.rulers-enabled .crosshair-coord,
    .rulers-enabled .crosshair-coord {
        display: block !important;
        font-size: 9px;
        padding: 3px 4px;
    }
}

/* ==========================================================================
   High-DPI Display Support
   ========================================================================== */

@media screen and (-webkit-min-device-pixel-ratio: 2),
screen and (min-resolution: 2dppx) {
    .ruler-mark {
        /* Ensure crisp lines on high-DPI displays */
        transform: translateZ(0);
    }

    .ruler-crosshair-vertical,
    .ruler-crosshair-horizontal {
        /* Sharper crosshairs on retina displays */
        transform: translateZ(0);
    }
}

/* ==========================================================================
   Animation and Transitions
   ========================================================================== */

/* Smooth ruler appearance/disappearance */
.rulers-container {
    transition: opacity 0.2s ease;
}

.rulers-container.hidden {
    opacity: 0;
    pointer-events: none;
}


/* Tick mark animations */
.ruler-mark {
    transition: background-color 0.1s ease;
}

.ruler-mark:hover {
    background-color: var(--ruler-accent);
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --ruler-border: black;
        --ruler-text: black;
        --ruler-tick-color: black;
        --ruler-crosshair: red;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    .rulers-container,
    .ruler-crosshair-vertical,
    .ruler-crosshair-horizontal,
    .coordinate-display {
        transition: none;
    }
}


/* ==========================================================================
   Debug and Development Helpers
   ========================================================================== */

/* Debug mode - shows ruler boundaries */
.rulers-container.debug {
    border: 2px dashed red;
}

.rulers-container.debug .ruler-horizontal {
    border: 1px dashed blue;
}

.rulers-container.debug .ruler-vertical {
    border: 1px dashed green;
}

/* Performance optimization classes */
.rulers-container.performance-mode * {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .rulers-container {
        display: none !important;
    }
}