@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&display=swap');

:root {
    --layer-domain-bg: rgba(254, 240, 138, 0.05);
    --layer-domain-border: rgba(254, 240, 138, 0.3);
    --layer-app-bg: rgba(252, 165, 165, 0.05);
    --layer-app-border: rgba(252, 165, 165, 0.3);
    --layer-adapter-bg: rgba(134, 239, 172, 0.05);
    --layer-adapter-border: rgba(134, 239, 172, 0.3);
    --layer-infra-bg: rgba(147, 197, 253, 0.05);
    --layer-infra-border: rgba(147, 197, 253, 0.3);

    --node-bg: #1e293b;
    --node-header-bg: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent-primary: #38bdf8;
    --danger: #ef4444;
    
    --header-height: 60px;
    --sidebar-width: 280px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; 
    padding: 0;
    width: 100vw; 
    height: 100vh;
    background: #0f172a;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow: hidden; 
}

#app-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.hidden { display: none !important; }

#loading-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: #0f172a;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.loader {
    width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent-primary); border-radius: 50%;
    animation: spin 1s linear infinite; margin-bottom: 15px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.app-header {
    height: var(--header-height);
    flex-shrink: 0; 
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 20px;
    background: rgba(30, 41, 59, 0.95);
    border-bottom: 1px solid #334155;
    z-index: 50;
    backdrop-filter: blur(8px);
    user-select: none;
}

