/* AeroForge Minimal SaaS — workspace form refinement (02A).
   All changes are opt-in CSS. No form IDs, data-targets or JS events change. */

/* Keep both engineering panes comfortably readable on wide screens.
   Avoid changing the legacy 900px mobile tab/visibility rules. */
@media (min-width: 901px) {
    .app-layout {
        grid-template-columns: clamp(370px, 32vw, 450px) minmax(0, 1fr);
    }
    .panel-input {
        padding: 22px 18px 28px;
    }
    .panel-results {
        padding: 25px clamp(18px, 3vw, 38px);
    }
}

.panel-input,
.panel-results {
    scrollbar-width: thin;
    scrollbar-color: var(--af-line-strong) transparent;
}

/* Sections remain controlled by app.js. The old 600px cap could hide
   electrical, avionics and extended environment fields when expanded. */
.form-section {
    margin-bottom: 12px;
    border-radius: var(--af-radius-md);
    box-shadow: none;
}

.form-section.open {
    border-color: var(--af-line-strong);
    box-shadow: var(--af-shadow);
}

.form-section .section-toggle {
    min-height: 48px;
    gap: 10px;
    padding: 13px 16px;
    font-size: 0.91rem;
    line-height: 1.35;
    letter-spacing: -0.012em;
    text-align: left;
}

.form-section .section-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    flex: 0 0 28px;
    font-size: 1.15rem;
    line-height: 1.25;
}

.form-section .chevron {
    font-size: 1.22rem;
    color: var(--af-ink-subtle);
}

/* No fixed content limit: form fields introduced by future components
   remain accessible without creating a second nested scroll area. */
.form-section.open .section-body {
    max-height: none;
    padding: 4px 16px 18px;
}

.form-section .section-body {
    padding-inline: 16px;
}

.form-section .field {
    min-width: 0;
    margin-bottom: 12px;
}

.form-section .field-row {
    column-gap: 12px;
    row-gap: 3px;
}

.field label {
    font-size: 0.78rem;
    line-height: 1.4;
    font-weight: 600;
    color: var(--af-ink-muted);
    margin-bottom: 6px;
    text-transform: none;
    letter-spacing: 0;
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field select,
.field textarea,
.modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.modal select,
.modal textarea {
    min-width: 0;
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border-color: var(--af-line-strong);
    border-radius: var(--af-radius-sm);
    background-color: var(--af-control);
    color: var(--af-ink);
    font-size: 0.86rem;
    line-height: 1.3;
}

.field input::placeholder,
.modal input::placeholder,
.modal textarea::placeholder {
    color: var(--af-ink-subtle);
    opacity: 1;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.modal input:focus,
.modal select:focus,
.modal textarea:focus {
    border-color: var(--af-brand);
    box-shadow: var(--af-focus);
    outline: none;
}

.field :is(input, select, textarea):disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

:where(.field, .modal) :is(input, select, textarea):focus-visible,
.form-section .section-toggle:focus-visible,
#btn-analyze:focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: 2px;
}

/* Component library fields and added mass rows remain fully interactive. */
.form-section .component-library-select {
    /* Shared dimensions for motor/propeller/ESC/battery library pickers. */
    margin-top: var(--af-space-2);
    margin-bottom: var(--af-space-4);
    padding-bottom: var(--af-space-4);
    border-bottom: 1px solid var(--af-line);
    background: var(--af-surface);
}

.component-entry {
    background: var(--af-surface-raised);
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius-sm);
    padding: 12px;
}

.mass-row {
    gap: 8px;
}

.btn-remove-mass,
.btn-remove-comp {
    border-radius: var(--af-radius-sm);
}

/* Harmonize Tom Select multi-layer input state with native controls. */
.ts-control,
.ts-wrapper.single .ts-control {
    min-height: 40px;
    padding: 9px 11px;
    background: var(--af-control) !important;
    border-color: var(--af-line-strong) !important;
    color: var(--af-ink) !important;
}

.ts-wrapper.focus .ts-control {
    border-color: var(--af-brand) !important;
    box-shadow: var(--af-focus) !important;
}

.ts-dropdown .option.active,
.ts-dropdown .option:hover {
    color: var(--af-ink) !important;
    background: var(--af-surface-raised) !important;
}

/* One clear submit action at the bottom; no sticky overlay or moved button. */
#btn-analyze {
    min-height: 48px;
    margin-top: 18px;
    padding: 12px 16px;
    border-radius: var(--af-radius-md);
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.012em;
}

@media (max-width: 900px) {
    .panel-input,
    .panel-results {
        padding: 18px 16px 86px;
    }
}

