/* ========================================
   TheOfferrer AI Assistant — Styles
   Design System: #1b5e4b (Primary), #f4a261 (Accent), #f8f9fa (Background Alt)
   ======================================== */

/* Root container */
#theofferrer-ai-root {
    --ai-primary: #1b5e4b;
    --ai-primary-hover: #14503d;
    --ai-accent: #f4a261;
    --ai-accent-hover: #e08c4f;
    --ai-bg: #ffffff;
    --ai-bg-alt: #f8f9fa;
    --ai-text: #242429;
    --ai-text-secondary: #666666;
    --ai-border: #e8e8e8;
    --ai-success: #2ecc71;
    --ai-error: #e74c3c;
    --ai-warning: #f39c12;
    --ai-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --ai-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --ai-radius: 12px;
    --ai-radius-sm: 8px;
    font-family: 'Inter', 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ========================================
   TOGGLE BUTTON (Floating)
   ======================================== */
.ai-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    z-index: 9999;
    transition: all 0.3s ease;
    box-shadow: var(--ai-shadow-lg);
}

.ai-toggle.ai-free {
    background: var(--ai-primary);
}

.ai-toggle.ai-pro {
    background: var(--ai-accent);
}

.ai-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.ai-toggle.ai-free:hover {
    background: var(--ai-primary-hover);
}

.ai-toggle.ai-pro:hover {
    background: var(--ai-accent-hover);
}

.ai-toggle svg {
    width: 26px;
    height: 26px;
}

/* Badge on toggle */
.ai-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--ai-error);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    border: 2px solid #fff;
    line-height: 1;
}

.ai-badge.pro {
    background: var(--ai-accent);
    font-size: 9px;
    padding: 3px 5px;
}

/* ========================================
   CHAT WINDOW
   ======================================== */
.ai-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 420px;
    max-height: 600px;
    min-height: 400px;
    resize: both;
    overflow: auto;
    background: var(--ai-bg);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow-lg);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-window.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

.ai-window:not(.hidden) {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ========================================
   HEADER
   ======================================== */
.ai-header {
    background: var(--ai-primary);
    color: #ffffff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    flex-shrink: 0;
    gap: 12px;
}

.ai-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-header-info strong {
    font-size: 15px;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
}

.ai-header-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.ai-header-badge.free {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.ai-header-badge.pro {
    background: var(--ai-accent);
    color: #242429;
}

.ai-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-icon-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.ai-icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   MESSAGES AREA
   ======================================== */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    width: 100%;
    box-sizing: border-box;
}

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

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

.ai-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

/* Welcome message */
.ai-welcome {
    background: var(--ai-bg-alt);
    border-radius: var(--ai-radius-sm);
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ai-text);
    width: 100%;
    box-sizing: border-box;
}

.ai-welcome p {
    margin: 0 0 8px 0;
}

.ai-welcome p:last-child {
    margin-bottom: 0;
}

.ai-welcome ul {
    margin: 8px 0;
    padding-left: 18px;
}

.ai-welcome li {
    margin: 4px 0;
}

.ai-limit-notice {
    background: #fff3e0;
    border-left: 3px solid var(--ai-accent);
    padding: 8px 10px;
    border-radius: 0 6px 6px 0;
    font-size: 13px;
    margin-top: 10px !important;
}

.ai-limit-notice a {
    color: var(--ai-primary);
    font-weight: 600;
    text-decoration: underline;
}

/* Message bubbles */
.ai-message {
    max-width: 100%;
    padding: 12px 16px;
    border-radius: var(--ai-radius-sm);
    font-size: 14px;
    line-height: 1.55;
    animation: aiFadeIn 0.3s ease;
    box-sizing: border-box;
    word-wrap: break-word;
}

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

.ai-message.user {
    align-self: flex-end;
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-left: 3px solid var(--ai-primary);
    color: var(--ai-text);
}

.ai-message.assistant {
    align-self: flex-start;
    background: var(--ai-bg-alt);
    color: var(--ai-text);
}

