/* AIBot/assets/css/chat-style.css */
/* ============================================
   ChonieDev Chat Bot - Responsive CSS
   รองรับทุกอุปกรณ์ Desktop, Tablet, Mobile
   ============================================ */

/* ===== Variables ===== */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-color: #667eea;
    --primary-dark: #5a67d8;
    --secondary-color: #764ba2;
    --success-color: #4caf50;
    --error-color: #f44336;
    --warning-color: #ff9800;
    --text-dark: #333;
    --text-light: #666;
    --text-white: #fff;
    --bg-light: #f8f9fa;
    --bg-white: #fff;
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 15px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 15px;
    --border-radius-xl: 20px;
    --transition: all 0.3s ease;
}

/* ===== Base Chat Widget ===== */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Sarabun', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ===== ปุ่มเปิดแชท ===== */
.chat-button {
    width: 60px;
    height: 60px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    position: relative;
    animation: bounceIn 0.5s ease;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0,0,0,0.2);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-icon {
    font-size: 28px;
    color: white;
    transition: var(--transition);
}

.chat-button:hover .chat-icon {
    transform: rotate(15deg);
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--error-color);
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

/* ===== หน้าต่างแชท ===== */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

/* ===== Chat Header ===== */
.chat-header {
    background: var(--primary-gradient);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

.chat-avatar {
    width: 45px;
    height: 45px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.chat-title {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 3px;
}

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

.chat-status::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    animation: blink 1s infinite;
}

.chat-close {
    cursor: pointer;
    font-size: 22px;
    font-weight: bold;
    transition: var(--transition);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.chat-close:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* ===== Chat Messages Area ===== */
.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: var(--bg-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ===== Message Bubbles ===== */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

.message.assistant {
    align-items: flex-start;
    margin-right: auto;
}

.message-content {
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.45;
    font-size: 14px;
}

.message.user .message-content {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-white);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    padding: 0 5px;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    font-size: 12px;
    color: var(--primary-color);
    margin-bottom: 8px;
    padding-left: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-indicator span {
    animation: pulse 1s infinite;
}

/* ===== Input Area ===== */
.chat-input-area {
    border-top: 1px solid var(--border-color);
    background: var(--bg-white);
    padding: 12px 15px;
    flex-shrink: 0;
}

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

#chatInput {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    background: var(--bg-white);
}

#chatInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-button {
    background: var(--primary-gradient);
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-button:hover {
    transform: scale(1.05);
}

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

.send-button svg {
    color: white;
    width: 20px;
    height: 20px;
}

/* Disabled state */
.send-button.disabled,
#chatInput:disabled + .send-button {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Animations ===== */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* ============================================
   RESPONSIVE DESIGN - Mobile First
   ============================================ */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .chat-window {
        width: 400px;
        height: 550px;
        bottom: 80px;
    }
}

/* Mobile Landscape (480px - 768px) */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 15px;
        right: 15px;
    }
    
    .chat-button {
        width: 55px;
        height: 55px;
    }
    
    .chat-icon {
        font-size: 26px;
    }
    
    .chat-window {
        width: calc(100vw - 30px);
        max-width: 400px;
        height: 550px;
        bottom: 75px;
        right: 0;
    }
}

/* Mobile Portrait (320px - 480px) */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-button {
        width: 50px;
        height: 50px;
    }
    
    .chat-icon {
        font-size: 24px;
    }
    
    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        border-radius: 0;
        bottom: auto;
        right: auto;
        animation: slideUpMobile 0.3s ease;
    }
    
    @keyframes slideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .chat-header {
        padding: 12px 16px;
        border-radius: 0;
    }
    
    .chat-avatar {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }
    
    .chat-title {
        font-size: 15px;
    }
    
    .chat-messages {
        padding: 12px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .message-content {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .chat-input-area {
        padding: 10px 12px;
    }
    
    #chatInput {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .send-button {
        width: 38px;
        height: 38px;
    }
    
    .send-button svg {
        width: 18px;
        height: 18px;
    }
}

/* Small Mobile (320px and below) */
@media (max-width: 360px) {
    .message {
        max-width: 95%;
    }
    
    .message-content {
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .chat-header-info {
        gap: 8px;
    }
    
    .chat-avatar {
        width: 35px;
        height: 35px;
        font-size: 20px;
    }
    
    .chat-title {
        font-size: 14px;
    }
    
    .chat-status {
        font-size: 10px;
    }
}

/* ===== Touch-friendly adjustments ===== */
@media (hover: none) and (pointer: coarse) {
    /* เพิ่มขนาดพื้นที่แตะบนมือถือ */
    .chat-button {
        cursor: default;
    }
    
    .chat-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    .send-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    #chatInput {
        font-size: 16px; /* ป้องกัน zoom บน iOS */
    }
}

/* ===== Dark Mode Support (Optional) ===== */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1e1e1e;
    }
    
    .chat-messages {
        background: #121212;
    }
    
    .message.assistant .message-content {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #404040;
    }
    
    .chat-input-area {
        background: #1e1e1e;
        border-color: #404040;
    }
    
    #chatInput {
        background: #2d2d2d;
        border-color: #404040;
        color: #e0e0e0;
    }
    
    #chatInput:focus {
        border-color: var(--primary-color);
    }
    
    .message-time {
        color: #666;
    }
}

/* ===== Loading/Spinner ===== */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Quick Reply Buttons (Optional) ===== */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.quick-reply-btn {
    background: var(--bg-white);
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.quick-reply-btn:hover {
    background: var(--primary-color);
    color: white;
}

@media (max-width: 480px) {
    .quick-reply-btn {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* ===== Unread Badge Animation ===== */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-3px);
    }
    75% {
        transform: translateX(3px);
    }
}

.chat-button.has-unread {
    animation: shake 0.5s ease;
}

/* ===== Safe Area Support (Notch phones) ===== */
@supports (padding: max(0px)) {
    .chat-window {
        padding-bottom: env(safe-area-inset-bottom, 0);
        padding-top: env(safe-area-inset-top, 0);
    }
    
    @media (max-width: 480px) {
        .chat-window {
            padding-bottom: max(10px, env(safe-area-inset-bottom));
        }
    }
}