/**
 * Room Visualizer Pro - Professional CSS with SOFT CONSTRAINT WARNINGS
 * Version: 4.3.0
 * Features: Red outline for products below walking space threshold, warning indicators
 */

:root {
    --rv-primary: #667eea;
    --rv-primary-dark: #5568d3;
    --rv-secondary: #764ba2;
    --rv-success: #06d6a0;
    --rv-warning: #ffd93d;
    --rv-danger: #ff6b6b;
    --rv-dark: #2d3748;
    --rv-light: #f7fafc;
    --rv-border: #e2e8f0;
    --rv-shadow: rgba(0, 0, 0, 0.1);
    --rv-shadow-lg: rgba(0, 0, 0, 0.15);
    --rv-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   MODAL
   ======================================== */
#room-visualizer-modal {
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: none;
}

.rv-modal-content {
    background: linear-gradient(to bottom, #ffffff 0%, #f8f9fa 100%);
    margin: 2% auto;
    padding: 0;
    border: none;
    border-radius: 16px;
    width: 96%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.rv-modal-header {
    padding: 24px 32px;
    background: linear-gradient(135deg, var(--rv-primary) 0%, var(--rv-secondary) 100%);
    color: white;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.rv-modal-header h2 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.rv-modal-subtitle {
    margin: 8px 0 0;
    font-size: 14px;
    opacity: 0.9;
    font-weight: 400;
}

.rv-close {
    position: absolute;
    right: 24px;
    top: 24px;
    color: white;
    font-size: 32px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    transition: var(--rv-transition);
    z-index: 10;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

.rv-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* ========================================
   CONTROLS SECTION
   ======================================== */
.rv-controls {
    padding: 20px 32px;
    background: white;
    border-bottom: 1px solid var(--rv-border);
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.rv-control-group {
    flex: 1;
    min-width: 200px;
}

.rv-control-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--rv-dark);
    margin-bottom: 8px;
}

.rv-control-label svg {
    color: var(--rv-primary);
}

.rv-controls input[type="file"] {
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--rv-border);
    border-radius: 8px;
    background: var(--rv-light);
    cursor: pointer;
    font-size: 14px;
    transition: var(--rv-transition);
}

.rv-controls input[type="file"]:hover {
    border-color: var(--rv-primary);
    background: white;
}

.rv-dimension-inputs {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rv-dimension-inputs input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--rv-border);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--rv-transition);
}

.rv-dimension-inputs input:focus {
    outline: none;
    border-color: var(--rv-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.rv-dimension-inputs span {
    color: var(--rv-dark);
    font-weight: 600;
}

.rv-offset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.rv-offset-grid input {
    padding: 10px 12px;
    border: 2px solid var(--rv-border);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--rv-transition);
}

.rv-offset-grid input:focus {
    outline: none;
    border-color: var(--rv-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* ========================================
   ENHANCED HUD with SOFT CONSTRAINT
   ======================================== */
.rv-hud-advanced {
    padding: 20px 32px;
    background: white;
    border-bottom: 1px solid var(--rv-border);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    flex-shrink: 0;
}

.rv-hud-section {
    padding: 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 1px solid var(--rv-border);
}

.rv-hud-walking-space {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #0ea5e9;
}

.rv-hud-width-info {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #f59e0b;
}

.rv-hud-depth-info {
    background: linear-gradient(135deg, #fce7f3 0%, #fbcfe8 100%);
    border: 2px solid #ec4899;
}

.rv-hud-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--rv-primary);
    margin-bottom: 12px;
}

.rv-hud-walking-space .rv-hud-title {
    color: #0369a1;
}

.rv-hud-width-info .rv-hud-title {
    color: #d97706;
}

.rv-hud-depth-info .rv-hud-title {
    color: #db2777;
}

.rv-hud-metrics {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rv-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rv-metric-label {
    font-size: 13px;
    color: #6c757d;
    font-weight: 500;
}

.rv-metric-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--rv-dark);
    background: white;
    padding: 4px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 4px var(--rv-shadow);
}

/* Status indicators */
.rv-status-good {
    color: var(--rv-success) !important;
    background: #f0fdf4 !important;
}

.rv-status-warning {
    color: #f59e0b !important;
    background: #fffbeb !important;
    animation: warningPulse 2s infinite;
}

@keyframes warningPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(1.03); }
}

