/* IA.css - version simplifiée et robuste pour Studio AI */

html,
body {
    height: 100%;
    min-height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
}

#sysimpleAIBuilder {
    height: 100vh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    flex: 0 0 auto;
}

.wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 320px;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
    box-sizing: border-box;
}

.pane,
#center,
#viewport,
#stageIA,
.card,
#chat-messages,
#aiOutput {
    min-width: 0;
}

.pane,
#center {
    min-height: 0;
    overflow: hidden;
}

.pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 4px;
}

#center {
    display: flex;
    flex-direction: column;
}

#viewport,
#stageIA {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

    #stageIA > .card:first-child {
        flex: 0 0 auto;
    }

    #stageIA > .card:last-child {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

#chat-messages.ai-chat-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 12px 18px 12px;
    box-sizing: border-box;
    background: transparent;
}

.ai-chat-footer {
    flex: 0 0 auto;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding-top: 10px;
}

.ai-selected-target {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 32px;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(26, 163, 255, 0.22);
    border-radius: 8px;
    background: rgba(26, 163, 255, 0.08);
    color: #243042;
    font-size: 12px;
    font-weight: 700;
}

    .ai-selected-target.hidden {
        display: none;
    }

    .ai-selected-target > i {
        color: #1aa3ff;
    }

    .ai-selected-target > span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ai-selected-target .btn-mini {
        width: 32px;
        min-width: 32px;
        height: 30px;
        padding: 0;
    }

#btnAiTargetPointer.is-active {
    border-color: rgba(26, 163, 255, 0.55);
    color: #ffffff;
    background: #1aa3ff;
}

body.ai-targeting,
body.ai-targeting * {
    cursor: crosshair !important;
}

.ai-target-hover {
    position: relative;
    outline: 2px solid #1aa3ff !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(26, 163, 255, 0.18) !important;
}

.direct-chat-msg {
    clear: both;
    width: 100%;
    margin-bottom: 16px;
}

    .direct-chat-msg:last-child {
        margin-bottom: 0;
    }

.direct-chat-info {
    margin: 0 0 4px 0;
    font-size: 12px;
    opacity: 0.75;
}

.direct-chat-name,
.direct-chat-timestamp {
    max-width: calc(100% - 56px);
}

.direct-chat-img {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50%;
    object-fit: cover;
}

.direct-chat-msg .direct-chat-img {
    float: left;
    margin: 0 10px 0 0;
}

.direct-chat-msg.right .direct-chat-img {
    float: right;
    margin: 0 0 0 10px;
}

.direct-chat-text {
    position: relative;
    display: block;
    width: fit-content;
    max-width: min(78%, 980px);
    min-width: 80px;
    padding: 12px 14px;
    box-sizing: border-box;
    border-radius: 16px;
    line-height: 1.45;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
    box-shadow: none;
}

.direct-chat-msg:not(.right) .direct-chat-text {
    margin-left: 44px;
    margin-right: auto;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: #243042;
}

.direct-chat-msg.right .direct-chat-text {
    margin-right: 44px;
    margin-left: auto;
    background: #dfe9f8;
    border: 1px solid rgba(67, 103, 160, 0.18);
    color: #243042;
}

.direct-chat-text > :first-child {
    margin-top: 0;
}

.direct-chat-text > :last-child {
    margin-bottom: 0;
}

.direct-chat-text p,
.direct-chat-text ul,
.direct-chat-text ol,
.direct-chat-text pre,
.direct-chat-text table,
.direct-chat-text blockquote,
.direct-chat-text .alert,
.direct-chat-text .card,
.direct-chat-text .panel {
    margin: 0 0 10px 0;
    max-width: 100%;
}

.direct-chat-text ul,
.direct-chat-text ol {
    padding-left: 20px;
}

.direct-chat-text pre,
#aiOutput {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.direct-chat-text code {
    white-space: pre-wrap;
}

.direct-chat-text table {
    display: block;
    overflow-x: auto;
}

.ai-command-output {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

    .ai-command-output pre {
        margin: 0;
        max-height: 220px;
        overflow: auto;
        background: #f7faf8;
        border: 1px solid #cfe8d3;
        border-radius: 10px;
        padding: 10px;
    }

#aiOutput {
    min-height: 160px;
    max-height: 40vh;
    overflow: auto;
    padding: 12px;
    border-radius: 12px;
    background: #f7f8fa;
    border: 1px solid rgba(0, 0, 0, 0.08);
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    color: #243042;
}

@media (max-width: 1200px) {
    .wrap {
        grid-template-columns: 250px minmax(0, 1fr) 290px;
    }
}

@media (max-width: 980px) {
    body {
        overflow: auto;
    }

    #sysimpleAIBuilder {
        height: auto;
        min-height: 100vh;
    }

    .wrap {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .pane,
    #center {
        overflow: visible;
    }

    #stageIA > .card:last-child,
    #chat-messages.ai-chat-area {
        min-height: 420px;
    }

    #aiOutput {
        max-height: 260px;
    }
}

