/* ═══════════════════════════════════════════════════════════
   Editor Visual HTML — Design System Compacto
   ═══════════════════════════════════════════════════════════ */

/* ── Variáveis: tema claro (padrão) ── */
:root {
    --primary: #5698D6;
    --primary-hover: #4080C0;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #2ecc71;

    --bg: #F0F0F4;
    --panel-bg: #FAFAFA;
    --panel-header: #EBEBF0;
    --border: #D4D4DE;
    --text: #1A1A2E;
    --text-secondary: #6A6A8A;
    --input-bg: #FFFFFF;
    --btn-bg: #E2E2EC;
    --btn-hover: #D4D4E2;
    --selected: #D0E4F8;

    --tree-hover: rgba(86, 152, 214, 0.12);
    --tree-active: rgba(86, 152, 214, 0.22);

    --left-panel-width: 260px;
    --right-panel-width: 280px;
    --header-h: 36px;
    --panel-header-h: 30px;
    --btn-h: 24px;
}

/* ── Variáveis: tema escuro ── */
.dark-theme {
    --bg: #18181A;
    --panel-bg: #1C1C20;
    --panel-header: #26262A;
    --border: #303034;
    --text: #DCDCDC;
    --text-secondary: #B4B4B4;
    --input-bg: #22222A;
    --btn-bg: #3A3A42;
    --btn-hover: #44444C;
    --selected: #2D5A8C;
}

/* ── Reset ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    height: 100vh;
}

/* ════════════════════════════════════════════════════════════
   Layout Principal
   ════════════════════════════════════════════════════════════ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Header ── */
header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    font-size: 13px;
}

.logo i {
    color: var(--primary);
    font-size: 14px;
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ── Main ── */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ════════════════════════════════════════════════════════════
   Painéis
   ════════════════════════════════════════════════════════════ */

.panel {
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border-right: 1px solid var(--border);
    overflow: hidden;
    min-height: 0;
}

.panel-header {
    height: var(--panel-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

.panel-actions {
    display: flex;
    gap: 3px;
}

.panel-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* ── Painel Esquerdo ── */
.left-panel {
    width: var(--left-panel-width);
    flex-shrink: 0;
}

.code-section {
    height: 55%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Linha de URL base (abaixo do header do painel HTML) */
.base-url-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.base-url-row > i {
    font-size: 9px;
    color: var(--text-secondary);
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}
.base-url-row input {
    flex: 1;
    min-width: 0;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-size: 10px;
    padding: 2px 5px;
    height: 20px;
    outline: none;
    font-family: 'Consolas', monospace;
}
.base-url-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}
.base-url-row input::placeholder {
    color: var(--text-secondary);
    opacity: 0.55;
    font-style: italic;
}

.dom-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Painel Código do Elemento — herda visual do prop-section ── */
.element-code-actions {
    padding: 4px 6px;
    border-top: 1px solid var(--border);
    background: var(--panel-header);
    flex-shrink: 0;
    display: none; /* aparece só quando há alteração não aplicada */
}
.element-code-actions .btn {
    flex: 1;
    height: 24px;
    font-size: 11px;
}

/* element-code-section agora é <details> — herda .prop-section sem height fixo */
details.element-code-section {
    flex-shrink: 0;
}

details.element-code-section .element-code-panel-content {
    height: 160px;
}

/* ── Modo janela flutuante ────────────────────────────────────────────────── */
#elementCodeSection.element-code-floating {
    position: fixed;
    z-index: 1100;
    width: 380px;
    min-width: 220px;
    min-height: 220px;
    background: var(--panel-bg);
    border: 1px solid var(--primary);
    border-radius: 10px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.55);
    display: flex !important;
    flex-direction: column;
    overflow: visible;
    flex-shrink: unset;
    /* impede que o details herde height do pai */
    height: auto;
}
#elementCodeSection.element-code-floating > summary {
    cursor: grab;
    border-radius: 10px 10px 0 0;
    user-select: none;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
}
#elementCodeSection.element-code-floating > summary:active {
    cursor: grabbing;
}
#elementCodeSection.element-code-floating .element-code-panel-content {
    flex: 1;
    height: auto;
    min-height: 80px;
}
#elementCodeSection.element-code-floating .element-code-editor {
    height: 100%;
    resize: none;
}
/* handle de resize — visível só no modo flutuante */
.element-code-resize-handle {
    display: none;
    position: absolute;
    width: 18px;
    height: 18px;
    bottom: 0;
    right: 0;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, var(--border) 50%, var(--primary) 100%);
    border-radius: 0 0 10px 0;
    z-index: 2;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.element-code-resize-handle:hover { opacity: 1; }
