* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #333;

    /* Versão abreviada e otimizada */
    background: #0a0909 url('img/logo_pluxen.png') no-repeat center;
}

html {
    height: 100%;
}

/* ========================================= */
/* ESTILOS DA TELA DE LOGIN          */
/* ========================================= */
/* Estilo geral da área de autenticação */
#login-area {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column; /* Para empilhar o formulário e a mensagem de erro */
    min-height: 100vh;
    background-color: #f0f2f5;
    font-family: Arial, sans-serif;
}

/* Estilo do "card" de autenticação */
.auth-container {
    background: #ffffff;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-container h2 {
    margin-bottom: 25px;
    color: #333;
}

/* Estilo dos campos de input */
.auth-container input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-sizing: border-box; /* Garante que o padding não afete a largura total */
    font-size: 16px;
}

.auth-container input:focus {
    outline: none;
    border-color: #007bff;
}

/* Estilo dos botões */
.auth-container button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    background-color: #007bff;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.auth-container button:hover {
    background-color: #0056b3;
}

/* Estilo específico do botão Google */
#google-login-button {
    background-color: #ffffff;
    color: #444;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px; /* Espaço entre o ícone e o texto */
    margin-top: 10px;
}

#google-login-button:hover {
    background-color: #f8f8f8;
}

#google-login-button img {
    width: 20px;
    height: 20px;
}

/* Divisor "ou" */
.divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: #aaa;
    margin: 20px 0;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #ddd;
}

.divider:not(:empty)::before {
    margin-right: .5em;
}

.divider:not(:empty)::after {
    margin-left: .5em;
}

/* Link "Esqueceu a senha" */
.forgot-password {
    display: block;
    text-align: right;
    margin-bottom: 20px;
    font-size: 14px;
    color: #007bff;
    text-decoration: none;
}
.forgot-password:hover {
    text-decoration: underline;
}


/* Link para trocar entre login e registo */
.auth-switch {
    margin-top: 25px;
    font-size: 14px;
    color: #555;
}

.auth-switch a {
    color: #007bff;
    font-weight: bold;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Mensagem de erro */
#auth-error {
    color: red;
    margin-top: 15px;
    font-weight: bold;
}


/* ========================================= */
/* ESTILOS DA APLICAÇÃO PRINCIPAL            */
/* ========================================= */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fff; /* Garante que a imagem não apareça na tela principal */
}

/* ... (o restante do CSS permanece igual) ... */

/* CABEÇALHO E BARRA DE FERRAMENTAS */
.header, .toolbar {
    flex-shrink: 0; 
    z-index: 1000;
}

/* !! AQUI ESTÁ A REGRA CORRIGIDA E COMBINADA PARA O HEADER !! */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom: 4px solid red;
    /* Regras de alinhamento que agora estão no lugar certo */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
}

.logo {
    font-size: 16px;
    font-weight: bold;
}

/* Estilos para a nova área de informações do usuário */
#user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}
#user-info p {
    margin: 0;
    font-size: 14px;
    color: white;
}
#user-info #logout-button {
    padding: 6px 12px;
    font-size: 13px;
    background-color: #525f7f;
    border-radius: 5px;
    cursor: pointer;
    border: 1px solid #8a98b5;
    color: white;
}
#user-info #logout-button:hover {
    background-color: #3b4660;
}

.toolbar {
    background: #fff;
    border-bottom: 1px solid #ddd;
    padding: 8px 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.tool-group {
    display: flex;
    gap: 5px;
}
.tool-btn {
    padding: 6px 10px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
}
.tool-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* ÁREA DE CONTEÚDO PRINCIPAL (SIDEBARS E CANVAS) */
.main-content {
    display: flex;
    flex-direction: row; 
    flex-grow: 1; 
    overflow: hidden; 
}

.sidebar, .properties-panel {
    background: #fff;
    overflow-y: auto;
    flex-shrink: 0;
}
.sidebar {
    width: 200px;
    border-right: 1px solid #ddd;
    padding: 15px;
}
.properties-panel {
    width: 250px;
    border-left: 1px solid #ddd;
    padding: 15px;
}

.canvas-container {
    flex-grow: 1; 
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e9e9e9;
    overflow: hidden; 
}
#canvas {
    background: #fff;
    touch-action: none;
}

/* ESTILOS DE COMPONENTES INTERNOS */
.sidebar-section h3 { font-size: 14px; margin-bottom: 10px; }
.component-item { width: 100%; padding: 8px; margin-bottom: 5px; border: 1px solid #ddd; background: #f9f9f9; border-radius: 4px; cursor: pointer; font-size: 12px; }
.properties-panel h3 { font-size: 16px; margin-bottom: 15px; }
.property-item { margin-bottom: 12px; }


/* MODAL DE CÁLCULOS */
#calculations-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    overflow: auto;
    padding: 20px;
}
#calculations-modal .modal-content {
    background: #fff;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
#calculations-modal table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
#calculations-modal th, #calculations-modal td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}
#calculations-modal th {
    background-color: #f2f2f2;
}
#calculations-modal ul {
    list-style-type: none;
    padding-left: 20px;
}
#calculations-modal ul ul {
    padding-left: 20px;
}

/* --- ÁREA DA LEGENDA DE FIAÇÃO --- */
.legend-area {
    flex-shrink: 0; /* Impede que a área encolha */
    background-color: #f7f7f7;
    border-top: 1px solid #ddd;
    max-height: 200px; /* Altura máxima para a área */
    overflow-y: auto; /* Rolagem vertical se o conteúdo for grande */
    padding: 0 15px 10px 15px; /* Espaçamento interno */
}

