/* Centralizar texto do botão SALVAR */
#saveBtn {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-weight: bold;
    width: 100%;
}
/* Ajuste para textos longos no histórico */
.history-entry p, .history-entry h4, .history-entry h5 {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-line;
    max-width: 100%;
}

.history-entry {
    max-width: 100%;
    overflow-x: auto;
}
/* Smaller text for rows inside history modal (less prominent than horário) */
.history-row {
    font-size: 0.85rem;
    color: #333;
    margin-bottom: 4px;
}
/* Green background for gains line in history modal */
.history-gains {
    background-color: #d4edda; /* light green */
    border: 1px solid #c3e6cb;
    color: #155724; /* dark green text */
    padding: 6px 8px;
    border-radius: 4px;
    font-weight: 600;
    margin-bottom: 6px;
}
/* Estilos personalizados para corresponder à sua captura */
.table-header-blue {
    background-color: #007bff;
    color: white;
    padding: 10px;
}

.table-header-yellow {
    background-color: #ffc107;
}

.highlight-green {
    background-color: #28a745;
    color: white;
}

.table-bordered th,
.table-bordered td {
    border: 1px solid #dee2e6;
}

.card {
    border: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* text-size-adjust removed — kept compatibility to valid properties only */

/* Estilos para inputs na tabela */

/* Campo CLI. AFET. ainda maior */
.cli-afet-input {
    /* Use full width of the cell but limit max width to avoid overflow */
    width: 100%;
    max-width: 260px;
    padding: 6px 12px;
    font-size: 1.08rem;
    box-sizing: border-box;
}

/* Aumentar campo CLI para ficar melhor ajustado (mais largo) */
.cli-afet-input {
    width: 100%;
    max-width: 360px; /* aumenta o máximo para telas maiores */
    padding: 8px 12px;
    font-size: 1.1rem;
}

/* Campos CLI. AFET. MANOBRA e TMA AFET. MANOBRA ainda menores */
.cli-afet-manobra-input,
.tma-afet-manobra-input {
    width: 60px; /* fixed small input to avoid stretching columns */
    padding: 4px 6px;
    font-size: 0.85rem;
    box-sizing: border-box;
}

/* Remove as setas dos campos number (Chrome, Edge, Opera) */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
/* Remove as setas dos campos number (Firefox) */
input[type=number] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.form-control-sm {
    padding: 6px 8px;
    font-size: 0.925rem;
    height: auto;
    width: 100%;
    box-sizing: border-box;
}

td {
    padding: 6px 8px; /* restored comfortable cell padding for better button spacing */
}

/* Estilo para o botão Remover, Duplicar e X */
.btn-sm {
    padding: 4px 8px; /* slightly larger tap targets */
    font-size: 0.8rem;
    margin-right: 6px;
    vertical-align: middle;
}

/* Estilo para legendas e rodapé */
.mt-2 p {
    margin-bottom: 0.5rem;
}

.card-body p {
    margin: 0;
    font-size: 0.9rem;
}

.card-body .btn {
    margin-top: 5px;
}

/* Banner do relatório que aparece abaixo dos botões */
.report-banner {
    background-color: #d9eefb; /* azul claro */
    color: #0b3d91; /* azul escuro para contraste */
    padding: 10px 15px;
    border-radius: 6px;
    margin-top: 6px;
    font-weight: 600;
}
.report-banner.d-none {
    display: none !important;
}
.report-banner.d-block {
    display: block !important;
}

/* Estilo do botão Gerar Relatório centralizado (azul claro) */
.btn-generate-report {
    background-color: #cfe9ff; /* azul claro */
    color: #0b3d91; /* texto azul escuro para contraste */
    border: 1px solid #9fd1ff;
    padding: 8px 18px;
    font-weight: 700;
    border-radius: 6px;
}
.btn-generate-report:hover {
    background-color: #b7e0ff;
}

/* Subtotal boxes under each table */
.subtotal-boxes {
    display: flex;
    gap: 12px;
}
.subtotal-card {
    background: #f7f9fb;
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 110px;
}
.subtotal-label {
    font-size: 0.85rem;
    color: #333;
}
.subtotal-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0b3d91;
    margin-top: 6px;
}

