/* --- General & Root Variables --- */
:root {
    --primary-color: #005A9C; /* Professional Blue */
    --accent-color: #2E8540; /* Trustworthy Green */
    --text-color: #333;
    --background-color: #FFFFFF;
    --border-color: #E0E0E0;
    --light-gray: #f9f9f9;
    --font-family: 'Helvetica Neue', Arial, sans-serif;
}

body.dark-mode {
    --primary-color: #4A90E2;
    --accent-color: #50E3C2;
    --text-color: #EAEAEA;
    --background-color: #1A1A1A;
    --border-color: #444;
    --light-gray: #282828;
}

/* --- Base Styles --- */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-family);
    margin: 0;
    line-height: 1.6;
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3 { color: var(--primary-color); line-height: 1.2; }
h1 { font-size: 2.5rem; margin-bottom: 1rem; }
h2 { font-size: 2rem; border-bottom: 2px solid var(--border-color); padding-bottom: 0.5rem; margin-top: 2rem; }
a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--accent-color); }
pre { background-color: var(--light-gray); padding: 1rem; border-radius: 5px; overflow-x: auto; }

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.main-content-area {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    padding: 2rem 1rem;
}
.content-main { flex: 3; min-width: 300px; }
.sidebar { flex: 1; min-width: 250px; }

/* --- Header --- */
header {
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo { font-size: 1.5rem; font-weight: bold; color: var(--primary-color); }
header nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 1rem; }
.header-extra { display: flex; align-items: center; }
#darkModeToggle { background: none; border: none; font-size: 1.5rem; cursor: pointer; }

/* --- Dropdown Menu --- */
.dropdown { position: relative; display: inline-block; }
.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--background-color);
    min-width: 160px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    z-index: 1;
    border: 1px solid var(--border-color);
    border-radius: 5px;
}
.dropdown-content a { color: var(--primary-color); padding: 12px 16px; text-decoration: none; display: block; }
.dropdown-content a:hover { background-color: var(--light-gray); }
.dropdown:hover .dropdown-content { display: block; }

/* --- Hero Section --- */
.hero {
    background-color: var(--light-gray);
    padding: 4rem 1rem;
    text-align: center;
}
.hero h1 { font-size: 3rem; }

/* --- Cards & Grids --- */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}
.card {
    display: block;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.card h3 { margin-top: 0; color: var(--accent-color); }

/* --- Sidebar Widgets --- */
.widget {
    background: var(--light-gray);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}
.widget h3 { margin-top: 0; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.widget ul { list-style: none; padding: 0; }
.widget ul li a { display: block; padding: 0.5rem 0; }
.ad-placeholder { border: 2px dashed var(--border-color); text-align: center; padding: 3rem 1rem; }

/* --- Search --- */
#siteSearch { width: 100%; padding: 0.75rem; border: 1px solid var(--border-color); border-radius: 5px; }
#searchResults { margin-top: 1rem; }
#searchResults a { display: block; padding: 0.5rem; border-radius: 3px; }
#searchResults a:hover { background-color: var(--border-color); }

/* --- Footer --- */
footer {
    background-color: #333;
    color: #ccc;
    padding: 2rem 0;
    margin-top: 2rem;
}
footer a { color: #fff; }
.footer-columns { display: flex; flex-wrap: wrap; gap: 2rem; justify-content: space-between; }
.footer-col { flex: 1; min-width: 200px; }
.footer-col h4 { color: #fff; border-bottom: 1px solid #555; padding-bottom: 0.5rem; }
.footer-col ul { list-style: none; padding: 0; }
.newsletter-form { display: flex; }
.newsletter-form input { flex-grow: 1; padding: 0.5rem; border: none; border-radius: 3px 0 0 3px; }
.newsletter-form button { padding: 0.5rem 1rem; background: var(--primary-color); color: #fff; border: none; cursor: pointer; border-radius: 0 3px 3px 0; }
.footer-bottom { text-align: center; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #555; }

/* --- Calculator Page Specific --- */
.calculator-container {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    background: var(--light-gray);
    padding: 2rem;
    border-radius: 8px;
    margin-top: 2rem;
}
.calculator-form { flex: 1; min-width: 280px; }
.calculator-results { flex: 1; min-width: 280px; background: var(--background-color); padding: 1.5rem; border-radius: 8px; border: 1px solid var(--border-color); }

.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; font-weight: bold; margin-bottom: 0.5rem; }
.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
}
.result-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; border-bottom: 1px solid var(--border-color); }
.result-item:last-of-type { border-bottom: none; }
.result-item strong { font-size: 1.5rem; color: var(--accent-color); }
.result-item .highlight { color: var(--primary-color); font-weight: bold; }
.result-actions { margin-top: 1rem; display: flex; gap: 1rem; }
.result-actions button {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
}
.result-actions .disabled-btn { background-color: #ccc; cursor: not-allowed; }

.social-share a { margin-right: 1rem; padding: 0.5rem 1rem; border: 1px solid var(--primary-color); border-radius: 5px; }

/* --- Responsive --- */
@media (max-width: 768px) {
    header .container { flex-direction: column; gap: 1rem; }
    header nav ul { justify-content: center; flex-wrap: wrap; }
    .main-content-area { flex-direction: column; }
    .calculator-container { flex-direction: column; }
    h1, .hero h1 { font-size: 2rem; }
}
/* --- Static Page Content --- */
.static-content {
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.static-content h1 {
    text-align: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}

.static-content h2 {
    border-bottom: none;
    color: var(--accent-color);
    margin-top: 2.5rem;
}

.static-content p, .static-content li {
    font-size: 1.1rem;
    color: var(--text-color);
}

.contact-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 2rem;
}

.contact-form .form-group {
    margin-bottom: 0;
}

.contact-form textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    font-family: inherit;
    min-height: 150px;
}

.contact-form button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    align-self: flex-start;
}
.contact-form button:hover {
    opacity: 0.9;
}
/* --- Reusable Button Style --- */
.btn-primary {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    text-align: center;
    text-decoration: none;
    transition: opacity 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}
/* --- UI Feedback Colors --- */
.loss-color {
    color: #D0021B !important; /* A clear, professional red for losses */
}

/* In dark mode, brighten the red slightly for better contrast */
body.dark-mode .loss-color {
    color: #FF4F64 !important;
}
/* --- Amortization Table Styles --- */
.amortization-table-container {
    margin-top: 2rem;
    max-height: 500px; /* Makes the table scrollable */
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 5px;
}

#amortizationTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#amortizationTable th, #amortizationTable td {
    padding: 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

#amortizationTable th {
    background-color: var(--light-gray);
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: bold;
}

#amortizationTable tbody tr:nth-child(even) {
    background-color: var(--light-gray);
}
body.dark-mode #amortizationTable tbody tr:nth-child(even) {
    background-color: #2c2c2c;
}

