/* ============================================================
   Akito AI Chatbot — Frontend Styles
   Version: 1.0.0
   ============================================================ */

/* CSS Custom Properties */
#akito-chatbot-wrapper {
    --akito-primary: #1a56db;
    --akito-accent: #ffffff;
    --akito-primary-dark: #1648c0;
    --akito-primary-light: #e8f0fe;
    --akito-bg: #ffffff;
    --akito-surface: #f8fafc;
    --akito-border: #e2e8f0;
    --akito-text: #1e293b;
    --akito-text-muted: #64748b;
    --akito-bot-bubble: #f1f5f9;
    --akito-user-bubble: var(--akito-primary);
    --akito-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.08);
    --akito-radius: 16px;
    --akito-radius-sm: 8px;
    --akito-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --akito-z: 999999;
    --akito-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--akito-font);
}

/* ---- Positioning ---- */
#akito-chatbot-wrapper {
    position: fixed;
    z-index: var(--akito-z);
    bottom: 24px;
}

#akito-chatbot-wrapper.akito-position-bottom-right {
    right: 24px;
}

#akito-chatbot-wrapper.akito-position-bottom-left {
    left: 24px;
}

/* ---- Toggle Button ---- */
.akito-toggle-btn {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--akito-primary);
    color: var(--akito-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(26, 86, 219, 0.4), 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform var(--akito-transition), box-shadow var(--akito-transition), background var(--akito-transition);
    outline: none;
    padding: 0;
}

.akito-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(26, 86, 219, 0.5), 0 4px 12px rgba(0, 0, 0, 0.2);
    background: var(--akito-primary-dark, #1648c0);
}

.akito-toggle-btn:focus-visible {
    outline: 3px solid var(--akito-primary);
    outline-offset: 3px;
}

.akito-toggle-btn svg {
    width: 26px;
    height: 26px;
    transition: transform var(--akito-transition), opacity var(--akito-transition);
}

.akito-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pulse animation on toggle */
.akito-toggle-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--akito-primary);
    opacity: 0;
    animation: akito-pulse 2.5s ease-out infinite;
}

@keyframes akito-pulse {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* Unread badge */
.akito-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: akito-bounce 0.5s ease;
}

@keyframes akito-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* ---- Chat Window ---- */
.akito-chat-window {
    position: absolute;
    bottom: 76px;
    width: 380px;
    max-height: 600px;
    background: var(--akito-bg);
    border-radius: var(--akito-radius);
    box-shadow: var(--akito-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--akito-border);
    animation: akito-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.akito-position-bottom-right .akito-chat-window {
    right: 0;
}

.akito-position-bottom-left .akito-chat-window {
    left: 0;
}

@keyframes akito-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ---- Header ---- */
.akito-chat-header {
    background: var(--akito-primary);
    color: var(--akito-accent);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.akito-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.akito-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.akito-avatar svg {
    width: 22px;
    height: 22px;
    color: var(--akito-accent);
}

.akito-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.akito-header-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--akito-accent);
}

.akito-header-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 4px;
}

.akito-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: akito-blink 2s ease-in-out infinite;
}

@keyframes akito-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

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

.akito-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    cursor: pointer;
    color: var(--akito-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--akito-transition);
    padding: 0;
}

.akito-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.akito-header-btn svg {
    width: 16px;
    height: 16px;
}

/* ---- Tab Navigation ---- */
.akito-tab-nav {
    display: flex;
    background: var(--akito-surface);
    border-bottom: 1px solid var(--akito-border);
    flex-shrink: 0;
}

.akito-tab-btn {
    flex: 1;
    padding: 10px 12px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--akito-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: color var(--akito-transition), border-color var(--akito-transition);
    font-family: var(--akito-font);
}

.akito-tab-btn:hover {
    color: var(--akito-primary);
}

.akito-tab-btn.active {
    color: var(--akito-primary);
    border-bottom-color: var(--akito-primary);
    background: var(--akito-bg);
}

/* ---- Tab Content ---- */
.akito-tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ---- Messages Area ---- */
.akito-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 200px;
    max-height: 320px;
}

