@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');

:root {
  --bg-color: #f4f6f8;
  --text-color: #2c3e50;
  --primary-color: #2563eb; 
  --accent-color: #10b981;  
  --danger-color: #ef4444;  
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --input-bg: #ffffff;
  --readonly-bg: #f1f5f9;
}

body.dark-mode {
  --bg-color: #0f172a;
  --text-color: #e2e8f0;
  --primary-color: #3b82f6;
  --card-bg: #1e293b;
  --border-color: #334155;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --input-bg: #0f172a;
  --readonly-bg: #334155;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  transition: background-color 0.3s, color 0.3s;
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
h1, h2, h3 { font-weight: 700; margin: 0; }
.section-title { margin: 20px 0 15px 0; color: var(--primary-color); font-size: 1.1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; }

/* Custom section header for toggle */
.section-header-with-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    margin: 20px 0 15px 0;
    padding-bottom: 5px;
}
.section-header-with-toggle .section-title { border-bottom: none; margin: 0; padding: 0; }

/* Base Toggle Switch */
.mode-toggle { display: flex; align-items: center; gap: 10px; }
.switch { position: relative; display: inline-block; width: 50px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(24px); }

/* Smaller Toggle Switch for PITI/Opp Cost */
.small-switch { width: 40px; height: 22px; margin-top: 4px; }
.small-switch .slider:before { height: 16px; width: 16px; left: 3px; bottom: 3px; }
.small-switch input:checked + .slider:before { transform: translateX(18px); }

#form-container {
  background-color: var(--card-bg); padding: 30px; border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; gap: 40px; margin-bottom: 30px;
}

form { flex: 2; min-width: 320px; }
.input-group-row { display: flex; gap: 20px; margin-bottom: 15px; }
.input-group { flex: 1; min-width: 140px; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.tooltip { font-size: 0.75rem; color: #888; margin-bottom: 4px; }

input, .custom-select {
  width: 100%; padding: 12px; border: 1px solid var(--border-color);
  border-radius: 6px; background-color: var(--input-bg);
  color: var(--text-color); font-size: 1rem; box-sizing: border-box;
}

button {
  width: 100%; padding: 14px; border: none; border-radius: 6px; margin-top: 15px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  background-color: var(--primary-color); color: white; transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }
button.secondary-btn { background-color: var(--border-color); color: var(--text-color); }

.circles-container {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; gap: 30px; min-width: 250px; padding-top: 20px;
}
.circle-wrapper { text-align: center; }
.circle-wrapper span { display: block; margin-top: 5px; font-weight: 600; font-size: 0.9rem; }

.true-payment-circle { width: 240px; height: 240px; }
.payment-breakdown-circle { width: 180px; height: 180px; }

#results-container {
  background-color: var(--card-bg); padding: 25px; border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 40px;
}
#results-container h3 { margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px;}
.results-row { flex-wrap: wrap; }
.highlight-group input { color: var(--accent-color); font-weight: bold; border-color: var(--accent-color); }
input[readonly] { background-color: var(--readonly-bg); cursor: default; }

#charts-container { padding: 10px; }
.chart-row { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 20px; }
.chart-box { flex: 1; min-width: 400px; background: var(--card-bg); border-radius: 8px; box-shadow: var(--shadow); padding: 15px; min-height: 400px; }

.full-width-chart { min-width: 100%; }
.comparison-title { text-align: center; margin: 40px 0 20px 0; color: var(--primary-color); }

#amortization-table-container { background: var(--card-bg); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); margin-top: 30px; }
.table-responsive { overflow-x: auto; max-height: 600px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border-color); }
th { background-color: var(--readonly-bg); font-weight: 600; position: sticky; top: 0; }

.print-buttons { text-align: center; margin: 40px 0; }
.print-buttons button { max-width: 200px; }
#error-message { background-color: var(--danger-color); color: white; padding: 15px; border-radius: 6px; margin-bottom: 20px; text-align: center; }

/* ========================================= */
/* PLOTLY OVERRIDES & CRISPNESS HACKS        */
/* ========================================= */

/* 1. Nuke the Plotly Modebar (Menu Bar) permanently */
.modebar, .modebar-container {
    display: none !important;
}