.app-title-block h1 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; color: #fff; }
.app-title-block p { margin: 0; font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.beta-tag { background: #facc15; color: black; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: bold; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.separator { width: 1px; height: 24px; background: #475569; margin: 0 5px; }

.template-selector {
    display: flex; align-items: center; gap: 8px;
    background: rgba(0,0,0,0.3);
    padding: 4px 10px; border-radius: 6px; border: 1px solid #475569;
}
.template-selector i { color: #fbbf24; }
.template-selector select {
    background: transparent; border: none; color: white; font-size: 13px; outline: none; cursor: pointer;
}
.template-selector select option { background: #1e293b; color: white; }

button { cursor: pointer; border: none; outline: none; transition: all 0.2s; font-family: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }

.btn-primary { background: var(--accent-primary); color: #0f172a; padding: 8px 16px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 0 10px rgba(56, 189, 248, 0.3); }

.btn-secondary { 
    background: rgba(255,255,255,0.05); color: #e2e8f0; 
    padding: 8px 12px; border-radius: 6px; 
    border: 1px solid #475569; font-size: 13px; 
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: #94a3b8; }

.btn-active { 
    background: var(--accent-primary) !important; color: #0f172a !important; 
    border-color: var(--accent-primary) !important; font-weight: bold; 
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.score-pill { display: flex; gap: 5px; font-size: 13px; background: rgba(0,0,0,0.3); padding: 5px 12px; border-radius: 20px; border: 1px solid #475569; align-items: center; margin-right: 10px; }
#score-val { color: #facc15; }

.dojo-container { 
    flex: 1; 
    display: flex; 
    overflow: hidden; 
    position: relative; 
    width: 100%; 
}

.sidebar-wrapper { 
    width: var(--sidebar-width); 
    flex-shrink: 0; 
    height: 100%; 
    position: relative; 
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40; 
    overflow: hidden; 
}

.sidebar-wrapper.collapsed { 
    width: 0 !important; 
    border: none;
}

.dojo-sidebar, .properties-panel {
    width: var(--sidebar-width); 
    height: 100%; 
    background: #0f172a; 
    border-right: 1px solid #334155; 
    display: flex; 
    flex-direction: column;
    user-select: none;
}
.properties-panel { border-right: none; border-left: 1px solid #334155; }

.sidebar-header { padding: 15px; border-bottom: 1px solid #334155; display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h3 { margin: 0; font-size: 14px; font-weight: 600; color: #e2e8f0; }
.btn-mini-toggle { background: transparent; color: #94a3b8; border: 1px solid #475569; border-radius: 4px; width: 24px; height: 24px; }
.btn-mini-toggle:hover { color: white; border-color: white; }

.sidebar-content, .props-content { flex: 1; overflow-y: auto; padding: 15px; }

/* -- SCROLLBAR PADRONIZADA (Incluindo Modal de Pastas) -- */
.sidebar-content, .props-content, #feedback-content,
.folder-config-scroll, .visual-tree-content, .simple-textarea {
    scrollbar-width: thin;
    scrollbar-color: #475569 rgba(2,6,23,0.6);
}
.sidebar-content::-webkit-scrollbar,
.props-content::-webkit-scrollbar,
#feedback-content::-webkit-scrollbar,
.folder-config-scroll::-webkit-scrollbar,
.visual-tree-content::-webkit-scrollbar,
.simple-textarea::-webkit-scrollbar {
    width: 10px;
    height: 10px; /* Para scroll horizontal */
}
.sidebar-content::-webkit-scrollbar-track,
.props-content::-webkit-scrollbar-track,
#feedback-content::-webkit-scrollbar-track,
.folder-config-scroll::-webkit-scrollbar-track,
.visual-tree-content::-webkit-scrollbar-track,
.simple-textarea::-webkit-scrollbar-track {
    background: rgba(2,6,23,0.6);
    border: 1px solid #334155;
    border-radius: 10px;
}
.sidebar-content::-webkit-scrollbar-thumb,
.props-content::-webkit-scrollbar-thumb,
#feedback-content::-webkit-scrollbar-thumb,
.folder-config-scroll::-webkit-scrollbar-thumb,
.visual-tree-content::-webkit-scrollbar-thumb,
.simple-textarea::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 10px;
    border: 2px solid rgba(2,6,23,0.8);
}
.sidebar-content::-webkit-scrollbar-thumb:hover,
.props-content::-webkit-scrollbar-thumb:hover,
#feedback-content::-webkit-scrollbar-thumb:hover,
.folder-config-scroll::-webkit-scrollbar-thumb:hover,
.visual-tree-content::-webkit-scrollbar-thumb:hover,
.simple-textarea::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

.component-group { margin-bottom: 20px; }
.component-group h4 { font-size: 11px; text-transform: uppercase; color: #64748b; margin-bottom: 8px; font-weight: 700; }

.draggable-item {
    display: flex; align-items: center; gap: 10px;
    background: #1e293b; border: 1px solid #334155;
    padding: 10px 12px; border-radius: 6px; margin-bottom: 6px; cursor: grab;
    font-size: 13px; transition: all 0.2s;
}
.draggable-item:hover { background: #334155; border-color: var(--accent-primary); transform: translateX(4px); }
.draggable-item[data-layer="domain"] { border-left: 3px solid #fcd34d; }
.draggable-item[data-layer="app"] { border-left: 3px solid #f87171; }
.draggable-item[data-layer="adapter"] { border-left: 3px solid #4ade80; }
.draggable-item[data-layer="infra"] { border-left: 3px solid #60a5fa; }

.btn-collapsed-trigger {
    position: absolute; 
    top: 15px; 
    z-index: 100;
    background: #334155; 
    border: 1px solid #475569; 
    color: white;
    width: 24px; height: 30px; 
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

.btn-collapsed-trigger:not(.right) { left: 0; border-radius: 0 4px 4px 0; }
.btn-collapsed-trigger.right { right: 0; border-radius: 4px 0 0 4px; }

.dojo-main {
    flex: 1; position: relative;
    background: #020617;
    background-image: radial-gradient(#1e293b 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden; cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

.canvas-area {
    position: absolute; width: 4200px; height: 4200px; 
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    transform-origin: center center; will-change: transform;
}

.layer-ring {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    border-radius: 50%; border: 2px dashed rgba(255,255,255,0.1);
    display: flex; justify-content: center; pointer-events: none;
}
.layer-label {
    position: absolute; top: 15px; font-size: 11px; font-weight: 700;
    text-transform: uppercase; opacity: 0.8; letter-spacing: 1px;
    user-select: none;
}
.layer-label.center { top: 45%; }

.layer-infra { width: 3200px; height: 3200px; background: var(--layer-infra-bg); color: #93c5fd; border-color: var(--layer-infra-border); }
.layer-adapter { width: 2400px; height: 2400px; background: var(--layer-adapter-bg); color: #86efac; border-color: var(--layer-adapter-border); }
.layer-app { width: 1500px; height: 1500px; background: var(--layer-app-bg); color: #fca5a5; border-color: var(--layer-app-border); }
.layer-domain { width: 800px; height: 800px; background: var(--layer-domain-bg); color: #fef08a; border-color: var(--layer-domain-border); }

#nodes-layer { position: absolute; inset: 0; z-index: 20; pointer-events: none; }

.arch-node {
    position: absolute; top: 0; left: 0;
    transform: translate(-50%, -50%);
    width: 200px; min-height: 100px;
    background: var(--node-bg);
    border: 1px solid #475569;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: flex; flex-direction: column;
    pointer-events: auto; cursor: default;
    user-select: none;
    -webkit-user-select: none;
    transition: box-shadow 0.2s, border-color 0.2s;
    overflow: visible; 
}
.arch-node:hover { border-color: #94a3b8; z-index: 100; }
.arch-node.selected { border-color: var(--accent-primary); box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.3); z-index: 100; }
.arch-node.connecting-source { border-color: #fbbf24; box-shadow: 0 0 15px rgba(251, 191, 36, 0.4); }
.arch-node.target-hover { border-color: #4ade80; box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.5); }
.arch-node.error-pos { border: 2px solid #ef4444; }
.arch-node.error-type { border: 2px solid #f97316; }

.node-header {
    background: var(--node-header-bg);
    padding: 6px 10px;
    border-bottom: 1px solid #475569;
    cursor: grab;
    border-radius: 6px 6px 0 0;
}
.node-stereotype { display: block; font-size: 9px; text-transform: uppercase; color: #cbd5e1; margin-bottom: 2px; text-align: center; }
.node-title { display: block; font-size: 13px; font-weight: 700; color: #fff; text-align: center; white-space: normal; overflow-wrap: anywhere; word-break: break-word; }

.arch-node[data-layer="domain"] .node-header { border-top: 3px solid #fcd34d; }
.arch-node[data-layer="app"] .node-header { border-top: 3px solid #f87171; }
.arch-node[data-layer="adapter"] .node-header { border-top: 3px solid #4ade80; }
.arch-node[data-layer="infra"] .node-header { border-top: 3px solid #60a5fa; }

.node-body, .node-footer { padding: 6px 10px; font-family: 'Fira Code', monospace; font-size: 10px; color: #e2e8f0; line-height: 1.4; }
.node-body { border-bottom: 1px solid #334155; min-height: 20px; background: rgba(0,0,0,0.2); }
.node-footer { min-height: 20px; background: rgba(0,0,0,0.1); border-radius: 0 0 6px 6px; }

.code-line { display: block; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; pointer-events: none; }
.code-line.attr { color: #9cdcfe; }
.code-line.method { color: #dcdcaa; }

.resizer {
    position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, #475569 50%); z-index: 102;
    border-radius: 0 0 6px 0;
}

.connection-handle {
    width: 14px;
    height: 14px;
    background-color: var(--accent-primary);
    border: 2px solid #fff;
    border-radius: 50%;
    position: absolute;
    right: -7px;
    top: 50%;
    transform: translateY(-50%);
    cursor: crosshair;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 150;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

.arch-node:hover .connection-handle { opacity: 1; }
.connection-handle:hover { transform: translateY(-50%) scale(1.2); background-color: #fff; border-color: var(--accent-primary); }

#connections-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

.connection-path { 
    fill: none; stroke: #64748b; stroke-width: 2px; pointer-events: none; transition: stroke 0.2s; 
}

.hit-path { 
    fill: none; stroke: transparent; stroke-width: 20px; pointer-events: stroke; cursor: pointer; 
}
.hit-path:hover + .connection-path { stroke: #fff; filter: drop-shadow(0 0 3px white); }

.temp-connection-path {
    fill: none; stroke: var(--accent-primary); stroke-width: 2px; stroke-dasharray: 5,5; pointer-events: none;
}
.connection-path.invalid { stroke: #ef4444; stroke-dasharray: 5,5; }

.arch-feedback {
    position: absolute; bottom: 20px; right: 300px; width: 320px;
    background: #1e293b; border: 1px solid #475569; border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.6); z-index: 200; overflow: hidden;
}
.feedback-header { background: #334155; padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; }
.feedback-header h4 { margin: 0; font-size: 13px; color: #fff; }
#feedback-content { padding: 15px; max-height: 200px; overflow-y: auto; font-size: 12px; color: #cbd5e1; }
.violation { padding: 8px; margin-bottom: 6px; background: rgba(239, 68, 68, 0.1); border-left: 3px solid #ef4444; border-radius: 4px; }
.success-msg { color: #4ade80; text-align: center; padding: 10px; font-weight: bold; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 11px; font-weight: 600; color: #94a3b8; text-transform: uppercase; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; background: #020617; border: 1px solid #475569; color: white;
    padding: 8px; border-radius: 4px; font-family: 'Inter', sans-serif; font-size: 12px;
}
.form-group input, .form-group textarea { user-select: text; -webkit-user-select: text; }
.form-group textarea { font-family: 'Fira Code', monospace; height: 80px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent-primary); outline: none; }

.hint-text { font-size: 12px; color: #64748b; margin-bottom: 10px; text-align: center; }

/* MODALS */
.modal-overlay { 
    position: fixed; inset: 0; background: rgba(0,0,0,0.8); 
    z-index: 10000; /* Z-Index padrão para modals */
    display: flex; align-items: center; justify-content: center; 
}
/* CORREÇÃO FIX 1: Z-Index maior para o modal customizado (Alert/Prompt) para ficar sobre o de pastas */
#custom-modal { z-index: 20000 !important; }

.modal-box { background: #1e293b; border: 1px solid #475569; padding: 24px; border-radius: 8px; width: 350px; }
.modal-title { font-size: 18px; font-weight: bold; color: white; margin-bottom: 10px; }
.modal-message { color: #cbd5e1; margin-bottom: 20px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-input { 
    width: 100%; background: #020617; border: 1px solid #475569; color: white;
    padding: 10px; border-radius: 4px; font-family: 'Inter', sans-serif; font-size: 14px;
}
.modal-input:focus { border-color: var(--accent-primary); outline: none; }


/* =========================
   Folder Structure Modal
   ========================= */
.modal-box.folder-modal {
    /* CORREÇÃO FIX 3: Aumentado para melhor visualização */
    width: min(1400px, 98vw);
    height: min(800px, 90vh);
    padding: 16px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.folder-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.folder-modal-header .modal-title { font-size: 16px; margin: 0; }
.folder-actions { display: flex; align-items: center; gap: 10px; }

/* Layout de 3 colunas: Config | Arvore Visual | Editor de Texto */
.folder-modal-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 260px 1fr 1.2fr;
    gap: 16px;
    align-items: stretch;
}

/* Painel de Configuração */
.folder-config-panel {
    display: flex; flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.folder-config-lang-row {
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.folder-config-lang-row span {
    font-size: 12px;
    font-weight: 700;
    color: #e2e8f0;
}

.folder-config-lang-select {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
}
.folder-config-header {
    padding: 10px; background: rgba(255, 255, 255, 0.05);
    font-size: 12px; font-weight: 700; color: #e2e8f0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.folder-config-scroll {
    flex: 1; overflow-y: auto; padding: 10px;
}
.folder-config-group { margin-bottom: 15px; }
.folder-config-group-title {
    font-size: 11px; font-weight: 800; color: var(--accent-primary);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.folder-config-item {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: #cbd5e1; margin-bottom: 4px; cursor: pointer;
}
.folder-config-item:hover { color: white; }
.folder-config-item input { margin: 0; cursor: pointer; accent-color: var(--accent-primary); }


/* Arvore Visual Interativa */
.visual-tree-container {
    background: #0b1121; /* Fundo bem escuro */
    border: 1px solid #334155;
    border-radius: 8px;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.visual-tree-toolbar {
    padding: 8px; background: #1e293b; border-bottom: 1px solid #334155;
    display: flex; gap: 8px; flex-wrap: wrap;
}
.visual-tree-toolbar input {
    background: #0f172a; border: 1px solid #475569; color: white;
    padding: 4px 8px; border-radius: 4px; font-size: 12px; min-width: 120px;
}
.visual-tree-toolbar button {
    background: #334155; color: #cbd5e1; border: 1px solid #475569;
    padding: 4px 8px; border-radius: 4px; font-size: 11px;
}
.visual-tree-toolbar button:hover { background: #475569; color: white; }
.visual-tree-content {
    flex: 1; overflow-y: auto; padding: 10px;
    font-family: 'Fira Code', monospace; font-size: 13px;
}

/* Nós da Arvore */
.tree-node {
    display: flex; flex-direction: column;
}
.tree-row {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 6px; cursor: pointer; border-radius: 4px;
    color: #cbd5e1; user-select: none;
}
.tree-row:hover { background: rgba(255, 255, 255, 0.05); color: white; }
.tree-row.selected { background: rgba(56, 189, 248, 0.15); color: var(--accent-primary); }

.tree-indent { display: inline-block; width: 20px; height: 100%; }
.tree-icon { width: 16px; text-align: center; }
.fa-folder { color: #facc15; } /* Amarelo */
.fa-folder-open { color: #facc15; }
.fa-file-code { color: #60a5fa; } /* Azul */
.fa-file { color: #94a3b8; } /* Cinza */
.fa-chevron-right, .fa-chevron-down { font-size: 10px; color: #64748b; width: 12px; }

/* Editor de Texto Simples (Coluna Direita) */
.text-editor-container {
    display: flex; flex-direction: column;
    background: #1e293b; border: 1px solid #334155; border-radius: 8px; overflow: hidden;
}
.text-editor-header {
    padding: 8px; background: #334155; border-bottom: 1px solid #475569;
    font-size: 11px; font-weight: bold; color: #cbd5e1; display: flex; justify-content: space-between; align-items: center;
}
.btn-copy-mini { background: transparent; border: 1px solid #64748b; color: #cbd5e1; padding: 2px 8px; border-radius: 4px; font-size: 10px; }
.btn-copy-mini:hover { background: white; color: #0f172a; }

.simple-textarea {
    flex: 1; width: 100%; height: 100%; border: none; resize: none;
    background: #0f172a; color: #94a3b8; padding: 10px;
    font-family: 'Fira Code', monospace; font-size: 11px; line-height: 1.5;
    outline: none;
}

/* Responsividade do Modal */
@media (max-width: 1000px) {
    .folder-modal-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    .folder-config-panel { max-height: 200px; }
    .text-editor-container { max-height: 200px; }
}

/* Export Image Modal */
.modal-box.export-image-modal{ width: min(1100px, 92vw); height: min(760px, 86vh); padding: 14px 14px 16px; border-radius: 14px; display: flex; flex-direction: column; gap: 12px; }
.export-image-body{ flex: 1; min-height: 0; background: #020617; border: 1px solid #475569; border-radius: 12px; position: relative; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 12px; }
.export-image-loading{ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #cbd5e1; font-size: 14px; background: rgba(2,6,23,0.65); backdrop-filter: blur(2px); }
.export-image-preview{ max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; display: none; }