#elementCodeSection.element-code-floating .element-code-resize-handle {
    display: block;
}
/* botão de destacar — ícone muda quando flutuante */
#elementCodeSection.element-code-floating #detachElementCodeBtn i {
    transform: scaleX(-1);
}
/* element-code-header-btns sempre visível quando flutuante */
#elementCodeSection.element-code-floating .element-code-header-btns {
    opacity: 1;
}

/* Botões de copiar/exportar no summary — aparecem no hover ou quando aberto */
.element-code-header-btns {
    display: flex;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s;
}
details.element-code-section > summary:hover .element-code-header-btns,
details.element-code-section[open] .element-code-header-btns {
    opacity: 1;
}

.element-code-tabs {
    display: flex;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.code-tab {
    flex: 1;
    height: 24px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 1px solid var(--border);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    font-family: inherit;
}
.code-tab:last-child { border-right: none; }
.code-tab:hover { background: var(--btn-hover); color: var(--text); }
.code-tab.active { background: var(--primary); color: white; }

.element-code-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.element-code-editor {
    flex: 1;
    width: 100%;
    padding: 6px 8px;
    background: var(--input-bg);
    color: var(--text);
    border: none;
    resize: none;
    font-family: 'Consolas', 'Fira Code', 'Monaco', monospace;
    font-size: 10.5px;
    line-height: 1.45;
    outline: none;
    tab-size: 2;
}
.element-code-editor:focus {
    box-shadow: inset 2px 0 0 var(--primary);
}


.code-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
}

.dom-panel-content {
    padding: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

#htmlInput {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 6px 8px;
    background: var(--input-bg);
    color: var(--text);
    border: none;
    border-radius: 0;
    resize: none;
    font-family: 'Consolas', 'Fira Code', 'Monaco', monospace;
    font-size: 11.5px;
    line-height: 1.5;
    tab-size: 2;
    outline: none;
}

#htmlInput:focus {
    box-shadow: inset 2px 0 0 var(--primary);
}

/* ── Painel Central ── */
.center-panel {
    flex: 1;
    min-width: 0;
}

.preview-panel-content {
    display: flex;
    flex: 1;
    min-height: 0;
    background: var(--bg);
    overflow: auto;
    position: relative;
}

/* Desktop: full width */
.preview-panel-content.desktop {
    padding: 0;
}

.preview-panel-content.desktop .device-frame {
    flex: 1;
    min-height: 0;
    min-width: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: white;
}

.preview-panel-content.desktop .device-top,
.preview-panel-content.desktop .device-bottom {
    display: none;
}