/* Ajuste para layout lado a lado e botão X */
.row > .col-md-6 {
    /* Aumenta o espaçamento lateral entre as colunas para evitar colagem das tabelas */
    padding: 0 22px;
    box-sizing: border-box;
}

/* Evita overflow horizontal inesperado quando inputs ou botões ficarem maiores */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Garante que a tabela ocupe toda a largura disponível da coluna e que seus conteúdos possam quebrar linhas */
.table {
    width: 100%;
    table-layout: auto;
}

.table td input, .table th {
    word-break: break-word;
}

table {
    margin-bottom: 0;
}

tbody tr td:nth-child(5) {
    border-right: none;
}

td[style*="rowSpan"] {
    vertical-align: middle;
    text-align: center;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
}

/* Estilo para o campo de incidência */
#incidence {
    max-width: 150px;
}

/* Estilo para o menu de contexto */
.context-menu {
    display: block;
    cursor: default;
}

.context-menu div {
    cursor: pointer;
}

.context-menu div:hover {
    background-color: #f0f0f0;
}

/* Fundo legado substituído pelo tema moderno abaixo */

/* Overlay escuro para legibilidade do conteúdo */
.container {
    max-width: 1200px; /* Limita largura em telas grandes para melhor leitura */
    margin: 0 auto; /* centraliza */
    background-color: rgba(255, 255, 255, 0.95); /* Fundo branco com pequena transparência */
    border-radius: 10px; /* Bordas arredondadas */
    padding: 18px; /* Espaçamento interno padrão */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08); /* Sombra suave */
}

/* Responsive tweaks */
@media (max-width: 1200px) {
    .row > .col-md-6 { padding: 0 18px; }
}

@media (max-width: 992px) {
    /* Em laptops menores reduzimos os gutters e os inputs ficam menores */
    .row > .col-md-6 { padding: 0 12px; }
    .cli-afet-input { max-width: 200px; }
    .report-banner { font-size: 0.95rem; }
}

@media (max-width: 768px) {
    /* Em tablets e celulares empilha as colunas e amplia inputs para 100% */
    .row > .col-md-6 { width: 100%; padding: 0; }
    .col-md-6 { margin-bottom: 12px; }
    .table { font-size: 0.95rem; }
    .cli-afet-input, .cli-afet-manobra-input, .tma-afet-manobra-input {
        max-width: 100%;
        width: 100%;
    }
    .btn-sm { margin-right: 4px; }
}

@media (max-width: 420px) {
    /* Ajustes finos para telas muito estreitas */
    .report-banner { font-size: 0.9rem; padding: 8px 10px; }
    .table td input { font-size: 0.9rem; }
    #saveBtn { font-size: 0.95rem; padding: 8px; }
}

/* Quando quisermos posicionar subtotais acima do cabeçalho */
.subtotal-boxes.before-header {
    justify-content: flex-start;
    margin-bottom: 8px;
}

/* Reduce spacing between gains panel and report banner */
.report-gains {
    margin-bottom: 6px;
}

/* Center text inside report banner */
#reportBanner {
    text-align: center;
}

/* Ocultar visualmente (mas manter no DOM) as colunas "CLI. AFET. MANOBRA" e "TMA AFET. MANOBRA"
   Mantemos inputs para cálculo, mas escondemos a coluna 3 e 4 para limpar a UI. */
/* Esconde o cabeçalho nas colunas 3 e 4 */
table.table thead th:nth-child(3),
table.table thead th:nth-child(4) {
    display: none;
}

/* Esconde as células dessas colunas no corpo da tabela */
table.table tbody td:nth-child(3),
table.table tbody td:nth-child(4) {
    display: none;
    width: 0; /* evita que ocupem espaço */
    padding: 0; /* remove padding para alinhar melhor */
}

/* Esconde os inputs dentro das células (caso existam) */
table.table tbody td:nth-child(3) input,
table.table tbody td:nth-child(4) input {
    display: none !important;
}

/* Modernização visual da calculadora */
:root {
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border-soft: #dbe4ef;
    --text-main: #102033;
    --text-muted: #64748b;
    --brand: #1d4ed8;
    --brand-dark: #173ea5;
    --success: #15803d;
    --danger: #dc2626;
    --info: #0e7490;
    --shadow-soft: 0 18px 50px rgba(15, 23, 42, 0.12);
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.18), transparent 32rem),
        linear-gradient(135deg, #eef4ff 0%, #f8fafc 52%, #eefdf6 100%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
    min-height: 100vh;
    padding: 28px 14px;
}

