:root {
    --primary-color: #3a7ca5;
    --primary-dark: #2c5d7c;
    --secondary-color: #f8f9fa;
    --border-color: #dee2e6;
    --success-color: #28a745;
    --error-color: #dc3545;
    --text-color: #343a40;
    --light-gray: #f5f5f5;
    --soft-blue: #d1e7f3;
    --soft-green: #d4edda;
    --soft-green-hover: #c3e6cb;
    --soft-orange: #ffe8d6;
    --soft-orange-hover: #fed7b3;
    --soft-gray: #e9ecef;
    --soft-gray-hover: #d8dde1;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #f8f9fa;
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    max-width: 550px;
    margin-left: auto;
    margin-right: auto;
}

h1 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.calculator {
    background-color: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    max-width: 550px;
    margin-left: auto;
    margin-right: auto;
}

.destacado {
    font-style: italic;
    font-weight: bold;
}

.form-group {
    margin-bottom: 25px;
    position: relative;
}

.form-group label,
.npv-form-container label,
.mirr-form-container label {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 20px;
}

.input-group {
    display: flex;
    align-items: center;
}

.input-group input {
    flex: 1;
}

.btn-toggle {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s;
    /* A margem será controlada pelo grupo quando houver mais de um botão */
    margin-left: 10px;
}

.btn-toggle:hover {
    background-color: var(--primary-dark);
}

/* --- NOVOS ESTILOS PARA O GRUPO DE BOTÕES DE TAXA --- */
.rate-button-group {
    display: flex;
    align-items: center;
    gap: 5px;
    /* Espaçamento entre os botões */
    margin-left: 10px;
    /* Margem do grupo todo */
}

/* Remove a margem individual dos botões quando estão dentro do grupo */
.rate-button-group .btn-toggle {
    margin-left: 0;
}

/* --- FIM DOS NOVOS ESTILOS --- */


input,
select {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 20px;
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(58, 124, 165, 0.2);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 12px auto;
    padding-right: 35px;
}

.button-group {
    display: grid;
    /* ALTERAÇÃO: Torna a grade responsiva. Ela tentará criar colunas com no mínimo 130px. */
    /* Se não couberem 3, ela se ajustará para 2 ou 1 automaticamente, evitando estouro. */
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 35px;
}

button {
    padding: 14px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    /* <-- Leve ajuste para mais conforto visual */
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #e9ecef;
}

.btn-info {
    background-color: var(--soft-blue);
    color: var(--primary-dark);
    border: 1px solid #b4cad6;
}

.btn-info:hover {
    background-color: #b9d7e9;
    border-color: #a0c2d6;
}

.btn-tool {
    background-color: var(--soft-green);
    color: #155724;
    border: 1px solid #badbcc;
}

.btn-tool:hover {
    background-color: var(--soft-green-hover);
    border-color: #a6c9b3;
}

.btn-action {
    background-color: var(--soft-orange);
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.btn-action:hover {
    background-color: var(--soft-orange-hover);
    border-color: #f1b0b7;
}

.btn-log {
    background-color: var(--soft-gray);
    color: var(--text-color);
    border: 1px solid #ced4da;
}

.btn-log:hover {
    background-color: var(--soft-gray-hover);
    border-color: #adb5bd;
}


.result-container {
    margin-top: 35px;
    padding: 25px;
    border-radius: 10px;
    background-color: var(--light-gray);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    display: none;
}

.result-container.visible {
    display: block;
}

.result-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-dark);
}

.result-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--primary-color);
}

.error {
    padding: 15px;
    margin-bottom: 20px;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    color: var(--error-color);
    display: none;
}

.error.visible {
    display: block;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
}

.modal-content {
    background-color: white;
    margin-top: 5vh;
    margin-bottom: 5vh;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    position: relative;
}


.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}

.close:hover,
.close:focus {
    color: var(--text-color);
    text-decoration: none;
}

.history-item {
    padding: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.history-item:last-child {
    border-bottom: none;
}

.history-detail {
    margin: 5px 0;
    font-size: 16px;
}

.history-result {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 18px;
}

.empty-history,
.empty-amortization {
    text-align: center;
    padding: 20px;
    color: #6c757d;
}

footer {
    margin-top: 30px;
    text-align: center;
    color: #6c757d;
    font-size: 14px;
    padding: 10px 0;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    max-width: 550px;
    margin-left: auto;
    margin-right: auto;
}

.amortization-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 14px;
}

