/* Estilos para o layout geral do editor */
body {
    font-family: sans-serif;
    margin: 0;
    background-color: #f4f7f6;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* --- Header --- */
.header {
    background-color: #2C3E50;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 45px;
    box-sizing: border-box;
}

.header h1 {
    margin: 0;
    font-size: 20px;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
}

.header .actions a {
    color: #2C3E50;
    background-color: white;
    padding: 8px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
    margin-left: 10px;
}

.header .actions button {
    color: white;
    background-color: #27ae60;
    padding: 8px 15px;
    border-radius: 4px;
    border: none;
    font-size: 16px;
    cursor: pointer;
    font-weight: bold;
    margin-left: 10px;
}

/* --- Layout Principal do Editor --- */
.editor-container {
    display: flex;
    height: calc(100vh - 45px);
}

.preview-pane {
    flex: 1;
    padding: 0;
    position: relative;
    text-align: center;
}

#preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background-color: white;
}

#highlighter {
    position: absolute;
    box-sizing: border-box;
    z-index: 9999;
    pointer-events: none;
    display: none;
    transition: all 50ms linear;
    border: 2px dashed #2ecc71;
    background-color: rgba(46, 204, 113, 0.2);
}

/* --- Painel de Edição (Direita) --- */
.editor-pane {
    flex: 0 0 400px;
    background-color: #ecf0f1;
    border-right: 2px solid #bdc3c7;
    display: flex;
    flex-direction: column;
}

.editor-menu {
    flex-shrink: 0;
    padding: 10px 15px;
    background-color: #dfe6e9;
    border-bottom: 2px solid #bdc3c7;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-fields, .editor-main-panel {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.editor-fields h2 {
    margin-top: 0;
    font-size: 18px;
    color: #2c3e50;
}

.elemento-selecionado-info {
    flex: 1;
    min-width: 0;
}

.elemento-selecionado-info label {
    font-size: 12px;
    color: #636e72;
    font-weight: bold;
    margin: 0;
}

.elemento-selecionado-info .tag-display {
    padding: 5px 10px;
    font-size: 13px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.tag-display {
    background-color: #dfe6e9;
    padding: 10px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    color: #2d3436;
    border: 1px solid #b2bec3;
}

.tag-display strong {
    color: #d35400;
}

/* --- Campos e Formulários do Painel --- */
.field-group {
    margin-bottom: 20px;
}

.field-group label {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    border-top: 1px solid #dee1e5;
    padding-top: 15px;
}

.field-group textarea, .field-group input, .field-group select, #btn-adicionar-elemento {
    width: 100%;
    font-family: monospace;
    font-size: 14px;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    padding: 8px;
    box-sizing: border-box;
}

.field-group input[type=color]{
    padding: 0px;
}

.info-text {
    font-size: 14px;
    color: #7f8c8d;
    line-height: 1.5;
}

.dynamic-styles-container {
    background-color: #fff;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    padding: 10px;
}

.style-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-family: monospace;
    font-size: 13px;
}

.style-row label {
    flex: 0 0 75px;
    text-align: right;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 0;
}

.style-row input {
    flex-grow: 1;
    font-family: monospace !important;
    font-size: 13px !important;
}

#editor-atributos .attr-row {
    display: flex;
    margin-bottom: 5px;
    gap: 5px;
}

#editor-atributos .attr-row input:first-child {
    flex: 0 0 120px;
}

.add-style-form, .add-attribute-form {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    padding-top: 10px;
}

.add-style-form input, .add-attribute-form input {
    flex-grow: 1;
}

/* --- Botões do Painel --- */
#btn-adicionar-estilo, #btn-adicionar-atributo {
    flex: 0 0 40px;
    font-size: 20px;
    font-weight: bold;
    background-color: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

#btn-toggle-adicionar {
    flex-shrink: 0;
    width: 35px;
    height: 35px;
    font-size: 24px;
    font-weight: bold;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background-color: #3498db;
    color: white;
    margin-left: 15px;
}

