/* RPA widget — aligné sur la charte Cara (light, blue/cyan).
 * JS dans rpa_widget.js + rpa_widget_inputs.js. */

/* Cache l'ancien panel split-screen */
#rpa-panel { display: none !important; }
body.rpa-active .app {
    padding-right: 0 !important;
    padding-bottom: 0 !important;
}

/* ────────── Container ────────── */
.rpa-widget {
    margin: 10px 0 6px;
    max-width: 560px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
    font-family: var(--font-ui);
    overflow: hidden;
    position: relative;
    animation: rw-pop 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.rpa-widget:hover { box-shadow: var(--shadow-lg); }

@keyframes rw-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ────────── Header ────────── */
.rpa-widget .rw-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: linear-gradient(180deg, rgba(0, 82, 255, 0.04), transparent);
    border-bottom: 1px solid var(--border-light);
    font-size: 0.78rem;
    font-weight: 550;
}

.rpa-widget .rw-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text-secondary);
    flex-shrink: 0;
    letter-spacing: -0.005em;
}
.rpa-widget .rw-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 0 rgba(0, 82, 255, 0.55);
    animation: rw-pulse 1.8s ease-in-out infinite;
}
.rpa-widget.rw-blocked .rw-status::before {
    background: var(--warning);
    box-shadow: 0 0 0 0 rgba(242, 169, 59, 0.55);
}
.rpa-widget.rw-completed .rw-status::before {
    background: var(--success);
    animation: none;
    box-shadow: none;
}
@keyframes rw-pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 82, 255, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(0, 82, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 82, 255, 0); }
}

.rpa-widget .rw-url {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.rpa-widget .rw-fullscreen {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    padding: 5px 9px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.rpa-widget .rw-fullscreen:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(0, 82, 255, 0.06);
}

/* ────────── Stage (frame) ────────── */
.rpa-widget .rw-stage {
    position: relative;
    background:
        repeating-linear-gradient(45deg, #FAFCFE 0, #FAFCFE 12px, #F4F8FC 12px, #F4F8FC 24px);
    aspect-ratio: 16 / 10;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.rpa-widget .rw-placeholder {
    color: var(--text-tertiary);
    font-size: 0.78rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}
.rpa-widget .rw-placeholder::before {
    content: '';
    width: 22px;
    height: 22px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: rw-spin 0.8s linear infinite;
}
@keyframes rw-spin {
    to { transform: rotate(360deg); }
}

.rpa-widget .rw-frame {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: crosshair;
    user-select: none;
    transition: opacity 0.2s ease;
    animation: rw-frame-fade 0.18s ease;
}
@keyframes rw-frame-fade {
    from { opacity: 0.85; }
    to { opacity: 1; }
}
.rpa-widget.rw-completed .rw-frame {
    cursor: default;
    filter: saturate(0.85);
}

/* ────────── Overlay captcha ────────── */
.rpa-widget .rw-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 249, 250, 0.96));
    backdrop-filter: blur(8px) saturate(1.1);
    -webkit-backdrop-filter: blur(8px) saturate(1.1);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 22px;
    text-align: center;
    line-height: 1.5;
}
.rpa-widget.rw-blocked .rw-overlay {
    display: flex;
    animation: rw-fade-in 0.25s ease;
}
@keyframes rw-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.rpa-widget .rw-overlay-icon {
    font-size: 28px;
    background: rgba(242, 169, 59, 0.14);
    color: var(--warning);
    width: 52px; height: 52px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.rpa-widget .rw-overlay-msg {
    max-width: 85%;
    color: var(--text-primary);
    font-size: 0.86rem;
    font-weight: 500;
}
.rpa-widget .rw-resume {
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: var(--radius-md);
    padding: 9px 18px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    font-family: inherit;
    box-shadow: 0 6px 16px rgba(0, 82, 255, 0.22);
    transition: var(--transition);
}
.rpa-widget .rw-resume:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(0, 82, 255, 0.28);
}

/* ────────── Footer ────────── */
.rpa-widget .rw-footer {
    padding: 7px 14px;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    background: var(--bg-surface-hover);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-family: var(--font-mono);
}
.rpa-widget .rw-action-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ────────── Mode plein écran (modal centrée) ────────── */
.rpa-widget.rw-fs {
    position: fixed;
    inset: 5vh 5vw;
    max-width: none;
    z-index: var(--ds-z-modal);
    box-shadow: 0 24px 60px rgba(11, 12, 16, 0.22);
    animation: rw-fs-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.rpa-widget.rw-fs .rw-stage {
    aspect-ratio: auto;
    height: calc(100% - 76px);
}
@keyframes rw-fs-in {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

#rpa-widget-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 12, 16, 0.40);
    backdrop-filter: blur(6px) saturate(0.95);
    -webkit-backdrop-filter: blur(6px) saturate(0.95);
    z-index: var(--ds-z-overlay);
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}
#rpa-widget-backdrop.open {
    display: block;
    opacity: 1;
}
