/**
 * ARDEV AI Chat Widget — Styles
 * Reuses the theme's existing design tokens (colors, spacing, radii)
 * so the widget looks native to the site, not bolted on.
 */

.ardev-chat-launcher {
    position: fixed;
    right: clamp(16px, 4vw, 32px);
    bottom: clamp(16px, 4vw, 32px);
    z-index: 9000;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 100px;
    padding: 14px 20px 14px 16px;
    cursor: pointer;
    background: var(--accent-gradient);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--text-sm);
    box-shadow: var(--shadow-glow, 0 8px 32px rgba(155, 109, 214, 0.4));
    transition: transform var(--transition-base, 300ms ease);
    animation: ardev-launcher-breathe 3.2s ease-in-out infinite;
}

@keyframes ardev-launcher-breathe {
    0%, 100% { box-shadow: 0 8px 32px rgba(155, 109, 214, 0.4), 0 0 0 0 rgba(155, 109, 214, 0.45); }
    50% { box-shadow: 0 8px 32px rgba(155, 109, 214, 0.5), 0 0 0 10px rgba(155, 109, 214, 0); }
}

.ardev-chat-launcher:hover {
    animation-play-state: paused;
}

.ardev-chat-launcher-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ardev-chat-launcher-live {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--bg-primary);
    animation: ardev-live-pulse 1.8s ease-in-out infinite;
}

@keyframes ardev-live-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.75; }
}

@media (prefers-reduced-motion: reduce) {
    .ardev-chat-launcher { animation: none; }
    .ardev-chat-launcher-live { animation: none; }
    .ardev-chat-callout { transition: opacity 0.2s ease; }
    .ardev-chat-callout-dot { animation: none; }
}

/* Marketing callout — position, color, and message all vary per appearance */
.ardev-chat-callout {
    position: fixed;
    z-index: 8999;
    max-width: 230px;
    border-radius: 16px;
    padding: 12px 30px 12px 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s ease;
}

.ardev-chat-callout.is-visible {
    opacity: 1;
    transform: translate(0, 0) scale(1);
    pointer-events: auto;
}

/* Position: diagonal — above and moderately left of the launcher */
.ardev-chat-callout.pos-diagonal {
    right: calc(clamp(16px, 4vw, 32px) + 24px);
    bottom: calc(clamp(16px, 4vw, 32px) + 78px);
    transform: translate(6px, 10px) scale(0.9);
    transform-origin: bottom right;
}
.ardev-chat-callout.pos-diagonal::after { bottom: -5px; right: 22px; top: auto; left: auto; }

/* Position: directly above the launcher */
.ardev-chat-callout.pos-above {
    right: clamp(16px, 4vw, 32px);
    bottom: calc(clamp(16px, 4vw, 32px) + 78px);
    transform: translateY(10px) scale(0.9);
    transform-origin: bottom right;
}
.ardev-chat-callout.pos-above::after { bottom: -5px; right: 28px; top: auto; left: auto; }

/* Position: directly beside (left of) the launcher, same level */
.ardev-chat-callout.pos-left {
    right: calc(clamp(16px, 4vw, 32px) + 180px);
    bottom: clamp(16px, 4vw, 32px);
    transform: translateX(10px) scale(0.9);
    transform-origin: center right;
}
.ardev-chat-callout.pos-left::after { top: 50%; right: -5px; bottom: auto; left: auto; transform: translateY(-50%) rotate(45deg); }

/* Position: above and further left — a wider diagonal */
.ardev-chat-callout.pos-diagonal-far {
    right: calc(clamp(16px, 4vw, 32px) + 90px);
    bottom: calc(clamp(16px, 4vw, 32px) + 92px);
    transform: translate(10px, 10px) scale(0.9);
    transform-origin: bottom right;
}
.ardev-chat-callout.pos-diagonal-far::after { bottom: -5px; right: 34px; top: auto; left: auto; }