.amortization-table th,
.amortization-table td {
    padding: 10px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.amortization-table th {
    background-color: var(--light-gray);
    color: var(--primary-dark);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.amortization-table tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

.amortization-table tr:last-child td {
    font-weight: bold;
    border-top: 2px solid var(--primary-color);
    background-color: var(--light-gray);
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.amortization-summary {
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background-color: var(--light-gray);
    border-radius: 5px;
    font-weight: 600;
}

.amortization-summary p {
    margin: 5px 0;
}


@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header,
    footer {
        max-width: 100%;
        padding-left: 15px;
        padding-right: 15px;
    }

    .calculator {
        padding: 20px;
        max-width: 100%;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
    }

    .amortization-table {
        font-size: 12px;
    }

    .amortization-table th,
    .amortization-table td {
        padding: 6px 4px;
    }

    .amortization-summary {
        font-size: 13px;
    }
}

.result-row {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 25px;
    margin-top: 20px;
}

.result-column {
    flex: 1;
    min-width: 200px;
    text-align: center;
}

.result-row.three-columns .result-column {
    flex-basis: 30%;
    min-width: 150px;
}

@media (max-width: 600px) {
    .result-row.three-columns {
        flex-direction: column;
        align-items: center;
    }

    .result-row.three-columns .result-column {
        flex-basis: auto;
        width: 80%;
        min-width: 0;
        margin-bottom: 15px;
    }
}

.custom-dropdown {
    position: relative;
    width: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.dropdown-button {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    cursor: pointer;
    background-color: white;
    transition: border-color 0.3s;
    font-size: 18px;
    line-height: 1.5;
}

.dropdown-button:hover,
.dropdown-button:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(58, 124, 165, 0.2);
}

.dropdown-icon {
    margin-left: 8px;
    color: var(--primary-color);
    font-size: 10px;
    transition: transform 0.2s ease-in-out;
}

.dropdown-list.visible .dropdown-icon {
    transform: rotate(180deg);
}


.dropdown-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    width: 100%;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
    padding: 5px 0;
    display: none;
}

.dropdown-list.visible {
    display: block;
}


.dropdown-item {
    padding: 10px 15px !important;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 16px;
    white-space: nowrap;
}

.dropdown-item:hover {
    background-color: var(--light-gray);
}

.dropdown-item.selected {
    background-color: var(--soft-blue);
    color: var(--primary-dark);
    font-weight: 600;
}


.calculator-modal {
    max-width: 340px;
    padding-top: 15px;
}

#calculatorContent h2 {
    text-align: center;
    font-size: 1.4em;
    color: var(--primary-dark);
    margin-bottom: 15px;
}

.calculator-modal .close {
    margin-right: 5px;
    margin-top: -5px;
}

.basic-calculator {
    background-color: #f8f9fa;
    border-radius: 10px;
    padding: 15px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    margin-left: 5px;
    color: var(--primary-color);
    font-weight: bold;
}

.tooltip .tooltiptext {
    visibility: hidden;
    background-color: #333;
    color: #fff;
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    font-size: 13px;
    line-height: 1.5;
    white-space: normal;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    width: auto;
    min-width: 180px;
    max-width: 280px;
    position: absolute;
    z-index: 101;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
}

.tooltip .tooltiptext.tooltiptext-above {
    bottom: calc(100% + 10px);
    top: auto;
}

.tooltip .tooltiptext.tooltiptext-above::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 100%;
    border-width: 6px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.tooltip .tooltiptext.tooltiptext-below {
    top: calc(100% + 10px);
    bottom: auto;
}

.tooltip .tooltiptext.tooltiptext-below::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 100%;
    top: auto;
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #333 transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

input[type="number"].highlighted,
input[type="text"].highlighted {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(58, 124, 165, 0.3);
}

.calc-display {
    margin-bottom: 15px;
}

.calc-display input {
    width: 100%;
    padding: 15px;
    font-size: 28px;
    text-align: right;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: white;
    color: var(--text-color);
    font-family: 'Consolas', 'Menlo', 'Courier New', monospace;
}

.calc-buttons {
    display: grid;
    grid-gap: 8px;
}

.calc-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 8px;
}

.calc-btn {
    padding: 15px 0;
    font-size: 18px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    background-clip: padding-box;
}

.calc-btn:active {
    transform: translateY(1px);
}


.calc-btn-num {
    background-color: white;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.calc-btn-num:hover {
    background-color: #f1f3f5;
}

.calc-btn-op {
    background-color: var(--soft-gray);
    color: var(--text-color);
    border: 1px solid #ced4da;
}

.calc-btn-op:hover {
    background-color: var(--soft-gray-hover);
}

.calc-btn-clear,
.calc-btn-backspace,
.calc-btn-ce {
    background-color: var(--soft-orange);
    color: #721c24;
    font-weight: bold;
    border: 1px solid #f5c6cb;
}

.calc-btn-clear:hover,
.calc-btn-backspace:hover,
.calc-btn-ce:hover {
    background-color: var(--soft-orange-hover);
}

.calc-btn-equal {
    background-color: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-dark);
}

.calc-btn-equal:hover {
    background-color: var(--primary-dark);
}

.calc-btn-const {
    background-color: var(--soft-blue);
    color: var(--primary-dark);
    border: 1px solid #b4cad6;
}

