/* ==========================================================================
   1. CONFIGURAÇÕES GERAIS (BASEADO NO SEU CÓDIGO)
   ========================================================================== */
:root {
    --accent-color: #0059CA;
    --accent-hover: #00459C;
    --success-color: #2ecc71;
    --success-hover: #27ae60;
    --danger-color: #e74c3c;
    --danger-hover: #c0392b;
    --bg-light: #f2f2f2;
    --bg-white: #ffffff;
    --text-dark: #1c1e21;
    --text-secondary: #6c757d;
    --border-color: #E0E0E0;
}

body {
    font-family: Helvetica, sans-serif;
    background-color: var(--bg-light);
    margin: 0;
    color: var(--text-dark);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   2. LAYOUT PRINCIPAL E MODAL
   ========================================================================== */
.editor-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    gap: 0px;
}

/* --- Estilos da Tela de Configuração (Modal Genérico) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-white);
    z-index: 1000;
    transition: opacity 0.3s;
    overflow-y: auto;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    border-radius: 0;
    box-shadow: none;
    padding: 60px 20px;
    margin: auto;
    box-sizing: border-box;  
    text-align: center;
}

.modal-content h2 { margin-top: 0; font-size: 24px; }
.modal-content p { margin-bottom: 25px; color: #666; }
.modal-form { display: flex; gap: 10px; margin-bottom: 20px; }
.modal-form .form-group { flex: 1; text-align: left; }
.modal-form label { display: block; margin-bottom: 8px; font-weight: 500; }
.modal-form input {
    width: 100%; padding: 10px; box-sizing: border-box;
    border-radius: 6px; border: 1px solid #ccc; font-size: 14px;
}

/* ==========================================================================
   3. BARRAS DE FERRAMENTAS
   ========================================================================== */

/* Barra de Ferramentas Contextual (Fixa) */
#layerControls {
    position: absolute;
    top: 40px;
    left: 50%;
    max-width: 90%;
    overflow-x: auto;
    transform: translateX(-50%);
    z-index: 99;
    transition: opacity 0.3s, transform 0.3s;
    transform-origin: top;
    border-radius: 8px;
    background-color: var(--bg-white);
    padding: 10px 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

/* Grupos de itens dentro das barras */
.toolbar-section { display: flex; align-items: center; gap: 15px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-group label { font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--text-secondary); }

/* ==========================================================================
   4. ÁREA DO CANVAS E CONTROLES
   ========================================================================== */
.canvas-area {
    flex-grow: 1;
    background-color: var(--bg-light);
    background-image: 
        linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    padding: 20px;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
    overflow: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.canvas-area::-webkit-scrollbar {
    display: none;
}

#imageCanvas {
    border: none;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    background-color: var(--bg-white);
    cursor: default;
    transform-origin: top left;
    transition: transform 0.1s linear;
}

#imageCanvas.cropping { cursor: crosshair; }

/* Melhoria nos controles de input */
input[type="range"] {
    -webkit-appearance: none;
    width: 140px; height: 6px; background: #e9ecef;
    border-radius: 3px; outline: none; cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; background: var(--accent-color);
    border-radius: 50%;
}

input[type="color"] {
    width: 35px; height: 35px; border: 1px solid var(--border-color);
    border-radius: 6px; padding: 2px; cursor: pointer; background-color: transparent;
}

#bgColorPicker{
    width: 100%;
    height: 100px;
}

/* ==========================================================================
   5. BOTÕES E DROPDOWN
   ========================================================================== */
