.mad-calculator {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    max-width: 900px;
    margin: 30px auto;
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    color: #333;
    border: 1px solid #e0e0e0;
}

.mad-calculator h2 {
    color: #0056b3;
    margin-bottom: 20px;
    font-size: 1.8em;
    width: 100%;
    text-align: center;
}

.mad-calculator h3 {
    color: #007bff;
    margin-top: 20px;
    margin-bottom: 15px;
    font-size: 1.3em;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 8px;
}

.input-section,
.results-section {
    flex: 1;
    min-width: 300px;
    background-color: #ffffff;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid #f0f0f0;
}

.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group textarea,
.form-group input[type="number"] {
    width: calc(100% - 22px); /* Account for padding */
    padding: 12px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    resize: vertical;
    min-height: 80px;
}

.form-group input[type="number"] {
    min-height: unset;
    height: auto;
}


.form-group textarea:focus,
.form-group input[type="number"]:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

button {
    background-color: #28a745;
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out;
    width: 100%;
}

button:hover {
    background-color: #218838;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

.result-box {
    background-color: #e9f7ef; /* Light green for results */
    border: 1px solid #d4edda;
    border-left: 5px solid #28a745;
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 8px;
}

.result-box p {
    margin: 8px 0;
    line-height: 1.5;
    color: #444;
}

.result-box p strong {
    color: #222;
}

.error-message {
    color: #dc3545;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 8px;
    display: none; /* Hidden by default */
    font-weight: 500;
}

.detailed-results {
    margin-top: 30px;
}

.data-table-container {
    overflow-x: auto;
    margin-top: 15px;
    max-height: 300px; /* Limit height for long tables */
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.data-table-container table {
    width: 100%;
    border-collapse: collapse;
    min-width: 300px;
}

.data-table-container th,
.data-table-container td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
}

.data-table-container th {
    background-color: #f1f7fe; /* Light blue header */
    color: #333;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table-container tbody tr:nth-child(even) {
    background-color: #fcfdff;
}

.data-table-container tbody tr:hover {
    background-color: #e6f7ff;
}

.final-sum {
    margin-top: 20px;
    font-weight: 600;
    color: #0056b3;
    font-size: 1.1em;
}

.chart-section {
    margin-top: 30px;
    text-align: center;
}

.chart-container {
    background-color: #ffffff;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.08);
    border: 1px solid #e0e0e0;
    max-width: 100%; /* Ensure responsiveness */
    height: 300px; /* Fixed height for chart area */
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    max-width: 100%;
    height: auto;
}

.tooltip {
    position: absolute;
    right: 0px;
    top: 0px;
    background-color: #007bff;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
    font-size: 0.8em;
    cursor: help;
    z-index: 10;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%; /* Position above the tooltip icon */
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9em;
    line-height: 1.4;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #555 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}


/* Mobile Responsiveness */
@media (max-width: 768px) {
    .mad-calculator {
        padding: 15px;
        flex-direction: column;
        gap: 20px;
    }

    .input-section,
    .results-section {
        padding: 18px;
    }

    .mad-calculator h2 {
        font-size: 1.5em;
    }

    .mad-calculator h3 {
        font-size: 1.2em;
    }

    button {
        padding: 10px 15px;
        font-size: 1em;
    }

    .form-group textarea {
        min-height: 60px;
    }

    .data-table-container th,
    .data-table-container td {
        padding: 10px;
        font-size: 0.9em;
    }

    .tooltip {
        top: -5px; /* Adjust tooltip position for smaller screens */
        right: 5px;
    }

    .tooltip .tooltiptext {
        width: 150px; /* Make tooltip text narrower */
        margin-left: -75px; /* Adjust for new width */
        bottom: 120%;
    }
}