/* =========================================
   1. VARIABLES GLOBALES & RESET
   ========================================= */
:root {
    --primary: #FF6B6B;       /* Coral Vibrante */
    --primary-dark: #EE5253;  /* Coral Oscuro (Hover) */
    --primary-light: #FFECEC; /* Fondo suave */
    --secondary: #2D3436;     /* Texto Principal */
    --bg-app: #F8F9FA;
    --shadow-soft: 0 10px 30px rgba(0,0,0,0.05);
    --shadow-card: 0 20px 60px rgba(0,0,0,0.12);
    --radius-md: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--secondary);
    min-height: 100vh;
    line-height: 1.6;
}

/* =========================================
   2. LAYOUT PRINCIPAL
   ========================================= */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
@media (min-width: 900px) {
    .app-container {
        flex-direction: row;
        height: 100vh;
        overflow: hidden;
    }
}

/* =========================================
   3. EDITOR
   ========================================= */
.editor-panel {
    flex: 1; background: #ffffff; padding: 25px; overflow-y: auto;
    z-index: 10; box-shadow: 5px 0 20px rgba(0,0,0,0.03); border-right: 1px solid rgba(0,0,0,0.05);
}
@media (min-width: 900px) { .editor-panel { max-width: 480px; padding: 40px; } }

