/* =====================================================
   HappyHag N8N Chat - Widget Stylesheet
   Version: 6.0.0
   Author: Hadi Mohammadi
   ===================================================== */

/* ============================================
   CSS Variables & Root
   ============================================ */
:root {
    --happyhag-primary-color: #FE5C36;
    --happyhag-primary-color-rgb: 254, 92, 54;
    --happyhag-secondary-color: #4A5568;
    --happyhag-secondary-color-rgb: 74, 85, 104;
    --happyhag-success-color: #10B981;
    --happyhag-info-color: #3B82F6;
    --happyhag-warning-color: #F59E0B;
    --happyhag-danger-color: #EF4444;
    --happyhag-border-radius: 16px;
    --happyhag-box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    --happyhag-box-shadow-hover: 0 6px 20px rgba(var(--happyhag-primary-color-rgb), 0.5);
    --happyhag-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --happyhag-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Segoe UI Emoji', sans-serif;
}

/* ============================================
   Container
   ============================================ */
.happyhag-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--happyhag-font-family);
    direction: rtl;
    font-size: 14px;
    line-height: 1.5;
}

/* ============================================
   Floating Button
   ============================================ */
.happyhag-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--happyhag-primary-color);
    border: none;
    box-shadow: 0 4px 12px rgba(var(--happyhag-primary-color-rgb), 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--happyhag-transition);
    position: relative;
    outline: none;
    z-index: 10;
}

.happyhag-chat-button:hover {
    transform: scale(1.1);
    box-shadow: var(--happyhag-box-shadow-hover);
}

.happyhag-chat-button:focus {
    outline: 2px solid var(--happyhag-primary-color);
    outline-offset: 3px;
}

.happyhag-chat-button.active {
    transform: rotate(45deg);
}

.happyhag-chat-icon,
.happyhag-chat-icon-close {
    width: 28px;
    height: 28px;
    color: white;
    stroke-width: 2;
    transition: var(--happyhag-transition);
}

.happyhag-chat-icon-close {
    display: none;
}

.happyhag-chat-button.active .happyhag-chat-icon {
    display: none;
}

.happyhag-chat-button.active .happyhag-chat-icon-close {
    display: block;
}

/* ============================================
   Badge (Unread Messages)
   ============================================ */
.happyhag-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--happyhag-danger-color);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    animation: pulse 2s infinite;
    z-index: 11;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* ============================================
   Chat Window
   ============================================ */
.happyhag-chat-window {
    position: absolute;
    bottom: 80px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: var(--happyhag-border-radius);
    box-shadow: var(--happyhag-box-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: var(--happyhag-transition);
}

.happyhag-chat-window.open {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: windowSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes windowSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   Header
   ============================================ */
.happyhag-chat-header {
    padding: 20px;
    background: linear-gradient(135deg, var(--happyhag-primary-color) 0%, #FF8A65 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.happyhag-chat-header-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.happyhag-chat-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.happyhag-chat-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.happyhag-chat-status {
    margin: 5px 0 0;
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
}

.happyhag-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10B981;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.7;
    }
}

.happyhag-chat-minimize {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--happyhag-transition);
}

.happyhag-chat-minimize:hover {
    background: rgba(255, 255, 255, 0.2);
}

.happyhag-chat-minimize svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

/* ============================================
   Chat Body
   ============================================ */
.happyhag-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
}

.happyhag-messages-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1;
}

/* ============================================
   Messages
   ============================================ */
