/* Shared Minimal SaaS UI components (phase: consistency pass).
   Loaded last on landing, workspace, and admin.
   Visual-only controls: all existing IDs, handlers and data-theme logic remain. */

:root {
    --af-control-size: 40px;
    --af-control-radius: var(--af-radius-sm, 8px);
}

.af-theme-toggle,
#theme-toggle-btn.af-theme-toggle,
#admin-theme-toggle.af-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 var(--af-control-size);
    width: var(--af-control-size);
    min-width: var(--af-control-size);
    height: var(--af-control-size);
    min-height: var(--af-control-size);
    margin: 0;
    padding: 0;
    border: 1px solid var(--af-line-strong);
    border-radius: var(--af-control-radius);
    background: var(--af-surface);
    box-shadow: none;
    color: var(--af-ink);
    font: inherit;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.af-theme-toggle:hover,
#theme-toggle-btn.af-theme-toggle:hover,
#admin-theme-toggle.af-theme-toggle:hover {
    background: var(--af-brand-tint);
    border-color: var(--af-brand);
    color: var(--af-ink);
}

.af-theme-toggle:focus-visible,
#theme-toggle-btn.af-theme-toggle:focus-visible,
#admin-theme-toggle.af-theme-toggle:focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: 3px;
}

.af-theme-glyph,
.af-theme-toggle .theme-switch-icon,
.af-theme-toggle .admin-theme-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin: 0;
}

.af-theme-toggle .lucide {
    width: 19px;
    height: 19px;
    margin: 0;
}

/* Keep the admin's header usable with a single icon-sized action. */
.admin-header #admin-email-display {
    min-width: 0;
}

@media (max-width: 600px) {
    :root {
        --af-control-size: 40px;
    }
}

/* Brand identity: same AeroForge mark and wordmark on all three screens.
   DI (public) and ERP (admin) remain small contextual suffixes. */
.af-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--af-line);
    background: var(--af-brand-tint);
    color: var(--af-brand);
    box-shadow: none;
}

.af-brand-mark .lucide,
.navbar-brand .af-brand-mark .lucide,
.admin-brand .af-brand-mark .lucide,
.header-brand .af-brand-mark .lucide {
    width: 21px;
    height: 21px;
    margin: 0;
    color: var(--af-brand);
}

.navbar-brand .af-brand-name,
.admin-brand .af-brand-name {
    color: var(--af-ink);
    font-size: 1.12rem;
    font-weight: 750;
    letter-spacing: -0.035em;
}

.admin-brand h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--af-ink);
}

.navbar-brand .af-brand-context,
.admin-brand .af-brand-context {
    color: var(--af-ink-subtle);
    font-size: 0.69rem;
    font-weight: 650;
    line-height: 1.15;
    letter-spacing: 0.03em;
}

.header-brand h1,
.navbar-brand .af-brand-name,
.admin-brand .af-brand-name {
    font-family: var(--font, 'Inter', -apple-system, sans-serif);
    text-wrap: nowrap;
}

/* Small navigation actions follow the same radii and keyboard-focus style;
   primary, warning and destructive actions retain their intent colors. */
:where(.btn-back, .btn-action, .filter-btn, .navbar-links > .btn) {
    border-radius: var(--af-radius-sm);
    font-weight: 600;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

:where(.btn-back, .btn-action, .filter-btn):focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: 3px;
}

@media (max-width: 480px) {
    .navbar-brand .af-brand-name {
        font-size: 1rem;
    }

    .navbar-brand .af-brand-context {
        display: none;
    }
}

/* Common field parity — engineering form and admin configuration fields.
   Excludes hidden, toggle, file and range controls; preserves JS validators. */
