:root {
    --aiagent-border: rgba(24, 36, 51, .12);
    --aiagent-muted: #667085;
    --aiagent-surface: #ffffff;
    --aiagent-subtle: #f6f8fb;
    --aiagent-accent: #2f6fed;
    --aiagent-success: #238636;
    --aiagent-shadow: 0 5px 18px rgba(31, 45, 61, .08);
}

.aiagent {
    width: 100%;
    margin: 0 0 12px;
}

.aiagent-card {
    overflow: hidden;
    border: 1px solid var(--aiagent-border);
    border-radius: 8px;
    background: var(--aiagent-surface);
    box-shadow: var(--aiagent-shadow);
}

.aiagent-header,
.aiagent-title,
.aiagent-actions,
.aiagent-status,
.aiagent-section-title,
.aiagent-resolution,
.aiagent-resolution-actions,
.aiagent-draft-head {
    display: flex;
    align-items: center;
}

.aiagent-header {
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--aiagent-border);
    background: var(--aiagent-subtle);
}

.aiagent-title {
    min-width: 0;
    gap: 7px;
    font-weight: 600;
}

.aiagent-actions,
.aiagent-resolution-actions {
    flex: 0 0 auto;
    gap: 6px;
}

.aiagent-mode-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border: 1px solid rgba(47, 111, 237, .22);
    border-radius: 999px;
    color: #2458b8;
    background: #edf4ff;
    font-size: 11px;
    font-weight: 600;
}

.aiagent-language-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 30px;
    padding: 0 7px;
    border: 1px solid rgba(24, 36, 51, .14);
    border-radius: 6px;
    background: #fff;
    color: #344054;
    font-size: 12px;
}

.aiagent-language-control select {
    width: 70px;
    border: 0;
    outline: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.aiagent-body {
    padding: 10px 12px 12px;
}

.aiagent-messages {
    height: 220px;
    overflow: auto;
    padding: 2px;
}

.aiagent-msg {
    display: flex;
    margin-bottom: 8px;
}

.aiagent-msg.user {
    justify-content: flex-end;
}

.aiagent-bubble {
    max-width: 92%;
    padding: 8px 10px;
    border: 1px solid var(--aiagent-border);
    border-radius: 8px;
    background: #fff;
    color: #253246;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
}

.aiagent-msg.user .aiagent-bubble {
    border-color: rgba(47, 111, 237, .22);
    background: #edf4ff;
}

.aiagent-bubble code {
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(24, 36, 51, .07);
    color: #253246;
    font-size: 12px;
}

.aiagent-status {
    gap: 7px;
    padding: 7px 0;
    color: var(--aiagent-muted);
    font-size: 12px;
}

.aiagent-sources,
.aiagent-resolution,
.aiagent-suggestions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--aiagent-border);
}

.aiagent-section-title {
    gap: 6px;
    color: #344054;
    font-size: 13px;
    font-weight: 600;
}

summary.aiagent-section-title {
    justify-content: space-between;
    cursor: pointer;
    list-style: none;
}

summary.aiagent-section-title::-webkit-details-marker {
    display: none;
}

summary.aiagent-section-title > span:first-child {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.aiagent-source-count {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #eef2f7;
    color: var(--aiagent-muted);
    text-align: center;
    font-size: 11px;
}

.aiagent-source-list {
    display: grid;
    gap: 4px;
    margin-top: 6px;
}

.aiagent-source {
    overflow: hidden;
    color: #2458b8;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aiagent-resolution {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    color: #344054;
    font-size: 13px;
}

.aiagent-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 10px;
}

.aiagent-compose textarea {
    min-height: 50px;
    resize: vertical;
}