.happyhag-message {
    display: flex;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

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

.happyhag-message-user {
    align-self: flex-end;
    margin-left: auto;
}

.happyhag-message-user .happyhag-message-content {
    background: linear-gradient(135deg, var(--happyhag-primary-color) 0%, #FF8A65 100%);
    color: white;
    border-radius: 18px 18px 4px 18px;
}

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

.happyhag-message-bot .happyhag-message-content {
    background: white;
    color: #333;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.happyhag-message-content {
    padding: 12px 16px;
    position: relative;
    word-wrap: break-word;
}

.happyhag-message-text {
    line-height: 1.5;
    font-size: 14px;
}

.happyhag-message-text a {
    color: inherit;
    text-decoration: underline;
    transition: var(--happyhag-transition);
}

.happyhag-message-user .happyhag-message-text a {
    color: rgba(255, 255, 255, 0.9);
}

.happyhag-message-user .happyhag-message-text a:hover {
    color: white;
}

.happyhag-message-bot .happyhag-message-text a {
    color: var(--happyhag-primary-color);
}

.happyhag-message-bot .happyhag-message-text a:hover {
    color: #e74d2a;
}

.happyhag-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 5px;
    text-align: left;
    display: block;
}

/* ============================================
   Typing Indicator
   ============================================ */
.happyhag-typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    align-self: flex-start;
    animation: typingSlideIn 0.3s ease-out;
}

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

.happyhag-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--happyhag-secondary-color);
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ============================================
   Authentication Form
   ============================================ */
.happyhag-chat-auth-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
}

.happyhag-auth-content {
    max-width: 320px;
    width: 100%;
}

.happyhag-auth-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--happyhag-primary-color) 0%, #FF8A65 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: white;
}

.happyhag-auth-icon svg {
    width: 40px;
    height: 40px;
    stroke-width: 1.5;
}

.happyhag-auth-content h3 {
    margin: 0 0 10px;
    color: #333;
    font-size: 22px;
    font-weight: 700;
}

.happyhag-auth-content p {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
    font-size: 14px;
}

/* ============================================
   Form Elements
   ============================================ */
#happyhag-user-info-form {
    width: 100%;
}

.happyhag-form-group {
    margin-bottom: 20px;
    text-align: right;
}

.happyhag-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
    font-size: 14px;
}

.happyhag-form-group input,
.happyhag-form-group select,
.happyhag-form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: var(--happyhag-transition);
    background: white;
}

.happyhag-form-group input:focus,
.happyhag-form-group select:focus,
.happyhag-form-group textarea:focus {
    outline: none;
    border-color: var(--happyhag-primary-color);
    box-shadow: 0 0 0 3px rgba(var(--happyhag-primary-color-rgb), 0.1);
}

.happyhag-error-message {
    color: var(--happyhag-danger-color);
    font-size: 12px;
    margin-top: 5px;
    display: none;
}

.happyhag-submit-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--happyhag-primary-color) 0%, #FF8A65 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--happyhag-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.happyhag-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--happyhag-primary-color-rgb), 0.3);
}

.happyhag-submit-btn:active {
    transform: translateY(0);
}

.happyhag-submit-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-text {
    display: inline-block;
}

.btn-loader {
    display: none;
}

.btn-loader .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Footer
   ============================================ */
.happyhag-chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

/* ============================================
   Quick Replies
   ============================================ */
.happyhag-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
    animation: quickRepliesSlideIn 0.3s ease-out;
}

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

.happyhag-quick-reply-btn {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--happyhag-primary-color);
    color: var(--happyhag-primary-color);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--happyhag-transition);
    font-weight: 500;
}

.happyhag-quick-reply-btn:hover {
    background: var(--happyhag-primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(var(--happyhag-primary-color-rgb), 0.3);
}

/* ============================================
   Message Form
   ============================================ */
.happyhag-message-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#happyhag-message-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #e9ecef;
    border-radius: 24px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    max-height: 150px;
    min-height: 48px;
    transition: var(--happyhag-transition);
    background: #f8f9fa;
    line-height: 1.5;
}

#happyhag-message-input:focus {
    outline: none;
    border-color: var(--happyhag-primary-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(var(--happyhag-primary-color-rgb), 0.1);
}

#happyhag-message-input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.happyhag-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--happyhag-primary-color) 0%, #FF8A65 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--happyhag-transition);
    flex-shrink: 0;
}

.happyhag-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(var(--happyhag-primary-color-rgb), 0.3);
}

.happyhag-send-btn:active {
    transform: scale(0.95);
}

.happyhag-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.happyhag-send-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

/* ============================================
   Rate Limit Warning
   ============================================ */