.btn {
    padding: 8px 16px; border: none; border-radius: 6px;
    background-color: var(--accent-color);
    color: white; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.btn:hover { background-color: var(--accent-hover); }
.btn.btn-success { background-color: var(--success-color); }
.btn.btn-success:hover { background-color: var(--success-hover); }
.btn.btn-danger { background-color: var(--danger-color); }
.btn.btn-danger:hover { background-color: var(--danger-hover); }

#side-panel label { font-weight: 600; font-size: 14px; margin-bottom: 8px; display: block; }
#side-panel input[type="number"] { padding: 8px; border-radius: 6px; border: 1px solid #ccc;}
#side-panel hr { border: none; border-top: 1px solid #eee; margin: 15px 0; }
#export-panel button {
    width: 100%; text-align: left; padding: 10px; background: none;
    color: var(--text-dark); border: none; border-radius: 6px; font-weight: 500;
    cursor: pointer;
}
#export-panel button:hover { background-color: #f0f0f0; }
#outputWidth, #qualitySlider{
    width:-webkit-fill-available;
}

/* ==========================================================================
   6. ESTADOS E COMPONENTES ESPECIAIS
   ========================================================================== */
.hidden { display: none !important; }

#layerControls.disabled {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
}

.preset-sizes {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.btn.btn-preset {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
    padding: 8px 12px;
    font-size: 13px;
    white-space: normal
}

.btn.btn-preset:hover {
    background-color: var(--bg-light);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.btn-align {
    background-color: transparent;
    color: var(--text-secondary);
    padding: 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-align:hover {
    background-color: var(--bg-light);
    color: var(--text-dark);
}

.btn-align.active {
    background-color: var(--accent-color);
    color: var(--bg-white); /* Assumindo que a cor do texto sobre cor de destaque seja branco */
}

.btn-align.active:hover {
    background-color: var(--accent-hover);
}

/* ==========================================================================
   7. NOVOS ESTILOS PARA O SETUP MODAL (VERSÃO 4.0)
   ========================================================================== */
#setupModal.modal-overlay {
    background-color: var(--bg-white);
}

#setupModal .modal-content {
    max-width: none;
    height: 100%;
    padding: 0;
    overflow: hidden;
    display: flex;
    text-align: left; /* Reset text-align */
}

.setup-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
}

.setup-left {
    flex: 0 0 100px;
    background-color: var(--bg-white);
    padding: 30px 15px;
    overflow-y: auto;
}

.setup-left h2 {
    font-size: 24px;
    margin-top: 0;
    color: var(--text-dark);
}

.setup-left > p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 15px;
}

.setup-left h3 {
    margin-top: 0;
    font-size: 18px;
    margin-bottom: 15px;
}

