/**
 * FlowWidget Main Styles
 * 
 * Conversational chat widget styling with smooth animations
 * and responsive design.
 * 
 * @version 1.0.0
 * @date 2026-02-04
 */

/* ===========================
   CSS Variables (Theming)
   =========================== */
:root {
    --primary-color: #518AB4;
    --secondary-color: #ffffff;
    --text-color: #333333;
    --text-light: #666666;
    --bg-color: #f5f7fa;
    --message-bot-bg: #518AB4;
    --message-bot-text: #ffffff;
    --message-user-bg: #e5e7eb;
    --message-user-text: #1f2937;
    --border-radius: 12px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===========================
   Base Styles
   =========================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* ===========================
   Main Container
   =========================== */
.flow-widget-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    background: #ffffff;
    overflow: hidden;
}

/* ===========================
   Header
   =========================== */
.flow-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: linear-gradient(135deg, var(--primary-color) 0%, #3a6a8f 100%);
    color: #ffffff;
    box-shadow: var(--shadow);
    z-index: 10;
}

.flow-header-content {
    flex: 1;
}

.flow-header-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.2;
}

.flow-header-subtitle {
    margin: 4px 0 0 0;
    font-size: 14px;
    opacity: 0.9;
}

.flow-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: #ffffff;
    font-size: 18px;
}

.flow-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ===========================
   Messages Container
   =========================== */
.flow-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-color);
}

/* Custom scrollbar */
.flow-messages-container::-webkit-scrollbar {
    width: 8px;
}

.flow-messages-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.flow-messages-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.flow-messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ===========================
   Message Bubbles
   =========================== */
.flow-message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.flow-message-bot {
    align-self: flex-start;
}

.flow-message-user {
    align-self: flex-end;
}

.flow-message-content {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    word-wrap: break-word;
    line-height: 1.5;
}

.flow-message-bot .flow-message-content {
    background: var(--message-bot-bg);
    color: var(--message-bot-text);
    border-bottom-left-radius: 4px;
}

.flow-message-user .flow-message-content {
    background: var(--message-user-bg);
    color: var(--message-user-text);
    border-bottom-right-radius: 4px;
}

.flow-message-content a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.flow-message-content a:hover {
    text-decoration: none;
}

.flow-message-timestamp {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.flow-message-bot .flow-message-timestamp {
    text-align: left;
}

.flow-message-user .flow-message-timestamp {
    text-align: right;
}

/* ===========================
   Button Group
   =========================== */
.flow-button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 85%;
    margin: 8px 0;
    animation: buttonGroupSlideIn 0.4s ease-out;
}

@keyframes buttonGroupSlideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.flow-button {
    background: #ffffff;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 14px 20px;
    border-radius: var(--border-radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    box-shadow: var(--shadow);
}

.flow-button:hover {
    background: var(--primary-color);
    color: #ffffff;
    transform: translateX(4px);
    box-shadow: var(--shadow-lg);
}

.flow-button:active {
    transform: scale(0.98);
}

/* ===========================
   Input Container
   =========================== */
.flow-input-container {
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.flow-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flow-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.flow-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: var(--border-radius);
    font-size: 15px;
    font-family: inherit;
    transition: var(--transition);
    background: #ffffff;
}

.flow-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(81, 138, 180, 0.1);
}

.flow-input::placeholder {
    color: #9ca3af;
}

textarea.flow-input {
    resize: vertical;
    min-height: 60px;
}

.flow-submit-btn {
    background: var(--primary-color);
    border: none;
    color: #ffffff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    font-size: 16px;
}

.flow-submit-btn:hover {
    background: #3a6a8f;
    transform: scale(1.05);
}

.flow-submit-btn:active {
    transform: scale(0.95);
}

.flow-submit-btn-full {
    width: 100%;
    height: auto;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
}

/* ===========================
   Multi-Field Form
   =========================== */
.flow-form-multi {
    gap: 16px;
}

.flow-field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.flow-field-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
}

/* ===========================
   Error Messages
   =========================== */
.flow-error-message {
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-size: 14px;
    animation: errorShake 0.4s ease-out;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===========================
   Loading Indicator
   =========================== */
.flow-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.flow-loading-dots {
    display: flex;
    gap: 8px;
}

.flow-loading-dots span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: loadingBounce 1.4s infinite ease-in-out both;
}

.flow-loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.flow-loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    .flow-header {
        padding: 16px 20px;
    }
    
    .flow-header-title {
        font-size: 18px;
    }
    
    .flow-header-subtitle {
        font-size: 13px;
    }
    
    .flow-messages-container {
        padding: 16px;
        gap: 12px;
    }
    
    .flow-message {
        max-width: 85%;
    }
    
    .flow-button-group {
        max-width: 90%;
    }
    
    .flow-input-container {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .flow-header {
        padding: 12px 16px;
    }
    
    .flow-messages-container {
        padding: 12px;
    }
    
    .flow-message {
        max-width: 90%;
    }
    
    .flow-message-content {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .flow-button {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* ===========================
   Accessibility
   =========================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
.flow-button:focus-visible,
.flow-input:focus-visible,
.flow-submit-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
