/**
 * 21st Castle Developers - Chat Widget
 * Self-contained styling (does not depend on styles.css) so it can be
 * dropped into any page, including standalone pages like 404.html and
 * green-boulevard.html.
 */

#ccwRoot {
    --ccw-primary: #0a0a0a;
    --ccw-accent: #c9a962;
    --ccw-accent-light: #e4d4a5;
    --ccw-white: #faf7f2;
    --ccw-whatsapp: #25D366;
    --ccw-font-display: 'Cormorant Garamond', Georgia, serif;
    --ccw-font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    position: fixed;
    z-index: 2147483000;
    bottom: 24px;
    left: 24px;
    font-family: var(--ccw-font-body);
}

#ccwRoot * {
    box-sizing: border-box;
}

/* Bubble button */
.ccw-bubble {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 9999px;
    border: 1px solid rgba(201, 169, 98, 0.5);
    background: linear-gradient(135deg, #c9a962 0%, #e4d4a5 100%);
    color: #0a0a0a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 rgba(201, 169, 98, 0);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    padding: 0;
}

.ccw-bubble:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4), 0 0 32px rgba(201, 169, 98, 0.35);
}

.ccw-bubble .ccw-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transform: scale(1) rotate(0deg);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ccw-bubble .ccw-icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-45deg);
}

#ccwRoot.ccw-open .ccw-bubble .ccw-icon-chat {
    opacity: 0;
    transform: scale(0.5) rotate(45deg);
}

#ccwRoot.ccw-open .ccw-bubble .ccw-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.ccw-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ccw-whatsapp);
    border: 2px solid var(--ccw-primary);
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ccw-badge.ccw-show {
    opacity: 1;
    transform: scale(1);
}

/* Panel */
.ccw-panel {
    position: absolute;
    bottom: 72px;
    left: 0;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(201, 169, 98, 0.25);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom left;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.25s ease;
}

#ccwRoot.ccw-open .ccw-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.ccw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    border-bottom: 1px solid rgba(201, 169, 98, 0.3);
    flex-shrink: 0;
}

.ccw-title {
    font-family: var(--ccw-font-display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ccw-accent-light);
    line-height: 1.2;
}

.ccw-subtitle {
    font-size: 0.75rem;
    color: rgba(250, 247, 242, 0.55);
    margin-top: 2px;
}

.ccw-close {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--ccw-white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    transition: background 0.2s ease, color 0.2s ease;
}

.ccw-close:hover {
    background: rgba(201, 169, 98, 0.2);
    color: var(--ccw-accent);
}

.ccw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(201, 169, 98, 0.4) transparent;
}

.ccw-messages::-webkit-scrollbar {
    width: 6px;
}

.ccw-messages::-webkit-scrollbar-thumb {
    background: rgba(201, 169, 98, 0.35);
    border-radius: 9999px;
}

.ccw-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-line;
}

.ccw-msg-bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(201, 169, 98, 0.15);
    color: var(--ccw-white);
    border-radius: 4px 14px 14px 14px;
}

.ccw-typing {
    padding: 12px 16px;
}

.ccw-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ccw-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ccw-accent-light);
    opacity: 0.4;
    animation: ccwTypingBounce 1s infinite ease-in-out;
}

.ccw-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.ccw-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes ccwTypingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.ccw-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #c9a962 0%, #e4d4a5 100%);
    color: #14120a;
    border-radius: 14px 4px 14px 14px;
    font-weight: 500;
}

.ccw-msg-link {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    text-decoration: none;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ccw-msg-link:hover {
    transform: translateY(-2px);
}

.ccw-msg-link-whatsapp {
    background: var(--ccw-whatsapp);
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
}

.ccw-msg-link-whatsapp:hover {
    box-shadow: 0 8px 20px rgba(37, 211, 102, 0.4);
}

.ccw-msg-link-maps,
.ccw-msg-link-site {
    background: transparent;
    border: 1px solid rgba(201, 169, 98, 0.5);
    color: var(--ccw-accent-light);
}

.ccw-msg-link-maps:hover,
.ccw-msg-link-site:hover {
    background: rgba(201, 169, 98, 0.15);
    box-shadow: 0 4px 14px rgba(201, 169, 98, 0.25);
}

.ccw-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-self: flex-start;
    max-width: 100%;
}

.ccw-chip {
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 9999px;
    border: 1px solid rgba(201, 169, 98, 0.5);
    background: rgba(201, 169, 98, 0.08);
    color: var(--ccw-accent-light);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.ccw-chip:hover {
    background: rgba(201, 169, 98, 0.18);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(201, 169, 98, 0.25);
}

.ccw-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(201, 169, 98, 0.15);
    flex-shrink: 0;
}

.ccw-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(201, 169, 98, 0.25);
    border-radius: 9999px;
    padding: 10px 16px;
    color: var(--ccw-white);
    font-family: var(--ccw-font-body);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s ease;
    min-width: 0;
}

.ccw-input::placeholder {
    color: rgba(250, 247, 242, 0.4);
}

.ccw-input:focus {
    border-color: var(--ccw-accent);
}

.ccw-send {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: var(--ccw-accent);
    color: var(--ccw-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.ccw-send:hover {
    background: var(--ccw-accent-light);
    transform: translateY(-1px);
}

.ccw-send:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

@media (max-width: 480px) {
    #ccwRoot {
        bottom: 16px;
        left: 16px;
    }

    .ccw-panel {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 88px;
        width: auto;
        max-width: none;
        height: min(70vh, 560px);
        max-height: none;
    }
}
