/* =========================================
   Global Reset & Base Styles
   ========================================= */
* {
    box-sizing: border-box;
}

body {
    background-color: #f0f2f5;
    color: #3b3b4f;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    margin: 0;
    width: 100%;
    min-height: 100vh;
}

/* Typography */
h1,
p,
small {
    display: block;
    margin: 0.6em auto;
    text-align: center;
    max-width: 700px;
}

h1 {
    font-size: 2em;
    letter-spacing: -0.5px;
}

small {
    font-size: 13px;
    color: #888;
}

a {
    color: #718d97;
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s;
}

a:hover {
    color: #3b3b4f;
    text-decoration: underline;
}

/* =========================================
   Layout Containers
   ========================================= */
.container {
    padding: 1.5em 1em 3em;
    max-width: 820px;
    margin: 0 auto;
}

.header {
    padding: 1.5em 0 1em;
}

/* =========================================
   Form Elements
   ========================================= */
fieldset {
    border: 1.5px solid #d0d4dc;
    padding: 1.5em 2em;
    margin-bottom: 1em;
    background: #fff;
    width: 100%;
    max-width: 820px;
    margin: 0 auto 1em;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

legend {
    font-weight: 600;
    padding: 0 0.5em;
    color: #3b3b4f;
    font-size: 0.95em;
    letter-spacing: 0.02em;
}

label {
    display: flex;
    align-items: center;
    margin: 0.5em 0;
    cursor: pointer;
}

textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.4em;
    border: 1.5px solid #d0d4dc;
    border-radius: 4px;
    padding: 0.6em 0.75em;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #3b3b4f;
    background: #fafbfc;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: #718d97;
    box-shadow: 0 0 0 3px rgba(113,141,151,0.15);
    background: #fff;
}

textarea::placeholder {
    color: #b0b8c4;
}

input[type="radio"] {
    margin-right: 0.5em;
    accent-color: #3b3b4f;
}

/* =========================================
   Section: Sequences
   ========================================= */
.section-sequences label {
    font-weight: 600;
    font-size: 0.9em;
    color: #555;
    margin-bottom: 0.1em;
}

.input-group {
    margin-bottom: 1.2em;
}

/* =========================================
   Section: Configuration Split (Type & Data)
   ========================================= */
.split-row {
    display: flex;
    gap: 1em;
    justify-content: space-between;
    margin-bottom: 1em;
}

.split-row fieldset {
    margin: 0;
}

.section-type {
    flex: 0 0 57%;
}

.section-data {
    flex: 0 0 40%;
}

/* Internal Layouts for Config Sections */
.config-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 0.8em;
    padding-left: 0.5em;
}

.label-heading {
    font-weight: 600;
    min-width: 100px;
    margin-right: 0.5em;
    padding-top: 0.25em;
    font-size: 0.9em;
    color: #555;
}

.grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.3em 1em;
    flex-grow: 1;
}

.grid-2x2 label {
    margin: 0;
    min-width: 100px;
    font-size: 0.95em;
}

.data-columns {
    display: flex;
    justify-content: space-around;
    padding-top: 0.3em;
}

.column {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
}

/* Disabled radio options */
input[type="radio"]:disabled + * {
    opacity: 0.4;
}

label:has(input[type="radio"]:disabled) {
    cursor: default;
    opacity: 0.45;
}

/* =========================================
   Controls (Buttons)
   ========================================= */
.controls {
    text-align: center;
    margin-top: 1.5em;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    width: 60%;
    padding: 0.85em 1.5em;
    background-color: #3b3b4f;
    color: white;
    border: 2px solid #3b3b4f;
    border-radius: 5px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, opacity 0.2s;
    letter-spacing: 0.02em;
}

button:hover:not(:disabled) {
    background-color: #555570;
    border-color: #555570;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Loading spinner inside button */
.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =========================================
   Result Output
   ========================================= */
#output {
    max-width: 820px;
    margin: 1.5em auto 0;
    border-radius: 6px;
    overflow: hidden;
    display: none;
}

#output.result-success {
    background: #fff;
    border: 1.5px solid #d0d4dc;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

#output.result-error {
    background: #fff8f8;
    border: 1.5px solid #e8b4b4;
}

/* Result header */
.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1em 1.5em 0.75em;
    border-bottom: 1px solid #eee;
}

.result-header h3 {
    margin: 0;
    font-size: 1em;
    font-weight: 700;
    color: #3b3b4f;
}

.result-badge {
    font-size: 0.78em;
    font-weight: 600;
    color: #718d97;
    background: #f0f4f6;
    padding: 0.25em 0.65em;
    border-radius: 20px;
    letter-spacing: 0.03em;
}

/* Strain names */
.result-strains {
    padding: 0.75em 1.5em;
    border-bottom: 1px solid #eee;
    font-size: 0.88em;
    color: #555;
    display: flex;
    flex-direction: column;
    gap: 0.25em;
}

.strain-label {
    font-weight: 700;
    color: #3b3b4f;
    display: inline-block;
    min-width: 72px;
    margin-right: 0.4em;
}

/* Metrics row */
.result-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-bottom: 1px solid #eee;
}

.metric {
    padding: 1em 0.75em;
    text-align: center;
    border-right: 1px solid #eee;
}

.metric:last-child {
    border-right: none;
}

.metric-value {
    font-size: 1.15em;
    font-weight: 700;
    color: #3b3b4f;
    line-height: 1.2;
}

.metric-label {
    font-size: 0.75em;
    color: #888;
    margin-top: 0.3em;
    letter-spacing: 0.02em;
}

/* Substitutions */
.result-substitutions {
    padding: 0.9em 1.5em 1.1em;
}

.result-substitutions h4 {
    margin: 0 0 0.6em;
    font-size: 0.88em;
    font-weight: 700;
    color: #3b3b4f;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-substitutions table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88em;
}

.result-substitutions td {
    padding: 0.35em 0.75em;
    border-bottom: 1px solid #f2f2f2;
    color: #444;
}

.result-substitutions tr:last-child td {
    border-bottom: none;
}

.result-substitutions td:first-child {
    font-weight: 600;
    color: #3b3b4f;
    width: 110px;
}

/* Error message */
.error-msg {
    margin: 0;
    padding: 1em 1.5em;
    font-size: 0.93em;
    color: #b94040;
}

.error-msg::before {
    content: "⚠ ";
}

/* =========================================
   Responsive — Mobile
   ========================================= */
@media (max-width: 600px) {
    h1 {
        font-size: 1.5em;
    }

    fieldset {
        padding: 1.2em 1em;
    }

    .split-row {
        flex-direction: column;
    }

    .section-type,
    .section-data {
        flex: none;
        width: 100%;
    }

    .data-columns {
        justify-content: flex-start;
        gap: 2em;
    }

    button {
        width: 100%;
    }

    .result-metrics {
        grid-template-columns: repeat(2, 1fr);
    }

    .metric:nth-child(2) {
        border-right: none;
    }

    .metric:nth-child(3) {
        border-right: 1px solid #eee;
    }

    .metric:nth-child(1),
    .metric:nth-child(2) {
        border-bottom: 1px solid #eee;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4em;
    }
}