.setup-left .preset-sizes {
    flex-direction: column;
    align-items: stretch; /* Faz os botões ocuparem a largura total */
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.setup-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 40px;
    overflow-y: auto;
    text-align: center;
    color: white;
    background: linear-gradient(145deg, var(--accent-color) 0%, #3c83f6 90%);
    border-radius: 20px 0px 0px 0px;
    margin-top: 0px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.setup-right h3 {
    font-size: 28px;
    font-weight: 600;
}

.setup-right .template-previews {
    position: relative; /* ESSENCIAL: para que os itens filhos sejam posicionados em relação a ele */
    width: 100%;
    max-width: 100%;
    margin: 30px auto auto;
}

.template-preview {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 32%; 
    padding-bottom: 5px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.95);
    transition: top 0.4s ease, left 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
}

.template-preview.visible {
    /* Estado Final: visível e no tamanho normal */
    opacity: 1;
    transform: scale(1);
}

.setup-right .template-preview .preview-box {
    background-color: white;
    border: none;
    border-radius: 8px;
    overflow: hidden; 
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: 10px;
}

.setup-right .template-preview .preview-box img {
    width: 100%;
    height: auto;
    display: block;
}

.setup-right .template-preview:hover .preview-box {
    transform: scale(1.02);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.setup-right .template-preview span {
    font-size: 13px;
    color: white;
    font-weight: 500;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

.loading-indicator {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(0, 0, 0, 0.1); /* Círculo cinza claro */
  border-top-color: var(--accent-color); /* A cor de destaque para a parte que gira */
  border-radius: 50%;
  margin: 30px auto; /* Centraliza o spinner */
  animation: spin 1s infinite linear; /* Aplica a animação de rotação */
}

/* ==========================================================================
   9. NOVOS ESTILOS DE LAYOUT (BARRA LATERAL)
   ========================================================================== */

/* 1. Ajusta o container principal do editor para ser horizontal */
.editor-container {
    flex-direction: row; /* Alterado de 'column' para 'row' */
    height: 100vh;
    overflow: hidden; /* Previne scroll da página inteira */
}

/* 2. Estilos para a nova Barra "Dock" à esquerda */
#left-toolbar {
    flex: 0 0 60px; /* Não cresce, não encolhe, largura fixa de 60px */
    background: linear-gradient(145deg, var(--accent-color) 0%, #3c83f6 90%);;
    border-right: 1px solid var(--border-color);
    padding: 15px 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 100;
}

.dock-btn {
    background-color: transparent;
    border: none;
    border-radius: 8px;
    width: 100%;
    height: auto;
    padding: 8px 4px;
    margin: 5px 0;
    display: flex;
    flex-direction: column;
    align-items: center; 
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s;
}
.dock-btn-label {
    font-size: 11px;
    font-weight: 500;
    margin-top: 4px;
    line-height: 1.2;
    color: var(--bg-light);
}
.dock-btn:hover {
    background-color: var(--accent-hover);
}
.dock-btn.active {
    background-color: var(--accent-hover);
    color: white;
}
.dock-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--bg-white);
}

/* 3. Estilos para o Painel Lateral (que abre/fecha) */
#side-panel {
    flex: 0 0 280px; /* Largura fixa de 280px */
    background-color: #fcfcfc;
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    z-index: 99;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    opacity: 1;
    transition: flex-basis 0.4s ease-out, opacity 0.2s ease-in, padding 0.4s ease-out;
}

#side-panel.hidden {
    display: flex !important;
    flex-basis: 0;
    padding-left: 0;
    padding-right: 0;
    opacity: 0;
    pointer-events: none;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.panel-section h3 {
    font-size: 18px;
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--text-dark);
}
.panel-section hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 5px 0;
}
.panel-section .btn {
    width: 100%; /* Faz os botões ocuparem 100% da largura do painel */
}

/* 4. Estilos para o Wrapper Principal (Canvas + LayerControls) */
.main-content {
    flex-grow: 1; /* Ocupa todo o espaço restante */
    position: relative; /* CRUCIAL: para #layerControls flutuar */
    display: flex; /* Garante que o canvas-area preencha */
    overflow: hidden; /* Garante que o canvas-area use o scroll interno */
}

/* O canvas-area em si não muda muito, apenas garantimos que ele cresça */
.canvas-area {
    height: 100%;
}

/* ==========================================================================
   12. ESTILOS DA GALERIA UNSPLASH
   ========================================================================== */

#unsplash-search-form {
    display: flex;
    gap: 5px;
}

#unsplash-search-input {
    flex-grow: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
}

.unsplash-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Duas colunas */
    gap: 10px;
    border-radius: 6px;
    padding: 0px;
}

.unsplash-gallery-grid img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.unsplash-gallery-grid img:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* Mensagens de feedback */
.unsplash-gallery-grid p {
    color: var(--text-secondary);
    grid-column: 1 / -1; /* Ocupa as duas colunas */
    text-align: left;
    font-size: 11px;
    margin: 5px 0;
}
.unsplash-gallery-grid a{
    color: var(--text-secondary);
}

/* ==========================================================================
   13. ESTILOS DO NOVO MENU SUPERIOR (SETUP)
   ========================================================================== */

/* 1. Ajusta o overlay principal para organizar o menu e o conteúdo */
.modal-overlay {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Alterado de 'auto' para 'hidden' */
}

/* 2. Ajusta o conteúdo da modal para ocupar o espaço *restante* */
#setupModal .modal-content {
    height: auto; /* Remove o 'height: 100%' */
    flex-grow: 1; /* Faz este elemento crescer para preencher o espaço */
    overflow: hidden; /* Mantém o 'overflow: hidden' que já tinha */
}

