/* ═══════════════════════════════════════════════════════════════
   AGENT PANEL v2.0 — Premium Glassmorphism Design
   Manus.ai / Linear / Notion inspired
   ═══════════════════════════════════════════════════════════════ */

/* ─── Overlay ──────────────────────────────────────────────── */
.ap-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.ap-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* ─── Panel Container — Glass Card ─────────────────────────── */
.ap-panel {
    width: 520px;
    max-width: 94vw;
    max-height: 88vh;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(60px) saturate(1.6);
    -webkit-backdrop-filter: blur(60px) saturate(1.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.ap-overlay.open .ap-panel {
    transform: translateY(0) scale(1);
}

/* ─── Header ───────────────────────────────────────────────── */
.ap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 24px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ap-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    animation: apFadeRight 0.4s ease 0.1s both;
}

@keyframes apFadeRight {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.ap-icon {
    width: 46px;
    height: 46px;
    min-width: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.15), rgba(99, 102, 241, 0.08));
    border: 1px solid rgba(129, 140, 248, 0.20);
    border-radius: 14px;
    transition: all 0.3s ease;
}

.ap-icon:hover {
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.22), rgba(99, 102, 241, 0.14));
    box-shadow: 0 0 20px rgba(129, 140, 248, 0.15);
}

.ap-icon svg {
    width: 20px;
    height: 20px;
    color: #818cf8;
}

/* Gmail-specific gradient icon */
.ap-panel[data-agent="gmail-agent"] .ap-icon {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(251, 146, 60, 0.10));
    border-color: rgba(239, 68, 68, 0.20);
}

.ap-panel[data-agent="gmail-agent"] .ap-icon svg {
    color: #f87171;
}

/* Drive-specific */
.ap-panel[data-agent="drive-agent"] .ap-icon {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(16, 185, 129, 0.10));
    border-color: rgba(59, 130, 246, 0.20);
}

.ap-panel[data-agent="drive-agent"] .ap-icon svg {
    color: #60a5fa;
}

/* Calendar-specific */
.ap-panel[data-agent="calendar-agent"] .ap-icon {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.12), rgba(16, 185, 129, 0.10));
    border-color: rgba(34, 197, 94, 0.20);
}

.ap-panel[data-agent="calendar-agent"] .ap-icon svg {
    color: #4ade80;
}

.ap-header-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ap-title {
    font-size: 1.12rem;
    font-weight: 650;
    color: #f0f0f3;
    letter-spacing: -0.3px;
}

.ap-desc {
    font-size: 0.76rem;
    color: rgba(161, 161, 170, 0.7);
    font-weight: 400;
    line-height: 1.4;
}

/* Close Button */
.ap-close-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    color: rgba(161, 161, 170, 0.5);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ap-close-btn svg {
    width: 15px;
    height: 15px;
}

.ap-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e4e4e7;
    transform: rotate(90deg);
}

/* ─── Body ─────────────────────────────────────────────────── */
.ap-body {
    padding: 6px 24px 24px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: none;
}

.ap-body::-webkit-scrollbar {
    display: none;
}

/* ─── Section ──────────────────────────────────────────────── */
.ap-section {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    animation: apFadeUp 0.35s ease both;
}

.ap-section:nth-child(1) {
    animation-delay: 0.08s;
}

.ap-section:nth-child(2) {
    animation-delay: 0.14s;
}

.ap-section:nth-child(3) {
    animation-delay: 0.20s;
}

.ap-section:nth-child(4) {
    animation-delay: 0.26s;
}

.ap-section:nth-child(5) {
    animation-delay: 0.32s;
}

.ap-section:last-child {
    border-bottom: none;
}

@keyframes apFadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ap-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(161, 161, 170, 0.45);
    text-transform: uppercase;
    margin-bottom: 12px;
}

/* ─── Status Pill ──────────────────────────────────────────── */
.ap-status-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ap-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    transition: all 0.3s ease;
}

.ap-pill-connected {
    background: linear-gradient(135deg, #22c55e, #10b981);
    color: #fff;
    box-shadow: 0 2px 16px rgba(34, 197, 94, 0.25);
}

.ap-pill-connected .ap-pill-dot {
    width: 7px;
    height: 7px;
    background: #fff;
    border-radius: 50%;
    animation: apPulse 2s ease-in-out infinite;
}

@keyframes apPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.ap-pill-disconnected {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(161, 161, 170, 0.7);
}

.ap-pill-disconnected .ap-pill-dot {
    width: 7px;
    height: 7px;
    background: #ef4444;
    border-radius: 50%;
}

/* ─── Permissions Badges ───────────────────────────────────── */
.ap-scopes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ap-scope-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 500;
    color: rgba(161, 161, 170, 0.8);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    padding: 5px 12px;
    border-radius: 8px;
    letter-spacing: 0.2px;
    transition: all 0.25s ease;
}