/* ========================================
   ALERTS for SOFT CONSTRAINT
   ======================================== */
.rv-hud-alerts {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rv-alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    animation: slideInDown 0.3s ease-out;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rv-alert-boundary {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 2px solid var(--rv-warning);
    color: #92400e;
}

/* Walking space WARNING (not error) */
.rv-alert-walking {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 2px solid #f59e0b;
    color: #78350f;
    font-weight: 700;
}

.rv-alert svg {
    flex-shrink: 0;
}

/* ========================================
   CANVAS CONTAINER
   ======================================== */
.rv-canvas-pro {
    flex: 1;
    margin: 0 auto;
    border: 3px solid var(--rv-border);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    background: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #f5f5f5;
    box-shadow: inset 0 2px 8px var(--rv-shadow);
    min-height: 400px;
}

.room-bg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
    user-select: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.rv-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #9ca3af;
    z-index: 1;
    pointer-events: none;
}

.rv-empty-state svg {
    opacity: 0.3;
    margin-bottom: 16px;
}

.rv-empty-state p {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px;
}

.rv-empty-state small {
    font-size: 13px;
    opacity: 0.7;
}

.rv-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(102, 126, 234, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(102, 126, 234, 0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 5;
}

/* ========================================
   PRODUCTS with SOFT CONSTRAINT WARNINGS
   ======================================== */
.rv-product-wrapper {
    position: absolute;
    cursor: move;
    transition: filter 0.2s, box-shadow 0.2s;
    touch-action: none;
    user-select: none;
    z-index: 10;
}

/* Preview state styling */
.rv-product-wrapper.rv-product-preview {
    opacity: 0.85;
}

.rv-product-wrapper.rv-product-preview .rv-product-item {
    border: 3px dashed var(--rv-warning) !important;
    box-shadow: 0 0 0 4px rgba(255, 217, 61, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* ⭐ RED OUTLINE FOR SOFT CONSTRAINT WARNING */
.rv-product-wrapper.rv-product-warning .rv-product-item {
    border: 4px solid #dc2626 !important;
    box-shadow: 
        0 0 0 4px rgba(220, 38, 38, 0.2), 
        0 0 20px rgba(220, 38, 38, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.15) !important;
    animation: warningBorder 2s infinite;
}

@keyframes warningBorder {
    0%, 100% {
        border-color: #dc2626;
        box-shadow: 
            0 0 0 4px rgba(220, 38, 38, 0.2), 
            0 0 20px rgba(220, 38, 38, 0.3),
            0 4px 12px rgba(0, 0, 0, 0.15);
    }
    50% {
        border-color: #ef4444;
        box-shadow: 
            0 0 0 6px rgba(220, 38, 38, 0.3), 
            0 0 30px rgba(220, 38, 38, 0.4),
            0 8px 20px rgba(0, 0, 0, 0.2);
    }
}

.rv-product-wrapper:hover {
    filter: brightness(1.05);
    z-index: 100;
}

.rv-product-wrapper.rv-selected {
    z-index: 1000;
}

.rv-product-wrapper.rv-selected .rv-product-item {
    border-color: var(--rv-primary);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2), 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Warning state takes precedence over selection */
.rv-product-wrapper.rv-product-warning.rv-selected .rv-product-item {
    border: 4px solid #dc2626 !important;
    box-shadow: 
        0 0 0 4px rgba(220, 38, 38, 0.2), 
        0 0 20px rgba(220, 38, 38, 0.3),
        0 8px 24px rgba(0, 0, 0, 0.2) !important;
}

.rv-product-wrapper.rv-dragging {
    opacity: 0.9;
    cursor: grabbing;
}

.rv-product-wrapper.rv-correcting {
    animation: correctPosition 0.3s ease-out;
}

@keyframes correctPosition {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.rv-product-item {
    display: block;
    width: 100%;
    height: auto;
    border: 3px solid transparent;
    border-radius: 8px;
    transition: var(--rv-transition);
    pointer-events: none;
    user-select: none;
    box-shadow: 0 4px 12px var(--rv-shadow);
}

.rv-product-wrapper:hover .rv-product-item {
    border-color: var(--rv-primary);
    box-shadow: 0 8px 24px var(--rv-shadow-lg);
}

/* Wall side indicators (still work with warning state) */
.rv-product-wrapper[data-wall-side="left"] .rv-product-item {
    border-left: 4px solid #3b82f6 !important;
}

.rv-product-wrapper[data-wall-side="right"] .rv-product-item {
    border-right: 4px solid #f59e0b !important;
}

.rv-product-wrapper[data-wall-side="center"] .rv-product-item {
    border-top: 4px solid #8b5cf6 !important;
}

/* Warning state overrides wall indicators */
.rv-product-wrapper.rv-product-warning[data-wall-side="left"] .rv-product-item,
.rv-product-wrapper.rv-product-warning[data-wall-side="right"] .rv-product-item,
.rv-product-wrapper.rv-product-warning[data-wall-side="center"] .rv-product-item {
    border: 4px solid #dc2626 !important;
}

/* Preview badge */
.rv-preview-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
    z-index: 100;
    pointer-events: none;
    animation: previewBadgePulse 2s ease-in-out infinite;
}

@keyframes previewBadgePulse {
    0%, 100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateX(-50%) scale(1.05);
        opacity: 0.9;
    }
}

.rv-size-label {
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--rv-primary) 0%, var(--rv-secondary) 100%);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 100;
}