.form-section .field :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]),
    select,
    textarea
),
.admin-content .cfg-input {
    box-sizing: border-box;
    min-width: 0;
    min-height: 40px;
    border: 1px solid var(--af-line-strong);
    border-radius: var(--af-radius-sm);
    background-color: var(--af-control);
    color: var(--af-ink);
    font-family: var(--font, 'Inter', -apple-system, sans-serif);
    font-size: 0.86rem;
    line-height: 1.35;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.form-section .field :is(input, select, textarea):focus-visible,
.admin-content .cfg-input:focus-visible {
    border-color: var(--af-brand);
    outline: 2px solid var(--af-brand);
    outline-offset: 2px;
}

.form-section .field :is(input, select, textarea):disabled,
.admin-content .cfg-input:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.form-section .field label,
.admin-content .cfg-label {
    color: var(--af-ink-muted);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.4;
}

/* Shared pricing card preview — concept figures, not backend entitlements.
   The actual checkout, plan logic and billing API are untouched. */
.af-pricing-note {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px;
    max-width: 650px;
    margin: 0 auto 28px;
    padding: 9px 12px;
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius-sm);
    background: var(--af-surface-raised);
    color: var(--af-ink-muted);
    font-size: 0.78rem;
    line-height: 1.5;
    text-align: center;
}
.af-pricing-note .lucide {
    width: 15px;
    height: 15px;
    margin: 0;
    color: var(--af-brand);
}
.pricing-grid .pricing-card .price,
.pricing-cards .pricing-card .price {
    color: var(--af-ink);
    font-weight: 750;
    letter-spacing: -0.04em;
    line-height: 1.12;
}
.pricing-grid .pricing-card > .btn,
.pricing-cards .pricing-card > .btn {
    min-height: 42px;
    border-radius: var(--af-radius-sm);
    font-weight: 650;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}
.pricing-grid .pricing-card > .btn {
    width: 100%;
    margin-top: auto;
}
.pricing-grid .pricing-card > .btn .lucide,
.pricing-cards .pricing-card > .btn .lucide {
    width: 16px;
    height: 16px;
    margin-right: 0;
}

/* Cross-screen action-state parity: preserve semantic colors and compact
   variants while normalizing focus, SVG placement and disabled feedback. */
:where(.btn, .btn-back, .btn-action, .filter-btn) {
    border-radius: var(--af-radius-sm);
    line-height: 1.35;
    font-family: var(--font, 'Inter', -apple-system, sans-serif);
}

:where(.btn, .btn-back, .btn-action, .filter-btn):focus-visible {
    outline: 2px solid var(--af-brand);
    outline-offset: 3px;
}

:where(.btn, .btn-back, .btn-action, .filter-btn):disabled {
    opacity: 0.58;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

:where(.btn, .btn-back, .btn-action, .filter-btn) .lucide {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    vertical-align: -0.15em;
    margin-right: 0;
}

/* Full-size navigation controls remain 40px; compact table actions and
   intentionally large hero/analyze buttons keep their own sizes. */
.header-actions > .btn:not(.btn-small),
.admin-header .btn-back,
.navbar-links > .btn:not(.btn-lg) {
    min-height: 40px;
}

/* The pricing modal previously left a large legacy gap above the draft
   disclosure, squeezing cards on laptop-height viewports. */
.pricing-modal-content .pricing-subtitle {
    margin-bottom: 12px;
}

.pricing-modal-content .af-pricing-note {
    margin-bottom: 24px;
}

@media (prefers-reduced-motion: reduce) {
    :where(.btn, .btn-back, .btn-action, .filter-btn) {
        transition-duration: 0.01ms;
    }
}

/* AeroForge semantic state palette — predictable contrast in both themes. */
:root {
    --af-ok-ink: #86efac;
    --af-ok-bg: rgba(34, 197, 94, 0.12);
    --af-ok-border: rgba(74, 222, 128, 0.35);
    --af-warn-ink: #fcd34d;
    --af-warn-bg: rgba(245, 158, 11, 0.13);
    --af-warn-border: rgba(251, 191, 36, 0.35);
    --af-danger-ink: #fca5a5;
    --af-danger-bg: rgba(239, 68, 68, 0.11);
    --af-danger-border: rgba(248, 113, 113, 0.38);
    --af-info-ink: #93c5fd;
    --af-info-bg: rgba(59, 130, 246, 0.11);
    --af-info-border: rgba(96, 165, 250, 0.34);
}

html[data-theme="light"]:root {
    --af-ok-ink: #166534;
    --af-ok-bg: #f0fdf4;
    --af-ok-border: #86efac;
    --af-warn-ink: #92400e;
    --af-warn-bg: #fffbeb;
    --af-warn-border: #fcd34d;
    --af-danger-ink: #b91c1c;
    --af-danger-bg: #fef2f2;
    --af-danger-border: #fecaca;
    --af-info-ink: #1d4ed8;
    --af-info-bg: #eff6ff;
    --af-info-border: #bfdbfe;
}

/* Shared language control — the button label shows the next language. */
.af-lang-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 62px;
    min-height: 40px;
    padding: 8px 11px;
    border: 1px solid var(--af-line-strong);
    border-radius: var(--af-radius-sm);
    background: var(--af-surface);
    color: var(--af-ink);
    font-size: 0.8rem;
    font-weight: 650;
    line-height: 1.2;
    white-space: nowrap;
}
.af-lang-toggle:hover { border-color: var(--af-brand); background: var(--af-brand-tint); }
.af-lang-toggle:focus-visible { outline: 2px solid var(--af-brand); outline-offset: 2px; }
.af-lang-toggle .lucide { width: 16px; height: 16px; margin: 0; }

