/**
 * Production Line Designer - Main Styles
 */

/* Main Container */
.pld-container {
    max-width: 1200px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.pld-workspace {
    display: flex;
    flex-direction: column;
    min-height: 600px;
    border: 1px solid #ddd;
    margin-top: 20px;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Sidebar Styles */
.pld-sidebar {
    width: 100%;
    background-color: #f7f7f7;
    border-bottom: 1px solid #ddd;
    padding: 15px;
    overflow-x: auto;
}

.pld-sidebar h3 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.pld-components {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.pld-component {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    text-align: center;
    cursor: grab;
    transition: all 0.2s ease;
}

.pld-component:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.pld-component-active {
    opacity: 0.6;
}

.pld-component-icon {
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
}

.pld-component-icon img {
    max-width: 100%;
    max-height: 100%;
}

.pld-component-name {
    font-size: 12px;
    font-weight: 500;
}

/* Grid Container */
.pld-grid-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.pld-toolbar {
    padding: 10px 15px;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.pld-btn {
    padding: 6px 12px;
    background-color: #2271b1;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s ease;
}

.pld-btn:hover {
    background-color: #135e96;
}

.pld-clear-btn {
    background-color: #dc3232;
}

.pld-clear-btn:hover {
    background-color: #b32d2e;
}

/* Space Settings Styles */
.pld-space-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.pld-dimension-input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

/* Grid Info Display */
.pld-grid-info {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 5px 15px;
    background-color: #f9f9f9;
    border-bottom: 1px solid #eee;
    font-size: 12px;
    color: #666;
}

.pld-scale-display {
    font-weight: 500;
}

/* Grid Styles */
.pld-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(20, 30px);
    grid-template-rows: repeat(20, 30px);
    gap: 1px;
    background-color: #f0f0f0;
    padding: 20px;
    overflow: auto;
    position: relative; /* For absolute positioning of components */
    -webkit-overflow-scrolling: touch;
}

.pld-grid-cell {
    background-color: #fff;
    border: 1px solid #eee;
    transition: background-color 0.2s;
}

.pld-grid-cell.highlight {
    background-color: rgba(33, 150, 243, 0.2);
}

/* Component Controls */
.pld-component-controls {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    gap: 5px;
    z-index: 20;
    visibility: hidden;
}

.pld-rotate-btn {
    width: 24px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background-color 0.2s, transform 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.pld-rotate-btn:hover {
    background-color: #2271b1;
    transform: scale(1.1);
}

.pld-rotate-btn svg {
    width: 14px;
    height: 14px;
    fill: white;
}

/* Rotated Component Styles */
.pld-rotated-90, .pld-rotated-180, .pld-rotated-270 {
    /* Higher z-index when rotated to appear above other components */
    z-index: 15 !important;
}

.pld-rotation-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px dashed rgba(33, 150, 243, 0.5);
    border-radius: 3px;
    pointer-events: none;
    z-index: 5;
    visibility: hidden;
}

.pld-component-resizing .pld-rotation-indicator {
    opacity: 0.5;
}

.pld-component-moving {
    opacity: 0.8;
    z-index: 25;
}

/* Improved resize handles during rotation/resize operations */
.pld-component-resizing {
    opacity: 0.9;
    z-index: 30;
}

/* Special class for handle visibility when element is rotated */
.pld-component-wrapper.pld-rotated-90 .ui-resizable-handle,
.pld-component-wrapper.pld-rotated-180 .ui-resizable-handle,
.pld-component-wrapper.pld-rotated-270 .ui-resizable-handle {
    background-color: #ff9800 !important;
    border-color: #fff !important;
}

/* Helper element for resize operations - should never be rotated */
.ui-resizable-helper {
    border: 2px dashed #2271b1 !important;
    background-color: rgba(33, 150, 243, 0.1) !important;
    transform: none !important;
    z-index: 120 !important;
}

/* Show the handles more prominently on hover */
.pld-placed-component-wrapper:hover .ui-resizable-handle {
    visibility: visible;
}

/* Improved Resizable Handles */
.ui-resizable-handle {
    position: absolute;
    width: 15px;
    height: 15px;
    background: #fff;
    border: 2px solid #2271b1;
    border-radius: 50%;
    z-index: 90;
    visibility: hidden;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Position the handles properly */
.ui-resizable-n {
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.ui-resizable-e {
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.ui-resizable-s {
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.ui-resizable-w {
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.ui-resizable-se {
    bottom: -8px;
    right: -8px;
    cursor: se-resize;
}

.ui-resizable-sw {
    bottom: -8px;
    left: -8px;
    cursor: sw-resize;
}

.ui-resizable-ne {
    top: -8px;
    right: -8px;
    cursor: ne-resize;
}

.ui-resizable-nw {
    top: -8px;
    left: -8px;
    cursor: nw-resize;
}

/* Make handles more visible on hover */
.pld-placed-component-wrapper .ui-resizable-handle:hover {
    transform: scale(1.2);
    background-color: #2271b1;
    border-color: #fff;
}

/* Handles for rotated components */
.rotated-handle {
    background-color: #ff9800;
    border-color: #fff;
}

.pld-placed-component-wrapper .rotated-handle:hover {
    background-color: #ff5722;
}

/* Component Size Display */
.pld-component-size {
    position: absolute;
    bottom: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 3px 6px;
    font-size: 10px;
    border-top-left-radius: 3px;
    z-index: 15;
    pointer-events: none;
    visibility: hidden;
}

/* Rotation Indicator */
.pld-rotation-badge {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: #2196f3;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
    z-index: 6;
    visibility: hidden;
}

/* Placed Component Styles */
.pld-placed-component-wrapper {
    background-color: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    cursor: grab;
    transition: box-shadow 0.2s, transform 0.3s;
    position: relative;
    transform-origin: center center;
    z-index: 10;
}

.pld-placed-component-wrapper:hover {
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}

.pld-placed-component {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    box-sizing: border-box;
}

.pld-placed-component img {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

/* Resizable Styles */
.ui-resizable-handle {
    position: absolute;
    display: block;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid #2271b1;
    border-radius: 50%;
    z-index: 90;
}

.ui-resizable-se {
    cursor: se-resize;
    bottom: -5px;
    right: -5px;
}

.ui-resizable-sw {
    cursor: sw-resize;
    bottom: -5px;
    left: -5px;
}

.ui-resizable-ne {
    cursor: ne-resize;
    top: -5px;
    right: -5px;
}

.ui-resizable-nw {
    cursor: nw-resize;
    top: -5px;
    left: -5px;
}

/* Make sure the placeholder is not rotated during resize */
.ui-resizable-helper {
    transform: none !important;
}

/* Modal Styles */
.pld-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow: auto;
}

.pld-modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 30px 20px;
    width: 80%;
    max-width: 500px;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.pld-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.pld-close:hover {
    color: #333;
}

.pld-form-group {
    margin-bottom: 15px;
}

.pld-form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.pld-form-group input {
    width: 100%;
    padding: 12px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 16px;
}

/* Saved Designs List */
.pld-designs-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.pld-design-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pld-design-item:last-child {
    border-bottom: none;
}

.pld-design-name {
    font-weight: 500;
}

.pld-design-date {
    color: #666;
    font-size: 0.9em;
    margin: 0 10px;
}

.pld-load-design-btn {
    padding: 4px 8px;
    font-size: 12px;
}

/* Admin Styles */
.pld-admin-tabs .tab-content {
    margin-top: 15px;
    background-color: #fff;
    padding: 20px;
    border: 1px solid #ccd0d4;
    border-top: none;
}

.pld-admin-tabs .tab-pane {
    display: none;
}

.pld-admin-tabs .tab-pane.active {
    display: block;
}

.pld-shortcode-box {
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 3px;
}

.pld-admin-filter {
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
    align-items: center;
}

/* Responsive Styles */
@media screen and (max-width: 782px) {
    .pld-workspace {
        flex-direction: column;
    }
    
    .pld-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    
    .pld-components {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media screen and (max-width: 480px) {
    .pld-components {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Connection Styles */
.pld-connection {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

.pld-connection svg {
    overflow: visible;
}

.pld-connection-delete {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: #e74c3c;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    pointer-events: auto;
    z-index: 15;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.pld-connection:hover .pld-connection-delete {
    opacity: 1;
    transform: scale(1.1);
}

.pld-connection-icon {
    position: absolute;
    width: 24px;
    height: 24px;
    background-color: #4CAF50;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 14;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.pld-connection-icon svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Component Sequence Number */
.pld-component-sequence {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 20px;
    height: 20px;
    background-color: #2196F3;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    z-index: 20;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Connection Sequence Badge */
.pld-connection-sequence {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: bold;
    pointer-events: none;
    z-index: 15;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Undo/Redo Notification */
.pld-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 1000;
    animation: slide-in 0.3s ease-out;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.pld-notification-success {
    background-color: rgba(46, 204, 113, 0.9);
}

.pld-notification-error {
    background-color: rgba(231, 76, 60, 0.9);
}

@keyframes slide-in {
    0% {
        transform: translateX(100px);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Touch-friendly controls */
.touch-handle {
    width: 20px !important;
    height: 20px !important;
    transform: translate(-50%, -50%);
}

/* Ensure touch targets are large enough */
.pld-btn, 
.pld-close,
.pld-connection-icon {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent text selection on touch */
.pld-container {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Fix for iOS Safari double-tap zoom */
.pld-placed-component-wrapper,
.pld-component,
.pld-grid,
.pld-grid-cell {
    touch-action: manipulation;
}

/* Ensure scrollability on touch */
.pld-grid {
    -webkit-overflow-scrolling: touch;
}

/* Increase form element sizes for touch */
@media (pointer: coarse) {
    .pld-form-group input,
    .pld-dimension-input {
        padding: 12px 8px;
        font-size: 16px;
    }
    
    .pld-btn {
        padding: 10px 16px;
        font-size: 16px;
    }
    
    .pld-component-name {
        font-size: 14px;
    }
} 