.happyhag-rate-limit-warning {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: #FFF3E0;
    border-right: 4px solid var(--happyhag-warning-color);
    border-radius: 8px;
    margin-top: 10px;
    font-size: 13px;
    color: #E65100;
    animation: warningSlideIn 0.3s ease-out;
}

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

.happyhag-rate-limit-warning svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-width: 2;
}

/* ============================================
   Scrollbar
   ============================================ */
.happyhag-chat-body::-webkit-scrollbar {
    width: 8px;
}

.happyhag-chat-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.happyhag-chat-body::-webkit-scrollbar-thumb {
    background: var(--happyhag-secondary-color);
    border-radius: 4px;
}

.happyhag-chat-body::-webkit-scrollbar-thumb:hover {
    background: var(--happyhag-primary-color);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 480px) {
    .happyhag-chat-container {
        bottom: 10px;
        right: 10px;
    }

    .happyhag-chat-button {
        width: 50px;
        height: 50px;
    }

    .happyhag-chat-icon,
    .happyhag-chat-icon-close {
        width: 24px;
        height: 24px;
    }

    .happyhag-chat-window {
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
        bottom: 0;
        left: 0;
        border-radius: 0;
    }

    .happyhag-chat-header {
        padding: 15px;
    }

    .happyhag-chat-body {
        padding: 15px;
    }

    .happyhag-chat-footer {
        padding: 10px;
    }

    #happyhag-message-input {
        font-size: 16px;
    }
}

/* ============================================
   High Contrast Mode
   ============================================ */
@media (prefers-contrast: high) {
    .happyhag-chat-button {
        border: 2px solid white;
    }

    .happyhag-chat-window {
        border: 2px solid #000;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .happyhag-chat-button,
    .happyhag-chat-window,
    .happyhag-message,
    .happyhag-typing-indicator,
    .happyhag-quick-replies,
    .happyhag-rate-limit-warning {
        transition: none;
        animation: none;
    }

    .happyhag-typing-dot {
        animation: none;
    }

    .happyhag-chat-badge {
        animation: none;
    }

    .happyhag-status-dot {
        animation: none;
    }
}

/* ============================================
   Dark Mode
   ============================================ */
@media (prefers-color-scheme: dark) {
    .happyhag-chat-window {
        background: #1a202c;
        color: #e2e8f0;
    }

    .happyhag-chat-header {
        background: #2d3748;
    }

    .happyhag-chat-body {
        background: linear-gradient(180deg, #1a202c 0%, #2d3748 100%);
    }

    .happyhag-message-bot .happyhag-message-content {
        background: #2d3748;
        color: #e2e8f0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .happyhag-message-user .happyhag-message-content {
        background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    }

    .happyhag-chat-auth-form {
        background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    }

    .happyhag-auth-content h3 {
        color: #e2e8f0;
    }

    .happyhag-auth-content p {
        color: #a0aec0;
    }

    .happyhag-form-group input,
    .happyhag-form-group select,
    .happyhag-form-group textarea {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .happyhag-form-group label {
        color: #cbd5e0;
    }

    .happyhag-chat-footer {
        background: #2d3748;
        border-color: #4a5568;
    }

    #happyhag-message-input {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .happyhag-quick-reply-btn {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }

    .happyhag-typing-indicator {
        background: #2d3748;
    }

    .happyhag-typing-dot {
        background: #cbd5e0;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .happyhag-chat-container {
        display: none !important;
    }
}

/* ============================================
   Utility Classes
   ============================================ */
.happyhag-hidden {
    display: none !important;
}

.happyhag-visible {
    display: block !important;
}

.happyhag-flex {
    display: flex !important;
}

.happyhag-flex-column {
    flex-direction: column !important;
}

.happyhag-flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.happyhag-text-primary {
    color: var(--happyhag-primary-color) !important;
}

.happyhag-bg-primary {
    background: var(--happyhag-primary-color) !important;
}

.happyhag-rounded {
    border-radius: var(--happyhag-border-radius) !important;
}

.happyhag-shadow {
    box-shadow: var(--happyhag-box-shadow) !important;
}

.happyhag-transition {
    transition: var(--happyhag-transition) !important;
}