.header { margin-bottom: 30px; text-align: center; }
.header h2 { font-family: 'Playfair Display', serif; font-size: 2rem; color: var(--secondary); margin-bottom: 5px; }
.back-link { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: #999; font-size: 0.9rem; margin-bottom: 10px; transition: color 0.3s; }
.back-link:hover { color: var(--primary); }

/* ACORDEÓN */
.accordion-item { border: 1px solid #eee; border-radius: var(--radius-md); margin-bottom: 15px; overflow: hidden; background: #fff; transition: box-shadow 0.3s; }
.accordion-item:hover { box-shadow: 0 5px 15px rgba(0,0,0,0.03); }
.accordion-header { background: #fafafa; padding: 15px 20px; cursor: pointer; font-weight: 600; font-size: 0.95rem; color: #555; display: flex; justify-content: space-between; align-items: center; transition: background 0.3s, color 0.3s; }
.accordion-header:hover { background: #f0f0f0; }
.accordion-header.active { background: var(--primary); color: white; }
.accordion-content { max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out; padding: 0 20px; background: white; }
.accordion-content.open { padding: 25px 20px; border-top: 1px solid #eee; }

/* INPUTS */
.form-group { margin-bottom: 20px; }
label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: #555; }
input[type="text"], input[type="tel"], input[type="date"], input[type="email"], input[type="url"], textarea, select {
    width: 100%; padding: 14px 16px; border: 2px solid #f0f0f0; border-radius: var(--radius-md); font-family: 'Inter', sans-serif; font-size: 0.95rem; background: #fff; transition: all 0.3s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.1); }
textarea { resize: vertical; min-height: 120px; }

/* INPUT FOTO */
.file-input-wrapper { position: relative; overflow: hidden; display: block; width: 100%; }
.btn-upload { border: 2px dashed #ccc; background: #fafafa; padding: 20px; text-align: center; border-radius: var(--radius-md); cursor: pointer; color: #777; font-weight: 600; transition: 0.3s; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.btn-upload i { font-size: 1.5rem; }
.btn-upload:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-upload.has-file { border-style: solid; border-color: #27ae60; color: #27ae60; background: #eafaf1; }
input[type=file] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* SELECTORES VISUALES */
.font-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.font-btn { padding: 12px; border: 1px solid #eee; background: #fafafa; border-radius: 8px; cursor: pointer; text-align: center; transition: all 0.2s; font-size: 0.9rem; }
.font-btn:hover { background: #fff; transform: translateY(-2px); border-color: #ddd; }
.font-btn.active { background-color: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }

.palette-grid { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.color-option { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid rgba(0,0,0,0.05); transition: transform 0.2s; position: relative; }
.color-option:hover { transform: scale(1.15); z-index: 2; }
.color-option.active { transform: scale(1.2); border: 2px solid #333; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 2; }
.color-custom-wrapper { position: relative; width: 34px; height: 34px; border-radius: 50%; overflow: hidden; cursor: pointer; background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); border: 2px solid rgba(0,0,0,0.1); }
.color-custom-input { position: absolute; top: -5px; left: -5px; width: 150%; height: 150%; opacity: 0; cursor: pointer; }

/* --- NUEVO: GRID PARA TEXTURAS DE FONDO --- */
.texture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 10px; margin-top: 10px; }
.texture-option { height: 60px; border-radius: 8px; background-size: cover; background-position: center; cursor: pointer; border: 2px solid #eee; transition: all 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.texture-option:hover { transform: scale(1.05); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.texture-option.active { border: 3px solid var(--primary); transform: scale(1.1); box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3); z-index: 2; }
.texture-option.remove-bg { background-color: #f1f2f6; display: flex; justify-content: center; align-items: center; color: #999; font-size: 1.2rem; }
.texture-option.remove-bg:hover { color: #ff4757; background-color: #ffe0e3; border-color: #ff4757; }

/* BOTONES DE ACCIÓN */
.actions-group { display: flex; gap: 10px; margin-bottom: 15px; }
.btn-ia { background: linear-gradient(135deg, var(--primary), #FF8E53); color: white; border: none; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: transform 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; flex: 1; font-size: 0.9rem; }
.btn-ia:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3); }
.btn-preview { width: 100%; padding: 16px; margin-top: 20px; margin-bottom: 10px; background: #333; color: white; border: none; border-radius: var(--radius-md); font-size: 1rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: background 0.3s; }
.btn-preview:hover { background: #000; }
.btn-whatsapp { width: 100%; padding: 16px; background-color: #25D366; color: white; border: none; border-radius: var(--radius-md); font-size: 1rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: background 0.3s; }
.btn-whatsapp:hover { background-color: #1EB856; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(37, 211, 102, 0.4); }

/* PREVIEW */
.preview-panel { flex: 1.5; background-color: #eef2f5; background-image: radial-gradient(#d1d5db 1px, transparent 1px); background-size: 24px 24px; display: flex; justify-content: center; align-items: center; padding: 40px 20px; }
.live-card { 
    width: 100%; max-width: 500px; min-height: 600px; 
    background-color: #fff; /* Default */
    background-size: cover; background-position: center; background-repeat: no-repeat;
    padding: 60px 50px; border-radius: 4px; box-shadow: var(--shadow-card); transition: all 0.4s; display: flex; flex-direction: column; position: relative; word-wrap: break-word; 
}
.card-date { text-align: right; margin-bottom: 40px; opacity: 0.8; font-size: 0.95rem; font-weight: 500; }
.card-body { flex: 1; font-size: 1.5rem; line-height: 1.6; white-space: pre-wrap; }
.btn-view-photo { display: none; margin: 20px auto 0; padding: 8px 16px; background: rgba(0,0,0,0.05); color: #555; border: 1px solid #ddd; border-radius: 20px; cursor: pointer; font-size: 0.85rem; align-items: center; gap: 6px; transition: 0.2s; }
.btn-view-photo:hover { background: rgba(0,0,0,0.1); color: #000; }
.btn-view-photo.visible { display: inline-flex; }
.card-footer { margin-top: 50px; text-align: right; font-size: 1.2rem; }

/* MODAL */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 2000; display: none; justify-content: center; align-items: center; backdrop-filter: blur(5px); }
.modal-close { position: absolute; top: 20px; right: 20px; background: white; border: none; width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem; cursor: pointer; z-index: 2010; }
.modal-envelope { width: 300px; height: 200px; background: #FFD1D1; position: relative; display: flex; justify-content: center; align-items: center; border-radius: 0 0 10px 10px; cursor: pointer; transition: transform 0.5s ease-in-out; }
.modal-envelope.opened { transform: translateY(100vh); opacity: 0; pointer-events: none; }
.modal-flap { position: absolute; top: 0; left: 0; width: 0; height: 0; border-left: 150px solid transparent; border-right: 150px solid transparent; border-top: 110px solid #ffbaba; z-index: 2; }
.modal-heart { position: absolute; top: 40px; z-index: 5; font-size: 2rem; animation: pulse 1.5s infinite; }
.modal-card-container { position: absolute; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; background: white; padding: 40px; border-radius: 12px; transform: translateY(50px) scale(0.8); opacity: 0; transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1); }
.modal-card-container.visible { transform: translateY(0) scale(1); opacity: 1; }

.photo-viewer { display: none; margin-top: 30px; text-align: center; perspective: 1000px; }
.photo-viewer img { max-width: 85%; max-height: 300px; border: 12px solid #fff; border-bottom-width: 25px; box-shadow: 0 5px 10px rgba(0,0,0,0.1), 0 15px 30px rgba(0,0,0,0.2); transform: rotate(-3deg) scale(1.02); background-color: white; transition: all 0.4s ease; }
.photo-viewer img:hover { transform: rotate(0deg) scale(1.1); box-shadow: 0 20px 40px rgba(0,0,0,0.3); z-index: 10; }

@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
.loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.95); z-index: 3000; display: none; flex-direction: column; justify-content: center; align-items: center; }
@media (max-width: 899px) {
    .editor-panel { order: 2; border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,0.1); }
    .preview-panel { order: 1; min-height: 450px; padding: 30px 15px; }
    .live-card { min-height: 400px; padding: 30px 20px; font-size: 0.9em; }
    .btn-preview { position: fixed; bottom: 20px; right: 20px; width: auto; z-index: 100; box-shadow: 0 5px 20px rgba(0,0,0,0.3); border-radius: 30px; padding: 12px 25px; }
    .actions-group { display: grid; grid-template-columns: 1fr 1fr; }
}