/* ============================================
   TEMPLATES CSS - Landing Page Builder
   ============================================ */

/* Templates Grid */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

/* Template Card */
.template-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.template-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

.template-color-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.template-color-badge.purple { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.template-color-badge.blue { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.template-color-badge.green { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); }
.template-color-badge.orange { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); }
.template-color-badge.dark { background: linear-gradient(135deg, #334155 0%, #1e293b 100%); }

.template-card-title {
    flex: 1;
}

.template-card-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.template-card-title .template-slug {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

.template-default-badge {
    font-size: 10px;
    padding: 3px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
}

.template-card-body {
    padding: 16px 20px;
}

.template-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.template-meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.template-meta-item span:first-child {
    font-size: 14px;
}

.template-card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-body);
}

.template-status {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.template-status.active {
    background: #dcfce7;
    color: #166534;
}

.template-status.draft {
    background: #fef3c7;
    color: #92400e;
}

.template-status.inactive {
    background: #fee2e2;
    color: #991b1b;
}

.template-actions {
    display: flex;
    gap: 8px;
}

.template-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.template-action-btn:hover {
    background: var(--bg-card);
}

.template-action-btn.edit:hover { color: #2563eb; }
.template-action-btn.settings:hover { color: #64748b; }
.template-action-btn.duplicate:hover { color: #7c3aed; }
.template-action-btn.preview:hover { color: #059669; }
.template-action-btn.delete:hover { color: #dc2626; }

/* Empty state */
.templates-grid .empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
}

.templates-grid .empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.templates-grid .empty-state h3 {
    font-size: 18px;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.templates-grid .empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

/* ============================================
   ADD/EDIT TEMPLATE MODAL
   ============================================ */

.template-modal-content {
    max-width: 600px;
}

.template-modal-content .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.color-presets {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.color-preset {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.color-preset:hover {
    transform: scale(1.1);
}

.color-preset.selected {
    border-color: var(--text-primary);
}

.color-preset.purple { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.color-preset.blue { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.color-preset.green { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); }
.color-preset.orange { background: linear-gradient(135deg, #f97316 0%, #ea580c 100%); }
.color-preset.dark { background: linear-gradient(135deg, #334155 0%, #1e293b 100%); }

/* ============================================
   TEMPLATE EDITOR (3-column layout)
   ============================================ */

.template-editor {
    display: grid;
    grid-template-columns: 250px 1fr 400px;
    gap: 20px;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.template-editor-sections {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    padding: 16px;
    overflow-y: auto;
}

.template-editor-sections h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-body);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: grab;
    transition: background 0.2s;
}

.section-item:hover {
    background: #e2e8f0;
}

.section-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.section-item .drag-handle {
    font-size: 12px;
    color: var(--text-muted);
}

.section-item.active .drag-handle {
    color: rgba(255, 255, 255, 0.7);
}

.section-item .section-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.section-item .section-toggle {
    width: 18px;
    height: 18px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
}

.template-editor-form {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    padding: 20px;
    overflow-y: auto;
}

.template-editor-preview {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-toolbar {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-body);
}

.preview-device-toggle {
    display: flex;
    gap: 4px;
}

.preview-device-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.preview-device-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.preview-iframe-container {
    flex: 1;
    padding: 20px;
    display: flex;
    justify-content: center;
    background: #e2e8f0;
}

.preview-iframe-container iframe {
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    background: white;
    transition: width 0.3s;
}

.preview-iframe-container.desktop iframe {
    width: 100%;
    height: 100%;
}

.preview-iframe-container.mobile iframe {
    width: 375px;
    height: 100%;
    max-height: 667px;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1200px) {
    .template-editor {
        grid-template-columns: 200px 1fr;
    }

    .template-editor-preview {
        display: none;
    }
}

@media (max-width: 768px) {
    .templates-grid {
        grid-template-columns: 1fr;
    }

    .template-editor {
        grid-template-columns: 1fr;
    }

    .template-editor-sections {
        max-height: 200px;
    }
}