.btn-remove-element {
    background-color: #e74c3c;
}

#btn-remover {
    width: calc(50% - 2.5px);
    color: white;
    background-color: #e74c3c;
    padding: 10px;
    border-radius: 4px;
    border: none;
    font-size: 15px;
    cursor: pointer;
    font-weight: bold;
}

#btn-duplicar {
    width: calc(50% - 2.5px);
    color: white;
    background-color: #3498db;
    padding: 10px;
    border-radius: 4px;
    border: none;
    font-size: 15px;
    cursor: pointer;
    font-weight: bold;
    margin-bottom: 10px;
}

.move-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.btn-move {
    flex-grow: 1;
    font-size: 20px;
    padding: 5px;
    background-color: #ecf0f1;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}
.btn-move:hover {
    background-color: #dfe6e9;
}
.btn-move:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Seletor de Modo (Switch) --- */
.mode-selector {
    display: flex;
    align-items: center;
}

.mode-selector label {
    margin: 0 10px;
    font-size: 14px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #3498db;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #9b59b6;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.modo-configurar .painel-criador {
    display: none;
}

.modo-criador .painel-configurar {
    display: none;
}

/* --- Estilos da Janela Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    width: 600px;
    max-width: 90%;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    height: 80%;
    overflow-y: auto;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
    color: #333;
}

.modal-content .form-group {
    margin-bottom: 15px;
}

.modal-content .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 14px;
}

.modal-content .form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    font-family: sans-serif;
    box-sizing: border-box;
}

.modal-content .modelos-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background-color: #f8f9fa;
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    max-height: 150px;
    overflow-y: auto;
}

.modal-content .modelos-list label {
    font-weight: normal;
    display: inline-block;
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

.btn-primary {
    background-color: #27ae60;
    color: white;
}

.btn-secondary {
    background-color: #bdc3c7;
    color: #333;
}

/* Estilos para o Acordeão de Estilos */
.accordion-header {
    background-color: #dfe6e9;
    color: #2d3436;
    cursor: pointer;
    padding: 12px 15px;
    width: 100%;
    border: none;
    border-bottom: 1px solid #bdc3c7;
    text-align: left;
    outline: none;
    font-size: 14px;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.accordion-header:hover, .accordion-header.active {
    background-color: #b2bec3;
}

/* Ícone de seta para indicar aberto/fechado */
.accordion-header::after {
    content: '\\02795'; /* Símbolo de MAIS (+) */
    font-size: 10px;
    color: #777;
    float: right;
    margin-left: 5px;
}

.accordion-header.active::after {
    content: "\\2796"; /* Símbolo de MENOS (-) */
}

/* Painel que contém os inputs de estilo */
.accordion-panel {
    padding: 0 15px;
    background-color: white;
    max-height: 0; /* Começa fechado */
    overflow: hidden;
    transition: max-height 0.2s ease-out; /* Animação suave de abrir/fechar */
    border-bottom: 1px solid #bdc3c7;
}

.accordion-panel .style-row {
    margin-top: 8px; /* Adiciona espaço no primeiro item */
}

.compound-input-container {
    display: flex;
    gap: 5px;
    align-items: center;
}
.compound-input-wrapper {
    position: relative;
    flex-grow: 1;
}
.compound-input-wrapper .icon {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 12px;
    pointer-events: none;
}
.compound-input-wrapper input {
    padding-left: 12px !important;
}
.view-controls {
    display: flex;
}
.view-controls button {
    border: 2px solid transparent !important;
    background: #fff !important;
    border-radius: 4px !important;
    padding: 5px 10px !important;
    cursor: pointer !important;
}
.view-controls button.active {
    border-color: #3498db !important;
}

.state-selector {
    display: flex;
    border: 1px solid #bdc3c7;
    border-radius: 5px;
    overflow: hidden;
    background-color: #ffffff;
}
.state-selector button {
    flex-grow: 1;
    padding: 8px;
    border: none;
    background-color: transparent;
    cursor: pointer;
    font-weight: bold;
    color: #34495e;
    transition: all 0.2s;
}
.state-selector button:first-child {
    border-right: 1px solid #bdc3c7;
}
.state-selector button.active {
    background-color: #3498db;
    color: white;
}
/* --- Estilos para a Nova Área de Visualização de Código --- */
.code-view-container {
    position: absolute;
    bottom: 0px;
    left: 402px; /* Largura do painel de edição + borda */
    right: 0px;
    height: 50%;
    background-color: #2d3436;
    color: #dfe6e9;
    border-top: 2px solid #bdc3c7;
    z-index: 10002;
    display: flex;
    flex-direction: column;
    transition: height 0.3s ease;
}

.code-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #636e72;
    flex-shrink: 0;
}

.code-view-header h3 {
    margin: 0;
    font-size: 16px;
}

.code-view-header button {
    margin-left: 10px;
    padding: 5px 10px;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    background-color: #dfe6e9;
    color: #2d3436;
    cursor: pointer;
    font-weight: bold;
}

#btn-fechar-codigo-gerado {
    background-color: #e74c3c;
    color: white;
    border-color: #c0392b;
    padding: 5px 12px;
}