.btn-mini.is-active {
    border-color: rgba(76, 132, 255, 0.55);
    box-shadow: 0 0 0 1px rgba(76, 132, 255, 0.18) inset;
}

.html-content h1,
.html-content h2,
.html-content h3,
.html-content h4,
.html-content h5,
.html-content h6 {
    margin-top: 0;
}

.html-content ul,
.html-content ol {
    margin-bottom: 0;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9999;
    display: none;
    min-width: 220px;
    max-width: 420px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(36, 48, 66, 0.96);
    color: #fff;
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
}

    .toast.is-error {
        background: rgba(148, 43, 43, 0.96);
    }

.ai-feedback-bar,
.ai-confirm-bar {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.ai-feedback-actions,
.ai-confirm-actions,
.ai-feedback-extra-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ai-feedback-btn,
.ai-confirm-btn,
.ai-feedback-submit-negative,
.ai-feedback-cancel {
    font-size: 12px;
    line-height: 1.2;
}

.ai-feedback-extra {
    margin-top: 10px;
}

    .ai-feedback-extra.hidden {
        display: none;
    }

.ai-feedback-text {
    resize: vertical;
    min-height: 64px;
    margin-bottom: 8px;
}

.ai-confirm-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ai-confirm-label {
    font-size: 12px;
    opacity: .8;
}

.ai-feedback-status {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: #2c6f57;
}

.ai-feedback-bar.is-sent,
.ai-confirm-bar.is-sent {
    opacity: .92;
}

.mobile-pane-btn,
.mobile-pane-backdrop {
    display: none;
}

@media (max-width: 980px) {
    html,
    body,
    #sysimpleAIBuilder {
        height: 100%;
        min-height: 100dvh;
    }

    body {
        overflow: hidden;
    }

    #sysimpleAIBuilder {
        height: 100dvh;
        min-height: 100dvh;
    }

    .topbar {
        position: relative;
        z-index: 1200;
    }

    .brand,
    .topbar-right {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .topbar .title {
        font-size: 18px;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-pane-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        border: 1px solid rgba(0,0,0,.12);
        background: #fff;
        color: #243042;
        border-radius: 10px;
        padding: 8px 10px;
        font-size: 12px;
        line-height: 1;
        flex: 0 0 auto;
    }

    .wrap {
        grid-template-columns: minmax(0, 1fr);
        padding: 10px;
        gap: 0;
        overflow: hidden;
        position: relative;
    }

    #center,
    #viewport,
    #stageIA,
    #stageIA > .card:last-child {
        min-height: 0;
        height: 100%;
    }

        #stageIA > .card:last-child {
            display: flex;
            flex-direction: column;
        }

    #chat-messages.ai-chat-area {
        min-height: 0;
    }

    .pane-left,
    .pane-right {
        position: fixed;
        top: 0;
        bottom: 0;
        width: min(86vw, 360px);
        max-width: 360px;
        background: #fff;
        z-index: 1250;
        padding: 72px 14px 14px 14px;
        box-shadow: 0 18px 40px rgba(0,0,0,.22);
        overflow-y: auto;
        transition: transform .22s ease;
        overscroll-behavior: contain;
    }

    .pane-left {
        left: 0;
        transform: translateX(-104%);
    }

    .pane-right {
        right: 0;
        transform: translateX(104%);
    }

        .pane-left.is-open,
        .pane-right.is-open {
            transform: translateX(0);
        }

    .mobile-pane-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(17, 24, 39, .36);
        z-index: 1240;
    }

        .mobile-pane-backdrop.is-visible {
            display: block;
        }

    #aiOutput {
        max-height: 30dvh;
    }
}

.ai-search-grid {
    margin-top: 8px;
}

.ai-search-grid-scroll {
    max-width: 100%;
    max-height: 420px;
    overflow-x: auto;
    overflow-y: auto;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    background: #fff;
}

.ai-search-grid-table {
    margin-bottom: 0;
    min-width: 900px;
    table-layout: auto;
    background: #fff;
}

.direct-chat-text .ai-search-grid-table {
    display: table;
    width: max-content;
    min-width: 100%;
    max-width: none;
    color: #263238;
}

.direct-chat-text .ai-search-grid-table th,
.direct-chat-text .ai-search-grid-table td {
    min-width: 120px;
    padding: 8px 10px;
    word-break: normal;
    overflow-wrap: normal;
    white-space: nowrap;
}

    .ai-search-grid-table thead th {
        position: sticky;
        top: 0;
        z-index: 2;
        background: #f7f8fa;
        white-space: nowrap;
    }

    .ai-search-grid-table th,
    .ai-search-grid-table td {
        vertical-align: top;
        white-space: nowrap;
    }

    .ai-search-grid-table td {
        max-width: 320px;
    }

        .ai-search-grid-table td > * {
            white-space: normal;
        }

.ai-grid-id {
    white-space: nowrap;
    font-weight: 600;
    color: #555;
}

.ai-grid-muted {
    color: #999;
}

.ai-grid-bool-true {
    color: #1e7e34;
    font-weight: 600;
}

.ai-grid-bool-false {
    color: #b52b27;
    font-weight: 600;
}