.rv-product-wrapper:hover .rv-size-label,
.rv-product-wrapper.rv-selected .rv-size-label,
.rv-product-wrapper.rv-dragging .rv-size-label {
    opacity: 1;
}

.rv-size-icon {
    margin-right: 6px;
    font-size: 14px;
}

.rv-delete-product {
    position: absolute !important;
    top: -12px;
    right: -12px;
    width: 32px;
    height: 32px;
    background: var(--rv-danger);
    color: white;
    border: 3px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    opacity: 0;
    transition: var(--rv-transition);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
    z-index: 10;
}

.rv-product-wrapper:hover .rv-delete-product,
.rv-product-wrapper.rv-selected .rv-delete-product {
    opacity: 1;
}

.rv-delete-product:hover {
    transform: scale(1.15) rotate(90deg);
    background: #ff5252;
}

/* ========================================
   TOOLBAR
   ======================================== */
.rv-toolbar {
    padding: 20px 32px;
    background: white;
    border-top: 1px solid var(--rv-border);
    display: flex;
    gap: 20px;
    align-items: center;
    flex-shrink: 0;
}

.rv-toolbar-section {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.rv-tool-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--rv-light);
    border: 2px solid var(--rv-border);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--rv-transition);
    color: var(--rv-dark);
}

.rv-tool-btn:hover {
    background: var(--rv-primary);
    border-color: var(--rv-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--rv-shadow);
}

.rv-tool-btn.active {
    background: var(--rv-primary);
    border-color: var(--rv-primary);
    color: white;
}

.rv-toolbar-section .rv-tool-btn svg {
    overflow: visible !important;
}

.rv-product-list {
    flex: 1;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}

.rv-product-list::-webkit-scrollbar {
    height: 6px;
}

.rv-product-list::-webkit-scrollbar-track {
    background: var(--rv-light);
    border-radius: 3px;
}

.rv-product-list::-webkit-scrollbar-thumb {
    background: var(--rv-border);
    border-radius: 3px;
}

.rv-product-list::-webkit-scrollbar-thumb:hover {
    background: var(--rv-primary);
}

.rv-product-card {
    flex-shrink: 0;
    width: 120px;
    background: white;
    border: 2px solid var(--rv-border);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: var(--rv-transition);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rv-product-card:hover {
    border-color: var(--rv-primary);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--rv-shadow-lg);
}

