/* --- Global Reset & Box Sizing --- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: #f0f8ff;
    color: #333;
    margin: 0;
    padding: 15px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background-color: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

header {
    text-align: center;
    border-bottom: 2px solid #e0f0ff;
    padding-bottom: 20px;
    margin-bottom: 30px;
}
header h1 { color: #0056b3; margin: 0; font-size: 1.8em; }
header p { color: #555; font-size: 1.1em; }

/* PC Layout: Side-by-side */
.input-section {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    margin-bottom: 30px;
}

.loan-input { background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 8px; padding: 20px; width: 100%; flex: 1; }
.loan-input h2 { margin-top: 0; color: #007bff; display: flex; align-items: center; }
.circle-a, .circle-b { display: inline-block; width: 30px; height: 30px; line-height: 30px; border-radius: 50%; color: white; text-align: center; margin-right: 10px; flex-shrink: 0; }
.circle-a { background-color: #007bff; }
.circle-b { background-color: #17a2b8; }

label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: bold; color: #555; }
input[type="number"], select { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 1em; font-family: 'Sarabun', sans-serif; }
.button-container { text-align: center; }
#calculateBtn { background-color: #007bff; color: white; padding: 12px 30px; border: none; border-radius: 5px; cursor: pointer; font-size: 1.2em; font-family: 'Sarabun', sans-serif; transition: background-color 0.3s; }
#calculateBtn:hover { background-color: #0056b3; }

#results-section.hidden { display: none; }
#results-section { margin-top: 40px; }
.summary-section, .graph-section, .tables-section { background: #fdfdff; padding: 25px; margin-bottom: 30px; border-radius: 8px; border: 1px solid #e9ecef; }

h3 { color: #0056b3; border-bottom: 2px solid #e0f0ff; padding-bottom: 10px; margin-top: 0; }
.toggle-title-h3 { border-bottom: none; padding-bottom: 0; margin: 0; }
h4.toggle-title { color: #007bff; margin:0; }

table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #dee2e6; padding: 8px 10px; text-align: right; font-size: 0.95em; white-space: nowrap; }
th { background-color: #e9ecef; color: #495057; text-align: center; }
td:nth-child(-n+2), th:nth-child(-n+2) { text-align: left; }
th:nth-child(3) { text-align: center; }

.table-wrapper { max-height: 400px; overflow-y: auto; overflow-x: auto; border: 1px solid #ddd; border-radius: 5px; margin-top: 10px; transition: all 0.3s ease-in-out; }
#summary-text-container { margin-top: 20px; padding: 15px; background-color: #e7f5ff; border-left: 5px solid #007bff; }

.chart-container { position: relative; height: 400px; width: 100%; margin-top: 20px; }
.toggle-header { display: flex; justify-content: space-between; align-items: center; }
.graph-section .toggle-header { justify-content: flex-end; }
.toggle-buttons .toggle-btn { background-color: #f0f0f0; border: 1px solid #ccc; padding: 8px 16px; cursor: pointer; transition: background-color 0.3s, color 0.3s; font-family: 'Sarabun', sans-serif; }
.toggle-buttons .toggle-btn:first-child { border-radius: 5px 0 0 5px; }
.toggle-buttons .toggle-btn:last-child { border-radius: 0 5px 5px 0; border-left: none; }
.toggle-buttons .toggle-btn.active { background-color: #007bff; color: white; border-color: #007bff; }
.table-toggle-wrapper { display: flex; align-items: center; gap: 15px; margin-top: 20px; }
.graph-section .table-toggle-wrapper { margin-top: 0; }
.tables-section .table-toggle-wrapper:first-of-type { margin-top: 30px; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.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: 28px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #007bff; }
input:checked + .slider:before { transform: translateX(22px); }

/* --- Mobile Responsive Styles --- */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    /* Mobile Layout: Top-and-bottom */
    .input-section {
        flex-direction: column;
        gap: 20px;
    }

    .graph-section .toggle-header {
        justify-content: center;
        width: 100%;
        margin-top: 15px;
    }
    header h1 {
        font-size: 1.5em;
    }
}