/* Alternating color themes — a different look each time it appears */
.ardev-chat-callout.theme-violet {
    background: linear-gradient(135deg, #b48ce8 0%, #9b6dd6 45%, #7048b8 100%);
    box-shadow: 0 10px 30px rgba(155, 109, 214, 0.4);
}
.ardev-chat-callout.theme-violet::after { background: #7048b8; }

.ardev-chat-callout.theme-teal {
    background: linear-gradient(135deg, #5eead4 0%, #2dd9c0 45%, #0d9488 100%);
    box-shadow: 0 10px 30px rgba(45, 217, 192, 0.4);
}
.ardev-chat-callout.theme-teal::after { background: #0d9488; }

.ardev-chat-callout.theme-coral {
    background: linear-gradient(135deg, #fb7185 0%, #f43f5e 45%, #be123c 100%);
    box-shadow: 0 10px 30px rgba(244, 63, 94, 0.4);
}
.ardev-chat-callout.theme-coral::after { background: #be123c; }

.ardev-chat-callout.theme-blue {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 45%, #1d4ed8 100%);
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4);
}
.ardev-chat-callout.theme-blue::after { background: #1d4ed8; }

.ardev-chat-callout-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--text-sm);
    color: #fff;
}

.ardev-chat-callout-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
    animation: ardev-live-pulse 1.8s ease-in-out infinite;
}

.ardev-chat-callout-tagline {
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    transition: opacity 0.25s ease;
}

.ardev-chat-callout-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast, 200ms), color var(--transition-fast, 200ms);
}

.ardev-chat-callout-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.ardev-chat-callout::after {
    content: '';
    position: absolute;
    bottom: -5px;
    right: 22px;
    width: 12px;
    height: 12px;
    transform: rotate(45deg);
    border-radius: 2px;
}

body.ardev-chat-modal-open .ardev-chat-callout,
body.mobile-menu-open .ardev-chat-callout {
    display: none;
}

@media (max-width: 480px) {
    .ardev-chat-callout.pos-diagonal,
    .ardev-chat-callout.pos-above,
    .ardev-chat-callout.pos-left,
    .ardev-chat-callout.pos-diagonal-far {
        max-width: calc(100vw - 32px);
        right: 16px;
        bottom: calc(16px + 70px);
        transform: translateY(10px) scale(0.9);
        transform-origin: bottom right;
    }
    .ardev-chat-callout.pos-diagonal::after,
    .ardev-chat-callout.pos-above::after,
    .ardev-chat-callout.pos-left::after,
    .ardev-chat-callout.pos-diagonal-far::after {
        bottom: -5px; right: 28px; top: auto; left: auto; transform: rotate(45deg);
    }
}

.ardev-chat-launcher:hover {
    transform: scale(1.04);
}

.ardev-chat-launcher-label {
    line-height: 1;
}

/* Hide the launcher while the modal is open behind it */
body.ardev-chat-modal-open .ardev-chat-launcher {
    display: none;
}

/* Also hide it while the mobile menu is open — it was overlapping the
   last menu item on small screens. */
body.mobile-menu-open .ardev-chat-launcher {
    display: none;
}

/* And hide it (plus the callout) once the footer scrolls into view — the
   footer has its own CTA button and email link in the same bottom-right
   corner, and a fixed clickable element sitting on top of them there was
   making that area very hard to scroll through. */
body.ardev-footer-in-view .ardev-chat-launcher,
body.ardev-footer-in-view .ardev-chat-callout,
body.ardev-cookie-banner-open .ardev-chat-launcher,
body.ardev-cookie-banner-open .ardev-chat-callout {
    display: none;
}

/* Smaller, icon-only footprint on narrow screens so the button covers
   far less of whatever content happens to be behind it at rest. */
@media (max-width: 480px) {
    .ardev-chat-launcher {
        padding: 14px;
        right: 16px;
        bottom: 16px;
    }
    .ardev-chat-launcher-label {
        display: none;
    }
}

.ardev-chat-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: 20px;
    overflow: hidden;
}

.ardev-chat-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--accent-gradient);
    color: #fff;
    flex-shrink: 0;
}

.ardev-chat-head-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ardev-chat-head-text strong {
    font-family: var(--font-display);
    font-size: var(--text-base);
}

.ardev-chat-head-text span {
    font-size: var(--text-xs);
    opacity: 0.85;
}

.ardev-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.ardev-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

/* "New messages" pill — floats above the input, appears only when the
   visitor has scrolled away from the bottom and something new arrived. */
.ardev-chat-new-messages {
    position: absolute;
    left: 50%;
    bottom: 76px;
    transform: translateX(-50%) translateY(8px);
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: 100px;
    padding: 7px 16px;
    font-size: var(--text-xs);
    font-weight: 600;
    box-shadow: 0 6px 20px rgba(155, 109, 214, 0.4);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 5;
}

