/* Flexcell BYOK AI assistant styles. Scoped to the AI panel. */
.fc-ai-panel {
    display: grid;
    gap: 16px;
}

.fc-ai-intro,
.fc-ai-privacy-note,
.fc-ai-status,
.fc-ai-response {
    min-width: 0;
    padding: 14px 16px;
    border: 1px solid var(--fc-line);
    border-radius: 12px;
    background: var(--fc-panel-soft);
}

.fc-ai-intro,
.fc-ai-privacy-note {
    color: var(--fc-muted);
}

.fc-ai-intro p,
.fc-ai-privacy-note p {
    margin: 6px 0 0;
}

.fc-ai-intro strong,
.fc-ai-privacy-note strong {
    color: var(--fc-text);
}

.fc-ai-privacy-note {
    border-color: color-mix(in srgb, var(--fc-warning) 38%, transparent);
    background: color-mix(in srgb, var(--fc-warning) 12%, var(--fc-panel));
    color: color-mix(in srgb, var(--fc-warning) 72%, var(--fc-text));
    font-size: 0.9rem;
}

.fc-ai-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.7fr);
    gap: 16px;
    align-items: start;
}

.fc-ai-card {
    display: grid;
    gap: 14px;
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--fc-line);
    border-radius: 14px;
    background: var(--fc-panel);
}

.fc-ai-card h3,
.fc-ai-card h4 {
    margin: 0;
    color: var(--fc-text);
}

.fc-ai-card-header,
.fc-ai-response-header,
.fc-ai-key-row,
.fc-ai-actions,
.fc-ai-response-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.fc-ai-field {
    display: grid;
    gap: 7px;
    min-width: 0;
}

.fc-ai-field label,
.fc-ai-field-label {
    color: var(--fc-muted);
    font-size: 0.88rem;
    font-weight: 700;
}

.fc-ai-field input,
.fc-ai-field select,
.fc-ai-field textarea {
    width: 100%;
    min-width: 0;
}

.fc-ai-field textarea {
    min-height: 110px;
    resize: vertical;
}

.fc-ai-help {
    margin: 0;
    color: var(--fc-muted);
    font-size: 0.82rem;
}

.fc-ai-key-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.fc-ai-key-row {
    justify-content: flex-start;
    padding: 10px 12px;
    border: 1px solid var(--fc-line);
    border-radius: 10px;
    background: color-mix(in srgb, var(--fc-bg-deep) 70%, var(--fc-panel));
}

.fc-ai-key-details {
    display: grid;
    flex: 1 1 150px;
    min-width: 0;
    gap: 2px;
}

.fc-ai-key-details strong,
.fc-ai-key-details code {
    overflow-wrap: anywhere;
}

.fc-ai-key-details code,
.fc-ai-model-id {
    color: var(--fc-secondary);
    font-size: 0.82rem;
}

.fc-ai-key-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.fc-ai-key-form {
    display: grid;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--fc-line);
}

.fc-ai-remember-option {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    color: var(--fc-text);
    font-size: 0.88rem;
    cursor: pointer;
}

.fc-ai-remember-option input {
    flex: 0 0 auto;
    width: auto;
    margin: 3px 0 0;
    accent-color: var(--fc-secondary);
}

.fc-ai-status {
    display: none;
    color: var(--fc-muted);
    overflow-wrap: anywhere;
}

.fc-ai-status:not(:empty) {
    display: block;
}

.fc-ai-status.is-error {
    border-color: color-mix(in srgb, var(--fc-danger) 45%, transparent);
    background: color-mix(in srgb, var(--fc-danger) 16%, var(--fc-panel));
    color: var(--fc-danger);
}

.fc-ai-status.is-success {
    border-color: color-mix(in srgb, var(--fc-success) 40%, transparent);
    background: color-mix(in srgb, var(--fc-success) 14%, var(--fc-panel));
    color: var(--fc-success);
}

.fc-ai-response {
    display: grid;
    gap: 12px;
    min-height: 180px;
}

.fc-ai-response-header {
    justify-content: flex-start;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--fc-line);
}

.fc-ai-response-header h3 {
    flex: 1 1 auto;
    margin: 0;
}

.fc-ai-response-meta {
    justify-content: flex-start;
    color: var(--fc-muted);
    font-size: 0.82rem;
}

.fc-ai-response-text {
    min-width: 0;
    min-height: 120px;
    max-height: min(65vh, 720px);
    margin: 0;
    padding: 14px;
    overflow: auto;
    border: 1px solid var(--fc-line);
    border-radius: 9px;
    background: color-mix(in srgb, var(--fc-bg-deep) 72%, var(--fc-panel));
    color: var(--fc-text);
    font: 0.9rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.fc-ai-response-text:empty::before {
    color: var(--fc-muted);
    content: "The AI response will appear here.";
    font-family: inherit;
}

.fc-ai-empty {
    padding: 14px;
    border: 1px dashed var(--fc-line);
    border-radius: 10px;
    color: var(--fc-muted);
    text-align: center;
}

.fc-ai-loading {
    cursor: progress;
    opacity: 0.72;
}

.fc-ai-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border: 1px solid var(--fc-line);
    border-radius: 999px;
    background: color-mix(in srgb, var(--fc-primary) 12%, var(--fc-panel));
    color: var(--fc-text);
    font-size: 0.78rem;
    font-weight: 700;
}

.fc-ai-warning {
    color: var(--fc-warning);
}

/* Header-triggered provider settings dialog; controls remain in one canonical DOM instance. */
dialog.fc-ai-settings-dialog {
    width: min(760px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    max-height: min(85vh, 900px);
    color: var(--fc-text);
    background: var(--fc-panel);
    border-color: var(--fc-line);
}

dialog.fc-ai-settings-dialog > form.fc-ai-settings-dialog-form {
    display: grid;
    gap: 16px;
    min-width: 0;
}

dialog.fc-ai-settings-dialog-form > h2 {
    margin: 0;
    color: var(--fc-text);
}

dialog.fc-ai-settings-dialog-description {
    margin: 0;
    color: var(--fc-muted);
}

.fc-ai-settings-dialog-content,
.fc-ai-settings {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.fc-ai-settings > h3 {
    margin: 0;
    color: var(--fc-text);
}

.fc-ai-settings .fc-ai-key-form {
    min-width: 0;
}

.fc-ai-settings .fc-ai-key-row {
    align-items: stretch;
}

.fc-ai-settings .fc-ai-key-row select {
    flex: 1 1 190px;
}

.fc-ai-settings .fc-ai-key-row .fc-button {
    flex: 0 0 auto;
}

.fc-ai-settings-dialog-form > .dialog-actions {
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px solid var(--fc-line);
}

@media (max-width: 760px) {
    .fc-ai-layout {
        grid-template-columns: 1fr;
    }

    .fc-ai-card {
        padding: 13px;
    }

    .fc-ai-response-header {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 520px) {
    dialog.fc-ai-settings-dialog > form.fc-ai-settings-dialog-form {
        gap: 12px;
        padding: 14px;
    }

    .fc-ai-settings-dialog-content,
    .fc-ai-settings {
        gap: 12px;
    }

    .fc-ai-settings .fc-ai-key-row {
        align-items: stretch;
        flex-direction: column;
    }

    .fc-ai-settings .fc-ai-key-row .fc-button {
        width: 100%;
    }

    .fc-ai-settings-dialog-form > .dialog-actions {
        align-items: stretch;
    }

    .fc-ai-settings-dialog-form > .dialog-actions .fc-button {
        width: 100%;
    }
}