/* Drivetrain Builder — Rail Flow layout styles */

/* === Motor fields grid === */
.motor-fields,
.field-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* === Stages header === */
.stages-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stages-header h2 {
    margin-bottom: 0;
}

/* === Gear stage (sub-card within Stages station) === */
.gear-stage {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
[data-theme="light"] .gear-stage {
    background: rgba(0,0,0,0.02);
}
.gear-stage:last-of-type {
    margin-bottom: 0;
}

/* Stage header */
.stage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.stage-name {
    font-weight: 600;
    font-size: 0.875rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    outline: none;
    min-width: 80px;
}
.stage-name:hover {
    background: var(--bg-card);
}
.stage-name:focus {
    background: var(--bg-card);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.stage-actions,
.stage-controls {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

/* === Stage tabs (pill style for ratio/pair) === */
.stage-tabs {
    display: flex;
    gap: var(--space-xs);
}
.stage-tab {
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--fg-secondary);
    background: none;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-body);
}
.stage-tab:hover {
    color: var(--fg);
    border-color: var(--border-hover);
}
.stage-tab--active {
    color: var(--accent);
    background: var(--accent-subtle);
    border-color: rgba(251,191,36,0.2);
}

/* === Pair fields === */
.pair-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* === Output mode tabs (underline style) === */
.output-mode-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}
.output-mode-tabs .stage-tab {
    border-radius: 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    margin-bottom: -1px;
    padding: 0.5rem 0.875rem;
    color: var(--fg-muted);
}
.output-mode-tabs .stage-tab:hover {
    color: var(--fg-secondary);
    background: none;
    border-color: transparent;
    border-bottom-color: var(--border-hover);
}
.output-mode-tabs .stage-tab--active {
    color: var(--accent);
    background: none;
    border-color: transparent;
    border-bottom-color: var(--accent);
}

.output-hint {
    color: var(--fg-muted);
    font-size: var(--text-sm);
    font-style: italic;
    margin-top: 0.75rem;
}

/* === Mobile === */
@media (max-width: 900px) {
    .field-pair,
    .motor-fields,
    .pair-fields {
        grid-template-columns: 1fr;
    }

    /* Output-mode tabs: allow wrap and tighten so long labels
       (e.g. "Linear (Circumference)") fit within the card. */
    .output-mode-tabs .stage-tab {
        padding: 0.5rem 0.625rem;
        font-size: var(--text-xs);
    }
}

@media (max-width: 480px) {
    .output-mode-tabs .stage-tab {
        padding: 0.4rem 0.5rem;
        flex: 1 0 auto;
    }
}

/* === v0.9.4: motor advanced, target, tier wink, component list === */

/* Shared disclosure style for Advanced sections (motor, output, stage).
   Hides the default summary marker and renders a chevron that rotates
   when the details element is open. */
.advanced-disclosure {
    margin-top: var(--space-md);
}
.advanced-disclosure > summary {
    cursor: pointer;
    color: var(--fg-muted);
    font-size: var(--text-sm);
    user-select: none;
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.advanced-disclosure > summary::-webkit-details-marker {
    display: none;
}
.advanced-disclosure > summary::before {
    content: "";
    width: 0.55rem;
    height: 0.55rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    margin-left: 0.1rem;
}
.advanced-disclosure[open] > summary::before {
    transform: rotate(45deg);
}
.advanced-disclosure > summary:hover {
    color: var(--fg-secondary);
}
.advanced-disclosure[open] > summary {
    color: var(--fg-secondary);
    margin-bottom: var(--space-sm);
}
.motor-advanced-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.field-hint {
    font-size: var(--text-xs);
    color: var(--fg-muted);
    margin: 0;
}
.field-hint--lead {
    margin-bottom: var(--space-sm);
}

.stage-limit-hint {
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
    color: var(--fg-secondary);
    background: var(--accent-subtle);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
}
.stage-limit-hint:empty {
    display: none;
}
.stage-limit-hint a {
    color: var(--accent);
    font-weight: 600;
}

.component-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}
.component-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.5rem 0.75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-sm);
}
.component-option:hover {
    border-color: var(--border-hover);
}
.component-option input[type="radio"] {
    accent-color: var(--accent);
}
.component-option:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-subtle);
}
.component-option-label {
    color: var(--fg);
    font-weight: 500;
}
.component-option-ratio {
    margin-left: auto;
    color: var(--fg-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.empty-component-message {
    font-size: var(--text-sm);
    color: var(--fg-muted);
    margin: 0;
}
.empty-component-message a {
    color: var(--accent);
}

/* === v0.9.5 refinements: stage header, ratio preview, add-stage, X, efficiency, inertia === */

/* Stage header: name on the left, tabs + X inline on the right. */
.gear-stage .stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    flex-wrap: wrap;
    margin-bottom: var(--space-sm);
}
.gear-stage .stage-name {
    font-weight: 600;
    color: var(--fg);
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    outline: none;
    min-width: 60px;
}
.gear-stage .stage-name:focus,
.gear-stage .stage-name:hover {
    background: var(--bg-input);
}
.gear-stage .stage-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: auto;
}
.gear-stage .stage-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.gear-stage .stage-tab {
    padding: 0.25rem 0.625rem;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--fg-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.gear-stage .stage-tab:hover {
    color: var(--fg);
}
.gear-stage .stage-tab--active {
    background: var(--accent);
    color: #fff;
}

/* Stage header icon buttons: circular, quiet by default, accent on hover.
   Remove tints red, Duplicate tints blue — matches v0.3.0's icon style. */
.gear-stage .btn-icon {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg-muted);
    font-size: 0.75rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
}
.gear-stage .btn-icon:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.gear-stage .btn-icon[data-action="remove"]:hover {
    color: #fff;
    background: var(--error);
    border-color: var(--error);
}