.rv-product-card-img {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--rv-light);
    border-radius: 8px;
    overflow: hidden;
}

.rv-product-card-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.rv-product-card-info {
    text-align: center;
}

.rv-product-card-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--rv-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rv-product-card-dims {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
}

.rv-empty-products {
    width: 100%;
    text-align: center;
    padding: 20px;
    color: #9ca3af;
}

/* ========================================
   PRIMARY BUTTON
   ======================================== */
.rv-primary-btn {
    background: linear-gradient(135deg, var(--rv-primary) 0%, var(--rv-secondary) 100%) !important;
    color: white !important;
    border: none !important;
    padding: 14px 28px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    transition: var(--rv-transition) !important;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
    display: inline-flex !important;
    align-items: center !important;
}

.rv-primary-btn:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4) !important;
}

.rv-primary-btn:active {
    transform: translateY(0) !important;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 1024px) {
    .rv-modal-content {
        width: 98%;
        margin: 1% auto;
    }

    .rv-modal-header {
        padding: 20px 24px;
    }

    .rv-controls,
    .rv-toolbar {
        padding: 16px 24px;
    }

    .rv-hud-advanced {
        padding: 16px 24px;
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .rv-modal-content {
        width: 100%;
        margin: 0;
        border-radius: 0;
    }

    .rv-modal-header h2 {
        font-size: 20px;
    }

    .rv-modal-subtitle {
        font-size: 12px;
    }

    .rv-close {
        right: 16px;
        top: 16px;
        width: 36px;
        height: 36px;
        font-size: 28px;
    }

    .rv-controls {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
    }

    .rv-control-group {
        min-width: 100%;
    }

    .rv-hud-advanced {
        padding: 12px 16px;
        gap: 10px;
    }

    .rv-hud-section {
        padding: 12px;
    }

    .rv-hud-title {
        font-size: 11px;
    }

    .rv-metric-label {
        font-size: 12px;
    }

    .rv-metric-value {
        font-size: 14px;
        padding: 3px 8px;
    }

    .rv-canvas-pro {
        min-height: 300px;
        margin: 0 16px;
    }

    .rv-toolbar {
        flex-wrap: wrap;
        padding: 16px;
    }

    .rv-toolbar-section {
        width: 100%;
        justify-content: center;
    }

    .rv-product-list {
        width: 100%;
    }

    .rv-product-card {
        width: 100px;
    }

    .rv-product-card-img {
        height: 70px;
    }

    .rv-delete-product {
        opacity: 0.9;
        width: 36px;
        height: 36px;
        font-size: 22px;
    }

    .rv-product-wrapper {
        min-width: 80px;
        min-height: 80px;
    }

    .rv-size-label {
        opacity: 0.8;
        font-size: 11px;
        padding: 4px 10px;
    }

    .rv-preview-badge {
        font-size: 10px;
        padding: 3px 10px;
    }

    .rv-canvas-pro,
    .rv-product-item {
        touch-action: none;
    }
}

@media (max-width: 480px) {
    .rv-modal-header {
        padding: 16px;
    }

    .rv-modal-header h2 {
        font-size: 18px;
    }

    .rv-controls {
        padding: 12px;
    }

    .rv-hud-advanced {
        padding: 10px 12px;
    }

    .rv-toolbar {
        padding: 12px;
    }

    .rv-product-card {
        width: 90px;
    }

    .rv-product-card-img {
        height: 60px;
    }

    .rv-product-card-name {
        font-size: 11px;
    }
}

@media print {
    #room-visualizer-modal,
    .room-visualizer-action {
        display: none !important;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rv-modal-content {
    animation: slideUp 0.4s ease-out;
}

.rv-product-wrapper {
    animation: fadeIn 0.3s ease-out;
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.rv-tool-btn:focus,
.rv-product-card:focus,
.rv-delete-product:focus {
    outline: 2px solid var(--rv-primary);
    outline-offset: 2px;
}

.rv-controls input:focus {
    outline: none;
    border-color: var(--rv-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .rv-product-wrapper {
        border: 2px solid currentColor;
    }

    .rv-alert {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}