/* assets/css/frontend.css - Revised to show button text on mobile */

/* General Styles */
body {
    font-family: sans-serif;
    line-height: 1.6;
    color: #333;
}

/* --- Customizer Overlay and Main Container --- */
.pc-customizer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh; /* Modern browsers handle this well */
    min-height: -webkit-fill-available; /* iOS Safari fix */
    min-height: 100vh; /* Fallback */
    background: rgba(0,0,0,0.9);
    z-index: 999999;
    display: none; /* Controlled by JS */
    overflow-y: auto; /* Allow scrolling for the whole overlay if content exceeds viewport */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding: 2vh 2vw; /* Add some padding around the main content box */
    box-sizing: border-box;
}

/* NEW: Wrapper inside the overlay for padding/centering */
.pc-customizer-content {
    width: 100%; /* Take full width of padded overlay */
    max-width: 1400px; /* Increased max-width for wider layouts */
    height: 100%; /* Take full height of padded overlay */
    margin: 0 auto; /* Center horizontally */
    background: #fff;
    border-radius: 12px; /* Slightly softer radius */
    display: flex;
    flex-direction: column; /* Stack header, toolbar, main area */
    overflow: hidden; /* Prevent content breaking out of rounded corners */
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
}

/* NEW: Optional Header */
.pc-header {
    display: flex;
    justify-content: flex-end; /* Push items to the right */
    align-items: center;
    padding: 8px 15px;
    border-bottom: 1px solid #e9ecef;
    background-color: #f8f9fa; /* Match toolbar */
    flex-shrink: 0;
}

.pc-header .pc-customized-price {
    margin-right: auto; /* Push price to the left */
    margin-bottom: 0; /* Reset margin */
    font-size: 16px;
    font-weight: bold;
    color: #007cba;
}

.pc-header .pc-close-overlay {
     /* Style the close button specifically if needed */
     background: none;
     border: none;
     padding: 5px;
     color: #6c757d;
     font-size: 20px; /* Adjust icon size if needed */
     cursor: pointer;
     line-height: 1;
}
.pc-header .pc-close-overlay:hover {
    color: #343a40;
}
.pc-header .pc-close-overlay .pc-button-text {
    display: none; /* Hide text for header close button, icon is enough */
}

/* Toolbar Styles (Adjusted for context) */
.pc-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 15px; /* Consistent padding */
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef; /* Add separator line */
    flex-shrink: 0; /* Prevent toolbar from shrinking */
}

/* Toolbar Buttons and Controls */
.pc-toolbar button,
.pc-toolbar select,
.pc-toolbar input[type="color"],
.pc-upload-label {
    padding: 6px 10px;
    border: 1px solid #dee2e6;
    background: #fff;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    color: #495057; /* Slightly muted color */
    font-size: 13px; /* Slightly larger base font */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px; /* Space between icon and text */
    line-height: 1.4;
    text-align: center;
    flex-grow: 0; /* Don't allow to grow by default */
    flex-shrink: 0;
    white-space: nowrap;
    overflow: visible; /* Ensure content isn't hidden */
    min-height: 34px; /* Ensure minimum button height */
    box-sizing: border-box;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.pc-toolbar button:hover,
.pc-toolbar select:hover,
.pc-toolbar input[type="color"]:hover,
.pc-upload-label:hover {
    border-color: #adb5bd;
    background-color: #e9ecef; /* Light grey background on hover */
}

.pc-toolbar button:active,
.pc-upload-label:active {
     background-color: #ced4da;
     box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.pc-toolbar button:disabled,
.pc-toolbar select:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    box-shadow: none;
}

/* Specific tool styling */
.pc-toolbar input[type="color"] {
    padding: 2px; /* Reduce padding for color input */
    min-width: 40px;
    min-height: 34px; /* Match height */
}

.pc-toolbar select.pc-font-selector {
    max-width: 150px; /* Limit font selector width */
    flex-grow: 1; /* Allow font selector to take more space */
}

/* Icons within Toolbar Buttons */
.pc-toolbar .dashicons {
    font-size: 18px; /* Adjust icon size */
    line-height: 1;
    height: 1em;
    width: 1em;
    vertical-align: middle;
    flex-shrink: 0;
}

/* --- NEW: Main Content Area (Canvas + Clipart) --- */
.pc-main-content-area {
    display: flex; /* Arrange canvas and clipart side-by-side */
    flex-direction: row; /* Horizontal layout */
    flex-grow: 1; /* Take remaining vertical space */
    overflow: hidden; /* Important for child elements with overflow:auto */
    padding: 15px; /* Padding around canvas and clipart panel */
    gap: 15px; /* Space between canvas and clipart panel */
    background-color: #e9ecef; /* Light background for the main area */
}

/* Canvas Wrapper Styles (Adapted) */
.pc-canvas-wrapper {
    flex-grow: 1; /* Allow canvas area to take most space */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff; /* White background for the canvas immediate wrapper */
    border-radius: 8px;
    overflow: hidden; /* Clip canvas if it overflows due to Fabric scaling bugs */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    min-width: 0; /* Prevent flex item from overflowing container */
}

#pc-main-canvas {
    /* Fabric.js sets width/height attributes, CSS affects display */
    display: block;
    max-width: 100%; /* Prevent canvas element exceeding wrapper */
    max-height: 100%;
    /* DO NOT set width/height via CSS */
}

