/**
 * Amazon Bedrock AI Chatbot - Frontend Styles
 */

:root {
    --bedrock-primary: #15803d;
    --bedrock-primary-hover: #166534;
    --bedrock-primary-rgb: 21, 128, 61;
    --bedrock-bubble-bot: #f3f4f6;
    --bedrock-text-bot: #1f2937;
    --bedrock-text-user: #ffffff;
    --bedrock-border: #e5e7eb;
    --bedrock-bg-white: #ffffff;
    --bedrock-shadow: 0 12px 35px -4px rgba(0, 0, 0, 0.18), 0 4px 12px -2px rgba(0, 0, 0, 0.08);
}

#bedrock-chatbot-root {
    position: fixed;
    z-index: 99999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

#bedrock-chatbot-root *,
#bedrock-chatbot-root *::before,
#bedrock-chatbot-root *::after {
    box-sizing: border-box;
}

/* Positions */
.bedrock-pos-bottom-right {
    bottom: 24px;
    right: 24px;
}

.bedrock-pos-bottom-left {
    bottom: 24px;
    left: 24px;
}

.bedrock-pos-bottom-left .bedrock-chat-window {
    left: 0;
    right: auto;
}

/* Launcher Button */
#bedrock-launcher-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--bedrock-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(var(--bedrock-primary-rgb), 0.4);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    position: relative;
}

#bedrock-launcher-btn:hover {
    transform: scale(1.08);
    background-color: var(--bedrock-primary-hover);
    box-shadow: 0 6px 24px rgba(var(--bedrock-primary-rgb), 0.5);
}

#bedrock-launcher-btn:active {
    transform: scale(0.96);
}

#bedrock-launcher-btn svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    transition: transform 0.25s ease;
}

/* Unread Badge */
.bedrock-badge-unread {
    position: absolute;
    top: -2px;
    right: -2px;
    background-color: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
}

/* Chat Window */
.bedrock-chat-window {
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 375px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: min(520px, calc(100vh - 130px));
    background: var(--bedrock-bg-white);
    border-radius: 16px;
    box-shadow: 0 12px 40px -6px rgba(0, 0, 0, 0.2), 0 4px 16px -2px rgba(0, 0, 0, 0.08);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.bedrock-chat-window.bedrock-open {
    display: flex !important;
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
    visibility: visible !important;
}

/* Header */
.bedrock-header {
    background: var(--bedrock-primary);
    color: #ffffff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.bedrock-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.bedrock-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: visible;
}

.bedrock-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.bedrock-avatar svg {
    width: 20px;
    height: 20px;
    stroke: #ffffff;
}

.bedrock-status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #22c55e;
    border: 2px solid var(--bedrock-primary);
}

.bedrock-titles {
    min-width: 0;
    flex: 1;
}

.bedrock-chat-title,
.bedrock-titles h3 {
    all: unset;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #ffffff !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    line-height: 1.25 !important;
    font-family: inherit !important;
    letter-spacing: normal !important;
}

.bedrock-subtitle {
    font-size: 11.5px !important;
    color: rgba(255, 255, 255, 0.85) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    margin: 2px 0 0 0 !important;
    padding: 0 !important;
    line-height: 1.2 !important;
    font-family: inherit !important;
}

.bedrock-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.bedrock-header-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.bedrock-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.bedrock-header-btn svg {
    width: 18px;
    height: 18px;
}

/* Messages Stream */
.bedrock-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
}

.bedrock-messages::-webkit-scrollbar {
    width: 6px;
}

.bedrock-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* Floating Scroll to Bottom Button */
.bedrock-scroll-bottom-btn {
    position: absolute;
    bottom: 68px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: #4b5563;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.18s ease, background-color 0.15s ease, color 0.15s ease;
    outline: none;
    padding: 0;
}

.bedrock-scroll-bottom-btn:hover {
    background-color: #f3f4f6;
    color: var(--bedrock-primary);
    transform: scale(1.08);
}

.bedrock-scroll-bottom-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* Message Rows & Bubbles */
.bedrock-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: bedrockFadeIn 0.25s ease-out;
}

@keyframes bedrockFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bedrock-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.bedrock-msg-bot {
    align-self: flex-start;
    align-items: flex-start;
}

.bedrock-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    word-break: break-word;
    font-size: 13.5px;
    line-height: 1.5;
}

.bedrock-msg-user .bedrock-bubble {
    background-color: var(--bedrock-primary);
    color: var(--bedrock-text-user);
    border-bottom-right-radius: 3px;
}

.bedrock-msg-bot .bedrock-bubble {
    background-color: var(--bedrock-bubble-bot);
    color: var(--bedrock-text-bot);
    border-bottom-left-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

/* Copy Action Button */
.bedrock-bubble-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.bedrock-action-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 11.5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    transition: background-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
    line-height: 1;
    font-family: inherit;
}

.bedrock-action-btn:hover {
    background-color: rgba(0, 0, 0, 0.06);
    color: #0f172a;
}

.bedrock-action-btn.copied {
    color: #15803d;
    font-weight: 500;
}

