/* static/styles.css*/

:root {
    --primary-color: #3498db;
    --secondary-color: #2ecc71;
    --background-color: #f4f7f9;
    --text-color: #34495e;
    --border-color: #bdc3c7;
    --input-bg: #ffffff;
    --input-focus-bg: #e8f0fe;
    --input-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --input-focus-shadow: 0 0 0 3px rgba(52, 152, 219, 0.25);
    --error-color: #e74c3c;
    --overlay-bg: rgba(255, 255, 255, 0.7);
}

/* --- Dark theme overrides (toggled by .theme-dark on <body>) --- */
body.theme-dark {
    --primary-color: #60a5fa;
    --secondary-color: #34d399;
    --background-color: #0f172a;
    --text-color: #e2e8f0;
    --border-color: #334155;
    --input-bg: #0b1220;
    --input-focus-bg: #141c2f;
    --input-shadow: 0 0 0 rgba(0,0,0,0);
    --input-focus-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25);
    --error-color: #f87171;
    --overlay-bg: rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px 20px;
    box-sizing: border-box;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    color: var(--primary-color);
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

h2 {
    color: var(--secondary-color);
    font-size: 1.8em;
    margin-top: 30px;
    margin-bottom: 20px;
}

nav {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.theme-toggle {
    border: 2px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 14px;
    cursor: pointer;
}
.theme-toggle:hover { filter: brightness(1.05); }

form {
    background-color: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
body.theme-dark form,
body.theme-dark .results-container {
    background-color: #0b1220;
    box-shadow: 0 0 0 rgba(0,0,0,0);
    border: 1px solid var(--border-color);
}

/* Reserve space for error text to avoid layout jumps */
.form-group {
    margin-bottom: 25px;
    position: relative;
    padding-bottom: 22px; /* room for absolute error label */
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-color);
    transition: color 0.3s ease;
}

input[type="text"] {
    width: 100%;
    padding: 12px 15px 12px 40px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px; /* mobile: prevents iOS zoom */
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    background-color: var(--input-bg);
    box-shadow: var(--input-shadow);
    color: var(--text-color);
}

input[type="text"]:focus-visible {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: var(--input-focus-shadow);
    background-color: var(--input-focus-bg);
}

.input-icon {
    position: absolute;
    top: 40px;
    left: 12px;
    color: var(--text-color);
    transition: color 0.3s ease;
    pointer-events: none; /* prevent cursor hiccups */
}

.form-group.focused .input-icon {
    color: var(--primary-color);
}

.plazo-group .plazo-inputs {
    display: flex;
    gap: 15px;
}

.plazo-group .plazo-inputs input {
    flex: 1;
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 30px;
    flex-wrap: wrap; /* mobile: wrap nicely */
}

button {
    padding: 12px 25px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-calculate {
    background-color: var(--primary-color);
    color: white;
}
.btn-calculate[disabled] { opacity: 0.7; cursor: wait; }

.btn-calculate:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn-reset {
    background-color: #e74c3c;
    color: white;
}

.btn-reset:hover {
    background-color: #c0392b;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn-download {
    background-color: #16a34a;
    color: #fff;
}
.btn-download:hover { filter: brightness(1.05); }

.results-container {
    background-color: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    margin-top: 40px;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none;
}

.error-message {
    color: var(--error-color);
    font-size: 0.9em;
    line-height: 1.1;
    position: absolute;   /* keep space stable */
    left: 0;
    bottom: 0;
    display: none;        /* toggled by JS to avoid layout shifts */
}

input.error {
    border-color: var(--error-color);
}

.summary {
    margin-bottom: 30px;
}

#summary-text {
    font-style: italic;
    color: var(--text-color);
    margin-bottom: 20px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.summary-item {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
body.theme-dark .summary-item { background-color: #0b1220; }

.summary-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.summary-item i {
    font-size: 2.2em;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.summary-item p {
    margin: 10px 0;
    font-size: 1em;
    color: #8892a6;
}

.summary-item strong {
    display: block;
    font-size: 1.3em;
    color: var(--secondary-color);
    margin-top: 10px;
}

.loan-summary {
    background-color: #f8f9fa;
    border-left: 4px solid var(--primary-color);
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-size: 1.1em;
    line-height: 1.6;
    color: #333;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.loan-summary:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.loan-summary strong {
    color: var(--primary-color);
    font-weight: 600;
}

.summary h2 {
    color: var(--primary-color);
    font-size: 2em;
    margin-bottom: 20px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 30px;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

tr:nth-child(even) {
    background-color: #f8f9fa;
}
body.theme-dark tr:nth-child(even) {
    background-color: #111a2f;
}

tr:hover {
    background-color: #e8f0fe;
}
body.theme-dark tr:hover {
    background-color: #1b2640;
}

.author {
    font-size: 1.2em;
    color: var(--secondary-color);
    margin-top: -10px;
    margin-bottom: 20px;
}

.site-footer {
    flex-shrink: 0;
    background-color: #2c3e50;
    color: #ecf0f1;
    padding: 40px 0 0;
    width: 100%;
}
body.theme-dark .site-footer { background-color: #0b1220; color: #cbd5e1; }

.footer-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-section {
    flex: 1;
    margin-bottom: 20px;
    min-width: 250px;
    padding: 0 15px;
}

.footer-section h3 {
    color: #3498db;
    font-size: 1.2em;
    margin-bottom: 15px;
    font-weight: 600;
}

.footer-section p {
    line-height: 1.6;
}

.footer-section.contact p {
    margin-bottom: 10px;
}

.footer-section.contact i {
    margin-right: 10px;
    color: #3498db;
}

.footer-section.social .social-icon {
    display: inline-block;
    margin-right: 15px;
    color: #ecf0f1;
    font-size: 1.5em;
    transition: color 0.2s ease;
}

.footer-section.social .social-icon:hover {
    color: #3498db;
}

/* Link-like button for footer legal link */
.linklike {
    background: none;
    border: none;
    color: #9bd; /* subtle link color on dark backgrounds */
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font: inherit;
}
.linklike:hover { filter: brightness(1.15); }
body.theme-dark .linklike { color: #93c5fd; }

.footer-bottom {
    background-color: #34495e;
    padding: 15px 0;
    text-align: center;
    margin-top: 20px;
    width: 100%;
}
body.theme-dark .footer-bottom { background-color: #0f172a; }

.copyright {
    font-size: 0.9em;
    color: #bdc3c7;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Loading overlay + spinner */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    display: none;           /* toggled via JS */
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}
#loading-overlay.active { display: flex; }
.spinner {
    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal (legal) */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(2px);
    z-index: 10000;
    display: none;
}
.modal-backdrop.show { display: block; }

.modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 10001;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.show { display: flex; }

.modal-dialog {
    width: min(840px, 95vw);
    max-height: 85vh;
    overflow: auto;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { margin: 0; }

.modal-body {
    padding: 18px;
}
.modal-body h4 { margin: 14px 0 8px; }
.modal-body p { margin: 8px 0; }
.modal-body ul { padding-left: 18px; margin: 8px 0; }
.modal-body li { margin: 6px 0; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.5s ease-in; }

@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.slide-in { animation: slideIn 0.5s ease-out; }

/* Tooltip styles */
.tooltip { position: relative; display: inline-block; }

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 10;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none; /* prevents hover fling/jank */
}

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

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ========= Mobile tweaks ========= */
@media (max-width: 768px) {
    .container { padding: 20px 10px; }
    form, .results-container { padding: 24px 16px; } /* a hair tighter */
    .loan-summary { font-size: 1em; padding: 15px; }
    .summary h2 { font-size: 1.6em; }
    .summary-grid { grid-template-columns: 1fr; }
    .summary-item { padding: 15px; }
    .summary-item i { font-size: 2em; }
    .summary-item strong { font-size: 1.15em; }
    .button-group { flex-direction: column; align-items: stretch; }
    button { width: 100%; }
    .plazo-group .plazo-inputs { flex-direction: column; gap: 10px; }
    .footer-content { flex-direction: column; align-items: center; }
    .footer-section { text-align: center; padding: 0 10px; width: 100%; }
    .footer-section.social { margin-top: 20px; }
}

@media (max-width: 480px) {
    h1 { font-size: 1.9em; }
    h2 { font-size: 1.4em; }
    input[type="text"] { font-size: 16px; } /* prevent iOS zoom */
    .loan-summary { font-size: 0.95em; padding: 12px; }
    .summary h2 { font-size: 1.5em; }
    .summary-item { padding: 12px; }
    .summary-item i { font-size: 1.8em; }
    .summary-item strong { font-size: 1.05em; }

    /* Table becomes cards for readability */
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    tr { border: 1px solid var(--border-color); margin-bottom: 10px; }
    td { border: none; position: relative; padding-left: 50%; }
    td:before {
        content: attr(data-label);
        position: absolute;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: bold;
    }
}

/* ========= Print tweaks (reliable PDF via window.print) ========= */
@media print {
    @page { margin: 12mm; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    nav, header, .site-footer, .footer-bottom, .button-group, .theme-toggle, #loading-overlay,
    .modal, .modal-backdrop { 
        display: none !important; 
    }
    #report-root { break-before: avoid; page-break-before: avoid; margin-top: 0 !important; }
    .print-header { display: block !important; margin-bottom: 8px; }
    h1, h2, .summary, .payment-details, table, tr, .summary-grid, .summary-item {
        break-inside: avoid; page-break-inside: avoid;
    }
    .container { padding: 0 !important; }
    .results-container { box-shadow: none; border: none; margin-top: 0 !important; padding: 0 !important; }
}