.akito-messages::-webkit-scrollbar {
    width: 4px;
}

.akito-messages::-webkit-scrollbar-track {
    background: transparent;
}

.akito-messages::-webkit-scrollbar-thumb {
    background: var(--akito-border);
    border-radius: 4px;
}

/* ---- Message Bubbles ---- */
.akito-message {
    display: flex;
    gap: 8px;
    animation: akito-fade-in 0.25s ease;
    max-width: 100%;
}

@keyframes akito-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.akito-message.akito-bot {
    align-items: flex-start;
}

.akito-message.akito-user {
    flex-direction: row-reverse;
}

.akito-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--akito-primary-light, #e8f0fe);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.akito-msg-avatar svg {
    width: 16px;
    height: 16px;
    color: var(--akito-primary);
}

.akito-msg-content {
    max-width: calc(100% - 40px);
}

.akito-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.akito-bot .akito-msg-bubble {
    background: var(--akito-bot-bubble);
    color: var(--akito-text);
    border-bottom-left-radius: 4px;
}

.akito-user .akito-msg-bubble {
    background: var(--akito-user-bubble);
    color: var(--akito-accent);
    border-bottom-right-radius: 4px;
}

.akito-msg-bubble a {
    color: inherit;
    text-decoration: underline;
}

.akito-bot .akito-msg-bubble a {
    color: var(--akito-primary);
}

.akito-msg-bubble strong {
    font-weight: 600;
}

.akito-msg-time {
    font-size: 11px;
    color: var(--akito-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.akito-user .akito-msg-time {
    text-align: right;
}

/* CTA Button in messages */
.akito-msg-cta {
    margin-top: 10px;
}

.akito-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: var(--akito-primary);
    color: var(--akito-accent) !important;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none !important;
    transition: background var(--akito-transition), transform var(--akito-transition);
    border: none;
    cursor: pointer;
    font-family: var(--akito-font);
}

.akito-cta-btn:hover {
    background: var(--akito-primary-dark, #1648c0);
    transform: translateY(-1px);
}

.akito-cta-btn svg {
    width: 14px;
    height: 14px;
}

/* Suggestion chips */
.akito-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.akito-suggestion-chip {
    padding: 5px 12px;
    background: var(--akito-bg);
    border: 1px solid var(--akito-primary);
    color: var(--akito-primary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--akito-transition), color var(--akito-transition);
    font-family: var(--akito-font);
}

.akito-suggestion-chip:hover {
    background: var(--akito-primary);
    color: var(--akito-accent);
}

/* ---- Lead Capture Form ---- */
.akito-lead-form {
    padding: 16px;
    background: var(--akito-surface);
    border-top: 1px solid var(--akito-border);
    flex-shrink: 0;
    animation: akito-fade-in 0.3s ease;
}

.akito-lead-prompt {
    font-size: 13px;
    color: var(--akito-text);
    margin: 0 0 12px;
    line-height: 1.5;
}

.akito-lead-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.akito-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--akito-border);
    border-radius: var(--akito-radius-sm);
    font-size: 13px;
    color: var(--akito-text);
    background: var(--akito-bg);
    font-family: var(--akito-font);
    transition: border-color var(--akito-transition), box-shadow var(--akito-transition);
    box-sizing: border-box;
}

.akito-input:focus {
    outline: none;
    border-color: var(--akito-primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.akito-lead-actions {
    display: flex;
    gap: 8px;
}

.akito-btn {
    padding: 8px 16px;
    border-radius: var(--akito-radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background var(--akito-transition), transform var(--akito-transition);
    font-family: var(--akito-font);
}

.akito-btn-primary {
    background: var(--akito-primary);
    color: var(--akito-accent);
    flex: 1;
}

.akito-btn-primary:hover {
    background: var(--akito-primary-dark, #1648c0);
    transform: translateY(-1px);
}

.akito-btn-ghost {
    background: transparent;
    color: var(--akito-text-muted);
    border: 1px solid var(--akito-border);
}

.akito-btn-ghost:hover {
    background: var(--akito-surface);
    color: var(--akito-text);
}

/* ---- Typing Indicator ---- */
.akito-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 8px;
    flex-shrink: 0;
}

.akito-typing-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--akito-primary-light, #e8f0fe);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.akito-typing-avatar svg {
    width: 16px;
    height: 16px;
    color: var(--akito-primary);
}

.akito-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--akito-bot-bubble);
    padding: 10px 14px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.akito-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--akito-text-muted);
    animation: akito-typing-dot 1.4s ease-in-out infinite;
}

