* {
    box-sizing: border-box;
}

html {
    overflow-y: scroll; /* Fallback for older browsers */
    scrollbar-gutter: stable; /* Modern approach - reserves space without always showing scrollbar */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    background: #f5f5f5;
    color: #333;
}

h1 {
    text-align: center;
    margin-bottom: 10px;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 20px;
}

/* Tab styles */
.tab-container {
    margin-bottom: 20px;
    position: relative;
}

.tab-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(to right, transparent, #f5f5f5);
    pointer-events: none;
    transition: opacity 0.2s;
}

.tab-container.scrolled-end::after {
    opacity: 0;
}

.tab-buttons {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #ddd;
    padding-bottom: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tab-buttons::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    padding: 12px 20px;
    border: none;
    background: #e0e0e0;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px 8px 0 0;
    transition: background 0.2s, color 0.2s;
    position: relative;
    bottom: -2px;
    flex-shrink: 0;
    white-space: nowrap;
}

.tab-btn:hover {
    background: #d0d0d0;
}

.tab-btn.active {
    background: white;
    border: 2px solid #ddd;
    border-bottom: 2px solid white;
    color: #007bff;
}

.tab-content {
    display: none;
    padding-top: 20px;
}

.tab-content.active {
    display: block;
}

.converter-section {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.converter-section h2 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #eee;
    font-size: 1.1rem;
}

.input-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 15px;
}

.input-field {
    flex: 1;
    min-width: 120px;
}

.input-field.narrow {
    flex: 0.7;
    min-width: 100px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 0.9rem;
}

input[type="number"], select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

input[type="number"]:focus, select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.result {
    background: #e8f4e8;
    padding: 15px;
    border-radius: 4px;
    font-size: 1.1rem;
    text-align: center;
}

.result strong {
    color: #2d6a2d;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.result-box {
    background: #e8f4e8;
    padding: 15px;
    border-radius: 4px;
    text-align: center;
}

.result-box.single {
    grid-column: 1 / -1;
}

.result-box h3 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: #555;
}

.result-box .value {
    font-size: 1.3rem;
    font-weight: 600;
    color: #2d6a2d;
}

.result-box .secondary {
    font-size: 0.95rem;
    color: #444;
    margin-top: 5px;
}

.formula {
    font-size: 0.85rem;
    color: #666;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.info-box {
    background: #f0f7ff;
    border-left: 4px solid #007bff;
    padding: 15px;
    margin-top: 15px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.info-box h4 {
    margin: 0 0 8px 0;
    color: #0056b3;
}

.info-box a {
    color: #007bff;
    text-decoration: none;
}

.info-box a:hover {
    text-decoration: underline;
}

.info-box.tip {
    background: #fff8e6;
    border-left-color: #f0a500;
}

.info-box.tip h4 {
    color: #c28400;
}

.constants {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-top: 20px;
}

.constants h3 {
    margin-top: 0;
    font-size: 0.95rem;
}

.constants ul {
    margin: 0;
    padding-left: 20px;
}

.constants li {
    margin-bottom: 5px;
}

.swap-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.swap-btn:hover {
    background: #0056b3;
}

/* Collapsible sections */
.collapsible {
    margin-top: 15px;
}

.collapsible-header {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 12px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    font-size: 0.95rem;
}

.collapsible-header:hover {
    background: #eee;
}

.collapsible-header .arrow {
    transition: transform 0.2s;
}

.collapsible-header.open .arrow {
    transform: rotate(180deg);
}

.collapsible-content {
    display: none;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    padding: 15px;
    background: white;
    overflow-x: auto;
}

.collapsible-content.open {
    display: block;
}

/* Reference tables */
.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 10px;
}

.ref-table th, .ref-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.ref-table th {
    background: #f5f5f5;
    font-weight: 600;
}

.ref-table tr:last-child td {
    border-bottom: none;
}

.ref-table .section-header {
    background: #e8e8e8;
    font-weight: 600;
}

/* Sample size table */
.sample-size-table {
    border-collapse: collapse;
    font-size: 0.75rem;
    width: auto;
}

.sample-size-table th,
.sample-size-table td {
    border: 1px solid #ddd;
    padding: 4px 6px;
    text-align: center;
    min-width: 36px;
}

.sample-size-table th {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.sample-size-table .row-header {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    left: 0;
}

.sample-size-table .corner-header {
    background: #e8e8e8;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 2;
}

.sample-size-table .diagonal {
    background: #d4d4d4;
    color: #888;
}

.sample-size-table .low {
    background: #d4edda;
}

.sample-size-table .medium {
    background: #f8d7da;
}

.sample-size-table .high {
    background: #c94c4c;
    color: white;
}

/* ES to MR table (reuses sample-size-table styles) */
.es-mr-table {
    border-collapse: collapse;
    font-size: 0.75rem;
    width: auto;
}

.es-mr-table th,
.es-mr-table td {
    border: 1px solid #ddd;
    padding: 4px 6px;
    text-align: center;
    min-width: 36px;
}

.es-mr-table th {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.es-mr-table .row-header {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    left: 0;
}

.es-mr-table .corner-header {
    background: #e8e8e8;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 2;
}

/* Bell curve styles */
.bell-curve-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
}

.bell-curve-svg {
    width: 100%;
    max-width: 500px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.bell-curve-labels {
    display: flex;
    justify-content: space-around;
    margin-top: 10px;
    font-size: 0.85rem;
}

.bell-curve-label {
    text-align: center;
}

.bell-curve-label .percentile {
    font-weight: 600;
    color: #555;
}

.bell-curve-label .value {
    font-size: 1rem;
    font-weight: 600;
}

.bell-curve-label.p5 .value { color: #28a745; }
.bell-curve-label.p50 .value { color: #007bff; }
.bell-curve-label.p95 .value { color: #dc3545; }

/* Percentile selector */
.percentile-selector {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.percentile-selector label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-weight: normal;
}

.percentile-selector input[type="radio"] {
    width: auto;
    margin: 0;
}

/* Warning box */
.warning-box {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 12px 15px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    display: none;
}

.warning-box.visible {
    display: block;
}

/* Distance input group (show/hide based on unit) */
.distance-group {
    display: none;
}

.distance-group.visible {
    display: block;
}

/* BPC comparison table */
.bpc-section {
    margin-top: 20px;
}

.bpc-section h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: #333;
}

.bpc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-bottom: 15px;
}

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

.bpc-table th {
    background: #f5f5f5;
    font-weight: 600;
    font-size: 0.85rem;
}

.bpc-table td:last-child {
    text-align: center;
    font-weight: 600;
}

.bpc-table .bpc-yes {
    background: #d4edda;
    color: #155724;
}

.bpc-table .bpc-no {
    background: #f8d7da;
    color: #721c24;
}

.bpc-table .bpc-plausible {
    background: #fff3cd;
    color: #856404;
}

.bpc-table .bpc-unknown {
    background: #e9ecef;
    color: #6c757d;
}

.bpc-table .example-col {
    font-size: 0.85rem;
    color: #666;
}

@media (max-width: 600px) {
    .input-field {
        min-width: 100%;
    }

    .input-field.narrow {
        min-width: 100%;
    }

    .result-grid {
        grid-template-columns: 1fr;
    }

    .tab-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }
}
