/**
 * FileHub Frontend Styles
 * Version: 1.0.1
 * Debug Version: Check console for FILEHUB VERSION logs
 */

/* Use theme (theme.json) CSS vars directly with safe fallbacks */
/* See https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/ */
/* This stylesheet avoids inventing new colors and references theme palette variables. */

/* Form Container */
.filehub-form-container {
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: block !important; /* Force visibility */
}

/* Theme conflict prevention */
.entry-content .filehub-field,
.page-content .filehub-field,
.site-content .filehub-field,
.site-main .filehub-field,
.content-area .filehub-field,
body .filehub-field {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.filehub-form {
    background: var(--wp--preset--color--base, #ffffff);
    padding: 30px;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
}

/* Form Fields */
.filehub-field {
    margin-bottom: 20px;
    display: block !important; /* Force visibility */
    visibility: visible !important;
    opacity: 1 !important;
}

/* Preview containers - hidden by default, shown by JavaScript when file selected */
.filehub-field.filehub-stl-viewer,
.filehub-field.filehub-step-viewer {
    display: none !important;
}

.filehub-field.filehub-stl-viewer.show-preview,
.filehub-field.filehub-step-viewer.show-preview {
    display: block !important;
}

.filehub-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--wp--preset--color--primary, #2271b1);
}

.filehub-input,
.filehub-textarea,
.filehub-select,
.filehub-field input[type="text"],
.filehub-field input[type="email"],
.filehub-field textarea,
.filehub-field select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    background: var(--wp--preset--color--base, #ffffff);
}

.filehub-field textarea {
    resize: vertical;
    min-height: 100px;
}

.filehub-field select[multiple] {
    min-height: 120px;
}

/* Dropzone */
.filehub-dropzone,
.filehub-gallery-dropzone {
    border: 2px dashed rgba(0,0,0,.08);
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: var(--wp--preset--color--base-2, #f7f7f7);
}

.filehub-dropzone:hover,
.filehub-gallery-dropzone:hover {
    border-color: var(--wp--preset--color--primary, #2271b1);
    background: #eef5ff;
}

.filehub-dropzone.dragging,
.filehub-gallery-dropzone.dragging {
    border-color: var(--wp--preset--color--primary, #2271b1);
    background: #e8f4f8;
}

.filehub-dropzone.file-accepted {
    border-color: var(--wp--preset--color--primary, #2271b1);
    background: #e8f5e8;
}

.filehub-dropzone.file-accepted .dropzone-content p:first-child {
    color: #155724;
    font-weight: 600;
}

.filehub-dropzone.file-accepted .dropzone-content .dashicons {
    color: #46b450;
}

.filehub-dropzone.file-error {
    border-color: #dc3232;
    background: #fef7f7;
}

.filehub-dropzone.file-error .dropzone-content p:first-child {
    color: #721c24;
    font-weight: 600;
}

.filehub-dropzone.file-error .dropzone-content .dashicons {
    color: #dc3232;
}

.filehub-dropzone.file-selected {
    border-color: var(--wp--preset--color--primary, #2271b1);
    background: #f0f8ff;
}

.filehub-dropzone input[type="file"],
.filehub-gallery-dropzone input[type="file"] {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.dropzone-content .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: #999;
    display: block;
    margin: 0 auto 10px;
}

.dropzone-content p {
    margin: 5px 0;
    color: #666;
}

/* Upload Restrictions Display */
.filehub-upload-restrictions {
    margin: 15px 0 5px 0;
    padding: 12px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.4;
}

.filehub-upload-restrictions .allowed-types {
    margin-bottom: 8px;
}

.filehub-upload-restrictions .size-limit {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filehub-upload-restrictions .restriction-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    color: var(--wp--preset--color--primary, #2271b1);
    margin-bottom: 4px;
}

.filehub-upload-restrictions .restriction-label .dashicons {
    font-size: 14px;
    width: 14px;
    height: 14px;
}

.filehub-upload-restrictions .extension-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.filehub-upload-restrictions .ext-group {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid transparent;
}

.filehub-upload-restrictions .ext-group .ext-label {
    font-weight: 600;
    margin-right: 4px;
}

.filehub-upload-restrictions .ext-3d {
    background: #e8f4fd;
    border-color: #0073aa;
    color: #0073aa;
}

.filehub-upload-restrictions .ext-image {
    background: #f0e8fd;
    border-color: #8e44ad;
    color: #8e44ad;
}

.filehub-upload-restrictions .ext-doc {
    background: #e8f5e8;
    border-color: #27ae60;
    color: #27ae60;
}

.filehub-upload-restrictions .ext-archive {
    background: #fff2e8;
    border-color: #e67e22;
    color: #e67e22;
}

.filehub-upload-restrictions .ext-media {
    background: #fce8e8;
    border-color: #e74c3c;
    color: #e74c3c;
}

.filehub-upload-restrictions .ext-other {
    background: #f8f9fa;
    border-color: #6c757d;
    color: #6c757d;
}

.filehub-upload-restrictions .size-value {
    font-weight: 600;
    color: var(--wp--preset--color--primary, #2271b1);
    background: #e8f4fd;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #0073aa;
}

.filehub-upload-restrictions .no-types-configured {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    color: #d63638;
    font-weight: 400;
}

.filehub-upload-restrictions .no-types-configured strong {
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.filehub-upload-restrictions .no-types-configured .dashicons {
    color: #d63638;
    font-size: 18px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Disabled state when no file types are allowed */
.filehub-dropzone:has(input[disabled]) {
    cursor: not-allowed;
    opacity: 0.6;
    background: #f5f5f5;
}

.filehub-dropzone:has(input[disabled]):hover {
    border-color: rgba(0,0,0,.08);
    background: #f5f5f5;
}

/* Responsive adjustments for upload restrictions */
@media (max-width: 768px) {
    .filehub-upload-restrictions .extension-groups {
        flex-direction: column;
        gap: 4px;
    }
    
    .filehub-upload-restrictions .ext-group {
        width: 100%;
        text-align: left;
    }
    
    .filehub-upload-restrictions .size-limit {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

/* Selected Files Display */
.selected-files-display {
    padding: 0;
}

.selected-file-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    gap: 12px;
    cursor: default;
    transition: background 0.2s;
}

.selected-file-item:hover {
    background: #f7f7f7;
}

.selected-file-item .dashicons {
    font-size: 32px;
    width: 32px;
    height: 32px;
    color: #646970;
    flex-shrink: 0;
}

.file-info-wrapper {
    flex: 1;
    text-align: left;
    min-width: 0;
}

.file-info-wrapper .file-name {
    display: block;
    font-weight: 600;
    color: #1d2327;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-info-wrapper .file-meta {
    display: block;
    color: #646970;
    font-size: 12px;
}

.remove-file-btn {
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.remove-file-btn:hover {
    background: #d63638;
}

.remove-file-btn:hover .dashicons {
    color: white;
}

.remove-file-btn .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
    color: #646970;
}

.file-list-details {
    padding: 10px 15px;
    background: #f7f7f7;
    border-radius: 0 0 8px 8px;
    margin-top: -10px;
}

.file-list-item {
    padding: 4px 0;
    color: #646970;
    font-size: 13px;
}

.filehub-dropzone.file-selected {
    padding: 10px;
}

.filehub-dropzone.file-selected .dropzone-content {
    padding: 0;
}

/* File Preview */
.filehub-file-preview,
.filehub-gallery-preview {
    margin-top: 10px;
}

/* Gallery Preview Styles */
.filehub-gallery-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.gallery-image-preview {
    position: relative;
    display: inline-block;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #f9f9f9;
    max-width: 120px;
}

.gallery-image-preview img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
}

.gallery-image-preview .image-name {
    display: block;
    padding: 5px 8px;
    font-size: 11px;
    color: #666;
    background: #f0f0f0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-image-preview .remove-image {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: rgba(220, 50, 50, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-image-preview .remove-image:hover {
    background: rgba(220, 50, 50, 1);
}

/* Gallery Info Text */
.gallery-info {
    font-size: 12px !important;
    color: #999 !important;
    margin: 0 !important;
}

/* STL 3D Viewer Styles */
.filehub-stl-viewer {
    border: 2px solid var(--wp--preset--color--primary, #2271b1);
    border-radius: 10px;
    padding: 20px;
    background: var(--wp--preset--color--base-2, #f8fbff);
    margin-bottom: 20px;
}

/* STEP Viewer - matching STL viewer styles */
.filehub-step-viewer {
    border: 2px solid var(--wp--preset--color--secondary, #B32821);
    border-radius: 10px;
    padding: 20px;
    background: var(--wp--preset--color--base-2, #fff8f8);
    margin-bottom: 20px;
}

.stl-viewer-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    background: var(--wp--preset--color--base-2, #f8fbff);
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 10px;
    overflow: hidden;
    /* expose model color var for JS to read from theme */
    --filehub-model-color: var(--wp--preset--color--primary, #2271b1);
}

.step-viewer-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    background: var(--wp--preset--color--base-2, #fff8f8);
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 10px;
    overflow: hidden;
    /* expose model color var for JS to read from theme */
    --filehub-model-color: var(--wp--preset--color--secondary, #B32821);
}

#stl-canvas {
    border: 2px solid rgba(0,0,0,.08);
    border-radius: 10px;
    background: var(--wp--preset--color--base, #ffffff);
    display: block;
    cursor: grab;
}

#stl-canvas:active {
    cursor: grabbing;
}

#step-canvas {
    border: 2px solid rgba(0,0,0,.08);
    border-radius: 10px;
    background: var(--wp--preset--color--base, #ffffff);
    display: block;
    cursor: grab;
}

#step-canvas:active {
    cursor: grabbing;
}

.stl-controls {
    min-width: 200px;
    flex-shrink: 0;
}

.step-controls {
    min-width: 200px;
    flex-shrink: 0;
}

.rotation-controls h4 {
    margin: 0 0 15px 0;
    color: var(--wp--preset--color--primary, #2271b1);
    font-size: 16px;
}

.slider-group {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    gap: 10px;
}

.slider-group label {
    min-width: 50px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.slider-group input[type="range"] {
    flex: 1;
    min-width: 100px;
}

.rotation-value {
    min-width: 35px;
    text-align: right;
    font-weight: 600;
    color: var(--wp--preset--color--primary, #2271b1);
    font-size: 12px;
}

#reset-rotation {
    margin-top: 15px;
    background: var(--wp--preset--color--primary, #2271b1);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
}

#reset-rotation:hover {
    filter: brightness(.9);
}

/* STEP viewer specific styles */
.step-controls .rotation-controls h4 {
    color: var(--wp--preset--color--secondary, #B32821);
}

.step-controls .rotation-value {
    color: var(--wp--preset--color--secondary, #B32821);
}

#step-reset-rotation {
    margin-top: 15px;
    background: var(--wp--preset--color--secondary, #B32821);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
}

#step-reset-rotation:hover {
    filter: brightness(.9);
}

.step-info {
    margin-top: 20px;
    padding: 15px;
    background: rgba(179, 40, 33, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--wp--preset--color--secondary, #B32821);
}

.step-warning {
    margin: 0;
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

/* Range slider styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--wp--preset--color--primary, #2271b1);
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--wp--preset--color--primary, #2271b1);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .stl-viewer-container {
        flex-direction: column;
    }
    
    #stl-canvas {
        width: 100%;
        height: auto;
        max-width: 400px;
        max-height: 400px;
    }
    
    .stl-controls {
        width: 100%;
        min-width: auto;
    }
}

.filehub-file-preview .file-item,
.filehub-gallery-preview .image-item {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: 4px;
    margin: 5px;
}

.filehub-gallery-preview img {
    max-width: 100px;
    max-height: 100px;
    margin: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Designer Info */
.filehub-designer-info {
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
}

.filehub-designer-info a {
    color: #0073aa;
    text-decoration: none;
    font-weight: 600;
}

.filehub-designer-info a:hover {
    text-decoration: underline;
}

.filehub-designer-info strong {
    display: block;
    margin-bottom: 5px;
}

/* Form descriptions */
.filehub-field .description {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    font-style: italic;
}

/* Terms Checkbox */
.filehub-terms label {
    display: flex;
    align-items: center;
    font-weight: normal;
}

.filehub-terms input[type="checkbox"] {
    margin-right: 8px;
}

/* Submit Button */
.filehub-submit {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.filehub-submit-btn {
    background: var(--wp--preset--color--primary, #2271b1);
    color: #fff;
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.filehub-submit-btn:hover {
    filter: brightness(.9);
}

.filehub-submit-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Loading */
.filehub-loading {
    display: inline-block;
    margin-left: 15px;
}

.filehub-loading .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--wp--preset--color--primary, #2271b1);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Field limit indicators */
.field-limit {
    font-size: 11px;
    color: #666;
    font-weight: normal;
    margin-left: 5px;
}

#description-counter {
    font-weight: bold;
}

.tag-limit-warning {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #d63638;
}

.filehub-field .description {
    font-size: 13px;
    color: #646970;
    margin-top: 5px;
}

/* Messages */
.filehub-messages {
    margin-top: 20px;
}

.filehub-message {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.filehub-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.filehub-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* File Validation Messages */
.filehub-file-validation {
    margin-top: 10px;
}

.filehub-validation-message {
    padding: 10px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
}

.filehub-validation-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.filehub-validation-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.filehub-notice {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.filehub-notice.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.filehub-notice.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.filehub-notice.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

/* Single File Template */
.filehub-single-file {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.filehub-single-file .entry-header {
    margin-bottom: 30px;
}

.filehub-single-file .entry-title {
    margin-bottom: 10px;
}

.filehub-designer {
    font-size: 16px;
    color: #666;
}

.filehub-featured-image {
    max-width: 100%;
    height: auto;
    margin-bottom: 30px;
    display: block;
}

.filehub-gallery {
    margin: 30px 0;
}

.filehub-gallery h3 {
    margin-bottom: 15px;
}

.filehub-gallery-images {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filehub-gallery-image {
    max-width: 200px;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.filehub-file-info {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 4px;
    margin: 30px 0;
}

.filehub-download-section {
    margin: 20px 0;
}

.filehub-download-button {
    display: inline-block;
    padding: 10px 20px;
    background: #0073aa;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    margin-right: 15px;
}

.filehub-download-button:hover {
    background: #005a87;
    color: #fff;
}

.filehub-download-count {
    color: #666;
    font-size: 14px;
}

.filehub-categories,
.filehub-tags {
    margin: 15px 0;
}

.filehub-tag {
    display: inline-block;
    padding: 3px 8px;
    background: #e0e0e0;
    border-radius: 3px;
    margin-right: 5px;
    text-decoration: none;
    color: #333;
    font-size: 13px;
}

.filehub-tag:hover {
    background: #d0d0d0;
}

/* ==========================================================================
   Comments Form Button Fix for FileHub Single File Pages
   ========================================================================== */

/* Fix for comment form button scaling issue in FileHub single file pages */
.single-filehub_file .wp-block-post-comments-form .wp-block-button__link,
.single-filehub_file .comment-form .wp-block-button__link,
.single-filehub_file .comment-form input[type="submit"].wp-block-button__link,
.single-filehub_file .comment-form input[type="submit"].wp-element-button,
.single-filehub_file #submit.wp-block-button__link {
    height: auto !important;
    padding: 12px 24px !important;
    min-height: 40px;
    width: auto !important;
    max-width: 200px;
    display: inline-block !important;
}

/* Ensure proper button container styling */
.single-filehub_file .wp-block-post-comments-form input[type="submit"],
.single-filehub_file .comment-form input[type="submit"] {
    height: auto !important;
    display: inline-block;
    box-sizing: border-box;
}

/* Prevent button from stretching to full width */
.single-filehub_file .form-submit,
.single-filehub_file .comment-form-submit {
    text-align: left;
}

/* Override any flex container issues */
.single-filehub_file .wp-block-post-comments-form .form-submit {
    display: block;
    margin-top: 1rem;
}