.container.app-container {
    max-width: 1320px;
    padding: 28px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(219, 228, 239, 0.9);
    border-radius: 28px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
}

.app-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    border-radius: 22px;
    color: #fff;
}

.eyebrow {
    display: inline-flex;
    margin-bottom: 6px;
    color: #bfdbfe;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.app-title {
    margin: 0;
    color: #fff;
    font-size: clamp(1.45rem, 2.2vw, 2.25rem);
    font-weight: 800;
}

.app-subtitle {
    max-width: 620px;
    margin: 8px 0 0;
    color: #dbeafe;
    font-size: 0.98rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.comparison-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.comparison-card,
.details-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.subtotal-boxes.before-header {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 16px;
}

.subtotal-card {
    min-width: 0;
    align-items: flex-start;
    padding: 16px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.subtotal-label {
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.subtotal-value {
    margin-top: 8px;
    color: var(--brand);
    font-size: clamp(1.35rem, 2vw, 1.85rem);
    font-weight: 850;
    line-height: 1;
}

.table-header-blue {
    margin: 0 0 14px;
    padding: 12px 16px;
    background: #eff6ff;
    color: var(--brand-dark);
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    font-size: 0.95rem;
    font-weight: 850;
    letter-spacing: 0.12em;
}

.table-card {
    border: 1px solid var(--border-soft);
    border-radius: 18px;
    overflow: auto;
    background: var(--surface-soft);
}

.table {
    margin-bottom: 0;
}

.table > :not(caption) > * > * {
    padding: 12px;
}

.table-header-yellow {
    background: #f8fafc;
}

.table-header-yellow th {
    color: #334155;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.table tbody tr {
    background: #fff;
}

.table tbody tr + tr {
    border-top: 1px solid #eef2f7;
}

.table-bordered th,
.table-bordered td {
    border-color: #e6edf5;
}

.form-label {
    color: #475569;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.form-control,
.form-control-sm,
.table input.form-control,
.table input.form-control-sm {
    min-height: 40px;
    border-color: #cbd5e1;
    border-radius: 12px;
    color: var(--text-main);
    background-color: #fff;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.form-control:focus,
.form-control-sm:focus,
.table input.form-control:focus,
.table input.form-control-sm:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.16);
}

.date-time-input,
input[data-type="dataFim"] {
    min-width: 195px;
}

.cli-afet-input,
input[data-type="cliAfet"] {
    width: 100%;
    min-width: 130px;
    max-width: none;
}

tbody td:last-child {
    min-width: 178px;
}

.row-actions,
tbody td:last-child {
    vertical-align: middle;
}

.row-actions .btn,
tbody td:last-child .btn {
    margin: 3px;
}

.btn {
    border-radius: 12px;
    border-width: 1px;
    font-weight: 750;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.14);
}

.btn:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.32);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--brand);
    border-color: var(--brand);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--brand-dark);
    border-color: var(--brand-dark);
}

.btn-success {
    background-color: var(--success);
    border-color: var(--success);
}

.btn-danger {
    background-color: var(--danger);
    border-color: var(--danger);
}

.btn-info {
    background-color: var(--info);
    border-color: var(--info);
    color: #fff;
}

.btn-info:hover,
.btn-info:focus {
    color: #fff;
}

.results-section {
    margin-top: 22px;
}

.report-gains {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px 28px;
    margin: 0;
    padding: 18px;
    background: linear-gradient(135deg, #dcfce7 0%, #effdf5 100%);
    border: 1px solid #86efac;
    border-radius: 20px;
    color: #14532d;
    font-size: 1.08rem;
    font-weight: 700;
}

.report-banner {
    padding: 14px 18px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 16px;
    color: #1e3a8a;
    cursor: pointer;
    flex: 1 1 320px;
    font-weight: 800;
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.08);
}

.report-banner:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.28);
    outline-offset: 2px;
}

