* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    color: #2c3e50;
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    color: #7f8c8d;
    font-size: 1.1em;
}

.input-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.pricing-sections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin: 25px 0;
}

.bedrock-section,
.selfhosting-section {
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.selfhosting-section {
    border-left-color: #e74c3c;
}

.bedrock-section h3,
.selfhosting-section h3 {
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 1.3em;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #34495e;
}

/* Standalone inputs (not in input groups) */
input[type="text"]:not(.input-group input),
input[type="number"]:not(.input-group input),
select:not(.input-group select) {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.3s ease;
    background-color: white;
}

input[type="text"]:not(.input-group input):focus,
input[type="number"]:not(.input-group input):focus,
select:not(.input-group select):focus {
    outline: none;
    border-color: #3498db;
}

input[readonly] {
    background-color: #f8f9fa;
    color: #6c757d;
}

/* Input Group Styling */
.input-group {
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid #ddd;
    border-radius: 6px;
    transition: border-color 0.3s ease;
}

.input-group input,
.input-group select {
    flex: 1;
    border: none;
    padding: 12px;
    background: transparent;
    font-size: 16px;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
}

.input-group:focus-within {
    border-color: #3498db;
}

.input-unit {
    padding: 0 12px;
    font-size: 0.8em;
    color: #6c757d;
    background-color: #f8f9fa;
    border-left: 1px solid #e9ecef;
    white-space: nowrap;
}

/* Reference Links Styling */
.pricing-note,
.reference-links {
    margin-top: 15px;
    margin-bottom: 0;
    font-size: 0.85em;
    text-align: center;
}

.reference-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.reference-link {
    color: #6c757d;
    text-decoration: none;
    font-size: 0.95em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s ease;
}

.reference-link:hover {
    color: #495057;
    text-decoration: underline;
}

.reference-link:visited {
    color: #6c757d;
}

/* Responsive adjustments for input groups and reference links */
@media (max-width: 768px) {
    .input-unit {
        font-size: 0.7em;
        padding: 0 8px;
    }

    .reference-links {
        flex-direction: column;
        gap: 10px;
    }

    .reference-link {
        font-size: 0.85em;
    }

    .input-group input,
    .input-group select {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 15px;
    margin-top: 20px;
}

button[type="submit"],
.clear-button {
    padding: 15px;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button[type="submit"] {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
}

.clear-button {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: white;
}

.clear-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(149, 165, 166, 0.4);
}

button:active {
    transform: translateY(0);
}

.results-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.results-section h2 {
    color: #2c3e50;
    margin-bottom: 30px;
    text-align: center;
    font-size: 2em;
}

.chart-container {
    position: relative;
    height: 400px;
    margin-bottom: 40px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.data-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background-color: #34495e;
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
}

tr:hover {
    background-color: #f5f5f5;
}

.cheaper-bedrock {
    background-color: #e8f4f8;
    color: #2980b9;
    font-weight: 600;
}

.cheaper-selfhost {
    background-color: #fdf2f2;
    color: #e74c3c;
    font-weight: 600;
}

.savings {
    font-weight: 600;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .pricing-sections {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 2em;
    }

    .input-section,
    .results-section {
        padding: 20px;
    }

    .chart-container {
        height: 300px;
    }
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Math Section Styling */
.math-section {
    margin-top: 40px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.math-toggle {
    width: 100%;
    padding: 20px 30px;
    border: none;
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background 0.3s ease;
}

.math-toggle:hover {
    background: linear-gradient(135deg, #2c3e50, #233140);
}

.math-icon {
    font-size: 20px;
}

.toggle-arrow {
    transition: transform 0.3s ease;
    font-size: 14px;
}

.toggle-arrow.rotated {
    transform: rotate(180deg);
}

.math-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    background: white;
}

.math-content.expanded {
    max-height: 2000px;
    transition: max-height 0.6s ease-in;
}

.math-explanation {
    padding: 30px;
    border-bottom: 1px solid #e9ecef;
}

.math-explanation h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.5em;
}

.math-explanation p {
    color: #6c757d;
    line-height: 1.6;
    font-size: 1.1em;
}

.formula-sections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    padding: 30px;
}

.formula-section {
    padding: 25px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.formula-section:last-child {
    border-left-color: #e74c3c;
}

.formula-section h4 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.2em;
}

.formula {
    background: white;
    padding: 15px;
    border-radius: 6px;
    border: 2px solid #e9ecef;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.1em;
    color: #2c3e50;
}

.formula-breakdown {
    margin-bottom: 20px;
}

.formula-step {
    background: #fff;
    padding: 12px 15px;
    margin-bottom: 10px;
    border-radius: 6px;
    border-left: 3px solid #17a2b8;
}

.formula-step code {
    background: transparent;
    color: #495057;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    font-weight: 500;
}

.formula-step small {
    display: block;
    color: #6c757d;
    font-style: italic;
    margin-top: 5px;
}

.formula-example {
    background: #e8f4f8;
    padding: 15px;
    border-radius: 6px;
    border-left: 3px solid #17a2b8;
    font-size: 0.95em;
    line-height: 1.6;
}

.math-notes {
    padding: 30px;
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.math-notes h4 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.math-notes ul {
    list-style: none;
    padding: 0;
}

.math-notes li {
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
    line-height: 1.5;
}

.math-notes li:last-child {
    border-bottom: none;
}

.math-notes strong {
    color: #495057;
}

/* Custom Tokens Section Styling */
.custom-tokens-section {
    margin: 25px 0;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #17a2b8;
}

.custom-tokens-section h3 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.section-description {
    color: #6c757d;
    font-size: 0.9em;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Cache Section Styling */
.cache-section {
    margin: 20px 0;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    overflow: hidden;
}

.cache-toggle {
    width: 100%;
    padding: 12px 15px;
    border: none;
    background: #f8f9fa;
    color: #495057;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease;
}

.cache-toggle:hover {
    background: #e9ecef;
}

.cache-arrow {
    transition: transform 0.3s ease;
    font-size: 12px;
}

.cache-arrow.rotated {
    transform: rotate(180deg);
}

.cache-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: white;
}

.cache-content.expanded {
    max-height: 500px;
    transition: max-height 0.5s ease-in;
}

.cache-content .form-group {
    margin: 15px;
    margin-bottom: 20px;
}

.cache-content .form-group:last-child {
    margin-bottom: 15px;
}

.optional-label {
    font-size: 0.8em;
    color: #6c757d;
    font-weight: 400;
    font-style: italic;
}

.field-help {
    display: block;
    margin-top: 4px;
    font-size: 0.75em;
    color: #6c757d;
    font-style: italic;
}

.cache-content input[type="number"] {
    font-size: 14px;
}

.cache-content .input-group {
    border: 1px solid #ddd;
}

.cache-content .input-group:focus-within {
    border-color: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.1);
}

/* Validation States */
.input-group.error {
    border-color: #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.1);
}

.validation-message {
    display: block;
    margin-top: 4px;
    font-size: 0.75em;
    color: #dc3545;
}

/* Responsive Math Section */
@media (max-width: 768px) {
    .math-toggle {
        padding: 15px 20px;
        font-size: 16px;
    }

    .math-explanation,
    .math-notes {
        padding: 20px;
    }

    .formula-sections {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 20px;
    }

    .formula-section {
        padding: 20px;
    }

    .formula {
        font-size: 1em;
    }

    .formula-step code {
        font-size: 0.85em;
    }

    .cache-toggle {
        font-size: 13px;
        padding: 10px 12px;
    }

    .cache-content .form-group {
        margin: 12px;
    }

    .custom-tokens-section {
        padding: 15px;
    }

    .custom-tokens-section h3 {
        font-size: 1.1em;
    }
}