/* AI manager floating widget */

.ai-mgr-mount {
    --ai-mgr-left: 1.25rem;
    --ai-mgr-bottom: 1.25rem;
    --ai-mgr-panel-bottom: 6.75rem;
}

body.panel-cabinet .ai-mgr-mount,
body.panel-admin .ai-mgr-mount,
body.panel-staff .ai-mgr-mount,
body.has-site-sidebar .ai-mgr-mount {
    --ai-mgr-left: calc(var(--cabinet-sidebar-w, var(--site-sidebar-w, 240px)) + 1rem);
}

@media (max-width: 900px) {
    body.panel-cabinet .ai-mgr-mount,
    body.panel-admin .ai-mgr-mount,
    body.panel-staff .ai-mgr-mount,
    body.has-site-sidebar .ai-mgr-mount {
        --ai-mgr-left: 1rem;
    }
}

.ai-mgr-widget[hidden],
.ai-mgr-widget:not(.ai-mgr-widget--open) {
    display: none !important;
}

body.panel-admin .ai-mgr-mount,
body.panel-staff .ai-mgr-mount {
    --ai-mgr-panel-bottom: 7.5rem;
}

body.panel-admin .ai-mgr-widget,
body.panel-staff .ai-mgr-widget {
    max-height: min(40rem, calc(100vh - var(--ai-mgr-panel-bottom) - 1.5rem));
}

.ai-mgr-widget {
    position: fixed;
    inset: 0;
    z-index: 1050;
    pointer-events: none;
}

.ai-mgr-widget.ai-mgr-widget--open {
    display: block !important;
    pointer-events: auto;
}

.ai-mgr-widget__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 0;
    cursor: pointer;
}