.bedrock-action-btn svg {
    width: 13px;
    height: 13px;
}

/* Typewriter Blinking Cursor */
.bedrock-typewriter-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background-color: var(--bedrock-primary);
    margin-left: 3px;
    vertical-align: -1px;
    border-radius: 1px;
    animation: bedrockBlink 0.7s infinite;
}

@keyframes bedrockBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.bedrock-msg-time {
    font-size: 10.5px;
    color: #9ca3af;
    margin-top: 4px;
    padding: 0 4px;
}

/* Bot Formatted Content */
.bedrock-bubble p {
    margin: 0 0 8px 0;
}
.bedrock-bubble p:last-child {
    margin-bottom: 0;
}

/* Headings inside chat bubbles */
.bedrock-bubble-h {
    all: unset;
    display: block !important;
    font-weight: 700 !important;
    margin: 12px 0 6px 0 !important;
    color: #111827 !important;
    line-height: 1.35 !important;
    letter-spacing: normal !important;
}

.bedrock-bubble p + .bedrock-bubble-h,
.bedrock-bubble ul + .bedrock-bubble-h,
.bedrock-bubble ol + .bedrock-bubble-h {
    margin-top: 14px !important;
}

.bedrock-bubble-h:first-child {
    margin-top: 0 !important;
}

.bedrock-bubble-h1 {
    font-size: 15px !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
    padding-bottom: 4px !important;
}

.bedrock-bubble-h2 {
    font-size: 14px !important;
    color: var(--bedrock-primary) !important;
}

.bedrock-bubble-h3 {
    font-size: 13.5px !important;
    font-weight: 600 !important;
    color: #15803d !important;
}

.bedrock-bubble-h4 {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #374151 !important;
}

/* Blockquotes & Dividers inside chat bubbles */
.bedrock-bubble-quote {
    margin: 8px 0;
    padding: 6px 12px;
    border-left: 3px solid var(--bedrock-primary);
    background: rgba(0, 0, 0, 0.03);
    color: #4b5563;
    font-style: italic;
    border-radius: 0 4px 4px 0;
}

.bedrock-bubble-hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin: 10px 0;
}

.bedrock-bubble ul,
.bedrock-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.bedrock-bubble li {
    margin-bottom: 4px;
}

.bedrock-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

.bedrock-bubble pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
}

.bedrock-bubble pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.bedrock-bubble a {
    color: var(--bedrock-primary);
    text-decoration: underline;
}

/* Starter Prompts */
.bedrock-starter-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.bedrock-prompt-chip {
    background: #ffffff;
    border: 1px solid var(--bedrock-border);
    color: #374151;
    padding: 7px 12px;
    border-radius: 16px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.bedrock-prompt-chip:hover {
    background: var(--bedrock-primary);
    color: #ffffff;
    border-color: var(--bedrock-primary);
    transform: translateY(-1px);
}

/* Typing Indicator */
.bedrock-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 10px 16px;
    background: #fafafa;
}

.bedrock-typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bedrock-bubble-bot);
    padding: 8px 12px;
    border-radius: 12px;
    border-bottom-left-radius: 3px;
}

.bedrock-typing-bubble span {
    width: 6px;
    height: 6px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: bedrockBounce 1.4s infinite ease-in-out both;
}

.bedrock-typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.bedrock-typing-bubble span:nth-child(2) { animation-delay: -0.16s; }
.bedrock-typing-bubble span:nth-child(3) { animation-delay: 0s; }

@keyframes bedrockBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.bedrock-typing-label {
    font-size: 11.5px;
    color: #9ca3af;
}

/* Footer & Input */
.bedrock-footer {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid var(--bedrock-border);
    flex-shrink: 0;
}

.bedrock-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f9fafb;
    border: 1px solid var(--bedrock-border);
    border-radius: 20px;
    padding: 6px 8px 6px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.bedrock-chat-form:focus-within {
    border-color: var(--bedrock-primary);
    box-shadow: 0 0 0 3px rgba(var(--bedrock-primary-rgb), 0.12);
    background: #ffffff;
}

#bedrock-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.4;
    max-height: 100px;
    min-height: 22px;
    padding: 4px 0;
    color: #1f2937;
}

#bedrock-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: var(--bedrock-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s, transform 0.15s, opacity 0.15s;
    outline: none;
}

#bedrock-send-btn:hover {
    background-color: var(--bedrock-primary-hover);
    transform: scale(1.04);
}

#bedrock-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#bedrock-send-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    margin-left: -1px;
}

.bedrock-footer-note {
    display: none !important;
}

/* Mobile Responsive & Bottom Nav Offset */
@media (max-width: 768px) {
    .bedrock-pos-bottom-right {
        bottom: 85px !important;
        right: 16px !important;
    }

    .bedrock-pos-bottom-left {
        bottom: 85px !important;
        left: 16px !important;
    }
}

@media (max-width: 480px) {
    .bedrock-chat-window {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100% !important;
        max-height: 100dvh !important;
        max-width: 100vw !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 999999999 !important;
    }
}