.aiagent-draft-head {
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.aiagent-kv {
    display: grid;
    grid-template-columns: minmax(90px, 34%) minmax(0, 1fr);
    gap: 5px 8px;
    font-size: 12px;
}

.aiagent-kv .k {
    color: var(--aiagent-muted);
}

.aiagent-kv .v {
    overflow-wrap: anywhere;
    color: #344054;
}

.aiagent-note {
    margin-top: 8px;
    color: var(--aiagent-muted);
    font-size: 11px;
}

.aiagent-review {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--aiagent-border);
}

.aiagent-review-body {
    display: grid;
    gap: 8px;
    margin-top: 8px;
    font-size: 12px;
}

.aiagent-review-body p {
    margin: 0;
    color: #344054;
}

.aiagent-review-status,
.aiagent-review-list-title {
    display: flex;
    align-items: center;
    gap: 6px;
}

.aiagent-review-status {
    padding: 7px 9px;
    border-radius: 8px;
    font-weight: 600;
}

.aiagent-review-status.ok {
    border: 1px solid rgba(35, 134, 54, .22);
    background: rgba(35, 134, 54, .08);
    color: var(--aiagent-success);
}

.aiagent-review-status.warning {
    border: 1px solid rgba(245, 158, 11, .28);
    background: rgba(245, 158, 11, .10);
    color: #946200;
}

.aiagent-review-status.blocked {
    border: 1px solid rgba(220, 53, 69, .24);
    background: rgba(220, 53, 69, .07);
    color: #b42318;
}

.aiagent-review-list {
    display: grid;
    gap: 4px;
}

.aiagent-review-list-title {
    color: #344054;
    font-weight: 600;
}

.aiagent-review-list ul {
    margin: 0;
    padding-left: 19px;
    color: #344054;
}

.aiagent-customer-hidden {
    display: none !important;
}

.aiagent-original-hidden {
    display: none !important;
}

.aiagent-controlled-select {
    width: 100%;
}

.aiagent-required-attention {
    border-radius: 8px;
    outline: 2px solid rgba(220, 53, 69, .38);
    outline-offset: 2px;
}

.aiagent-locked-select {
    pointer-events: none;
    background-color: #f8fafc;
}

.aiagent-hidden {
    display: none !important;
}

/* Existing ticket auto-reply status popup */
.aiagent-autoreply-pop {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9999;
    width: min(420px, calc(100vw - 36px));
}

.aiagent-autoreply-card {
    overflow: hidden;
    border: 1px solid var(--aiagent-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: var(--aiagent-shadow);
}

.aiagent-autoreply-head,
.aiagent-autoreply-head .title,
.aiagent-autoreply-head .actions {
    display: flex;
    align-items: center;
}

.aiagent-autoreply-head {
    justify-content: space-between;
    gap: 8px;
    padding: 9px 11px;
    border-bottom: 1px solid var(--aiagent-border);
    background: var(--aiagent-subtle);
}

.aiagent-autoreply-head .title,
.aiagent-autoreply-head .actions {
    gap: 6px;
}

.aiagent-autoreply-head .title {
    font-weight: 600;
}

.aiagent-autoreply-body {
    padding: 9px 11px 11px;
    font-size: 13px;
}

.aiagent-autoreply-body .rowline {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
}

.aiagent-autoreply-body .rowline > span:first-child,
.aiagent-autoreply-body .hint {
    color: var(--aiagent-muted);
}

.aiagent-autoreply-body .err {
    max-height: 160px;
    overflow: auto;
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(220, 53, 69, .25);
    border-radius: 8px;
    background: rgba(220, 53, 69, .06);
    white-space: pre-wrap;
}

.aiagent-autoreply-body .hint {
    margin-top: 8px;
    font-size: 12px;
}

@media (max-width: 576px) {
    .aiagent-mode-chip {
        display: none;
    }

    .aiagent-resolution,
    .aiagent-draft-head {
        align-items: stretch;
        flex-direction: column;
    }

    .aiagent-resolution-actions .btn,
    .aiagent-draft-head .btn {
        flex: 1 1 auto;
    }
}