.preview-panel-content.desktop .device-screen {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Tablet: 768px frame */
.preview-panel-content.tablet {
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.preview-panel-content.tablet .device-frame {
    width: 768px;
    height: 900px;
    flex-shrink: 0;
    background: #232330;
    border: 8px solid #232330;
    border-radius: 18px;
    box-shadow:
        inset 0 0 0 1px #3A3A48,
        0 24px 70px rgba(0,0,0,0.5);
    overflow: hidden;
}

.preview-panel-content.tablet .device-top {
    height: 20px;
    background: #232330;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-panel-content.tablet .device-top::after {
    content: '';
    width: 48px;
    height: 6px;
    background: #3A3A4A;
    border-radius: 3px;
}

.preview-panel-content.tablet .device-bottom {
    height: 16px;
    background: #232330;
    flex-shrink: 0;
}

.preview-panel-content.tablet .device-screen {
    flex: 1;
    background: white;
    overflow: auto;
    min-height: 0;
}

/* Mobile: phone frame real */
.preview-panel-content.mobile {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.preview-panel-content.mobile .device-frame {
    width: 375px;
    height: 812px;
    flex-shrink: 0;
    background: #1A1A2E;
    border-radius: 50px;
    overflow: hidden;
    box-shadow:
        inset 0 0 0 1px #444,
        0 0 0 2px #1A1A2E,
        0 0 0 4px #333,
        0 40px 100px rgba(0,0,0,0.7),
        0 0 0 6px rgba(255,255,255,0.04);
    position: relative;
}

/* Notch / Dynamic Island */
.preview-panel-content.mobile .device-top {
    height: 44px;
    background: #1A1A2E;
    border-radius: 50px 50px 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.preview-panel-content.mobile .device-top::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 126px;
    height: 30px;
    background: #1A1A2E;
    border-radius: 0 0 22px 22px;
    border: 1px solid #2A2A3E;
    border-top: none;
}

/* Camera dot */
.preview-panel-content.mobile .device-top::before {
    content: '';
    position: absolute;
    top: 18px;
    left: calc(50% + 48px);
    width: 10px;
    height: 10px;
    background: #2A2A3E;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px #333;
    z-index: 1;
}

.preview-panel-content.mobile .device-screen {
    flex: 1;
    background: white;
    overflow: hidden;
    position: relative;
}

/* Home indicator */
.preview-panel-content.mobile .device-bottom {
    height: 34px;
    background: #1A1A2E;
    border-radius: 0 0 50px 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-panel-content.mobile .device-bottom::after {
    content: '';
    width: 130px;
    height: 5px;
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
}

/* Device frame base */
.device-frame {
    display: flex;
    flex-direction: column;
}

/* Preview iframe */
.preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: white;
}

/* Desktop: iframe fills all */
.preview-panel-content.desktop .preview-frame {
    width: 100%;
    height: 100%;
}

/* Tablet: iframe fills device screen */
.preview-panel-content.tablet .preview-frame {
    width: 100%;
    height: 100%;
    min-height: 860px;
}

/* Mobile: iframe fills phone screen */
.preview-panel-content.mobile .preview-frame {
    width: 375px;
    height: 100%;
}

/* ── Painel Direito ── */
.right-panel {
    width: var(--right-panel-width);
    flex-shrink: 0;
    border-right: none;
}

/* ════════════════════════════════════════════════════════════
   Botões
   ════════════════════════════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: var(--btn-h);
    padding: 0 8px;
    background: var(--btn-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}

.btn:hover:not(:disabled) {
    background: var(--btn-hover);
}

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

.btn.icon-btn {
    width: var(--btn-h);
    padding: 0;
    font-size: 12px;
}

/* Botão salvar no arquivo — destaque verde quando ativo */
.save-file-btn {
    background: transparent;
    color: #4caf50 !important;
    border-color: #4caf50 !important;
    font-size: 12px;
    padding: 0 10px;
    height: var(--btn-h);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.save-file-btn:hover:not(:disabled) {
    background: rgba(76, 175, 80, 0.15) !important;
    border-color: #66bb6a !important;
}

.btn.primary-btn {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn.primary-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn.delete-btn {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn.delete-btn:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.view-btn {
    width: var(--btn-h);
    padding: 0;
}

/* ════════════════════════════════════════════════════════════
   Árvore DOM
   ════════════════════════════════════════════════════════════ */

/* ── Árvore DOM ── */
.element-tree {
    font-size: 11px;
    line-height: 1.2;
    user-select: none;
    padding: 2px 0;
    /* Clipa overflow horizontal no nível raiz da árvore */
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* Cada item ocupa a largura disponível do seu container pai
   À medida que nesting aumenta, o container pai fica mais estreito
   pelo margin-left do .tree-item-children — isso é suficiente */
.tree-item {
    display: flex;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    min-height: 22px;
    padding: 2px 4px 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    /* overflow: hidden garante que nada vaze horizontalmente */
    overflow: hidden;
    transition: background 0.1s;
}

.tree-item:hover {
    background: var(--tree-hover);
}

.tree-item.active {
    background: var(--tree-active);
}

/* Flex row com truncagem: min-width:0 em toda a cadeia é crítico */
.tree-item-content {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;       /* Permite que filhos flex encolham abaixo do tamanho intrínseco */
    overflow: hidden;
    gap: 3px;
}

.tree-item-icon {
    font-size: 10px;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    color: var(--text-secondary);
}

/* Nome: trunca com ellipsis — NUNCA expande o item */
.tree-item-name {
    flex: 1;
    min-width: 0;       /* Crítico: sem isso text-overflow não funciona em flex */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--text);
}

/* Cores por tipo de elemento */
.tree-item-name.type-heading  { color: #9c27b0; }
.tree-item-name.type-link     { color: #00bcd4; }
.tree-item-name.type-image    { color: #4caf50; }
.tree-item-name.type-button   { color: #f44336; }
.tree-item-name.type-input    { color: #ff9800; }
.tree-item-name.type-text     { color: var(--text-secondary); }
.tree-item-name.type-semantic { color: var(--primary); font-weight: 600; }

/* Botões de controle — aparecem só no hover */
.tree-item-controls {
    display: flex;
    gap: 1px;
    opacity: 0;
    flex-shrink: 0;     /* Nunca encolhem — têm prioridade sobre o nome */
    transition: opacity 0.15s;
}

.tree-item:hover .tree-item-controls {
    opacity: 1;
}

.tree-control-btn {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--btn-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 2px;
    font-size: 9px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.tree-control-btn:hover {
    background: var(--btn-hover);
}

.tree-control-btn.delete-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.tree-control-btn.duplicate-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── Drag & Drop da Árvore DOM ─────────────────────────────────── */
.tree-drag-handle {
    flex-shrink: 0;
    width: 12px;
    font-size: 9px;
    color: var(--text-secondary);
    opacity: 0;
    cursor: grab;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
}
.tree-item:hover .tree-drag-handle {
    opacity: 0.5;
}
.tree-drag-handle:hover {
    opacity: 1 !important;
    color: var(--primary);
}
.tree-dragging {
    opacity: 0.4;
    outline: 1px dashed var(--primary);
    border-radius: 3px;
}
/* Indicador: soltar ANTES do elemento */
.tree-drop-before {
    border-top: 2px solid var(--primary) !important;
    border-radius: 0 !important;
}
/* Indicador: soltar DEPOIS do elemento */
.tree-drop-after {
    border-bottom: 2px solid var(--primary) !important;
    border-radius: 0 !important;
}
/* Indicador: soltar DENTRO do elemento */
.tree-drop-inside {
    background: rgba(86, 152, 214, 0.18) !important;
    outline: 1px solid var(--primary);
    border-radius: 3px;
}

/* Container de filhos: recuo de 10px por nível
   width:100% herda a largura do pai que já está 10px menor → itens ficam automaticamente mais estreitos */
.tree-item-children {
    margin-left: 10px;
    position: relative;
    width: calc(100% - 10px);  /* Garante que não estoura o pai */
    box-sizing: border-box;
    /* SEM overflow:hidden aqui — o clipe é feito no .element-tree e nos .tree-item */
}

/* Linha vertical de hierarquia */
.tree-item-children::before {
    content: "";
    position: absolute;
    left: -5px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
    opacity: 0.5;
}

/* ════════════════════════════════════════════════════════════
   Painel de Propriedades (sem abas — painel único)
   ════════════════════════════════════════════════════════════ */

.properties-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

/* Badge do elemento selecionado */
.element-badge {
    display: block;
    padding: 5px 8px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--border);
    font-family: 'Consolas', monospace;
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Seções colapsáveis */
.prop-section {
    border-bottom: 1px solid var(--border);
}

.prop-section-title {
    display: flex;
    align-items: center;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    background: var(--panel-header);
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background 0.1s;
}

.prop-section-title:hover {
    background: var(--btn-hover);
}

details.prop-section > summary::-webkit-details-marker {
    display: none;
}

details.prop-section > summary::before {
    content: '▶';
    font-size: 8px;
    margin-right: 5px;
    display: inline-block;
    transition: transform 0.15s;
    opacity: 0.6;
}

details.prop-section[open] > summary::before {
    transform: rotate(90deg);
}

/* Linha de propriedade */
.prop-row {
    display: flex;
    align-items: center;
    padding: 3px 6px;
    gap: 5px;
    min-height: 26px;
}

.prop-row.full-row {
    flex-direction: column;
    align-items: stretch;
    padding: 4px 6px;
}

.prop-label {
    font-size: 10.5px;
    color: var(--text-secondary);
    width: 58px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Inputs de propriedade */
.prop-input {
    flex: 1;
    min-width: 0;
    height: 22px;
    padding: 0 5px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.prop-input:focus {
    border-color: var(--primary);
}

.prop-textarea {
    height: auto;
    resize: vertical;
    padding: 4px 5px;
    font-family: 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.4;
    width: 100%;
}

.prop-select {
    flex: 1;
    min-width: 0;
    height: 22px;
    padding: 0 4px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

.prop-select:focus {
    border-color: var(--primary);
}

/* Cor */
.color-input-wrapper {
    display: flex;
    flex: 1;
    gap: 4px;
    align-items: center;
    min-width: 0;
}

.prop-color {
    width: 22px;
    height: 22px;
    padding: 1px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--input-bg);
    cursor: pointer;
    flex-shrink: 0;
}

/* Número + unidade */
.number-unit-group {
    display: flex;
    flex: 1;
    min-width: 0;
}

.number-unit-group .prop-input {
    border-radius: 3px 0 0 3px;
    border-right: none;
    min-width: 0;
}

.unit-select {
    width: 42px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 0 3px 3px 0;
    border-left: none;
    padding: 0 2px;
    background: var(--btn-bg);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 10px;
    cursor: pointer;
    font-family: inherit;
}

/* Alinhamento */
.align-btns {
    display: flex;
    flex: 1;
    gap: 2px;
}

.align-btns .prop-btn {
    flex: 1;
    height: 22px;
    padding: 0;
    font-size: 11px;
}

/* Espaçamento grid */
.spacing-group-label {
    font-size: 10px;
    color: var(--text-secondary);
    padding: 4px 6px 1px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.spacing-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 2px 6px 6px;
}

.spacing-cell {
    display: flex;
    align-items: center;
    gap: 3px;
}

.spacing-side-label {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 700;
    width: 10px;
    text-align: center;
    flex-shrink: 0;
}

.spacing-input {
    height: 22px;
    flex: 1;
}

/* Toggle */
.toggle-switch-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.toggle-checkbox {
    display: none;
}

.toggle-track-new {
    width: 34px;
    height: 18px;
    background: var(--btn-bg);
    border-radius: 9px;
    position: relative;
    transition: background 0.2s;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.toggle-track-new::after {
    content: '';
    width: 12px;
    height: 12px;
    background: var(--text-secondary);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: left 0.2s, background 0.2s;
}

.toggle-checkbox:checked + .toggle-track-new {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-checkbox:checked + .toggle-track-new::after {
    left: 18px;
    background: white;
}

/* Botão pequeno de propriedade */
.prop-btn {
    height: 22px;
    width: 22px;
    padding: 0;
    font-size: 10px;
    flex-shrink: 0;
}

/* Mensagem sem seleção */
.no-selection-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px 20px;
    text-align: center;
    color: var(--text-secondary);
    height: 100%;
    min-height: 180px;
}

.no-selection-message i {
    font-size: 24px;
    opacity: 0.5;
}

.no-selection-message p {
    font-size: 11px;
    line-height: 1.5;
    opacity: 0.7;
}

/* Duplicar / Excluir no panel-header — ocultos quando desabilitados */
.panel-actions #duplicateBtn:disabled,
.panel-actions #deleteBtn:disabled {
    opacity: 0;
    pointer-events: none;
    width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}
.panel-actions #deleteBtn:not(:disabled):hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* ════════════════════════════════════════════════════════════
   Modais
   ════════════════════════════════════════════════════════════ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    width: 480px;
    max-width: 94vw;
    max-height: 90vh;
    background: var(--panel-bg);
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-wide {
    width: 680px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 7px;
}

.close-modal-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal-btn:hover {
    background: var(--btn-hover);
    color: var(--text);
}

/* Compat para spans usados como close */
.close-modal {
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    line-height: 1;
}

.close-modal:hover {
    color: var(--text);
}

.modal-body {
    padding: 14px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 6px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 12px;
    transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(86, 152, 214, 0.05);
}

.upload-area i {
    font-size: 24px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: block;
}

.upload-area p {
    font-size: 12px;
    color: var(--text-secondary);
}

.url-input-section {
    margin-bottom: 10px;
}

.url-input-section label {
    font-size: 11px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 5px;
}

.input-group {
    display: flex;
    gap: 6px;
}

.input-group input {
    flex: 1;
    height: 28px;
    padding: 0 8px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
}

.image-preview {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    text-align: center;
    margin-top: 8px;
}

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 3px;
}

/* Export code */
.export-options {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
}

.export-code-wrapper {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: auto;
    max-height: 55vh;
}

#exportCode {
    padding: 10px;
    font-family: 'Consolas', monospace;
    font-size: 11px;
    white-space: pre;
    color: var(--text);
    line-height: 1.4;
}

/* ════════════════════════════════════════════════════════════
   Scrollbar personalizada
   ════════════════════════════════════════════════════════════ */

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ════════════════════════════════════════════════════════════
   FAB + Painel de Adição de Elementos
   ════════════════════════════════════════════════════════════ */

/* position context já está em .preview-panel-content */

/* ── FAB (Floating Action Button) ── */
.element-adder-fab {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 100;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
}
.element-adder-fab:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.element-adder-fab.open {
    transform: rotate(45deg);
    background: var(--danger);
}
.element-adder-fab.open:hover {
    background: var(--danger-hover);
}

/* ── Painel flutuante ── */
.element-adder-panel {
    position: absolute;
    bottom: 62px;
    left: 16px;
    z-index: 99;
    width: 248px;
    max-height: calc(100% - 96px);
    min-height: 200px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: adderSlideIn 0.18s ease;
}
@keyframes adderSlideIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Cabeçalho */
.adder-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--text);
}
.adder-header i:first-child { color: var(--primary); font-size: 13px; }
.adder-close { margin-left: auto; }

/* Barra de busca */
.adder-search-wrap {
    padding: 6px 8px;
    flex-shrink: 0;
    position: relative;
    border-bottom: 1px solid var(--border);
}
.adder-search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 10px;
    pointer-events: none;
}
.adder-search {
    width: 100%;
    height: 26px;
    padding: 0 8px 0 24px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.adder-search:focus { border-color: var(--primary); }

/* Conteúdo scrollável */
.adder-content {
    overflow-y: auto;
    flex: 1;
    padding: 4px 0 8px;
}

/* ── Categorias ── */
.adder-category { margin-bottom: 4px; }

.adder-cat-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    padding: 6px 10px 3px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.adder-cat-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    opacity: 0.5;
}

.adder-items-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 2px 6px 4px;
}

/* ── Item de elemento ── */
.adder-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 4px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    cursor: grab;
    font-size: 9px;
    color: var(--text-secondary);
    text-align: center;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.1s;
    user-select: none;
    min-height: 50px;
}
.adder-item i {
    font-size: 15px;
    color: var(--primary);
    transition: color 0.12s;
}
.adder-item:hover {
    background: var(--btn-hover);
    border-color: var(--primary);
    color: var(--text);
    transform: translateY(-1px);
}
.adder-item:hover i { color: var(--primary); }
.adder-item:active  { cursor: grabbing; transform: scale(0.96); }

/* Item "Da Página" — ocupa linha completa */
.adder-item.page-element {
    grid-column: span 3;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 6px 10px;
    gap: 8px;
    min-height: 36px;
    text-align: left;
}
.page-el-tag {
    font-size: 9px;
    font-weight: 700;
    color: var(--primary);
    background: rgba(86,152,214,0.1);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    font-family: monospace;
}
.page-el-preview {
    flex: 1;
    font-size: 10px;
    color: var(--text-secondary);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* ════════════════════════════════════════════════════════════
   Auth UI — Login Google + Avatar
   ════════════════════════════════════════════════════════════ */

.auth-login-btn {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 0 12px;
    height: var(--btn-h);
    white-space: nowrap;
}
.auth-login-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.auth-user-menu {
    display: flex;
    align-items: center;
    gap: 6px;
}

.auth-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
}

.auth-username {
    font-size: 11px;
    color: var(--text);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-premium-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 700;
    color: #f4b942;
    background: rgba(244, 185, 66, 0.12);
    border: 1px solid rgba(244, 185, 66, 0.3);
    border-radius: 10px;
    padding: 2px 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ════════════════════════════════════════════════════════════
   Paywall Modal
   ════════════════════════════════════════════════════════════ */

.paywall-modal-content {
    width: 400px;
    max-width: 94vw;
    text-align: center;
    padding: 32px 28px 24px;
    position: relative;
    border-top: 3px solid #f4b942;
}

.paywall-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.paywall-close:hover { background: var(--btn-hover); color: var(--text); }

.paywall-icon {
    font-size: 36px;
    color: #f4b942;
    margin-bottom: 12px;
}

.paywall-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.paywall-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.paywall-features {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    text-align: left;
}

.paywall-feature {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text);
}

.paywall-feature i {
    color: var(--success);
    font-size: 13px;
    flex-shrink: 0;
}

.paywall-price {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 2px;
    margin-bottom: 18px;
    padding: 12px;
    background: var(--input-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.paywall-currency {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.paywall-amount {
    font-size: 36px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}
.paywall-period {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 2px;
}

.paywall-btn {
    width: 100%;
    height: 42px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary), #764ba2);
    border-color: transparent;
}
.paywall-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-hover), #6a3d9a);
    border-color: transparent;
}

.paywall-footer {
    font-size: 10px;
    color: var(--text-secondary);
    margin: 0;
}

/* ════════════════════════════════════════════════════════════
   Responsividade
   ════════════════════════════════════════════════════════════ */

@media (max-width: 1280px) {
    :root {
        --left-panel-width: 230px;
        --right-panel-width: 260px;
    }
}

@media (max-width: 960px) {
    :root {
        --left-panel-width: 200px;
        --right-panel-width: 240px;
    }
}
