/**
 * Email Builder Styles
 * Grandma-friendly design with clear visual hierarchy
 */

/* Hide x-cloak elements until Alpine initializes */
[x-cloak] {
    display: none !important;
}

/* Ensure x-show works properly */
[x-show] {
    transition: opacity 0.2s ease;
}

/* Main Builder Container - Fixed layout */
.email-builder {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    min-height: 600px;
}

/* Builder Content Area */
.email-builder-content {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.5rem;
    flex: 1;
    overflow: hidden;
}

/* Page Actions - Fixed at bottom */
.email-builder-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-top: 1px solid #e5e7eb;
    background: white;
    flex-shrink: 0;
}

@media (max-width: 1280px) {
    .email-builder-content {
        grid-template-columns: 200px 1fr;
    }
}

@media (max-width: 768px) {
    .email-builder-content {
        grid-template-columns: 1fr;
    }
    .email-builder .block-palette {
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        z-index: 50;
        max-height: 300px;
        overflow-y: auto;
    }
}

/* Block Palette - Sticky sidebar */
.block-palette {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    position: sticky;
    top: 0;
    height: fit-content;
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.block-palette-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    color: #111827;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.block-palette-list {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    flex: 1;
}

.block-palette-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    background: #f9fafb;
    border: 1px solid transparent;
    flex-shrink: 0;
}

.block-palette-item:hover {
    background: #6CC5A5;
    color: white;
    transform: translateX(4px);
}

.block-palette-item:hover .block-palette-icon {
    color: white;
}

.block-palette-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: #6b7280;
    flex-shrink: 0;
}

.block-palette-name {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Editor Canvas - Scrollable */
.editor-canvas {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex overflow */
}

.editor-canvas-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.editor-canvas-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: #f9fafb;
}

/* Block Wrapper */
.email-block {
    position: relative;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    border: 2px solid transparent;
    background: white;
    transition: all 0.15s ease;
}

.email-block:hover {
    border-color: #d1d5db;
}

.email-block.selected {
    border-color: #6CC5A5;
    box-shadow: 0 0 0 3px rgba(108, 197, 165, 0.2);
}

.email-block.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

/* Block Controls */
.block-controls {
    position: absolute;
    top: -12px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 10;
}

.email-block:hover .block-controls,
.email-block.selected .block-controls {
    opacity: 1;
}

.block-control-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: white;
    border: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #6b7280;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.block-control-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.block-control-btn.danger:hover {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.block-control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.block-control-btn svg {
    width: 16px;
    height: 16px;
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.15s ease;
    color: #9ca3af;
    background: linear-gradient(to right, #f3f4f6, transparent);
    border-radius: 0.5rem 0 0 0.5rem;
}

.email-block:hover .drag-handle {
    opacity: 1;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Block Content */
.block-content {
    padding: 1rem 1rem 1rem 2.5rem;
}

.block-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: #f3f4f6;
    border-radius: 9999px;
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 0.75rem;
}

.block-type-badge svg {
    width: 14px;
    height: 14px;
}

/* Block Editor Fields */
.block-field {
    margin-bottom: 1rem;
}

.block-field:last-child {
    margin-bottom: 0;
}

.block-field-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: #6b7280;
    margin-bottom: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.block-field-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.15s ease;
    background: white;
}

.block-field-input:focus {
    outline: none;
    border-color: #6CC5A5;
    box-shadow: 0 0 0 3px rgba(108, 197, 165, 0.2);
}

.block-field-input::placeholder {
    color: #9ca3af;
}

textarea.block-field-input {
    min-height: 80px;
    resize: vertical;
}

/* Variable Button */
.variable-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: #e0f2fe;
    border: 1px solid #7dd3fc;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    color: #0369a1;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-top: 0.375rem;
}

.variable-btn:hover {
    background: #bae6fd;
}

/* Variable Placeholder Styling */
.variable-placeholder {
    display: inline-block;
    background: #e0f2fe;
    border: 1px solid #7dd3fc;
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 12px;
    color: #0369a1;
    white-space: nowrap;
}

/* Add Block Button */
.add-block-btn {
    width: 100%;
    padding: 1.5rem;
    border: 2px dashed #d1d5db;
    border-radius: 0.75rem;
    background: transparent;
    color: #6b7280;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.15s ease;
}

.add-block-btn:hover {
    border-color: #6CC5A5;
    color: #6CC5A5;
    background: rgba(108, 197, 165, 0.05);
}

.add-block-btn svg {
    width: 20px;
    height: 20px;
}


/* Mode Toggle */
.mode-toggle {
    display: inline-flex;
    background: #f3f4f6;
    border-radius: 0.5rem;
    padding: 0.25rem;
}

.mode-toggle-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    color: #6b7280;
}

.mode-toggle-btn.active {
    background: white;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.mode-toggle-btn:hover:not(.active) {
    color: #111827;
}

/* Block Picker Modal */
.block-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.block-picker-modal {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.block-picker-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 1rem;
}

.block-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.block-picker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease;
    background: white;
}

.block-picker-item:hover {
    border-color: #6CC5A5;
    background: rgba(108, 197, 165, 0.05);
}

.block-picker-item svg {
    width: 24px;
    height: 24px;
    color: #6b7280;
}

.block-picker-item:hover svg {
    color: #6CC5A5;
}

.block-picker-item span {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

/* Variable Picker Modal */
.variable-picker-modal {
    background: white;
    border-radius: 0.75rem;
    padding: 1rem;
    min-width: 320px;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 10000;
    position: relative;
}

.variable-group {
    margin-bottom: 0.75rem;
}

.variable-group:last-child {
    margin-bottom: 0;
}

.variable-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.375rem;
    padding: 0 0.5rem;
}

.variable-item {
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: #374151;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid transparent;
}

.variable-item:hover {
    background: #e0f2fe;
    color: #0369a1;
    border-color: #7dd3fc;
}

.variable-item span:first-child {
    font-weight: 500;
}

.variable-item button {
    width: 100%;
    text-align: left;
}

/* HTML Editor */
.html-editor {
    width: 100%;
    min-height: 400px;
    height: 100%;
    padding: 1rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    background: #1e1e1e;
    color: #d4d4d4;
    border: none;
    border-radius: 0.5rem;
    resize: none;
}

.html-editor:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(108, 197, 165, 0.3);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: #6b7280;
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    color: #d1d5db;
}

.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: #e5e7eb;
    border-radius: 12px;
    transition: all 0.15s ease;
    position: relative;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.toggle-switch input:checked + .toggle-slider {
    background: #6CC5A5;
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

/* Color Input */
.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input {
    width: 40px;
    height: 40px;
    padding: 2px;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    cursor: pointer;
    background: white;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: 0.375rem;
}

/* Select Input */
.block-field-select {
    width: 100%;
    padding: 0.625rem 2rem 0.625rem 0.875rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") no-repeat right 0.75rem center;
    background-size: 1rem;
    appearance: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.block-field-select:focus {
    outline: none;
    border-color: #6CC5A5;
    box-shadow: 0 0 0 3px rgba(108, 197, 165, 0.2);
}

/* Saved Indicator */
.save-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.save-indicator.saved {
    color: #059669;
}

.save-indicator svg {
    width: 14px;
    height: 14px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.email-block {
    animation: slideIn 0.2s ease;
}

.block-picker-overlay {
    animation: fadeIn 0.15s ease;
}

.block-picker-modal {
    animation: slideIn 0.2s ease;
}