#amortizationTable td:first-child, #amortizationTable th:first-child {
    text-align: center; /* Center the payment number */
}
/* --- Scientific Calculator Styles --- */
.sci-calculator-container {
    max-width: 500px;
    margin: 2rem auto;
    padding: 1.5rem;
    background-color: var(--light-gray);
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.calculator-display {
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    text-align: right;
    font-family: 'Courier New', Courier, monospace;
}

.display-expression {
    min-height: 24px;
    font-size: 1rem;
    color: #888;
    word-break: break-all;
}

.display-main {
    min-height: 48px;
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--text-color);
    word-break: break-all;
}

.calculator-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
}

.calculator-grid button {
    padding: 1rem;
    font-size: 1.2rem;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.calculator-grid button:hover {
    background-color: var(--border-color);
}

.btn-operator {
    background-color: #e6f0ff; /* Light blue */
    color: var(--primary-color);
    font-weight: bold;
}
body.dark-mode .btn-operator {
    background-color: #2a3a50;
}

.btn-function {
    background-color: #e6f7ee; /* Light green */
    color: var(--accent-color);
}
body.dark-mode .btn-function {
    background-color: #2a4a3a;
}

.btn-equals {
    grid-column: span 2;
    background-color: var(--accent-color);
    color: white;
}
body.dark-mode .btn-equals {
    background-color: var(--primary-color);
}
/* --- Fraction Calculator Styles --- */
.fraction-calculator-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

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

.fraction-input-group input {
    width: 100px;
    text-align: center;
    font-size: 1.5rem;
}

.fraction-input-group hr {
    width: 100%;
    border: 1px solid var(--text-color);
    margin: 0.25rem 0;
}

#fractionOperator {
    padding: 0.75rem;
    font-size: 1.5rem;
    font-weight: bold;
}
/* --- Percentage Calculator Tabs --- */
.percent-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.percent-tab {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    background-color: transparent;
    border: none;
    font-size: 1rem;
    color: var(--text-color);
    border-bottom: 3px solid transparent;
}

.percent-tab.active {
    border-bottom-color: var(--primary-color);
    font-weight: bold;
}

.percent-panel {
    display: none;
}

.percent-panel.active {
    display: block;
}

/* Style for the inline problem structure */
.percent-problem {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.percent-problem input {
    width: 120px;
    font-size: 1.2rem;
    text-align: center;
}
.percent-problem span {
    font-size: 1.2rem;
}
/* --- Random Number Generator Styles --- */
.rng-options {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    align-items: center;
    flex-wrap: wrap;
}
.rng-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.rng-options input[type="checkbox"] {
    width: auto; /* Override general input styles */
}
.rng-hidden {
    display: none;
}

#rngResults {
    width: 100%;
    min-height: 150px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    padding: 1rem;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    resize: vertical;
}

#rngCopyBtn {
    margin-top: 1rem;
}
/* --- Half-Life Calculator Styles --- */
.half-life-input-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.half-life-input-row .form-group {
    flex-grow: 1; /* Make the input field expand */
    margin-bottom: 0;
}
.half-life-input-row label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap; /* Prevent "solve for this" from wrapping */
}

/* Style for the input field that is currently the result */
.result-input {
    background-color: var(--background-color) !important;
    border: 2px solid var(--accent-color) !important;
    font-weight: bold;
    color: var(--accent-color) !important;
}
/* --- Quadratic Formula Calculator Styles --- */
#quadEquationDisplay {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    padding: 1rem;
    background-color: var(--background-color);
    border-radius: 5px;
    margin-bottom: 1rem;
}

.imaginary-part {
    font-style: italic;
    color: var(--accent-color);
}
/* --- Log Calculator Styles --- */
.log-base-input {
    width: 80px;
    font-size: 1rem;
    vertical-align: sub;
    margin: 0 0.25rem;
}
/* --- Ratio Calculator Styles --- */
.solved-input {
    background-color: var(--background-color) !important;
    border: 2px solid var(--accent-color) !important;
    font-weight: bold;
    color: var(--accent-color) !important;
}
/* --- Factor Calculator Styles --- */


#roundingResult {
  display: block;
  font-size: 2.2rem;
  font-weight: bold;
  color: var(--primary-color, #0077cc);
  margin-top: 0.5rem;
  
  