.ai-mgr-widget__panel {
    position: fixed;
    left: var(--ai-mgr-left);
    bottom: var(--ai-mgr-panel-bottom);
    z-index: 2;
    width: min(36rem, calc(100vw - var(--ai-mgr-left) - 1.25rem));
    /* Занимаем почти весь экран над кнопкой — раньше 34rem «не разворачивался» полностью */
    height: calc(100vh - var(--ai-mgr-panel-bottom) - 1rem);
    max-height: calc(100vh - var(--ai-mgr-panel-bottom) - 1rem);
    background: var(--bg-elevated, #252830);
    border: 1px solid var(--border, #3a404c);
    border-top: 2px solid var(--accent, #20c997);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.35),
        0 16px 48px rgba(0, 0, 0, 0.55),
        0 0 32px rgba(32, 201, 151, 0.08);
    overflow: hidden;
    pointer-events: auto;
}

.ai-mgr-widget__panel.ai-mgr-widget__panel--full {
    left: max(0.75rem, var(--ai-mgr-left));
    right: 0.75rem;
    top: 0.75rem;
    bottom: var(--ai-mgr-panel-bottom);
    width: auto;
    height: auto;
    max-height: none;
    border-radius: 12px;
}

.ai-mgr-widget__fab {
    position: fixed;
    left: var(--ai-mgr-left);
    bottom: var(--ai-mgr-bottom);
    z-index: 1060;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    border: none;
    background: var(--accent, #20c997);
    color: #0d1f1a;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    pointer-events: auto;
    touch-action: none;
}

.ai-mgr-mount--dragging {
    user-select: none;
}

.ai-mgr-mount--dragging .ai-mgr-widget__fab,
.ai-mgr-mount--dragging .ai-mgr-widget__head[data-ai-mgr-drag-handle] {
    cursor: grabbing;
}

.ai-mgr-mount--dragging .ai-mgr-widget__fab {
    transition: none;
}

.ai-mgr-widget__head[data-ai-mgr-drag-handle] {
    cursor: grab;
    touch-action: none;
}

.ai-mgr-widget__fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.ai-mgr-widget__fab[aria-expanded="true"] {
    z-index: 1070;
    background: var(--bg-elevated, #252830);
    color: var(--text-secondary, #ccc);
    border: 1px solid var(--border, #3a404c);
}

.ai-mgr-widget__fab[aria-expanded="true"] .ai-mgr-widget__fab-icon--open {
    display: none;
}

.ai-mgr-widget__fab[aria-expanded="true"] .ai-mgr-widget__fab-icon--close {
    display: block;
}

.ai-mgr-widget__fab-icon--close {
    display: none;
    font-size: 1.5rem;
    line-height: 1;
}

.ai-mgr-widget__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-soft, rgba(255, 255, 255, 0.08));
    background: var(--accent-soft, rgba(32, 201, 151, 0.12));
    flex-shrink: 0;
}

.ai-mgr-widget__head-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.ai-mgr-widget__new-topic,
.ai-mgr-widget__clear-history {
    font-size: 0.6875rem;
    padding: 0.2rem 0.45rem;
    border-radius: 0.35rem;
    border: 1px solid var(--border-soft, #444);
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.ai-mgr-widget__pending {
    margin: 0 0.75rem 0.5rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--accent-border, #3d5a80);
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.15);
    pointer-events: auto;
}

.ai-mgr-widget__pending-title {
    font-size: 0.6875rem;
    margin-bottom: 0.35rem;
}

.ai-mgr-widget__pending-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-top: 0.35rem;
}

.ai-mgr-widget__pending-text {
    flex: 1;
    font-size: 0.8125rem;
    min-width: 8rem;
}

.ai-mgr-widget__alerts {
    margin: 0 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    pointer-events: auto;
}

.ai-mgr-widget__docs {
    margin: 0 0.75rem 0.5rem;
    padding: 0.5rem 0.65rem;
    border: 1px dashed var(--border-soft, #444);
    border-radius: 0.5rem;
    font-size: 0.75rem;
    pointer-events: auto;
}

.ai-mgr-widget__docs-title {
    margin-bottom: 0.25rem;
}

.ai-mgr-widget__doc {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.ai-mgr-widget__doc-upload {
    display: inline-block;
    margin-top: 0.35rem;
    cursor: pointer;
}

.ai-mgr-widget__alert {
    font-size: 0.75rem;
    line-height: 1.35;
    padding: 0.45rem 0.55rem;
    border-radius: 0.4rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.ai-mgr-widget__alert--warning {
    border: 1px solid rgba(255, 180, 80, 0.45);
    background: rgba(255, 180, 80, 0.08);
}

.ai-mgr-widget__alert--info {
    border: 1px solid rgba(120, 160, 255, 0.35);
    background: rgba(120, 160, 255, 0.08);
}

.ai-mgr-widget__alert-text {
    flex: 1;
    min-width: 10rem;
}

.ai-mgr-widget__alert-link {
    font-size: 0.6875rem;
    white-space: nowrap;
}


.ai-mgr-widget__title {
    display: block;
    font-size: 0.9375rem;
}

.ai-mgr-widget__sub {
    display: block;
    font-size: 0.7rem;
    margin-top: 0.15rem;
}

.ai-mgr-widget__minimize {
    background: var(--bg, #1a1d24);
    border: 1px solid var(--border, #3a404c);
    color: var(--text-secondary, #ccc);
    font-size: 0.75rem;
    line-height: 1.2;
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-mgr-widget__minimize:hover {
    border-color: var(--accent, #20c997);
    color: var(--accent, #20c997);
}

.ai-mgr-widget__close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    padding: 0 0.15rem;
    flex-shrink: 0;
}

.ai-mgr-widget__close:hover {
    opacity: 1;
}

.ai-mgr-widget__log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    min-height: 12rem;
}

.ai-mgr-widget__msg {
    margin-bottom: 0.75rem;
}

.ai-mgr-widget__msg-role {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-bottom: 0.15rem;
}

.ai-mgr-widget__msg-body {
    white-space: pre-wrap;
    line-height: 1.4;
}

.ai-mgr-widget__cta {
    padding: 0 1rem 0.75rem;
    flex-shrink: 0;
}

.ai-mgr-widget__compose {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-soft, rgba(255, 255, 255, 0.08));
    background: rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.ai-mgr-widget__attach {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    height: 2.5rem;
    padding: 0 0.55rem;
    margin: 0;
    border-radius: 8px;
    border: 1px solid var(--border, #3a404c);
    background: var(--bg, #1a1d24);
    color: inherit;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    user-select: none;
}

.ai-mgr-widget__attach:hover {
    border-color: var(--accent, #20c997);
    color: var(--accent, #20c997);
}

.ai-mgr-widget__attach.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-mgr-widget__attach input {
    display: none;
}

.ai-mgr-widget__expand {
    background: var(--bg, #1a1d24);
    border: 1px solid var(--border, #3a404c);
    color: var(--text-secondary, #ccc);
    font-size: 0.75rem;
    line-height: 1.2;
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.ai-mgr-widget__expand:hover {
    border-color: var(--accent, #20c997);
    color: var(--accent, #20c997);
}

.ai-mgr-widget__compose textarea {
    flex: 1;
    min-width: 0;
    resize: none;
    min-height: 2.25rem;
    max-height: 6rem;
    font-size: 0.8125rem;
    padding: 0.5rem 0.625rem;
    border-radius: 8px;
    border: 1px solid var(--border, #3a404c);
    background: var(--bg, #1a1d24);
    color: inherit;
}

.ai-mgr-widget__compose .ai-mgr-widget__send {
    flex-shrink: 0;
    margin: 0;
    padding: 0.5rem 0.75rem;
    min-width: 2.75rem;
    font-size: 0.8125rem;
    line-height: 1.2;
    white-space: nowrap;
}

.ai-mgr-widget__cta .btn {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
}

.ai-mgr-widget__foot {
    font-size: 0.7rem;
    text-align: center;
    padding: 0 1rem 0.5rem;
    margin: 0;
    flex-shrink: 0;
}

.ai-mgr-widget__disclaimer {
    font-size: 0.625rem;
    line-height: 1.35;
    padding: 0 1rem 0.35rem;
    margin: 0;
    opacity: 0.75;
    flex-shrink: 0;
}

.ai-mgr-widget--loading .ai-mgr-widget__compose .ai-mgr-widget__send {
    pointer-events: none;
    opacity: 0.6;
}

body.ai-mgr-widget-open {
    overflow: hidden;
}

@media (max-width: 480px) {
    .ai-mgr-mount {
        --ai-mgr-left: 0.75rem;
        --ai-mgr-bottom: 1rem;
        --ai-mgr-panel-bottom: 5rem;
    }

    .ai-mgr-widget__panel {
        width: calc(100vw - 1.5rem);
        height: calc(100vh - 5.5rem);
        max-height: calc(100vh - 5.5rem);
    }
}
