/**
 * Rich Snippet Editor Styles
 * Smart Builder + Code Editor for URL Detail View
 *
 * @package CustomSchemaSchemafy
 * @since 2.1.0
 */

/* ==========================================================================
   Modal Overlay & Container - Redesigned for Horizontal Layout
   ========================================================================== */

.schemafy-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 999999;
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.schemafy-snippet-modal-content {
    width: 95%;
    max-width: 1400px;
    max-height: 90vh;
    margin: auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.schemafy-snippet-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    border-bottom: 2px solid var(--schemafy-gray-200);
    background: #0F172A;
    flex-shrink: 0;
}

.schemafy-snippet-modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.schemafy-snippet-modal-header .dashicons {
    font-size: 26px;
    color: #ffffff;
}

.schemafy-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    color: #ffffff;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.schemafy-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.schemafy-snippet-modal-body {
    padding: 28px;
    overflow-y: auto;
    flex: 1;
    background: var(--schemafy-gray-50);
}

/* ==========================================================================
   Snippet Editor Container
   ========================================================================== */

.schemafy-snippet-editor-section {
    margin-top: 32px;
    padding: 24px;
    background: white;
    border-radius: var(--schemafy-radius);
    box-shadow: var(--schemafy-shadow);
    border: 2px solid var(--schemafy-gray-200);
}

.schemafy-snippet-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--schemafy-gray-200);
}

.schemafy-snippet-editor-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    color: var(--schemafy-gray-800);
}

.schemafy-snippet-editor-title .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
    color: var(--schemafy-primary);
}

.schemafy-add-snippet-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--schemafy-primary);
    border: none;
    border-radius: var(--schemafy-radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: var(--schemafy-transition);
    box-shadow: var(--schemafy-shadow-sm);
}

.schemafy-add-snippet-btn:hover {
    background: var(--schemafy-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--schemafy-shadow-md);
}

.schemafy-add-snippet-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   Editor Form
   ========================================================================== */

.schemafy-snippet-editor-form {
    display: none;
    margin-top: 24px;
    padding: 24px;
    background: var(--schemafy-gray-50);
    border-radius: var(--schemafy-radius-sm);
    border: 1px solid var(--schemafy-gray-200);
}

.schemafy-snippet-editor-form.active {
    display: block;
    animation: fadeInUp 0.3s ease-out;
}

/* Mode Toggle - Horizontal Layout */
.schemafy-snippet-mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    padding: 6px;
    background: #0F172A;
    border-radius: 10px;
    width: fit-content;
    box-shadow: 0 4px 15px rgba(79, 110, 245, 0.3);
}

.schemafy-snippet-mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: all 0.3s ease;
}

.schemafy-snippet-mode-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.schemafy-snippet-mode-btn.active {
    background: white;
    color: #0F172A;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.schemafy-snippet-mode-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* Horizontal Layout Container */
.schemafy-snippet-content-wrapper {
    display: grid;
    grid-template-columns: 1fr 450px;
    gap: 24px;
    margin-bottom: 20px;
}

/* Schema Type Selector */
.schemafy-snippet-type-selector {
    margin-bottom: 20px;
}

.schemafy-snippet-type-selector label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--schemafy-code-border);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#schemafy-snippet-schema-type {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    border: 2px solid var(--schemafy-gray-200);
    border-radius: 10px;
    background: white;
    transition: all 0.3s ease;
    font-weight: 500;
}

#schemafy-snippet-schema-type:focus {
    outline: none;
    border-color: #0F172A;
    box-shadow: 0 0 0 4px rgba(79, 110, 245, 0.15);
    transform: translateY(-1px);
}

/* Basic Info Fields */
.schemafy-snippet-basic-info {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.schemafy-snippet-field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.schemafy-snippet-field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--schemafy-gray-800);
}

.schemafy-snippet-field-label .required {
    color: var(--schemafy-danger);
    font-size: 16px;
}

.schemafy-snippet-field {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid var(--schemafy-gray-300);
    border-radius: var(--schemafy-radius-sm);
    background: white;
    color: var(--schemafy-gray-900);
    transition: var(--schemafy-transition);
}