/* Reusable presentation-only wrappers. Admin tables and centered doughnut
   charts formerly declared these values inline in their HTML. */
.af-table-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.af-chart-centered {
    display: flex;
    justify-content: center;
}


/* Consistent small-screen utility navigation for workspace + admin.
   Desktop children remain in the normal action row; no duplicate buttons. */
.af-utility-panel {
    display: contents;
}
.af-utility-heading,
.af-mobile-more,
.af-utility-caption {
    display: none;
}
.af-scroll-tabs {
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}
.af-scroll-tabs::-webkit-scrollbar {
    display: none;
}
.results-nav-bar.af-scroll-tabs {
    position: sticky;
    top: 0;
    z-index: 30;
    isolation: isolate;
    background: var(--af-surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--af-line);
    border-radius: var(--af-radius-md);
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.16);
    padding: 10px;
    margin-bottom: 18px;
}
.results-nav-bar.af-scroll-tabs .nav-btn {
    flex: 0 0 auto;
}
/* The navigation scroll target must not disappear under the sticky toolbar. */
.panel-results :is(#result-summary, #metrics-performance, #metrics-energy,
    #metrics-flight, #findings-list, #metrics-plm) {
    scroll-margin-top: 80px;
}
/* Save is a stable, predictable action, not a hovering floating button. */
.summary-actions #btn-save-design {
    background: var(--af-action-primary);
    border: 1px solid var(--af-action-primary);
    color: var(--af-action-on-primary);
    box-shadow: none;
}
.summary-actions #btn-save-design:hover {
    background: var(--af-action-primary-hover);
    border-color: var(--af-action-primary-hover);
}
.summary-actions .btn,
.summary-actions .btn:hover,
.summary-actions .btn:active {
    transform: none;
}
.sidebar-toggle-label {
    display: none;
}
@media (max-width: 900px) {
    /* The legacy saved-design sidebar must overlay instead of shifting the
       entire narrow workspace sideways when opened. */
    body:has(.app-layout),
    body.sidebar-closed:has(.app-layout) {
        padding-left: 0;
    }
    .app-header {
        padding: 10px 12px;
        gap: 8px;
        min-width: 0;
        position: relative;
        z-index: 110;
    }
    .app-header .header-brand {
        min-width: 0;
        gap: 7px;
        flex: 0 1 auto;
    }
    .app-header .header-brand h1 {
        font-size: 0.96rem;
    }
    .app-header .header-brand .header-subtitle {
        font-size: 0.65rem;
    }
    .app-header .header-brand .logo-icon {
        flex: 0 0 34px;
        width: 34px;
        height: 34px;
    }
    .app-header .header-actions,
    .admin-header-actions {
        display: flex;
        align-items: center;
        gap: 7px;
        min-width: 0;
        flex: 0 0 auto;
    }
    .app-header .header-actions {
        margin-left: auto;
    }
    .app-header #btn-demo {
        min-height: 40px;
        padding: 8px 11px;
        white-space: nowrap;
    }
    .af-mobile-more {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        border: 1px solid var(--af-line-strong);
        border-radius: var(--af-radius-sm);
        background: var(--af-surface);
        color: var(--af-ink);
        cursor: pointer;
    }
    .af-mobile-more:hover,
    .af-mobile-more[aria-expanded="true"] {
        background: var(--af-brand-tint);
        border-color: var(--af-brand);
    }
    .af-mobile-more:focus-visible {
        outline: 2px solid var(--af-brand);
        outline-offset: 2px;
    }
    .app-header .af-utility-panel,
    .admin-header .af-utility-panel {
        display: none;
        position: absolute;
        right: 12px;
        top: calc(100% + 6px);
        z-index: 350;
        width: min(340px, calc(100vw - 24px));
        max-height: min(72dvh, 610px);
        padding: 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: var(--af-surface);
        border: 1px solid var(--af-line-strong);
        border-radius: var(--af-radius-lg);
        box-shadow: var(--af-shadow);
    }
    .app-header .af-utility-panel.is-open,
    .admin-header .af-utility-panel.is-open {
        display: flex;
    }
    .af-utility-panel .af-utility-caption {
        display: inline;
        font-size: 0.84rem;
        font-weight: 600;
    }
    .af-utility-panel .af-utility-heading {
        display: block;
        color: var(--af-ink-subtle);
        font-size: 0.76rem;
        font-weight: 700;
        padding: 5px 8px;
    }
    /* Explicit header specificity overrides the fixed 40px theme switch
       and auth flex sizing. Equal full-width 44px actions across pages. */
    :is(.app-header, .admin-header) .af-utility-panel > :is(button, a),
    :is(.app-header, .admin-header) .af-utility-panel .auth-state > button,
    .admin-header #admin-theme-toggle.af-theme-toggle,
    .app-header #theme-toggle-btn.af-theme-toggle {
        box-sizing: border-box;
        display: flex;
        flex: 0 0 auto;
        justify-content: flex-start;
        align-items: center;
        width: 100%;
        min-width: 0;
        min-height: 44px;
        height: 44px;
        margin: 0;
        padding: 9px 12px;
        border-radius: var(--af-radius-sm);
        text-align: left;
    }
    :is(.app-header, .admin-header) .af-utility-panel :is(.af-theme-toggle, .af-lang-toggle) {
        border: 1px solid var(--af-line-strong);
    }
    .af-utility-panel .auth-state {
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: var(--af-space-2);
        margin: 0;
        width: 100%;
        border-top: 1px solid var(--af-line);
        padding-top: var(--af-space-3);
    }
    .af-utility-panel #user-email,
    .af-utility-panel #admin-email-display {
        max-width: 100%;
        min-width: 0;
        overflow-wrap: anywhere;
        white-space: normal;
        padding: 7px;
        font-size: 0.8rem;
        color: var(--af-ink-muted);
    }
    .af-utility-panel :is(.af-lang-toggle, .af-theme-toggle, .admin-theme-toggle) {
        min-width: 0;
        min-height: 40px;
        width: 100%;
        padding: 8px 11px;
        display: inline-flex;
        justify-content: flex-start;
    }
    .admin-header {
        position: relative;
        z-index: 20;
        flex-wrap: nowrap;
        min-width: 0;
    }
    .admin-header-title {
        min-width: 0;
        font-size: 0.95rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .admin-header-actions {
        margin-left: auto;
    }
    .admin-header .btn-back {
        white-space: nowrap;
        flex-shrink: 0;
    }
    .admin-nav.af-scroll-tabs {
        scrollbar-width: none;
    }
    .mobile-tab-bar #btn-sidebar-toggle {
        position: static;
        transform: none;
        inset: auto;
        z-index: auto;
        min-width: 0;
        padding: 8px;
        flex: 1 1 0;
        border-radius: var(--af-radius-sm);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        background: transparent;
        border: 0;
        box-shadow: none;
        color: var(--af-ink-muted);
        transition: background-color 0.18s ease, color 0.18s ease;
    }
    .mobile-tab-bar #btn-sidebar-toggle[aria-expanded="true"] {
        background: var(--af-brand-tint);
        color: var(--af-brand);
    }
    .mobile-tab-bar .sidebar-toggle-label {
        display: inline;
    }
    .summary-actions {
        min-width: 0;
        align-items: stretch;
    }
    .summary-actions .btn {
        white-space: normal;
        min-width: 0;
    }
}
@media (max-width: 540px) {
    .admin-header .admin-back-text {
        display: none;
    }
    .admin-header .btn-back {
        width: 40px;
        min-width: 40px;
        padding: 9px;
    }
    .results-nav-bar.af-scroll-tabs {
        border-radius: var(--af-radius-sm);
        margin-bottom: 12px;
    }
    .summary-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .summary-actions #btn-save-design {
        grid-column: 1 / -1;
    }
}