#btn-fechar-editor-pane {
    background-color: #e74c3c;
    color: white;
    border-color: #c0392b;
    border-radius: 4px;
    padding: 8px 12px;
    margin-right: 15px;
    display: none;
}

.code-view-container pre {
    flex-grow: 1;
    margin: 0;
    overflow: auto;
    padding: 15px;
    font-size: 13px;
    background-color: #242424;
}

.code-view-container code {
    font-family: 'Courier New', Courier, monospace;
    white-space: pre;
}

/* --- #################################### --- */
/* --- ### ESTILOS PARA A VERSÃO MOBILE ### --- */
/* --- #################################### --- */

/* Aplica as regras quando a tela for de 768px de largura ou menos */
@media (max-width: 768px) {

    body{
        /*overflow-y: scroll;*/
    }

    /* Ajusta o cabeçalho para permitir quebra de linha e melhora o espaçamento */
    .header {
        height: auto; /* */
        min-height: 45px; /* */
        flex-wrap: wrap; /* */
        padding: 10px; /* */
        gap: 10px;
    }

    .header h1 {
        flex-basis: 100%; /* */
        text-align: center;
        margin-bottom: 5px;
    }
    
    .header .actions {
        width: 100%;
        justify-content: center;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    .view-controls{
        display: none;
    }
    
    .header .actions button,
    .header .actions a {
        flex-grow: 1;
        text-align: center;
        margin-left: 0; /* */
    }

    /* Empilha o painel de edição e o de visualização em vez de ficarem lado a lado */
    .editor-container {
        flex-direction: column; /* */
        height: calc(100dvh - 93px); /* */
        overflow-y: hidden; /* Permite rolar a página inteira do editor */
    }

    /* O painel de edição agora ocupa toda a largura e não tem mais largura fixa */
    .editor-pane {
        position: absolute;
        z-index: 10001;
        height: 50vh;
        left: 0px;
        bottom: 0px;
        flex: 1 1 auto;
        width: 100%;
        border-right: none;
        border-bottom: 2px solid #bdc3c7;
        order: 2;
        display: none;
    }
    
    #btn-fechar-editor-pane {
        display: block;
    }

    /* O painel de visualização (iframe) vem primeiro e tem uma altura fixa para garantir visibilidade */
    .preview-pane {
        flex: 1 1 auto; /* */
        width: 100%;
        height: calc(100dvh - 93px); /* Ocupa 70% da altura da tela */
        /* Garante que o preview venha antes do painel de edição */
        order: 1;
    }

    /* A janela de código gerado também deve se adaptar ao novo layout */
    .code-view-container {
        position: absolute;
        left: 0px;
        bottom: 0px;
        width: 100%;
        height: 50vh;
        /* Garante que a janela de código venha por último */
        order: 3; 
    }
    
    .modal-content {
        width: 95%; /* */
        height: 90%; /* */
    }
}