.report-output {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.copy-feedback {
    min-height: 24px;
    color: #15803d;
    font-size: 0.9rem;
    font-weight: 800;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.copy-feedback.is-visible {
    opacity: 1;
}

.details-card {
    margin-bottom: 8px;
}

#incidence {
    max-width: none;
}

.modal-content {
    border: 0;
    border-radius: 22px;
    box-shadow: var(--shadow-soft);
}

.modal-header,
.modal-footer {
    border-color: #e2e8f0;
}

.history-entry {
    padding: 14px;
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    background: #fff;
}

.history-entry + .history-entry {
    margin-top: 12px;
}

.history-gains {
    background: #dcfce7;
    border-color: #86efac;
    color: #14532d;
    border-radius: 12px;
}

.history-modal-content .modal-body {
    background: #f8fafc;
}

.history-empty-state {
    padding: 28px;
    background: #fff;
    border: 1px dashed var(--border-soft);
    border-radius: 18px;
    color: var(--text-muted);
    font-weight: 700;
    text-align: center;
}

.history-card {
    padding: 18px;
    border-radius: 20px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.07);
}

.history-card-header,
.history-footer-actions,
.history-totals {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.history-card-header h4 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.05rem;
    font-weight: 850;
}

.history-kicker {
    display: inline-flex;
    margin-bottom: 4px;
    color: var(--brand);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.history-actions,
.history-footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.history-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.history-summary-grid div {
    min-width: 0;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
}

.history-summary-grid span {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.history-summary-grid strong {
    display: block;
    color: var(--text-main);
    overflow-wrap: anywhere;
}

.history-totals {
    margin: 10px 0 16px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    color: #1e3a8a;
    font-weight: 800;
}

.history-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.history-details-grid h5 {
    margin: 0 0 8px;
    color: var(--brand-dark);
    font-size: 0.85rem;
    font-weight: 850;
    letter-spacing: 0.08em;
}

.history-row-card {
    display: grid;
    grid-template-columns: auto repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    color: #334155;
    font-size: 0.86rem;
}

.history-row-card + .history-row-card {
    margin-top: 8px;
}

.history-empty-note {
    margin: 0;
    padding: 10px;
    color: var(--text-muted);
    background: #fff;
    border: 1px dashed var(--border-soft);
    border-radius: 12px;
}

.report-type-modal .modal-header {
    align-items: flex-start;
}

.modal-kicker {
    display: inline-flex;
    margin-bottom: 4px;
    color: var(--brand);
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.report-type-help {
    margin: 0 0 14px;
    color: var(--text-muted);
}

.report-type-options {
    display: grid;
    gap: 12px;
}

.report-type-option {
    width: 100%;
    padding: 16px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    color: var(--text-main);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.report-type-option strong,
.report-type-option span {
    display: block;
}

.report-type-option strong {
    margin-bottom: 5px;
    color: var(--brand-dark);
    font-size: 0.9rem;
    letter-spacing: 0.05em;
}

.report-type-option span {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.report-type-option:hover,
.report-type-option:focus-visible {
    border-color: var(--brand);
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.14);
    transform: translateY(-1px);
}

.report-type-option:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.22);
    outline-offset: 2px;
}

@media (max-width: 1100px) {
    .app-navbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .toolbar {
        justify-content: flex-start;
    }
}

@media (max-width: 900px) {
    .app-shell {
        padding: 16px 8px;
    }

    .container.app-container {
        padding: 18px;
        border-radius: 22px;
    }

    .comparison-grid {
        grid-template-columns: 1fr;
    }

    .history-summary-grid,
    .history-details-grid {
        grid-template-columns: 1fr;
    }

    .history-row-card {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 576px) {
    .app-navbar,
    .comparison-card,
    .details-card {
        padding: 16px;
        border-radius: 18px;
    }

    .toolbar,
    .toolbar .btn,
    #addRowAntes,
    #addRowDepois {
        width: 100%;
    }

    .toolbar .btn {
        justify-content: center;
    }

    .subtotal-boxes.before-header {
        grid-template-columns: 1fr;
    }

    .report-gains {
        align-items: stretch;
        flex-direction: column;
        text-align: left;
    }

    .report-output {
        width: 100%;
    }

    .history-actions,
    .history-footer-actions,
    .history-actions .btn,
    .history-footer-actions .btn {
        width: 100%;
    }
}