/* The utility menu is a real vertical button stack, not a squeezed desktop row.
   Keep email as supporting text, all controls have the same 44px target. */
@media (max-width: 900px) {
    :is(.app-header, .admin-header) .af-utility-panel {
        gap: var(--af-space-2);
        padding: var(--af-space-3);
    }
    :is(.app-header, .admin-header) .af-utility-panel #admin-email-display {
        display: block;
        width: 100%;
        margin: 0;
        max-width: 100%;
    }
    :is(.app-header, .admin-header) .af-utility-panel .af-lang-toggle,
    :is(.app-header, .admin-header) .af-utility-panel .af-theme-toggle {
        gap: var(--af-space-3);
    }
    .af-mobile-more {
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
    }
}


/* Control-height parity: only full-size form/toolbar controls, not chips,
   icon badges, table actions or engineering chart overlays. */
@media (max-width: 900px) {
    .panel-input .field :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea),
    .panel-input .form-section .ts-control {
        box-sizing: border-box;
        min-height: var(--af-control-height);
    }
    .panel-input .field :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select) {
        height: var(--af-control-height);
    }
    .panel-input :is(.btn-add-component, #btn-add-mass, #btn-analyze),
    .panel-input .btn:not(.section-toggle):not(.btn-remove-comp):not(.btn-remove-mass),
    .panel-results .summary-actions .btn,
    .mobile-tab-bar > :is(.mobile-tab, #btn-sidebar-toggle),
    .app-header #btn-demo {
        box-sizing: border-box;
        min-height: var(--af-control-height);
    }
    .panel-input .btn-remove-mass {
        height: var(--af-control-height);
        min-height: var(--af-control-height);
    }
    .navbar-links > :is(.af-theme-toggle, .af-lang-toggle, .af-nav-launch),
    .admin-header :is(.btn-back, .af-mobile-more) {
        box-sizing: border-box;
        min-height: var(--af-control-height);
        height: var(--af-control-height);
    }

    /* Result navigation is part of the scrolling pane header, not a floating
       rounded card over an animated title. Its own opaque surface hides text. */
    .app-layout .panel-results {
        padding-top: 0;
        overflow-x: hidden;
        min-width: 0;
    }
    .panel-results > .results-nav-bar.af-scroll-tabs {
        position: sticky;
        top: 0;
        z-index: 80;
        width: calc(100% + 32px);
        max-width: none;
        box-sizing: border-box;
        margin: 0 -16px var(--af-space-4);
        padding: var(--af-space-3) var(--af-space-4);
        border: 0;
        border-bottom: 1px solid var(--af-line);
        border-radius: 0;
        box-shadow: none;
        background: var(--af-surface);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        transform: none;
        animation: none;
    }
    .panel-results > .results-nav-bar.af-scroll-tabs .nav-btn {
        min-height: 40px;
    }
}
