/* ---------- type-constraints form ---------- */
.type-constraints {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.5rem;
}
.type-row {
    display: grid;
    grid-template-columns: 9rem 1fr 1fr;
    gap: 0.5rem;
    align-items: center;
}
.type-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #2d3748;
}
.type-label small {
    font-weight: 400;
    color: #718096;
    font-size: 0.78rem;
}
.type-row label {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}
.type-row input[type="number"] {
    width: 80px;
}

/* ---------- combo breakdown ---------- */
.combo-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}
.type-breakdown {
    font-size: 0.82rem;
    color: #4a5568;
    line-height: 1.6;
}
.type-line .type-name {
    display: inline-block;
    background: #edf2f7;
    border-radius: 4px;
    padding: 0 0.35rem;
    font-weight: 600;
    font-size: 0.78rem;
    margin-right: 0.25rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f0f4f8;
    color: #1a202c;
    padding: 2rem 1rem;
}
.container {
    max-width: 1000px;
    margin: 0 auto;
}
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}
h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #2d3748;
}

.card {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Plans table */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
th,
td {
    padding: 0.5rem 0.75rem;
    text-align: center;
    border-bottom: 1px solid #e2e8f0;
}
th {
    background: #edf2f7;
    font-weight: 600;
}
tr:last-child td {
    border-bottom: none;
}

/* Form */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}
label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    font-weight: 500;
}
input[type="number"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 1rem;
    width: 100%;
}
input[type="number"]:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

button {
    margin-top: 1.25rem;
    padding: 0.65rem 2rem;
    background: #4299e1;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
button:hover:not(:disabled) {
    background: #3182ce;
}
button:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}
.btn-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Result */
#result {
    display: none;
}
.result-summary {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.stat {
    flex: 1;
    min-width: 140px;
    background: #ebf8ff;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.stat .label {
    font-size: 0.78rem;
    color: #4a5568;
    margin-bottom: 0.2rem;
}
.stat .value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #2b6cb0;
}
.stat.highlight {
    background: #e6fffa;
}
.stat.highlight .value {
    color: #276749;
}

.combo-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.combo-list li {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
}
.combo-list li .per-gb {
    color: #2b6cb0;
    font-weight: 600;
    margin-right: 0.75rem;
    font-size: 0.85rem;
    background: #ebf8ff;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
}

/* Range table */
#range-result {
    display: none;
}
.range-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.range-table th,
.range-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid #e2e8f0;
    text-align: center;
}
.range-table th {
    background: #edf2f7;
    font-weight: 600;
    position: sticky;
    top: 0;
}
.range-table tr:last-child td {
    border-bottom: none;
}
.range-table td.combos {
    text-align: left;
    font-size: 0.8rem;
    color: #4a5568;
}
/* Range legend */
.range-legend {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.legend-item {
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-weight: 600;
}
.legend-best   { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
.legend-median { background: #ebf8ff; color: #2b6cb0; border: 1px solid #90cdf4; }
.legend-worst  { background: #fff5f5; color: #c53030; border: 1px solid #feb2b2; }

/* Range row highlights */
.range-table tr.row-best td { background: #f0fff4; }
.range-table tr.row-worst td { background: #fff5f5; }
.range-table tr.row-median td { background: #ebf8ff; }
.range-table tr.row-best td:nth-child(4) { color: #276749; font-weight: 700; }
.range-table tr.row-worst td:nth-child(4) { color: #c53030; font-weight: 700; }
.range-table tr.row-median td:nth-child(4) { color: #2b6cb0; font-weight: 700; }
    color: #a0aec0;
    font-style: italic;
}
.range-scroll {
    height: 420px;
    min-height: 120px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    resize: vertical;
}

/* Chart */
.chart-wrap {
    margin-top: 1.25rem;
    position: relative;
}
.chart-wrap canvas {
    width: 100%;
    display: block;
    border-radius: 8px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
}
.chart-tooltip {
    position: absolute;
    pointer-events: none;
    display: none;
    background: rgba(26, 32, 44, 0.88);
    color: #fff;
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    white-space: nowrap;
}

/* Mode tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.25rem;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}
.tab-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: #edf2f7;
    color: #4a5568;
    transition: background 0.15s, color 0.15s;
    margin-top: 0;
}
.tab-btn.active {
    background: #4299e1;
    color: #fff;
}
.tab-btn:hover:not(.active) {
    background: #e2e8f0;
}
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

/* Free mode results */
#free-result {
    display: none;
}
#free-range-result {
    display: none;
}

.error {
    background: #fff5f5;
    border: 1px solid #fc8181;
    color: #c53030;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
}

#loading {
    color: #718096;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}
