/* Definições Globais e Anti-Overflow */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background-color: #f4f7f9;
    color: #333;
    /* Evita que o iOS redimensione o texto arbitrariamente */
    -webkit-text-size-adjust: 100%;
}

body {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.app-container {
    background-color: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 1000px;
    box-sizing: border-box;
}

h1 {
    color: #2c3e50;
    font-size: 2.2rem;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
    text-align: center;
}

/* Menu de Navegação */
.nav-menu {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
}

.nav-btn {
    background: #e0e0e0;
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1rem;
    color: #555;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.nav-btn.active {
    background-color: #007bff;
    color: white;
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

/* Painéis de Ferramentas */
.tool-panel {
    display: none;
}

.tool-panel.active {
    display: block;
}

h2 {
    color: #007bff;
    text-align: center;
    margin-bottom: 20px;
}

/* Formulários e Inputs */
.form-section {
    margin-bottom: 20px;
}

.form-section label, .table-header {
    font-weight: bold;
    color: #555;
}

input[type="text"], input[type="date"], input[type="number"], textarea {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 5px;
}

.status-msg {
    margin-top: 10px;
    font-weight: bold;
    color: #28a745;
    text-align: center;
}

/* Ishikawa */
.ishikawa-factors {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.factor-column {
    display: flex;
    flex-direction: column;
}

.factor-column h3 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 5px;
}

.factor-input {
    min-height: 100px;
    resize: vertical;
}

/* 5W2H */
.table-5w2h {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 15px;
    align-items: center;
}

.table-header {
    background-color: #f0f0f0;
    padding: 10px;
    border-radius: 5px;
    text-align: center;
}

/* Pareto */
.pareto-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.pareto-item .problema { flex: 3; }
.pareto-item .frequencia { flex: 1; }

.pareto-item button.remove-item {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: 4px;
    cursor: pointer;
}

#add-pareto-item {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
}

.action-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 20px;
    width: 100%;
}

/* Container de botões de Arquivos */
.file-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.file-btn {
    flex: 1;
    padding: 10px;
    font-size: 0.95rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    transition: background-color 0.2s ease;
}

.export-btn {
    background-color: #17a2b8;
    color: white;
}

.export-btn:hover {
    background-color: #138496;
}

.import-label {
    background-color: #6c757d;
    color: white;
    display: inline-block;
}

.import-label:hover {
    background-color: #5a6268;
}

.chart-container {
    margin-top: 30px;
    height: 350px;
    position: relative;
    width: 100%;
    max-width: 100%;
}

.chart-container canvas {
    max-width: 100% !important;
    height: 100% !important;
}

.pareto-analysis {
    text-align: left;
    margin-top: 20px;
    border-top: 1px solid #e0e0e0;
    padding-top: 20px;
}

.main-footer {
    margin-top: 40px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-weight: bold;
    color: #7f8c8d;
}

/* Corretor de Escala para Mobile-First Estrito */
@media (max-width: 768px) {
    body {
        padding: 8px; /* Reduz espaço externo para não esmagar conteúdo */
        align-items: flex-start;
    }
    
    .app-container {
        padding: 12px;
        border-radius: 6px;
    }

    h1 { 
        font-size: 1.4rem; 
        margin-bottom: 15px;
    }
    
    h2 {
        font-size: 1.2rem;
    }

    .nav-menu {
        flex-direction: column; /* Botões empilhados evitam quebra de linha feia */
        width: 100%;
        gap: 6px;
    }

    .nav-btn {
        width: 100%;
        text-align: center;
        padding: 10px;
        font-size: 0.95rem;
    }

    .ishikawa-factors {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .table-5w2h {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .table-header {
        text-align: left;
        background: transparent;
        padding: 4px 0 0 2px;
        font-size: 0.9rem;
    }

    .pareto-item {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
        border-bottom: 1px solid #eee;
        padding-bottom: 10px;
    }

    .pareto-item button.remove-item {
        width: 100%;
    }
    
    .chart-container {
        height: 280px; /* Reduz altura do gráfico para telas menores */
    }

    .file-actions {
        flex-direction: column;
        gap: 6px;
    }
}