.akito-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.akito-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes akito-typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Input Area ---- */
.akito-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--akito-border);
    background: var(--akito-bg);
    flex-shrink: 0;
}

.akito-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--akito-surface);
    border: 1px solid var(--akito-border);
    border-radius: 12px;
    padding: 8px 8px 8px 14px;
    transition: border-color var(--akito-transition), box-shadow var(--akito-transition);
}

.akito-input-wrapper:focus-within {
    border-color: var(--akito-primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.akito-message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    color: var(--akito-text);
    resize: none;
    outline: none;
    font-family: var(--akito-font);
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
    padding: 0;
}

.akito-message-input::placeholder {
    color: var(--akito-text-muted);
}

.akito-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--akito-primary);
    color: var(--akito-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--akito-transition), transform var(--akito-transition), opacity var(--akito-transition);
    padding: 0;
}

.akito-send-btn:hover:not(:disabled) {
    background: var(--akito-primary-dark, #1648c0);
    transform: scale(1.05);
}

.akito-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.akito-send-btn svg {
    width: 16px;
    height: 16px;
}

.akito-input-footer {
    margin-top: 6px;
    text-align: center;
}

.akito-powered-by {
    font-size: 11px;
    color: var(--akito-text-muted);
}

.akito-powered-by a {
    color: var(--akito-primary);
    text-decoration: none;
    font-weight: 500;
}

/* ---- iFrame Tab ---- */
.akito-iframe-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--akito-surface);
    border-bottom: 1px solid var(--akito-border);
    flex-shrink: 0;
}

.akito-iframe-label {
    font-size: 12px;
    color: var(--akito-text-muted);
    font-weight: 500;
}

.akito-iframe-expand {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--akito-primary);
    text-decoration: none;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background var(--akito-transition);
}

.akito-iframe-expand:hover {
    background: var(--akito-primary-light, #e8f0fe);
    text-decoration: none;
}

.akito-iframe-expand svg {
    width: 13px;
    height: 13px;
}

.akito-iframe-container {
    position: relative;
    flex: 1;
    min-height: 400px;
}

#akito-platform-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    min-height: 400px;
}

.akito-iframe-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--akito-bg);
    gap: 12px;
}

.akito-iframe-loading p {
    font-size: 13px;
    color: var(--akito-text-muted);
    margin: 0;
}

.akito-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--akito-border);
    border-top-color: var(--akito-primary);
    border-radius: 50%;
    animation: akito-spin 0.8s linear infinite;
}

@keyframes akito-spin {
    to { transform: rotate(360deg); }
}

/* ---- Markdown-like formatting in bubbles ---- */
.akito-msg-bubble p {
    margin: 0 0 6px;
}

.akito-msg-bubble p:last-child {
    margin-bottom: 0;
}

.akito-msg-bubble ul,
.akito-msg-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}

.akito-msg-bubble li {
    margin-bottom: 3px;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    #akito-chatbot-wrapper.akito-position-bottom-right,
    #akito-chatbot-wrapper.akito-position-bottom-left {
        right: 12px;
        left: 12px;
        bottom: 16px;
    }

    .akito-chat-window {
        width: 100%;
        max-height: 80vh;
        bottom: 72px;
        right: 0;
        left: 0;
        border-radius: var(--akito-radius) var(--akito-radius) 0 0;
    }

    .akito-toggle-btn {
        width: 54px;
        height: 54px;
    }
}

/* ---- Accessibility ---- */
@media (prefers-reduced-motion: reduce) {
    .akito-toggle-btn::before,
    .akito-status-dot,
    .akito-typing-dots span {
        animation: none;
    }

    .akito-chat-window {
        animation: none;
    }
}