/* 3. Estilos do próprio menu */
#setup-top-menu {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 40px;
    background-color: var(--bg-white);
    flex-shrink: 0; /* Impede que o menu encolha */
    z-index: 1001; /* Garante que fique acima de tudo */
}

/* 4. Estilos dos filhos do menu */
.menu-left img {
    height: 40px;
    display: block;
}

.menu-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 5. Ajusta o formulário (que foi movido) para o layout horizontal */
.menu-right .modal-form {
    display: flex;
    gap: 2px;
    margin-bottom: 0; /* Remove a margem que tinha antes */
}

/* Esconde as labels "Largura (px)" e "Altura (px)" */
.menu-right .modal-form label {
    display: none;
}

/* Ajusta o tamanho dos inputs no menu */
.menu-right .modal-form input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.menu-right .modal-form input {
    width: 60px; /* Um tamanho fixo para os inputs */
    padding: 8px 10px;
    font-size: 14px;
    -moz-appearance: textfield;
}

/* style.css */
.magic-btn.active {
    background-color: #007bff;
    border-color: #0056b3;
    transform: scale(1.05);
}
#btnMagicMarker.active { background-color: #0984e3; }
#btnMagicAdd.active { background-color: #28a745; }
#btnMagicErase.active { background-color: #dc3545; }

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   8. ESTILOS PARA MOBILE E TELAS MENORES
   ========================================================================== */
/* --- AJUSTES PARA DESKTOPS MAIORES --- */
@media (min-width: 900px) {
    .setup-left {
        flex: 0 0 200px;
        padding: 40px;
    }
    .setup-left h2 {
        font-size: 28px;
    }
}

/* --- AJUSTES PARA TELAS ATÉ 768px (TABLETS E MOBILE) --- */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Evita zoom indesejado em inputs no iOS */
    }

    .setup-right .template-previews {
        column-count: 2;
    }

    .setup-right {
        padding: 20px;
    }

    #layerControls {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        transform: translateX(0%);
        width: 100%;
        max-width: calc(100% - 16px);
        border-radius: 0px 0px 12px 12px;
        padding: 8px;
        justify-content: space-between;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 20px;
        z-index: 100;
    }
    
    /* Agrupando regras para esconder a barra de rolagem no mobile */

    #layerControls .toolbar-group input[type="range"] {
        width: 100px;
    }
    
    #elementColorControls {
        gap: 10px;
    }
    
    .btn.btn-danger {
        margin-right: 20px;
    }

    .modal-content {
        padding: 20px;
    }

    /* 1. Muda a direção do layout principal para vertical */
    .editor-container {
        flex-direction: column;
    }

    /* 2. Transforma a barra lateral em barra superior */
    #left-toolbar {
        flex: 0 0 auto;
        height: auto;
        flex-direction: row;
        justify-content: space-between;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 10px 15px;
        background: linear-gradient(90deg, var(--accent-color) 0%, #3c83f6 100%);
    }

    .button-menu-left{
        display: flex;
    }

    /* 3. Ajusta os botões da Dock para ficarem menores e na horizontal */
    .dock-btn {
        width: auto;
        padding: 2px 12px;
        margin: 0 5px;
    }

    /* 4. Ajuste do Painel Lateral (que abre ao clicar) */
    #side-panel {
        border-right: none;
        border-top: 1px solid var(--border-color);
        order: 2;
    }

    /* 5. Ajuste da Área do Canvas */
    .main-content {
        width: 100%;
        height: 100%;
    }
}

/* --- AJUSTES PARA CELULARES --- */
@media (max-width: 480px) {
    .setup-right .template-previews {
        column-count: 1; /* Apenas uma coluna em telas muito pequenas */
    }
    #setup-top-menu {
        padding: 10px;
    }
}