.ap-scope-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 2px;
    background: #818cf8;
    opacity: 0.7;
}

.ap-scope-badge:hover {
    background: rgba(129, 140, 248, 0.08);
    border-color: rgba(129, 140, 248, 0.18);
    color: #c7d2fe;
    box-shadow: 0 0 12px rgba(129, 140, 248, 0.08);
}

/* ─── Buttons Base ─────────────────────────────────────────── */
.ap-auth-actions,
.ap-test-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ap-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 18px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.82rem;
    font-weight: 530;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    background: transparent;
}

.ap-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

/* ─── Connect Button — Premium CTA ────────────────────────── */
.ap-btn-connect {
    background: linear-gradient(135deg, #818cf8, #6366f1);
    border: none;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(129, 140, 248, 0.25);
    position: relative;
    overflow: hidden;
}

.ap-btn-connect::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.ap-btn-connect:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(129, 140, 248, 0.35);
}

.ap-btn-connect:hover::after {
    opacity: 1;
}

.ap-btn-connect:active {
    transform: translateY(0);
}

.ap-btn-connect:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
    box-shadow: none;
}

/* Spinner */
.ap-spin {
    animation: apSpin 0.8s linear infinite;
}

@keyframes apSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ─── Disconnect Button — Destructive ──────────────────────── */
.ap-btn-disconnect {
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
}

.ap-btn-disconnect:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.10), rgba(220, 38, 38, 0.08));
    border-color: rgba(239, 68, 68, 0.35);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.12);
    transform: translateY(-1px);
}

.ap-btn-disconnect:active {
    transform: translateY(0) scale(0.98);
}

/* ─── Test Buttons — Accordion Style ───────────────────────── */
.ap-btn-test {
    background: rgba(255, 255, 255, 0.03);
    color: rgba(161, 161, 170, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    position: relative;
}

.ap-btn-test::before {
    content: '▸';
    font-size: 0.7rem;
    color: rgba(161, 161, 170, 0.3);
    transition: transform 0.3s ease, color 0.3s;
    margin-right: -4px;
}

.ap-btn-test:hover {
    background: rgba(129, 140, 248, 0.06);
    border-color: rgba(129, 140, 248, 0.14);
    color: #c7d2fe;
    box-shadow: 0 2px 12px rgba(129, 140, 248, 0.08);
}

.ap-btn-test:hover::before {
    color: #818cf8;
    transform: rotate(90deg);
}

.ap-btn-test:hover svg {
    color: #818cf8;
}

.ap-btn-test svg {
    color: rgba(161, 161, 170, 0.4);
}

/* ─── Compose Email Button (Gmail-specific) ────────────────── */
.ap-btn-compose {
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border: none;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.2);
}

.ap-btn-compose:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.35);
}

/* ─── Test Output — Code Editor Style ──────────────────────── */
.ap-test-output {
    display: none;
    margin-top: 14px;
    padding: 0;
    background: rgba(0, 0, 0, 0.40);
    backdrop-filter: blur(40px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    overflow: hidden;
    animation: apSlideDown 0.3s ease both;
}

.ap-test-output.visible {
    display: block;
}

.ap-output-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
}

.ap-output-bar .ap-dot-red,
.ap-output-bar .ap-dot-yellow,
.ap-output-bar .ap-dot-green {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.ap-dot-red {
    background: #ef4444;
}

.ap-dot-yellow {
    background: #eab308;
}

.ap-dot-green {
    background: #22c55e;
}

.ap-output-bar span:last-child {
    margin-left: auto;
    font-size: 0.62rem;
    color: rgba(161, 161, 170, 0.35);
    font-weight: 500;
    letter-spacing: 0.5px;
}

.ap-output-code {
    padding: 16px 18px;
    color: rgba(161, 161, 170, 0.85);
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
    font-size: 0.7rem;
    line-height: 1.7;
    max-height: 260px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    scrollbar-width: none;
}

.ap-output-code::-webkit-scrollbar {
    display: none;
}

@keyframes apSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Send Email Trigger Row ───────────────────────────────── */
.ap-compose-section {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    animation: apFadeUp 0.35s ease 0.34s both;
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 540px) {
    .ap-panel {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 16px 16px 0 0;
        margin-top: auto;
    }

    .ap-header {
        padding: 18px 18px 14px;
    }

    .ap-body {
        padding: 4px 18px 20px;
    }

    .ap-icon {
        width: 38px;
        height: 38px;
        min-width: 38px;
        border-radius: 12px;
    }

    .ap-icon svg {
        width: 17px;
        height: 17px;
    }
}