/* --- REGRA PARA ESPAÇAMENTO DA ÁREA DE PROJETOS --- */
#projects-area {
    margin-top: 25px; /* Adiciona espaço acima */
    padding-top: 15px; /* Adiciona um espaço interno */
    border-top: 1px solid #eee; /* Adiciona uma linha sutil de separação */
}


/* ========================================= */
/* DESIGN RESPONSIVO PARA MOBILE (VERSÃO MELHORADA) */
/* ========================================= */

@media (max-width: 768px) {
    /* Faz o container principal ocupar toda a altura da tela */
    .app-container {
        height: 100vh;
        max-height: 100vh;
    }

    /* O conteúdo principal agora é uma coluna que ocupa todo o espaço */
    .main-content {
        flex-direction: column;
        /* height: 100%; --- REMOVIDO PARA CORRIGIR O CÁLCULO DE ALTURA DO FLEXBOX */
    }

    /* --- INÍCIO DA NOVA REGRA PARA A BARRA DE FERRAMENTAS SUPERIOR --- */
    .toolbar {
        /* Força os grupos de botões a ficarem em uma única linha */
        flex-wrap: nowrap;
        /* Habilita a barra de rolagem horizontal */
        overflow-x: auto;
        /* Melhora a experiência de rolagem em dispositivos de toque */
        -webkit-overflow-scrolling: touch;
        /* Opcional: Deixa a barra de rolagem mais fina */
        scrollbar-width: thin; 
    }

    .toolbar .tool-group {
        /* Impede que os grupos de botões encolham */
        flex-shrink: 0;
    }
    /* --- FIM DA NOVA REGRA --- */


    /* BARRA DE FERRAMENTAS DE COMPONENTES (TOPO) */
    .sidebar {
        width: 100%;
        height: auto;
        flex-shrink: 0; /* Impede que a barra encolha */
        border-right: none;
        border-bottom: 1px solid #ddd;
        display: flex; /* Alinha os grupos de ferramentas lado a lado */
        overflow-x: auto; /* A MÁGICA: Permite rolar horizontalmente */
        padding: 5px;
        background-color: #f7f7f7;
    }

    /* Cada grupo de ferramentas dentro da barra lateral */
    .sidebar-section {
        white-space: nowrap; /* Impede que os botões quebrem a linha */
        padding: 0 10px;
        border-right: 1px solid #eee;
    }
    .sidebar-section:last-child {
        border-right: none;
    }
    .sidebar-section h3 {
        margin-bottom: 5px;
    }

    /* Itens/botões dentro da barra lateral */
    .component-item {
        display: inline-block; /* Alinha os botões na mesma linha */
        width: auto;
        margin-right: 5px;
    }

    /* ÁREA DO CANVAS (CENTRO) */
    .canvas-container {
        flex-grow: 1;  /* Ocupa todo o espaço vertical restante */
        min-height: 200px; /* Garante uma altura mínima */
    }

    /* PAINEL DE PROPRIEDADES (FUNDO) */
    .properties-panel {
        width: 100%;
        max-height: 50vh; /* limite de altura */
        overflow-y: auto; /* rolagem interna só na barra */
        -webkit-overflow-scrolling: touch;
        border-left: none;
        border-top: 1px solid #ddd;
        flex-shrink: 0;
        background-color: #fff;
        position: relative; /* garante que não vaze */
        z-index: 1; /* mantém acima do canvas, se necessário */
    }


    /* Oculta a área da legenda em telas pequenas */
    .legend-area {
        display: none;
    }
}


/* === ESTILOS DA LEGENDA === */
.legend-description {
    font-weight: 500;
}

.legend-wiring {
    font-family: monospace;
    background: #f8f9fa;
    padding: 4px;
    border-radius: 3px;
}

.legend-summary {
    background: #f8f9fa;
    padding: 15px;
    border-top: 1px solid #dee2e6;
    font-size: 14px;
}

.legend-summary p {
    margin: 5px 0;
}

.legend-table-container {
    margin-top: 10px; /* Margem superior para separar do canvas */
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto; /* Garante a rolagem da tabela */
}

.legend-table-container h3 {
    background: #34495e;
    color: white;
    margin: 0;
    padding: 15px;
    font-size: 16px;
}

.wiring-legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.wiring-legend-table th {
    background: #ecf0f1;
    padding: 12px 8px;
    text-align: left;
    font-weight: bold;
    border-bottom: 2px solid #bdc3c7;
}

.wiring-legend-table td {
    padding: 8px 6px;
    border-bottom: 1px solid #ecf0f1;
    vertical-align: top;
    line-height: 1.3;
    white-space: normal; /* Permite quebra de linha no desktop */
}

/* Garante que a tabela não quebre linha no mobile, forçando a rolagem */
@media (max-width: 768px) {
    .wiring-legend-table th, .wiring-legend-table td {
        white-space: nowrap;
    }
}

.legend-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    text-align: center;
    min-width: 24px;
}

.legend-badge.trunk {
    background: #8e44ad;
}

.legend-badge.circuit {
    background: #3498db;
}

.legend-wiring {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    padding: 6px 4px;
    border-radius: 3px;
    font-size: 10px;
    line-height: 1.2;
}

.legend-gauge {
    font-family: 'Courier New', monospace;
    background: #e8f4f8;
    padding: 6px 4px;
    border-radius: 3px;
    font-size: 10px;
    line-height: 1.2;
}

/* Destaque especial para o tronco */
.legend-row.legend-t {
    background-color: #f8f3ff;
    border-left: 4px solid #8e44ad;
}

.legend-row.legend-t .legend-wiring,
.legend-row.legend-t .legend-gauge {
    font-weight: bold;
    background: #e8dff5;
}

.legend-summary {
    background: #f8f9fa;
    padding: 15px;
    border-top: 1px solid #dee2e6;
    font-size: 14px;
}

.legend-summary p {
    margin: 5px 0;
}