@media (max-width: 600px) {
    .form-section.open .section-body {
        padding: 4px 13px 15px;
    }

    .form-section .section-body {
        padding-inline: 13px;
    }

    .form-section .section-toggle {
        padding: 12px 13px;
    }

    .form-section .field-row {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 0;
    }

    /* Each extra-mass item remains legible at 390px: row one is type/name,
       row two is mass + a dedicated delete cell. Never overlap an input. */
    .mass-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: var(--af-space-2);
        align-items: end;
        padding: 10px;
        border: 1px solid var(--af-line);
        border-radius: var(--af-radius-sm);
        background: var(--af-surface-raised);
        margin-bottom: var(--af-space-3);
    }
    .mass-row > .field {
        min-width: 0;
        margin: 0;
    }
    .mass-row > .field:nth-child(3) {
        grid-column: 1;
    }
    .mass-row .btn-remove-mass {
        grid-column: 2;
        justify-self: end;
        align-self: end;
        width: 44px;
        height: 42px;
        margin: 0;
        flex: none;
    }
    .component-entry {
        padding: var(--af-space-3);
    }
    /* First row: name + remove control. Category occupies a full row
       beneath; other measurements keep their single-column mobile stack. */
    .component-entry > .field-row:first-child {
        grid-template-columns: minmax(0, 1fr) 44px;
        column-gap: var(--af-space-2);
        row-gap: var(--af-space-2);
        align-items: center;
    }
    .component-entry > .field-row:first-child > .field:first-child {
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
        margin: 0;
        align-self: stretch;
    }
    .component-entry > .field-row:first-child > .field:first-child > .comp-name {
        display: block;
        width: 100%;
        height: var(--af-control-height, 44px);
        min-height: var(--af-control-height, 44px);
        box-sizing: border-box;
    }
    .component-entry > .field-row:first-child > .field:nth-child(2) {
        grid-column: 1 / -1;
        grid-row: 2;
        min-width: 0;
    }
    .component-entry > .field-row:first-child > .btn-remove-comp {
        position: static;
        grid-column: 2;
        grid-row: 1;
        justify-self: stretch;
        align-self: center;
        width: var(--af-control-height, 44px);
        height: var(--af-control-height, 44px);
        min-height: var(--af-control-height, 44px);
        padding: 0;
        margin: 0;
        box-sizing: border-box;
        transform: none;
    }
    .component-entry > .field-row:first-child > .btn-remove-comp:hover {
        transform: none;
    }
}

/* Compact, keyboard-accessible Demo menu anchored to the existing header button. */
.demo-dropdown-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.demo-dropdown-trigger {
    min-height: 36px;
}

.demo-dropdown-chevron {
    font-size: 0.78rem;
    margin-left: 3px;
    color: var(--af-ink-subtle);
}

.demo-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 9px);
    z-index: 300;
    width: min(310px, calc(100vw - 24px));
    padding: 7px;
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius-md);
    background: var(--af-surface);
    color: var(--af-ink);
    box-shadow: 0 15px 42px rgba(15, 23, 42, 0.20);
}

.demo-dropdown[hidden] {
    display: none !important;
}

.demo-dropdown-heading {
    padding: 9px 10px 8px;
    font-size: 0.73rem;
    font-weight: 700;
    color: var(--af-ink-subtle);
    letter-spacing: 0.01em;
}

.demo-dropdown-option {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    min-height: 56px;
    padding: 10px 12px;
    border: 0;
    border-radius: var(--af-radius-sm);
    background: transparent;
    text-align: left;
    color: var(--af-ink);
    cursor: pointer;
    font-family: var(--font, 'Inter', sans-serif);
}

.demo-dropdown-option:hover,
.demo-dropdown-option:focus-visible {
    background: var(--af-surface-raised);
}

.demo-dropdown-option:focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: -2px;
}

.demo-option-title {
    font-size: 0.84rem;
    font-weight: 650;
}

.demo-option-description {
    font-size: 0.73rem;
    color: var(--af-ink-muted);
}

@media (max-width: 600px) {
    .demo-dropdown {
        position: fixed;
        top: 68px;
        right: 12px;
        width: min(310px, calc(100vw - 24px));
    }
}

/* Add controls need room below the last item, whether the list is empty
   or populated with one or more dynamically inserted engineering rows. */
.form-section .section-body > :is(.btn-add-component, #btn-add-mass) {
    margin-top: var(--af-space-3);
    min-height: 36px;
}
@media (max-width: 600px) {
    .form-section .section-body > :is(.btn-add-component, #btn-add-mass) {
        margin-top: var(--af-space-4);
    }
}

/* Phone editing rows share the 44px control height (input/delete),
   while the following component-category row stays full width. */