.schemafy-snippet-field:focus {
    outline: none;
    border-color: var(--schemafy-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.schemafy-snippet-field:disabled {
    background: var(--schemafy-gray-100);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Visual Builder - Left Column */
.schemafy-snippet-visual-builder {
    display: block;
}

.schemafy-snippet-visual-builder.hidden {
    display: none;
}

.schemafy-snippet-fields-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    border: 2px solid var(--schemafy-gray-200);
    max-height: calc(90vh - 320px);
    overflow-y: auto;
}

.schemafy-snippet-fields-container::-webkit-scrollbar {
    width: 8px;
}

.schemafy-snippet-fields-container::-webkit-scrollbar-track {
    background: var(--schemafy-gray-100);
    border-radius: 10px;
}

.schemafy-snippet-fields-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.schemafy-snippet-fields-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.schemafy-snippet-field-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: var(--schemafy-gray-50);
    border-radius: var(--schemafy-radius-sm);
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.schemafy-snippet-field-item:focus-within {
    border-left-color: var(--schemafy-primary);
    background: white;
    box-shadow: var(--schemafy-shadow-sm);
}

/* Textarea */
textarea.schemafy-snippet-field {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    line-height: 1.5;
}

/* Select */
select.schemafy-snippet-field {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%236c757d' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
    padding-right: 40px;
}

/* Code Editor */
.schemafy-snippet-code-editor {
    display: none;
}

.schemafy-snippet-code-editor.active {
    display: block;
}

.schemafy-snippet-code-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    background: var(--schemafy-gray-100);
    border-radius: var(--schemafy-radius-sm);
}

.schemafy-snippet-code-toolbar button {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--schemafy-gray-300);
    border-radius: 4px;
    font-size: 13px;
    color: var(--schemafy-gray-700);
    cursor: pointer;
    transition: var(--schemafy-transition);
}

.schemafy-snippet-code-toolbar button:hover {
    background: var(--schemafy-gray-50);
    border-color: var(--schemafy-gray-600);
}

#schemafy-snippet-code-textarea {
    width: 100%;
    min-height: 400px;
    padding: 16px;
    font-family: var(--schemafy-font-mono);
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid var(--schemafy-gray-300);
    border-radius: var(--schemafy-radius-sm);
    background: #f8f9fa;
    color: #212529;
    resize: vertical;
    transition: var(--schemafy-transition);
}

#schemafy-snippet-code-textarea:focus {
    outline: none;
    border-color: var(--schemafy-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: white;
}

#schemafy-snippet-code-textarea.error {
    border-color: var(--schemafy-danger);
    background: #fff5f5;
}

/* Preview Section - Right Column Sticky */
.schemafy-snippet-preview-section {
    padding: 20px;
    background: white;
    border-radius: 12px;
    border: 2px solid var(--schemafy-gray-200);
    position: sticky;
    top: 20px;
    height: fit-content;
    max-height: calc(90vh - 260px);
    display: flex;
    flex-direction: column;
}

.schemafy-snippet-preview-section h4 {
    margin: 0 0 14px;
    font-size: 14px;
    font-weight: 700;
    color: var(--schemafy-code-border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.schemafy-snippet-preview-section h4::before {
    content: '';
    width: 4px;
    height: 16px;
    background: #0F172A;
    border-radius: 2px;
}

#schemafy-snippet-json-preview {
    padding: 16px;
    background: var(--schemafy-code-bg);
    color: #94a3b8;
    border-radius: 10px;
    font-family: var(--schemafy-font-mono);
    font-size: 12px;
    line-height: 1.7;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    flex: 1;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

#schemafy-snippet-json-preview::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#schemafy-snippet-json-preview::-webkit-scrollbar-track {
    background: #0f172a;
    border-radius: 10px;
}

#schemafy-snippet-json-preview::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 10px;
}

#schemafy-snippet-json-preview::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Action Buttons - Redesigned */
.schemafy-snippet-editor-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 2px solid var(--schemafy-gray-200);
}

#schemafy-save-snippet,
#schemafy-update-snippet {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: #0F172A;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(79, 110, 245, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#schemafy-save-snippet:hover,
#schemafy-update-snippet:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(79, 110, 245, 0.6);
    background: #4F6EF5;
}

#schemafy-save-snippet:active,
#schemafy-update-snippet:active {
    transform: translateY(0);
}

#schemafy-cancel-snippet-edit {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    background: white;
    border: 2px solid var(--schemafy-gray-200);
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: all 0.3s ease;
}

#schemafy-cancel-snippet-edit:hover {
    background: var(--schemafy-gray-50);
    border-color: #cbd5e1;
    color: #475569;
    transform: translateY(-1px);
}

/* Empty State */
.schemafy-snippet-editor-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--schemafy-gray-600);
}

.schemafy-snippet-editor-empty .dashicons {
    font-size: 64px;
    width: 64px;
    height: 64px;
    color: var(--schemafy-gray-300);
    margin-bottom: 16px;
}

.schemafy-snippet-editor-empty h4 {
    margin: 0 0 8px;
    font-size: 18px;
    color: var(--schemafy-gray-800);
}

.schemafy-snippet-editor-empty p {
    margin: 0;
    font-size: 14px;
}

/* Repeatable Fields */
.schemafy-snippet-repeatable-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.schemafy-snippet-repeatable-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.schemafy-snippet-repeatable-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 12px;
    background: white;
    border: 1px solid var(--schemafy-gray-200);
    border-radius: var(--schemafy-radius-sm);
    transition: var(--schemafy-transition);
}

.schemafy-snippet-repeatable-item:hover {
    border-color: var(--schemafy-gray-400);
    box-shadow: var(--schemafy-shadow-sm);
}

