/* --- Modern Calculator Styles --- */

/* Define a color palette and base styles */
:root {
    --background-color: #f4f7f9;
    --container-color: #ffffff;
    --primary-color: #3b82f6; /* Blue 600 */
    --primary-text-color: #1f2937; /* Gray 800 */
    --secondary-text-color: #4b5563; /* Gray 600 */
    --light-gray-color: #e5e7eb; /* Gray 200 */
    --border-color: #d1d5db; /* Gray 300 */
    --error-color: #ef4444; /* Red 500 */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Universal box-sizing for more predictable layouts */
*, *::before, *::after {
    box-sizing: border-box;
}

/* General body styles */
body {
    font-family: var(--font-sans);
    margin: 0;
    padding: 10px; /* Adjusted padding for mobile */
    background: var(--background-color);
    color: var(--primary-text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Main application container */
#app-container {
    max-width: 800px; /* Increased width for two-column layout */
    margin: 20px auto; /* Adjusted margin for mobile */
    padding: 24px; /* Adjusted padding for mobile */
    background: var(--container-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05), 0 10px 30px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--light-gray-color);
}

/* Typography */
h1 {
    text-align: center;
    margin-block-start: 0;
    margin-block-end: 8px;
    font-size: 24px; /* Slightly smaller for mobile */
    font-weight: 600;
}

h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-text-color);
}

.subtitle {
    color: var(--secondary-text-color);
    text-align: center;
    margin-top: 0;
    margin-bottom: 24px; /* Adjusted margin */
    font-size: 16px;
}

/* Mode Toggle Buttons */
.button-group {
    display: flex;
    flex-wrap: wrap; /* Allow buttons to wrap onto the next line */
    justify-content: center;
    background-color: var(--light-gray-color);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px; /* Adjusted margin */
}

.toggle-button {
    flex: 1 1 auto; /* Allow shrinking and growing */
    padding: 10px 8px; /* Adjusted padding for smaller text */
    border: none;
    background-color: transparent;
    border-radius: 6px;
    font-weight: 500;
    font-size: 14px; /* Ensure text fits on mobile */
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
    color: var(--secondary-text-color);
    white-space: nowrap; /* Prevent text wrapping */
}

.toggle-button.active {
    background-color: var(--container-color);
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Form layout and styling - Switched to Flexbox for better responsive control */
.form-grid {
    display: flex;
    flex-direction: column; /* Default to single column for mobile */
    gap: 24px;
}

.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
}

.input-group label {
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--primary-text-color);
}

.input-with-unit {
    display: flex;
    width: 100%; /* Ensure the container takes full width */
}

input[type="number"], input[type="text"] {
    flex-grow: 1; /* Allow input to take up available space */
    flex-shrink: 1; /* Allow input to shrink */
    min-width: 0; /* Critical for allowing shrinking in flexbox */
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -moz-appearance: textfield; /* Firefox */
}
input[type="number"] {
    border-right: none;
    border-radius: 8px 0 0 8px;
}


input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}


input[type="number"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    z-index: 1;
}

.unit-label {
    flex-shrink: 0; /* Prevent the unit label from shrinking */
    padding: 10px 12px;
    background-color: var(--light-gray-color);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    font-size: 14px;
    color: var(--secondary-text-color);
    -webkit-appearance: none; /* For iOS styling */
    -moz-appearance: none;
    appearance: none;
}

/* Summary Box */
.summary-box {
    padding: 20px;
    background-color: #f9fafb; /* Gray 50 */
    border-radius: 8px;
    border: 1px solid var(--light-gray-color);
}

.summary-box h2 {
    text-align: center;
    margin-top: 0;
}

.summary-box p {
    margin: 4px 0;
    font-size: 14px;
    word-break: break-word; /* Prevent long words from overflowing */
}

.summary-box .formula-note {
    font-size: 12px;
    color: var(--secondary-text-color);
    text-align: center;
    margin-bottom: 12px;
}

.summary-box hr {
    border: none;
    border-top: 1px solid var(--light-gray-color);
    margin: 12px 0;
}

.summary-box .summary-result {
    font-weight: 600;
    font-size: 16px;
}

/* Error Display */
.error-display {
    color: var(--error-color);
    font-weight: 500;
    text-align: center;
    margin-top: 24px;
    min-height: 20px; /* Reserve space */
}

/* Results Table */
.result-section {
    margin-top: 24px;
    overflow-x: auto; /* Allow table to scroll horizontally if needed */
}

.result-section h2 {
    text-align: center;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.result-table th, .result-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--light-gray-color);
    word-wrap: break-word; /* Wrap long content within cells */
}

.result-table thead {
    background-color: #f9fafb; /* Gray 50 */
}

.result-table th {
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary-text-color);
}

.result-table .placeholder {
    text-align: center;
    color: var(--secondary-text-color);
    font-style: italic;
}

/* Footer */
.page-footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--light-gray-color);
    text-align: center;
    font-size: 12px;
    color: var(--secondary-text-color);
}

.page-footer p {
    margin: 4px 0;
}

/* --- Responsive Styles --- */
@media (min-width: 768px) {
    /* Switch to two columns on larger screens */
    .form-grid {
        flex-direction: row; /* Side-by-side on larger screens */
    }

    .form-grid > * {
        flex: 1; /* Make columns equal width */
        min-width: 0; /* Prevent overflow */
    }

    #app-container {
        padding: 32px;
    }

    h1 {
        font-size: 26px;
    }
}