/* "1:2.00 (speed reduction)" preview under each stage's ratio/teeth inputs. */
.stage-ratio-preview {
    margin-top: 0.5rem;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--fg-muted);
    min-height: 1.25em;
}
.stage-ratio-preview:empty {
    display: none;
}

/* Add Stage row: ghost-outline button below the last stage, full-width feel. */
.stage-add-row {
    margin-top: var(--space-md);
}
.btn-add-stage {
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--fg-secondary);
    font-weight: 500;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-add-stage:hover {
    border-color: var(--border-hover);
    color: var(--fg);
    background: var(--bg-elevated);
}

/* === v0.3.0-style result tiles === */

.results-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}
.result-tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-md);
}
.result-tile {
    padding: var(--space-md);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}
.result-tile-value {
    font-family: var(--font-mono);
    font-size: var(--text-result);
    font-weight: 600;
    color: var(--result-color);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.result-tile[data-empty] .result-tile-value {
    color: var(--fg-muted);
    font-weight: 400;
}
.result-tile-label {
    font-size: var(--text-sm);
    color: var(--fg-secondary);
    margin-bottom: 0.35rem;
}
.result-tile-unit {
    color: var(--fg-muted);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    margin-left: 0.25rem;
}

/* `result-tile` variant: label perfectly centered on top, big mono
   value full-width beneath, unit select floated in the top-right corner
   so the label stays axis-centered on the tile. `display: contents` on
   .value-field-inner removes its box so the unit select (DOM-nested
   inside inner) can be absolute-positioned against the tile itself.
   Selected via the `variant="result-tile"` include kwarg on the
   value_field partial rather than a location-scoped selector. */
.value-field--result-tile {
    position: relative;
    padding: var(--space-md);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 0;
}
.value-field--result-tile > label {
    font-size: var(--text-sm);
    color: var(--fg-secondary);
    margin: 0 0 0.35rem;
}
.value-field--result-tile .value-field-inner {
    display: contents;
}
.value-field--result-tile .value-field-slot {
    width: 100%;
}
.value-field--result-tile .value-field-input {
    font-family: var(--font-mono);
    font-size: var(--text-result);
    font-weight: 600;
    color: var(--result-color);
    line-height: 1.2;
    text-align: center;
    background: transparent;
    padding: 0;
    font-variant-numeric: tabular-nums;
    width: 100%;
    flex: 1 1 auto;
    min-width: 0;
    border: none;
}
.value-field--result-tile .value-field-unit {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    padding: 0;
    background: transparent;
    border: none;
    color: var(--fg-muted);
    font-size: var(--text-xs);
    min-width: auto;
}
.value-field--result-tile .value-field-unit:hover {
    color: var(--fg-secondary);
}
.result-tile--good { border-color: rgba(34,197,94,0.45); background: rgba(34,197,94,0.08); }
.result-tile--good .result-tile-value { color: var(--success); }
.result-tile--warn { border-color: rgba(245,158,11,0.45); background: rgba(245,158,11,0.08); }
.result-tile--warn .result-tile-value { color: var(--warning); }

.result-subsection {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.result-subsection[hidden],
.result-tile[hidden],
.result-inertia-warning[hidden],
.stage-breakdown-eff-col[hidden] {
    display: none !important;
}
.result-subsection-title {
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-muted);
    margin: 0;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.result-inertia-warning {
    margin: 0;
    padding: 0.625rem 0.875rem;
    font-size: var(--text-sm);
    color: var(--warning);
    background: rgba(245,158,11,0.08);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
}

/* Stage breakdown table */
.stage-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.stage-breakdown-table th,
.stage-breakdown-table td {
    padding: 0.5rem 0.625rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.stage-breakdown-table th {
    color: var(--fg-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.stage-breakdown-table td.mono {
    font-family: var(--font-mono);
    color: var(--result-color);
    text-align: right;
}

/* Simpler "Advanced" expand blocks on motor/output/stage.
   Width is driven by the enclosing grid cell — no hard cap here, so
   rows inside `.field-pair` match the Speed/Torque inputs above. */
.advanced-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0;
}
.advanced-field label {
    font-size: var(--text-sm);
    color: var(--fg-secondary);
}
.advanced-field .value-field-input {
    padding: 0.5rem 0.625rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg);
    width: 100%;
}
.advanced-field--valuefield .value-field-input {
    max-width: none;
}

.stage-advanced-body {
    padding-top: var(--space-sm);
    border-top: 1px dashed var(--border);
}