.ardev-chat-new-messages.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.ardev-chat-messages {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.ardev-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: var(--text-sm);
    line-height: 1.5;
    white-space: pre-wrap;
}

.ardev-chat-msg-assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    white-space: normal;
}

.ardev-chat-msg-assistant p {
    margin: 0 0 8px;
}
.ardev-chat-msg-assistant p:last-child {
    margin-bottom: 0;
}
.ardev-chat-msg-assistant strong {
    font-weight: 700;
    color: var(--text-primary);
}
.ardev-chat-msg-assistant ul {
    margin: 4px 0 10px;
    padding-left: 20px;
}
.ardev-chat-msg-assistant li {
    margin-bottom: 4px;
}
.ardev-chat-msg-assistant br {
    display: block;
    content: '';
    margin-top: 4px;
}

/* Pricing / package tables rendered from the assistant's markdown */
.ardev-chat-table-wrap {
    overflow-x: auto;
    margin: 6px 0 12px;
    border-radius: 10px;
}
.ardev-chat-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    font-size: var(--text-xs);
    border: 1px solid var(--border-medium);
    border-radius: 10px;
    overflow: hidden;
}
.ardev-chat-table th {
    background: var(--accent-gradient);
    color: #fff;
    font-weight: 700;
    text-align: left;
    padding: 8px 10px;
}
.ardev-chat-table td {
    padding: 8px 10px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
}
.ardev-chat-table tr:nth-child(even) td {
    background: var(--bg-secondary);
}
.ardev-chat-table th:first-child, .ardev-chat-table td:first-child {
    font-weight: 600;
}

.ardev-chat-msg-user {
    align-self: flex-end;
    background: var(--accent-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ardev-chat-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
}

.ardev-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: ardev-chat-bounce 1.2s infinite ease-in-out;
}

.ardev-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ardev-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ardev-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.ardev-chat-form {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.ardev-chat-input {
    flex: 1;
    resize: none;
    max-height: 120px;
    min-height: 40px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-medium);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    outline: none;
}

.ardev-chat-input:focus {
    border-color: var(--accent-primary);
}

.ardev-chat-send {
    flex-shrink: 0;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0 var(--space-md);
    height: 40px;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
}

.ardev-chat-send:disabled {
    opacity: 0.6;
    cursor: default;
}

.ardev-chat-panel-inline {
    position: static;
    width: 100%;
    height: 100%;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,0.45));
    display: flex;
    flex-direction: column;
}

.ardev-chat-head-inline {
    border-radius: 0;
}

/* Terminal titlebar */
.ardev-term-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 20px 20px 0 0;
    flex-shrink: 0;
}

.ardev-term-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-strong);
}

.ardev-term-dot:nth-child(1) { background: var(--accent-primary); }
.ardev-term-dot:nth-child(2) { background: var(--accent-secondary); }

.ardev-term-tab {
    margin-left: var(--space-sm);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Boot sequence */
.ardev-term-boot {
    flex: 1;
    padding: var(--space-lg);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.ardev-term-line {
    animation: ardev-term-fade-in 300ms ease both;
}

.ardev-term-prompt {
    color: var(--accent-primary);
    font-weight: 600;
}

@keyframes ardev-term-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Quick-command chips */
.ardev-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 var(--space-md) var(--space-sm);
    flex-shrink: 0;
}

.ardev-chat-chip {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: 100px;
    padding: 6px 12px;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.ardev-chat-chip:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
}

.ardev-chat-messages {
    font-family: var(--font-primary);
}

.ardev-term-expand {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 6px;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.ardev-term-expand:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.ardev-chat-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    background: rgba(11, 13, 16, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    animation: ardev-modal-fade-in 200ms ease both;
}

@keyframes ardev-modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ardev-chat-expanded {
    position: static !important;
    inset: auto !important;
    width: min(760px, 100%) !important;
    height: min(82vh, 760px) !important;
    max-width: 100%;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6) !important;
    border-radius: 20px !important;
}

body.ardev-chat-modal-open {
    overflow: hidden;
}

@media (max-width: 640px) {
    .ardev-chat-modal-overlay { padding: 0; }
    .ardev-chat-expanded { width: 100% !important; height: 100% !important; border-radius: 0 !important; }
}

@media (max-width: 480px) {
    .ardev-chat-panel {
        right: -8px;
        width: calc(100vw - 24px);
    }
}