.calc-btn-const:hover {
    background-color: #b9d7e9;
}

.calc-btn-apply {
    background-color: var(--success-color);
    color: white;
    grid-column: span 4;
    font-weight: bold;
    border: 1px solid #1e7e34;
}

.calc-btn-apply:hover {
    background-color: #1e7e34;
}

#calculatorModal {
    z-index: 1050;
}

/* Adicione estas regras ao final do seu arquivo calculadora.css */

/* --- Estilos para o Seletor de Modo ALG/RPN --- */
.calc-mode-selector {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
    border-radius: 5px;
    background-color: var(--soft-gray);
    padding: 4px;
}

.calc-mode-btn {
    flex: 1;
    padding: 8px 10px;
    border: none;
    background-color: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    border-radius: 5px;
    transition: all 0.3s ease;
}

.calc-mode-btn.active {
    background-color: white;
    color: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* --- Estilos para o Visor RPN --- */
#calcDisplayContainer {
    margin-bottom: 15px;
}

.calc-display-rpn {
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px 15px;
    font-family: 'Consolas', 'Menlo', 'Courier New', monospace;
    text-align: right;
    display: flex;
    flex-direction: column;
}

.rpn-stack-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: #6c757d;
    /* Cinza suave para registros T, Z, Y */
    font-size: 16px;
    line-height: 1.4;
}

.rpn-stack-row.main {
    color: var(--text-color);
    /* Cor principal para o registro X */
    font-size: 28px;
    font-weight: 600;
}

.rpn-reg {
    color: var(--primary-color);
    font-weight: normal;
    font-size: 0.8em;
    margin-right: 10px;
}

.rpn-stack-row.main .rpn-reg {
    font-size: 0.7em;
}

/* Esconder o visor ALG quando em modo RPN */
.calculator-modal.rpn-mode #algDisplay {
    display: none;
}

/* Mostrar o visor RPN quando em modo RPN */
.calculator-modal.rpn-mode #rpnDisplay {
    display: flex;
    /* Usamos flex por causa do flex-direction: column */
}

/* Esconder o visor RPN por padrão (quando não está em rpn-mode) */
.calculator-modal:not(.rpn-mode) #rpnDisplay {
    display: none;
}

/* --- Estilos para Tooltip Customizada Mobile --- */
.custom-tooltip-popup {
    position: fixed;
    /* Fica fixo na tela */
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px 15px;
    z-index: 2000;
    /* Garante que fique acima de tudo */
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    /* Não interfere com cliques */
    font-size: 14px;
    max-width: 80%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.custom-tooltip-popup.visible {
    opacity: 1;
}

/* --- Estilos para Botão com Ícone de Tooltip (CORRIGIDO) --- */
/* --- Estilos para Botão com Ícone (ALINHAMENTO CENTRALIZADO) --- */

/* ADICIONE esta nova regra */
/* --- Estilos para Botão com Ícone (ALINHAMENTO CENTRALIZADO) --- */

/* Esta regra garante que TODOS os botões na grade se centralizem da mesma forma */
.button-group>button {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Esta regra adiciona o espaçamento APENAS ao botão que tem um ícone */
.btn-with-icon {
    gap: 8px;
}

/* Estilo para o ícone '?' em si (sem alterações aqui) */
.tooltip-trigger-icon {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    font-weight: bold;
    font-family: 'Segoe UI', sans-serif;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    cursor: help;
    user-select: none;
    transition: background-color 0.2s;
}

.tooltip-trigger-icon:hover {
    background-color: var(--primary-dark);
}

/* --- Estilo para destacar o label principal --- */
.form-group .label-highlight {
    font-weight: 700;
    /* Torna a fonte mais forte que o padrão 600 dos outros labels */
}

/* --- Estilos para Tooltips Inseridas nos Botões RPN --- */
.rpn-special-btn {
    position: relative;
    /* Mantém a referência para o ícone */

    /* Estas 3 linhas garantem que o texto principal fique perfeitamente centralizado */
    display: flex;
    justify-content: center;
    align-items: center;
}

.tooltip-icon-inset {
    position: absolute;
    /* Posiciona o ícone como uma camada flutuante */
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    line-height: 14px;
    font-size: 10px;
    font-weight: normal;
    opacity: 0.7;
}

.rpn-special-btn:hover .tooltip-icon-inset {
    opacity: 1;
}

/* --- Estilo para Tabela de Amortização Responsiva --- */
.amortization-table-container {
    overflow-x: auto;
    /* A MÁGICA ACONTECE AQUI: Adiciona rolagem horizontal se necessário */
    -webkit-overflow-scrolling: touch;
    /* Melhora a experiência de rolagem em iPhones/iPads */
    margin: 0 -20px;
    /* Compensa o padding do modal para a rolagem ir de ponta a ponta */
    padding: 0 20px;
    /* Adiciona o padding de volta dentro do container */
}