/**
 * Flat Design 2.0 Frontend Styles for Dyronics Chat
 * 
 * @package DyronicsChat
 * @version 2.0.0
 * @author Dyronics
 * @since 1.0.0
 */

/* === RESET & BASE STYLES === */
.dyronics-chat-widget,
.dyronics-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
}

/* === MODERN COLOR PALETTE === */
:root {
    --chat-primary: #6366f1;
    --chat-primary-hover: #5b5bd6;
    --chat-primary-light: #f0f0ff;
    --chat-secondary: #f1f5f9;
    --chat-accent: #10b981;
    --chat-danger: #ef4444;
    --chat-warning: #f59e0b;
    --chat-text: #1e293b;
    --chat-text-light: #64748b;
    --chat-border: #e2e8f0;
    --chat-bg: #ffffff;
    --chat-bg-alt: #f8fafc;
    --chat-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --chat-shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --chat-radius: 16px;
    --chat-radius-sm: 8px;
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === CHAT WIDGET CONTAINER === */
.dyronics-chat-widget {
    position: fixed;
    z-index: 999999;
    direction: ltr;
    text-align: left;
    font-size: 14px;
}

.dyronics-chat-widget.position-bottom-right {
    bottom: 24px;
    right: 24px;
}

.dyronics-chat-widget.position-bottom-left {
    bottom: 24px;
    left: 24px;
}

.dyronics-chat-widget.position-top-right {
    top: 24px;
    right: 24px;
}

.dyronics-chat-widget.position-top-left {
    top: 24px;
    left: 24px;
}

/* === CHAT TOGGLE BUTTON === */
.chat-toggle {
    position: relative;
}

.chat-toggle-btn {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    color: white;
    cursor: pointer;
    box-shadow: var(--chat-shadow-lg);
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 32px 64px -12px rgba(99, 102, 241, 0.4);
}

.chat-toggle-btn:active {
    transform: translateY(0);
}

.chat-toggle-btn.active {
    background: var(--chat-danger);
}

.chat-toggle-btn .icon-chat,
.chat-toggle-btn .icon-close {
    width: 24px;
    height: 24px;
    transition: var(--chat-transition);
}

.chat-toggle-btn.active .icon-chat {
    display: none;
}

.chat-toggle-btn:not(.active) .icon-close {
    display: none;
}

/* === NOTIFICATION BADGE === */
.notification-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--chat-danger);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    box-shadow: var(--chat-shadow);
    animation: pulse 2s infinite;
}

.notification-badge.hidden {
    display: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* === CHAT WINDOW === */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 600px;
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: var(--chat-transition);
    border: 1px solid var(--chat-border);
}

.chat-window.show {
    transform: translateY(0) scale(1);
    opacity: 1;
}

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

.position-top-right .chat-window {
    bottom: auto;
    top: 80px;
}

.position-top-left .chat-window {
    bottom: auto;
    top: 80px;
    right: auto;
    left: 0;
}

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

.header-info {
    flex: 1;
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    opacity: 0.9;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-accent);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: #94a3b8;
    animation: none;
}

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

.minimize-btn,
.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: var(--chat-radius-sm);
    cursor: pointer;
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.minimize-btn:hover,
.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* === CHAT CONTENT === */
.chat-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--chat-bg-alt);
}

/* === SCREEN MANAGEMENT === */
.chat-content>div {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    visibility: hidden;
    transition: var(--chat-transition);
    z-index: 1;
    background: var(--chat-bg);
}

.chat-content>div:not([style*="display: none"]) {
    opacity: 1;
    visibility: visible;
    z-index: 2;
}

.chat-content>div[style*="display: none"] {
    opacity: 0 !important;
    visibility: hidden !important;
    z-index: 0 !important;
    pointer-events: none !important;
}

/* === WELCOME SCREEN === */
.welcome-screen {
    padding: 40px 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(135deg, var(--chat-bg) 0%, var(--chat-bg-alt) 100%);
}

.agent-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    box-shadow: var(--chat-shadow);
}

.welcome-message h5 {
    font-size: 24px;
    font-weight: 700;
    color: var(--chat-text);
    margin-bottom: 12px;
}

.welcome-text {
    color: var(--chat-text-light);
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 32px;
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    z-index: 10;
}

.action-btn {
    padding: 16px 24px;
    border-radius: var(--chat-radius-sm);
    border: 2px solid var(--chat-border);
    background: var(--chat-bg);
    color: var(--chat-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 56px;
    position: relative;
    z-index: 10;
}

.action-btn:hover {
    border-color: var(--chat-primary);
    background: var(--chat-primary-light);
    color: var(--chat-primary);
    transform: translateY(-1px);
    box-shadow: var(--chat-shadow);
}

.action-btn.start-whatsapp {
    background: #25d366;
    color: white;
    border-color: #25d366;
}

.action-btn.start-whatsapp:hover {
    background: #128c7e;
    border-color: #128c7e;
    color: white;
}

.action-icon {
    width: 20px;
    height: 20px;
}

/* === CONTACT FORMS === */
.contact-form-screen,
.offline-form-screen {
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
    z-index: 12;
}

.contact-form-screen.active,
.offline-form-screen.active {
    z-index: 20;
}

.form-header {
    text-align: center;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.form-header h5 {
    font-size: 20px;
    font-weight: 700;
    color: var(--chat-text);
    margin-bottom: 8px;
}

.form-header p {
    color: var(--chat-text-light);
    font-size: 14px;
    line-height: 1.5;
}

/* === CHAT CONTACT FORM === */
.chat-contact-form {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--chat-bg);
    position: relative;
    z-index: 15;
}

.chat-contact-form .form-content {
    flex: 1;
    overflow: hidden;
    padding-bottom: 16px;
}

.form-field {
    margin-bottom: 20px;
    position: relative;
    z-index: 16;
}

.form-field:last-of-type {
    margin-bottom: 0;
}

.form-field label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-text);
    margin-bottom: 8px;
    position: relative;
    z-index: 17;
}

