﻿:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-bg: rgba(99,102,241,0.08);
    --bg: #0f1117;
    --bg2: #1a1b26;
    --sidebar: #16171f;
    --canvas-bg: #808080;
    --text: #e2e8f0;
    --text2: #94a3b8;
    --border: rgba(255,255,255,0.08);
    --border2: rgba(255,255,255,0.14);
    --r: 8px;
    --rl: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
.app-container { display: flex; height: 100vh; width: 100vw; }

/* SIDEBAR */
.sidebar { width: 270px; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 20; }
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo svg { color: var(--primary); }
.logo h2 { font-size: 1.1rem; font-weight: 700; background: linear-gradient(135deg, var(--primary-light), var(--primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.subtitle { font-size: 0.78rem; color: var(--text2); margin-top: 6px; }

.elements-grid { padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; overflow-y: auto; flex: 1; align-content: start; }
.draggable-item { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: grab; transition: all 0.22s cubic-bezier(.4,0,.2,1); user-select: none; }
.draggable-item:hover { border-color: var(--primary); background: var(--primary-bg); transform: translateY(-3px); box-shadow: 0 4px 16px rgba(99,102,241,.2); }
.draggable-item:active { cursor: grabbing; transform: scale(0.96); }
.draggable-item[data-type="section"], .draggable-item[data-type="columns"] { grid-column: span 2; flex-direction: row; padding: 10px 14px; justify-content: center; background: rgba(99,102,241,0.05); }
.item-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.section-icon { background: rgba(99,102,241,.15); color: #818cf8; }
.col-icon { background: rgba(236,72,153,.15); color: #f472b6; }
.heading-icon { background: rgba(251,146,60,.15); color: #fb923c; }
.text-icon { background: rgba(96,165,250,.15); color: #60a5fa; }
.image-icon { background: rgba(52,211,153,.15); color: #34d399; }
.spacer-icon { background: rgba(167,139,250,.15); color: #a78bfa; }
.divider-icon { background: rgba(251,113,133,.15); color: #fb7185; }
.list-icon { background: rgba(45,212,191,.15); color: #2dd4bf; }
.draggable-item span { font-size: 0.68rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; }
.primary-btn, .secondary-btn { width: 100%; padding: 10px 14px; border-radius: var(--r); font-size: 0.83rem; font-weight: 600; cursor: pointer; transition: all .2s; border: none; display: flex; align-items: center; justify-content: center; gap: 7px; font-family: 'Inter', sans-serif; }
.primary-btn { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; box-shadow: 0 2px 12px rgba(99,102,241,.35); }
.primary-btn:hover { box-shadow: 0 4px 20px rgba(99,102,241,.5); transform: translateY(-1px); }
.secondary-btn { background: rgba(255,255,255,.05); color: var(--text2); border: 1px solid var(--border); }
.secondary-btn:hover { background: rgba(255,255,255,.09); color: var(--text); }

/* WORKSPACE */
.workspace { position: relative; flex: 1; overflow: auto; background: var(--bg); display: flex; justify-content: center; padding: 40px; background-image: radial-gradient(circle at 20% 80%, rgba(99,102,241,.05) 0%, transparent 50%), radial-gradient(circle at 80% 20%, rgba(167,139,250,.05) 0%, transparent 50%); }

/* FIXED LINES */
.canvas-wrapper { width: 210mm; min-height: 297mm; box-shadow: 0 12px 48px rgba(0,0,0,.6); transition: width 0.3s, min-height 0.3s; background: #fff; display: flex; flex-direction: column; }
.a4-canvas { width: 100%; flex: 1; background: transparent; position: relative; display: flex; flex-direction: column; }

.empty-state { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); text-align: center; color: #94a3b8; pointer-events: none; z-index: 5; }
.empty-state svg { margin-bottom: 14px; opacity: .45; display: block; margin-left: auto; margin-right: auto; }
.empty-state h3 { font-size: 1rem; font-weight: 600; margin-bottom: 5px; color: #64748b; }
.empty-state p { font-size: 0.82rem; color: #94a3b8; }

/* CANVAS ITEMS & DROPZONES */
.canvas-dropzone { min-height: 40px; transition: background 0.2s; position: relative; }
.canvas-dropzone.dragover { background: rgba(99,102,241,0.05); outline: 2px dashed var(--primary); outline-offset: -2px; }
.main-dropzone.dragover { background: rgba(248,250,252,0.8); }

.canvas-item { position: relative; border: 2px dashed transparent; transition: all .18s; cursor: default; }
/* Elementos basicos tienen padding, bloques estructurales no para permitir ful width */
.canvas-item:not([data-type="section"]):not([data-type="columns"]) { padding: 4px; margin-bottom: 4px; border-radius: 4px; }
.canvas-item:not([data-type="section"]):not([data-type="columns"]):hover { border-color: #e2e8f0; }

.canvas-item.active { border-color: var(--primary) !important; box-shadow: 0 0 0 1px var(--primary) inset; z-index: 10; }
.canvas-item[data-type="section"].active, .canvas-item[data-type="columns"].active { box-shadow: 0 0 0 2px var(--primary) inset; border-style: solid; }

.item-controls { position: absolute; top: 0; right: 0; display: none; gap: 1px; background: #fff; border: 1px solid #e2e8f0; border-bottom-left-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.12); z-index: 100; overflow: hidden; padding: 2px; }
.item-badge { background: #f1f5f9; color: #64748b; font-size: 10px; font-weight: bold; padding: 4px 8px; text-transform: uppercase; display: flex; align-items: center; border-right: 1px solid #e2e8f0; }
.canvas-item.active > .item-controls { display: flex; }
/* Secciones y columnas: mostrar controles en hover sin necesidad de seleccionarlas */
.canvas-item[data-type="section"]:hover > .item-controls,
.canvas-item[data-type="columns"]:hover > .item-controls { display: flex; }
/* Drag handle para reordenar */
.drag-handle { cursor: grab; color: #94a3b8; padding: 4px 6px; display: flex; align-items: center; font-size: 14px; border-right: 1px solid #e2e8f0; }
.drag-handle:hover { color: #6366f1; background: #f1f5f9; }
.drag-handle:active { cursor: grabbing; }
/* Drop indicator */
.canvas-item.drop-above { border-top: 3px solid #6366f1 !important; }
.canvas-item.drop-below { border-bottom: 3px solid #6366f1 !important; }
.control-btn { background: none; border: none; padding: 4px 8px; cursor: pointer; color: #94a3b8; font-size: 13px; transition: all .15s; line-height: 1; border-radius: 2px; }
.control-btn:hover { color: #111827; background: #f1f5f9; }
.control-btn.del-btn:hover { color: #ef4444; background: #fef2f2; }
.control-btn.ai-edit-btn { color: #a78bfa; }
.control-btn.ai-edit-btn:hover { color: #7c3aed; background: rgba(124,58,237,.1); }

/* RICH TEXT TOOLBAR */
.rich-text-toolbar { position: absolute; top: 0; left: 0; background: var(--bg2); border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0,0,0,0.5); border-radius: var(--r); padding: 5px; display: none; align-items: center; gap: 2px; z-index: 50; flex-wrap: wrap; max-width: calc(100% - 20px); }
.rich-text-toolbar.show { display: flex; }
.rt-btn { background: transparent; border: none; color: var(--text); padding: 6px 10px; font-size: 14px; border-radius: 4px; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; font-family: 'Inter', sans-serif; }
.rt-btn:hover { background: rgba(255,255,255,0.1); color: var(--primary-light); }
.rt-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.rt-select { background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12); color: var(--text); border-radius: 4px; padding: 4px 6px; font-size: 0.78rem; cursor: pointer; outline: none; max-width: 105px; }
.rt-select:hover { background: rgba(255,255,255,0.12); }
.rt-color-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 5px 8px; border-radius: 4px; cursor: pointer; color: var(--text); transition: background 0.2s; gap: 1px; }
.rt-color-btn:hover { background: rgba(255,255,255,0.1); }
.hubspot-module { position: relative; }
.hubspot-btn { gap: 6px; font-weight: 500; font-size: 13px; background: rgba(99,102,241,0.1); color: var(--primary-light); }
.hubspot-btn:hover { background: rgba(99,102,241,0.2); }
.hubspot-dropdown { position: absolute; top: 110%; left: 0; width: 220px; background: var(--sidebar); border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 10px 40px rgba(0,0,0,0.6); display: none; flex-direction: column; overflow-y: auto; max-height: 250px; z-index: 51; }
.hubspot-dropdown.show { display: flex; }
.hs-category { padding: 8px 12px; font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; background: rgba(0,0,0,0.2); border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); margin-top: -1px; }
.hs-option { padding: 8px 16px; font-size: 13px; color: var(--text); cursor: pointer; transition: background 0.15s; }
.hs-option:hover { background: rgba(99,102,241,0.15); color: var(--primary-light); }

/* PROPERTIES PANEL */
.properties-panel { width: 300px; background: var(--sidebar); border-left: 1px solid var(--border); display: none; flex-direction: column; overflow-y: auto; z-index: 20; }
.properties-panel.show { display: flex; }
.panel-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.panel-header h3 { font-size: .9rem; font-weight: 600; color: #fff; }
.icon-btn { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 1.3rem; padding: 3px 6px; line-height: 1; transition: color .15s; }
.icon-btn:hover { color: var(--text); }
.panel-content { padding: 18px; }
.muted-text { color: var(--text2); font-size: .82rem; }

.prop-group { margin-bottom: 16px; }
.prop-group label { display: block; margin-bottom: 5px; font-size: .72rem; color: var(--text2); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.prop-group input, .prop-group textarea, .prop-group select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r); background: rgba(255,255,255,.05); color: var(--text); font-family: 'Inter', sans-serif; font-size: .83rem; transition: border-color .2s; }
.prop-group input:focus, .prop-group select:focus, .prop-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.prop-group input[type="color"] { height: 36px; padding: 3px; cursor: pointer; }
.prop-group select option { background: #1a1b26; color: #e2e8f0; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(6px); display: none; justify-content: center; align-items: center; z-index: 100; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg2); border-radius: var(--rl); width: 90%; max-width: 800px; border: 1px solid var(--border); box-shadow: 0 24px 64px rgba(0,0,0,.6); display: flex; flex-direction: column; animation: modal-in .22s ease; }
@keyframes modal-in { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 22px; }
.modal-body textarea { width: 100%; height: 340px; font-family: 'Courier New', monospace; font-size: .78rem; padding: 14px; border: 1px solid var(--border); border-radius: var(--r); background: rgba(0,0,0,.3); color: #a5f3fc; resize: none; line-height: 1.5; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* HTML Module empty state */
.html-placeholder { background: #f1f5f9; border: 1px dashed #cbd5e1; padding: 15px; text-align: center; color: #64748b; font-size: 12px; font-family: monospace; border-radius: 4px; pointer-events: none; }
/* EDITOR TOP NAV */
body { display: flex; flex-direction: column; height: 100vh; }
.editor-top-nav { height: 60px; background: var(--sidebar); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; z-index: 50; flex-shrink: 0;}
.nav-left, .nav-right { display: flex; align-items: center; gap: 15px; }
.back-btn { display: flex; align-items: center; gap: 6px; color: var(--text2); text-decoration: none; font-size: 0.85rem; font-weight: 500; padding: 6px 10px; border-radius: 6px; transition: background 0.2s; }
.back-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-divider { width: 1px; height: 24px; background: var(--border); }
.template-name-input { background: transparent; border: 1px solid transparent; color: #fff; font-size: 1.1rem; font-weight: 600; font-family: 'Inter', sans-serif; padding: 4px 8px; border-radius: 4px; transition: border-color 0.2s; width: 300px; }
.template-name-input:hover { border-color: var(--border); }
.template-name-input:focus { outline: none; border-color: var(--primary); background: rgba(0,0,0,0.2); }
.save-status { font-size: 0.8rem; color: #34d399; opacity: 0; transition: opacity 0.3s; }
.save-status.show { opacity: 1; }

.app-container { height: calc(100vh - 60px); }

/* AI CHAT WIDGET */
.ai-chat-widget { position: fixed; bottom: 30px; right: 30px; z-index: 1000; font-family: 'Inter', sans-serif; display: flex; flex-direction: column; align-items: flex-end; }
.ai-chat-toggle { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(99,102,241,0.5); transition: transform 0.2s; }
.ai-chat-toggle:hover { transform: scale(1.05); }
.ai-chat-panel { width: 340px; height: 450px; background: var(--sidebar); border: 1px solid var(--border); border-radius: var(--rl); box-shadow: 0 12px 40px rgba(0,0,0,0.6); display: none; flex-direction: column; margin-bottom: 15px; overflow: hidden; transform-origin: bottom right; animation: pop-up 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes pop-up { from { opacity: 0; transform: scale(0.9) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.ai-chat-panel.show { display: flex; }
.ai-chat-header { padding: 15px 20px; background: rgba(0,0,0,0.2); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.ai-chat-header h3 { font-size: 0.95rem; font-weight: 600; color: #fff; display: flex; align-items: center; gap: 8px; }
.ai-chat-header h3::before { content: ''; display: block; width: 8px; height: 8px; background: #34d399; border-radius: 50%; box-shadow: 0 0 8px #34d399; }
.ai-chat-body { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: var(--r); font-size: 0.82rem; line-height: 1.4; }
.ai-msg { background: rgba(99,102,241,0.15); color: var(--text); align-self: flex-start; border-bottom-left-radius: 2px; }
.user-msg { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
.ai-chat-input-area { padding: 12px 15px; border-top: 1px solid var(--border); display: flex; gap: 8px; background: var(--bg2); }
.ai-chat-input-area input { flex: 1; background: rgba(0,0,0,0.3); border: 1px solid var(--border); color: #fff; border-radius: var(--r); padding: 0 12px; font-size: 0.85rem; outline: none; transition: border-color 0.2s; }
.ai-chat-input-area input:focus { border-color: var(--primary); }
.typing-indicator { font-size: 0.8rem; color: var(--text2); font-style: italic; align-self: flex-start; display: none; margin-left: 5px; }
.typing-indicator.show { display: block; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
