@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');

:root {
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --secondary-color: #17a2b8;
    --light-bg: #f0f8ff;
    --white-bg: #ffffff;
    --text-color: #333;
    --border-color: #dee2e6;
    --header-font-size: 1.8em;
}

body {
    font-family: 'Sarabun', sans-serif;
    background-color: var(--light-bg);
    color: var(--text-color);
    margin: 0;
    padding: 15px;
    -webkit-font-smoothing: antialiased;
}
.container {
    max-width: 1000px;
    margin: 0 auto;
    background-color: var(--white-bg);
    padding: 20px;
    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: var(--primary-dark); margin: 0; font-size: var(--header-font-size); }
header p { color: #555; font-size: 1em; }

.input-section { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 30px; }
.loan-input { background-color: #f8f9fa; border: 1px solid var(--border-color); border-radius: 8px; padding: 20px; width: 100%; flex: 1; }
.loan-input h2 { margin-top: 0; color: var(--primary-color); 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: var(--primary-color); }
.circle-b { background-color: var(--secondary-color); }

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; box-sizing: border-box; font-size: 1em; font-family: 'Sarabun', sans-serif; }
.button-container { text-align: center; display: flex; gap: 15px; justify-content: center; }
.main-btn, .secondary-btn { padding: 12px 30px; border: none; border-radius: 5px; cursor: pointer; font-size: 1.1em; font-family: 'Sarabun', sans-serif; transition: all 0.3s; }
.main-btn { background-color: var(--primary-color); color: white; }
.main-btn:hover { background-color: var(--primary-dark); }
.secondary-btn { background-color: #6c757d; color: white; }
.secondary-btn:hover { background-color: #5a6268; }

#results-section.hidden { display: none; }
#results-section { 
    margin-top: 40px; 
    animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.summary-section, .graph-section, .tables-section { background: #fdfdff; padding: 25px; margin-bottom: 30px; border-radius: 8px; border: 1px solid #e9ecef; }
h3 { color: var(--primary-dark); 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: var(--primary-color); margin:0; }

table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid var(--border-color); padding: 8px 10px; text-align: right; font-size: 0.95em; white-space: nowrap; }
th { background-color: #e9ecef; color: #495057; text-align: center; }
td:first-child, th:first-child { text-align: left; }
.summary-section td:first-child, .summary-section th:first-child { font-weight: bold; }

.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 var(--primary-color); }
.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: var(--primary-color); color: white; border-color: var(--primary-color); }

.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: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }

/* --- IMPROVED MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    :root { --header-font-size: 1.5em; }
    .container { padding: 15px; }
    .input-section { flex-direction: column; gap: 20px; }
    .graph-section .toggle-header { justify-content: center; width: 100%; margin-top: 15px;}
    
    /* Responsive Summary Table - "Card" layout */
    .summary-section table thead {
        display: none;
    }
    .summary-section table,
    .summary-section table tbody,
    .summary-section table tr,
    .summary-section table td {
        display: block;
        width: 100%;
    }
    .summary-section table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 5px;
        padding: 10px;
    }
    .summary-section table td {
        text-align: right !important;
        position: relative;
        padding-left: 50%;
        border: none;
        padding-top: 8px;
        padding-bottom: 8px;
    }
    .summary-section table td:before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: calc(50% - 20px);
        text-align: left;
        font-weight: bold;
    }
    .tables-section td { font-size: 0.9em; }
}