.required {
    color: var(--chat-danger);
    margin-left: 4px;
}

.form-field input,
.form-field textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--chat-border);
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--chat-bg);
    color: var(--chat-text);
    transition: var(--chat-transition);
    position: relative;
    z-index: 17;
}

.form-field input:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-field input:invalid,
.form-field textarea:invalid {
    border-color: var(--chat-danger);
}

.form-field textarea {
    resize: none;
    height: 80px;
    font-family: inherit;
}

.char-counter {
    font-size: 12px;
    color: var(--chat-text-light);
    text-align: right;
    margin-top: 4px;
}

.consent-field {
    margin-top: 24px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.5;
    color: var(--chat-text-light);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--chat-primary);
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--chat-border);
    border-radius: 4px;
    position: relative;
    flex-shrink: 0;
    transition: var(--chat-transition);
}

.checkbox-label input[type="checkbox"]:checked+.checkmark {
    background: var(--chat-primary);
    border-color: var(--chat-primary);
}

.checkbox-label input[type="checkbox"]:checked+.checkmark::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* === FORM ACTIONS === */
.form-actions {
    display: flex;
    gap: 16px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
    position: relative;
    z-index: 17;
}

.btn-secondary,
.btn-primary {
    flex: 1;
    padding: 14px 20px;
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chat-transition);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    position: relative;
    z-index: 18;
}

.btn-secondary {
    background: var(--chat-secondary);
    color: var(--chat-text-light);
    border-color: var(--chat-border);
}

.btn-secondary:hover {
    background: var(--chat-border);
    color: var(--chat-text);
}

.btn-primary {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--chat-primary-hover);
    border-color: var(--chat-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--chat-shadow);
}

.btn-primary:disabled {
    background: var(--chat-text-light);
    border-color: var(--chat-text-light);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-loading {
    display: none;
}

.loading-spinner {
    animation: spin 1s linear infinite;
}

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

    to {
        transform: rotate(360deg);
    }
}

/* === CHAT MESSAGES === */
.chat-messages {
    height: 100%;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

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

.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.agent .message-bubble {
    background: var(--chat-secondary);
    color: var(--chat-text);
    border-bottom-left-radius: 6px;
}

.message.user .message-bubble {
    background: var(--chat-primary);
    color: white;
    border-bottom-right-radius: 6px;
}

.message-time {
    font-size: 11px;
    color: var(--chat-text-light);
    margin-top: 4px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    color: var(--chat-text-light);
    font-size: 13px;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--chat-text-light);
    border-radius: 50%;
    animation: typingDots 1.4s infinite;
}

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

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

@keyframes typingDots {

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

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* === CHAT INPUT === */
.chat-input-area {
    padding: 16px 20px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--chat-bg-alt);
    border: 2px solid var(--chat-border);
    border-radius: var(--chat-radius-sm);
    padding: 8px;
    transition: var(--chat-transition);
}

.input-container:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#chat-message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 12px;
    max-height: 120px;
    min-height: 20px;
    color: var(--chat-text);
}

#chat-message-input:focus {
    outline: none;
}

#chat-message-input::placeholder {
    color: var(--chat-text-light);
}

.input-actions {
    display: flex;
    gap: 4px;
}

.send-btn,
.attach-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--chat-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover,
.attach-btn:hover {
    background: var(--chat-primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--chat-text-light);
    cursor: not-allowed;
    transform: none;
}

.char-counter {
    font-size: 11px;
    color: var(--chat-text-light);
    text-align: right;
    margin-top: 4px;
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 768px) {
    .chat-window {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        border-radius: 0;
        transform: translateY(100%);
        resize: none;
    }

    .chat-window.show {
        transform: translateY(0);
    }

    .dyronics-chat-widget.position-bottom-right,
    .dyronics-chat-widget.position-bottom-left {
        bottom: 16px;
        right: 16px;
        left: auto;
    }

    .chat-header {
        padding: 16px 20px;
    }

    .welcome-screen {
        padding: 32px 24px;
    }

    .contact-form-screen,
    .offline-form-screen {
        padding: 20px 24px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .chat-window {
        width: 380px;
        height: 580px;
    }
}

@media (min-width: 1025px) {
    .chat-window {
        width: 420px;
        height: 640px;
    }

    .contact-form-screen,
    .offline-form-screen {
        padding: 28px 32px;
    }

    .form-header h5 {
        font-size: 22px;
    }

    .welcome-message h5 {
        font-size: 26px;
    }
}

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

/* === DARK MODE SUPPORT === */
@media (prefers-color-scheme: dark) {
    :root {
        --chat-text: #f8fafc;
        --chat-text-light: #94a3b8;
        --chat-bg: #1e293b;
        --chat-bg-alt: #334155;
        --chat-border: #475569;
        --chat-secondary: #475569;
    }
}

/* === UTILITY CLASSES === */
.hidden {
    display: none !important;
}

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

/* === ANIMATIONS === */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 100%, 0);
    }

    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.animate-slide-in-up {
    animation: slideInUp 0.3s ease-out;
}

.animate-fade-in {
    animation: fadeIn 0.2s ease-out;
}