/* --- NEW: Clip Art Panel Styles --- */
.pc-clipart-panel {
    flex: 0 0 220px; /* Fixed width for the clipart panel */
    display: flex;
    flex-direction: column; /* Stack title and list vertically */
    background-color: #f8f9fa; /* Match toolbar background */
    border-radius: 8px;
    border: 1px solid #dee2e6;
    overflow: hidden; /* Clip content within rounded corners */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.pc-panel-title {
    margin: 0;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    background-color: #e9ecef; /* Slightly different background for title */
    border-bottom: 1px solid #dee2e6;
    text-align: center;
    flex-shrink: 0; /* Prevent title from shrinking */
}

#pc-clipart-list {
    flex-grow: 1; /* Allow list to take available vertical space */
    overflow-y: auto; /* Add scrollbar if content overflows */
    padding: 10px; /* Padding inside the scrollable area */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling */
    background-color: #fff; /* White background for the grid area */
}

.pc-clipart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); /* Responsive grid */
    gap: 8px; /* Space between thumbnails */
    align-content: start;
}

.pc-clipart-item {
    border: 1px solid #e9ecef;
    padding: 4px;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1 / 1; /* Make items square */
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.pc-clipart-item:hover {
    border-color: #adb5bd;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.3); /* Subtle glow on hover */
}

.pc-clipart-item img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain; /* Ensure image fits without distortion */
    transition: transform 0.2s ease-in-out;
}

.pc-clipart-item:hover img {
     transform: scale(1.05); /* Slight zoom on hover */
}

/* Style for loading/error messages inside the clipart grid */
.pc-loading-cliparts {
    text-align: center;
    color: #6c757d;
    padding: 20px 10px;
    grid-column: 1 / -1; /* Span full width of the grid */
    font-size: 13px;
}

.pc-clipart-item img.load-error {
    /* Optional: style images that failed to load */
    opacity: 0.5;
    border: 1px dashed #dc3545; /* Red dashed border for error */
}


/* Inquiry Form Styles (Keep Existing, ensure classes match HTML) */
.pc-inquiry-form {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 0; /* Reset padding */
    border-radius: 8px;
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
    z-index: 1000000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pc-inquiry-header {
    display: flex;
    justify-content: space-between; /* Space title and close button */
    align-items: center;
    background-color: #f0f0f0;
    padding: 10px 15px; /* Adjusted padding */
    border-bottom: 1px solid #ddd;
    cursor: move;
    font-weight: bold; /* Make title bold */
    color: #333;
    flex-shrink: 0;
}

/* Use the form title element itself for dragging, no need for extra span */
/* .pc-move-handle { ... remove this rule ... } */

.pc-inquiry-header .pc-close-form { /* Style the close button in header */
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    flex-shrink: 0;
}
.pc-inquiry-header .pc-close-form:hover {
    color: #000;
}

#pc-inquiry-form { /* Style the form element itself */
    padding: 15px;
    overflow-y: auto; /* Make form content scrollable */
    flex-grow: 1; /* Allow form to take remaining space */
    -webkit-overflow-scrolling: touch;
    text-align: left;
}

.pc-inquiry-form .pc-preview-image {
    max-width: 100%;
    max-height: 200px; /* Adjusted max height */
    margin: 0 auto 15px auto; /* Center image */
    border: 1px solid #eee;
    object-fit: contain;
    display: block; /* Needed for margin:auto centering */
}

/* Form fields styling (Keep existing relevant rules) */
.pc-inquiry-form p { margin-bottom: 12px; }