.ai-message.assistant a {
    color: var(--ai-primary);
    text-decoration: underline;
    font-weight: 500;
}

.ai-message.assistant a:hover {
    color: var(--ai-primary-hover);
}

.ai-message.assistant strong {
    color: var(--ai-text);
}

.ai-message.assistant ul,
.ai-message.assistant ol {
    margin: 8px 0;
    padding-left: 18px;
}

.ai-message.assistant li {
    margin: 3px 0;
}

/* Typing indicator */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    align-self: flex-start;
    background: var(--ai-bg-alt);
    border-radius: var(--ai-radius-sm);
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ai-text-secondary);
    border-radius: 50%;
    animation: aiTyping 1.4s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTyping {
    0%, 60%, 100% { transform: scale(0.6); opacity: 0.4; }
    30% { transform: scale(1); opacity: 1; }
}

/* Error / Limit reached */
.ai-error {
    background: #fdeaea;
    border: 1px solid var(--ai-error);
    border-radius: var(--ai-radius-sm);
    padding: 12px;
    font-size: 13px;
    color: var(--ai-error);
}

.ai-error a {
    color: var(--ai-primary);
    font-weight: 600;
}

/* ========================================
   CHIPS (Quick Actions)
   ======================================== */
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 12px;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.ai-chip {
    background: #ffffff;
    border: 1px solid var(--ai-border);
    border-radius: 16px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ai-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.ai-chip:hover {
    border-color: var(--ai-accent);
    color: var(--ai-accent);
    background: #fff8f0;
}

.ai-chip:active {
    transform: scale(0.96);
}

/* ========================================
   INPUT AREA
   ======================================== */
.ai-input-area {
    border-top: 1px solid var(--ai-border);
    padding: 12px 20px;
    flex-shrink: 0;
    background: #ffffff;
    width: 100%;
    box-sizing: border-box;
}

.ai-limit-bar {
    height: 3px;
    background: var(--ai-bg-alt);
    border-radius: 2px;
    margin-bottom: 8px;
    overflow: hidden;
}

.ai-limit-bar-fill {
    height: 100%;
    background: var(--ai-primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.ai-limit-bar-fill.warning {
    background: var(--ai-warning);
}

.ai-limit-bar-fill.danger {
    background: var(--ai-error);
}

.ai-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

#ai-input {
    flex: 1;
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--ai-text);
    outline: none;
    transition: border-color 0.2s;
    background: #ffffff;
}

#ai-input:focus {
    border-color: var(--ai-primary);
}

#ai-input::placeholder {
    color: #aaaaaa;
}

#ai-input:disabled {
    background: var(--ai-bg-alt);
    cursor: not-allowed;
}

.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--ai-radius-sm);
    border: none;
    background: var(--ai-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.ai-send-btn:hover {
    background: var(--ai-primary-hover);
}

.ai-send-btn:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

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

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */
@media (max-width: 480px) {
    .ai-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .ai-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    }

    .ai-window.hidden {
        transform: translateY(100%);
    }

    .ai-header {
        border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    }
}

/* ========================================
   PRO FEATURE BADGE IN MESSAGES
   ======================================== */
.ai-pro-badge {
    display: inline-block;
    background: var(--ai-accent);
    color: #242429;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

/* ========================================
   RESIZE HANDLE (top-right corner, visible icon)
   ======================================== */
.ai-resize-handle {
    position: relative;
    width: 22px;
    height: 22px;
    margin-right: 8px;
    cursor: nwse-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    transition: all 0.2s;
    z-index: 5;
}

.ai-resize-handle:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.25);
}

.ai-resize-handle svg {
    width: 14px;
    height: 14px;
}

/* Larger messages area when window is expanded */
.ai-window[style*="width"] .ai-messages,
.ai-window[style*="height"] .ai-messages {
    max-height: none;
}
/* Resize cursor on window edges */
.ai-window {
    cursor: default;
}

.ai-window:hover {
    cursor: auto;
}