.schemafy-snippet-repeatable-item .schemafy-snippet-field {
    flex: 1;
}

.schemafy-snippet-remove-item {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--schemafy-danger);
    border-radius: var(--schemafy-radius-sm);
    color: var(--schemafy-danger);
    cursor: pointer;
    transition: var(--schemafy-transition);
}

.schemafy-snippet-remove-item:hover {
    background: var(--schemafy-danger);
    color: white;
    transform: scale(1.05);
}

.schemafy-snippet-remove-item .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

.schemafy-snippet-add-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--schemafy-gray-100);
    border: 1px dashed var(--schemafy-gray-400);
    border-radius: var(--schemafy-radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--schemafy-gray-700);
    cursor: pointer;
    transition: var(--schemafy-transition);
    width: fit-content;
}

.schemafy-snippet-add-item:hover {
    background: var(--schemafy-primary);
    border-color: var(--schemafy-primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--schemafy-shadow-sm);
}

.schemafy-snippet-add-item .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* Object Fields */
.schemafy-snippet-object-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    background: white;
    border: 1px solid var(--schemafy-gray-200);
    border-radius: var(--schemafy-radius-sm);
    margin-top: 8px;
}

.schemafy-snippet-object-group .schemafy-snippet-field-item {
    margin-left: 0;
}

/* Responsive Design - Comprehensive */

/* Tablets and smaller desktops (≤1200px) */
@media (max-width: 1200px) {
    .schemafy-snippet-content-wrapper {
        grid-template-columns: 1fr 380px;
        gap: 20px;
    }

    .schemafy-snippet-modal-content {
        max-width: 95%;
    }
}

/* Tablets (≤992px) */
@media (max-width: 992px) {
    .schemafy-snippet-content-wrapper {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .schemafy-snippet-preview-section {
        position: static;
        max-height: 400px;
    }

    .schemafy-snippet-modal-body {
        padding: 20px;
    }

    .schemafy-modal-overlay {
        padding: 10px;
    }

    .schemafy-snippet-modal-content {
        max-height: 95vh;
    }
}

/* Mobile devices (≤782px) */
@media (max-width: 782px) {
    .schemafy-snippet-editor-section {
        padding: 16px;
    }

    .schemafy-snippet-editor-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .schemafy-snippet-mode-toggle {
        width: 100%;
        flex-wrap: wrap;
    }

    .schemafy-snippet-mode-btn {
        flex: 1;
        justify-content: center;
        min-width: 140px;
    }

    #schemafy-snippet-schema-type {
        font-size: 14px;
    }

    .schemafy-snippet-editor-actions {
        flex-direction: column-reverse;
    }

    #schemafy-save-snippet,
    #schemafy-update-snippet,
    #schemafy-cancel-snippet-edit {
        width: 100%;
        justify-content: center;
    }

    .schemafy-snippet-modal-header {
        padding: 16px 20px;
    }

    .schemafy-snippet-modal-header h2 {
        font-size: 18px;
    }

    .schemafy-snippet-modal-body {
        padding: 16px;
    }

    .schemafy-snippet-fields-container {
        padding: 16px;
        max-height: none;
    }

    .schemafy-snippet-preview-section {
        max-height: 350px;
    }
}

/* Small mobile devices (≤480px) */
@media (max-width: 480px) {
    .schemafy-modal-overlay {
        padding: 0;
        align-items: flex-start;
    }

    .schemafy-snippet-modal-content {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .schemafy-snippet-modal-header {
        border-radius: 0;
    }

    .schemafy-snippet-mode-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-width: auto;
    }

    .schemafy-snippet-preview-section {
        max-height: 300px;
    }

    #schemafy-snippet-json-preview {
        font-size: 11px;
    }

    #schemafy-save-snippet,
    #schemafy-update-snippet {
        padding: 12px 24px;
        font-size: 14px;
    }

    #schemafy-cancel-snippet-edit {
        padding: 12px 24px;
        font-size: 14px;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes rotation {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.schemafy-snippet-field-item {
    animation: fadeInUp 0.3s ease-out;
}

.schemafy-snippet-field-item:nth-child(1) { animation-delay: 0.05s; }
.schemafy-snippet-field-item:nth-child(2) { animation-delay: 0.1s; }
.schemafy-snippet-field-item:nth-child(3) { animation-delay: 0.15s; }
.schemafy-snippet-field-item:nth-child(4) { animation-delay: 0.2s; }
.schemafy-snippet-field-item:nth-child(5) { animation-delay: 0.25s; }

/* Accessibility */
.schemafy-snippet-field:focus-visible {
    outline: 2px solid var(--schemafy-primary);
    outline-offset: 2px;
}

.schemafy-snippet-add-item:focus-visible,
.schemafy-snippet-remove-item:focus-visible,
#schemafy-save-snippet:focus-visible,
#schemafy-update-snippet:focus-visible {
    outline: 2px solid var(--schemafy-primary);
    outline-offset: 2px;
}