/* ========================================= */
/* MOBILE OPTIMIZATION (CELLPHONES)          */
/* ========================================= */
@media (max-width: 768px) {
    .container { padding: 10px; }
    header h1 { font-size: 1.5rem; }

    #form-container { padding: 15px; gap: 20px; }
    form { min-width: 100%; }
    .input-group-row { flex-direction: column; gap: 15px; }
    .input-group { min-width: 100%; }

    .true-payment-circle { width: 200px; height: 200px; }
    .payment-breakdown-circle { width: 150px; height: 150px; }
    .circles-container { padding-top: 0; gap: 20px; }

    #results-container { padding: 15px; }

    /* Increased min-height slightly to 320px to account for the new top margin */
    .chart-box { min-width: 100%; min-height: 320px; padding: 5px; margin-bottom: 15px; }
    .chart-row { gap: 10px; margin-bottom: 10px; }
    
    #amortization-table-container { padding: 10px; }
    th, td { padding: 8px 10px; font-size: 0.9rem; }
}

@media print {
    body { background-color: white; color: black; }
    header, .print-buttons, #form-container, #results-container { display: none; }
    #printable-content { display: block; }
    .chart-box { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; margin-bottom: 20px; }
    #amortization-table th { background-color: #eee !important; color: black; position: static; }
    #amortization-table td { border-bottom: 1px solid #ccc; }
    .js-plotly-plot { margin-bottom: 20px; }
}  border-radius: 6px; background-color: var(--input-bg);
  color: var(--text-color); font-size: 1rem; box-sizing: border-box;
}

button {
  width: 100%; padding: 14px; border: none; border-radius: 6px; margin-top: 15px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  background-color: var(--primary-color); color: white; transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }
button.secondary-btn { background-color: var(--border-color); color: var(--text-color); }

.circles-container {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; gap: 30px; min-width: 250px; padding-top: 20px;
}
.circle-wrapper { text-align: center; }
.circle-wrapper span { display: block; margin-top: 5px; font-weight: 600; font-size: 0.9rem; }

.true-payment-circle { width: 240px; height: 240px; }
.payment-breakdown-circle { width: 180px; height: 180px; }

#results-container {
  background-color: var(--card-bg); padding: 25px; border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 40px;
}
#results-container h3 { margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px;}
.results-row { flex-wrap: wrap; }
.highlight-group input { color: var(--accent-color); font-weight: bold; border-color: var(--accent-color); }
input[readonly] { background-color: var(--readonly-bg); cursor: default; }

#charts-container { padding: 10px; }
.chart-row { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 20px; }
.chart-box { flex: 1; min-width: 400px; background: var(--card-bg); border-radius: 8px; box-shadow: var(--shadow); padding: 15px; min-height: 400px; }

.full-width-chart { min-width: 100%; }
.comparison-title { text-align: center; margin: 40px 0 20px 0; color: var(--primary-color); }

#amortization-table-container { background: var(--card-bg); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); margin-top: 30px; }
.table-responsive { overflow-x: auto; max-height: 600px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border-color); }
th { background-color: var(--readonly-bg); font-weight: 600; position: sticky; top: 0; }

.print-buttons { text-align: center; margin: 40px 0; }
.print-buttons button { max-width: 200px; }
#error-message { background-color: var(--danger-color); color: white; padding: 15px; border-radius: 6px; margin-bottom: 20px; text-align: center; }

/* ========================================= */
/* MOBILE OPTIMIZATION (CELLPHONES)          */
/* ========================================= */
@media (max-width: 768px) {
    /* Tighten outer screen padding */
    .container { padding: 10px; }
    
    /* Shrink Header */
    header h1 { font-size: 1.5rem; }

    /* Make form stack perfectly */
    #form-container { padding: 15px; gap: 20px; }
    form { min-width: 100%; }
    .input-group-row { flex-direction: column; gap: 15px; }
    .input-group { min-width: 100%; }

    /* Shrink the Visual Summary Circles so they fit on a single phone screen */
    .true-payment-circle { width: 200px; height: 200px; }
    .payment-breakdown-circle { width: 150px; height: 150px; }
    .circles-container { padding-top: 0; gap: 20px; }

    /* Optimize Results Summary */
    #results-container { padding: 15px; }

    /* Restrict Chart Sizes (Prevent them from taking up the entire vertical screen) */
    .chart-box { min-width: 100%; min-height: 280px; padding: 5px; margin-bottom: 15px; }
    .chart-row { gap: 10px; margin-bottom: 10px; }
    
    /* Make table scrollable but visually neat */
    #amortization-table-container { padding: 10px; }
    th, td { padding: 8px 10px; font-size: 0.9rem; }
}

@media print {
    body { background-color: white; color: black; }
    header, .print-buttons, #form-container, #results-container { display: none; }
    #printable-content { display: block; }
    .chart-box { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; margin-bottom: 20px; }
    #amortization-table th { background-color: #eee !important; color: black; position: static; }
    #amortization-table td { border-bottom: 1px solid #ccc; }
    .js-plotly-plot { margin-bottom: 20px; }
}