.pc-inquiry-form input[type="text"],
.pc-inquiry-form input[type="email"],
.pc-inquiry-form input[type="tel"],
.pc-inquiry-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
}

.pc-inquiry-form textarea {
    resize: vertical;
    min-height: 80px;
}

.pc-inquiry-form button[type="submit"] {
    background-color: #007bff;
    color: #fff;
    padding: 10px 20px;
    font-size: 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 100%;
    margin-top: 10px;
}

.pc-inquiry-form button[type="submit"]:hover {
    background-color: #0056b3;
}


/* --- Responsiveness --- */

@media (max-width: 992px) {
     /* Adjustments for tablet-like sizes */
    .pc-main-content-area {
        flex-direction: column; /* Stack canvas and clipart panel vertically */
        padding: 10px;
        gap: 10px;
    }

    .pc-clipart-panel {
        flex: 0 0 auto; /* Allow panel height to be auto */
        max-height: 250px; /* Limit height when stacked */
        width: 100%; /* Take full width when stacked */
    }

     #pc-clipart-list {
         /* Adjust padding if needed when horizontal */
         padding: 8px;
     }

     .pc-clipart-grid {
         grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); /* Slightly smaller items */
         gap: 6px;
     }

    .pc-canvas-wrapper {
        min-height: 350px; /* Adjust min height if needed */
    }
}

/* Mobile Styles (Merging your existing rules and adjusting) */
@media (max-width: 768px) {
    .pc-customizer-overlay {
        padding: 1vh 1vw; /* Reduce padding on mobile */
    }

    .pc-customizer-content {
        border-radius: 8px; /* Smaller radius */
    }

    .pc-header {
        padding: 6px 10px;
    }
    .pc-header .pc-customized-price {
        font-size: 14px;
    }

    .pc-toolbar {
        gap: 5px;
        padding: 8px 10px;
    }

    .pc-toolbar button,
    .pc-toolbar select,
    .pc-toolbar input[type="color"],
    .pc-upload-label {
        padding: 5px 8px;
        font-size: 11px; /* Smaller font for more buttons to fit */
        gap: 3px;
        min-height: 32px;
    }

    /* --- MODIFIED RULE TO SHOW TEXT ON MOBILE --- */
    /* Hide text labels on mobile to save space? NO, keep them visible. */
    .pc-toolbar .pc-button-text {
        /* display: none; */ /* REMOVED or COMMENTED OUT to show text */
        /* Adjust display if needed, usually inline is fine with flex */
        display: inline;
    }
    /* --- END MODIFIED RULE --- */


    .pc-main-content-area {
        padding: 8px;
        gap: 8px;
    }

    .pc-clipart-panel {
        max-height: 200px; /* Further limit height */
    }

     #pc-clipart-list {
        padding: 6px;
     }

    .pc-clipart-grid {
        grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
        gap: 5px;
    }
    .pc-clipart-item {
        padding: 3px;
    }


    .pc-canvas-wrapper {
        min-height: 300px; /* Adjust as needed */
    }

    /* Inquiry form adjustments (Keep existing) */
    .pc-inquiry-form {
        width: 95%;
        max-height: 95vh;
    }
    .pc-inquiry-header {
        padding: 8px 12px;
        font-size: 14px;
    }
     #pc-inquiry-form { padding: 12px; }
     .pc-inquiry-form p { margin-bottom: 10px; }
     .pc-inquiry-form input[type="text"],
     .pc-inquiry-form input[type="email"],
     .pc-inquiry-form input[type="tel"],
     .pc-inquiry-form textarea { font-size: 13px; padding: 6px 8px; }
     .pc-inquiry-form button[type="submit"] { padding: 8px 15px; font-size: 14px; }
}

@media (max-width: 480px) {
     /* Fine-tune for very small screens */
     .pc-toolbar { padding: 5px; }
     .pc-toolbar button,
     .pc-toolbar select,
     .pc-toolbar input[type="color"],
     .pc-upload-label {
        font-size: 10px; /* Even smaller */
        min-height: 30px;
        padding: 4px 6px;
     }
     .pc-toolbar .dashicons { font-size: 16px; }

     /* If still too crowded, you might need to reduce gap or padding further */
     .pc-toolbar { gap: 3px; }
     .pc-toolbar button, .pc-toolbar select, .pc-toolbar input[type="color"], .pc-upload-label { gap: 2px; }
}