/* ====================================
   Megatek AI Assistant - Chat Styles
   ==================================== */

/* CSS Variables */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-user-bubble: #e8e8e8;
    --bg-ai-bubble: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent-color: #e53935;
    --accent-hover: #c62828;
    --border-color: #e0e0e0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    --max-width: 480px;
    --header-height: 56px;
    --input-height: 72px;
    --quick-actions-height: 52px;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    max-width: var(--max-width);
    margin: 0 auto;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 10;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    border-radius: 50%;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--bg-primary);
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-spacer {
    width: 40px;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    scroll-behavior: smooth;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100%;
}

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

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

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

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.message.assistant .message-bubble {
    background: var(--bg-ai-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* Rich Text Content in Messages */
.message-content {
    font-size: 15px;
    line-height: 1.6;
}

.message-content p {
    margin: 0 0 12px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content ul, 
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 6px 0;
}

.message-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

.message-content a {
    color: var(--accent-color);
    text-decoration: none;
}

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

.message-content code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
}

.message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

/* Product Card Style (for product recommendations) */
.product-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

.product-card img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}

.product-info {
    flex: 1;
    min-width: 0;
}

.product-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.product-code {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.product-price {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 8px;
}

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

.product-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.product-btn.primary {
    background: var(--accent-color);
    color: white;
}

.product-btn.primary:hover {
    background: var(--accent-hover);
}

.product-btn.secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
}

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

/* Category Card */
.category-card {
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.category-title {
    font-weight: 600;
    font-size: 14px;
}

.category-items {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.category-item {
    flex-shrink: 0;
    width: 60px;
    text-align: center;
}

.category-item img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
    margin: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
}

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

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

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

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

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar {
    display: none;
}

.quick-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quick-btn:hover {
    background: var(--bg-primary);
    border-color: var(--text-muted);
}

.quick-btn:active {
    transform: scale(0.98);
}

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

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 4px 4px 4px 16px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
}

.message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    padding: 8px 0;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-color);
    border: none;
    cursor: pointer;
    color: white;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

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

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Voice Button */
.voice-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--accent-color);
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-right: 4px;
}

.voice-btn:hover {
    background: rgba(229, 57, 53, 0.1);
}

.voice-btn:active,
.voice-btn.recording {
    background: var(--accent-color);
    color: white;
    transform: scale(1.1);
}

.voice-btn.recording {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.4);
    }
    50% {
        box-shadow: 0 0 0 12px rgba(229, 57, 53, 0);
    }
}

/* Voice Recording Overlay */
.voice-recording-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.voice-recording-overlay.active {
    display: flex;
}

.voice-recording-indicator {
    text-align: center;
    color: white;
    padding: 32px 48px;
    border-radius: var(--radius-md);
    background: rgba(229, 57, 53, 0.9);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.voice-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 48px;
    margin-bottom: 16px;
}

.voice-wave span {
    display: block;
    width: 4px;
    height: 20px;
    background: white;
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}

.voice-wave span:nth-child(1) { animation-delay: 0s; }
.voice-wave span:nth-child(2) { animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% {
        height: 20px;
    }
    50% {
        height: 40px;
    }
}

.voice-recording-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.voice-recording-hint {
    font-size: 14px;
    opacity: 0.8;
}

/* Transcribing state */
.voice-btn.transcribing {
    background: var(--accent-color);
    color: white;
    animation: transcribe-pulse 0.8s infinite;
}

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

/* Loading State */
.message.loading .message-bubble {
    background: transparent;
    box-shadow: none;
    padding: 8px 0;
}

/* Error State */
.message.error .message-bubble {
    background: #ffebee;
    color: #c62828;
}

/* ====================================
   Responsive Design
   ==================================== */

/* Tablet and larger */
@media (min-width: 768px) {
    :root {
        --max-width: 480px;
    }
    
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 20px;
    }
    
    .chat-container {
        height: calc(100vh - 40px);
        max-height: 800px;
        border-radius: var(--radius-md);
        overflow: hidden;
    }
}

/* Large screens */
@media (min-width: 1024px) {
    :root {
        --max-width: 420px;
    }
    
    .chat-container {
        max-height: 700px;
    }
}

/* Small phones */
@media (max-width: 374px) {
    .message-bubble {
        padding: 10px 12px;
    }
    
    .quick-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .header-title {
        font-size: 15px;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .chat-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-user-bubble: #404040;
        --bg-ai-bubble: #363636;
        --text-primary: #f5f5f5;
        --text-secondary: #b0b0b0;
        --text-muted: #808080;
        --border-color: #404040;
    }
    
    .message-content code {
        background: #404040;
    }
    
    body {
        background: var(--bg-primary);
    }
    
    @media (min-width: 768px) {
        body {
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
        }
    }
}

/* Print styles */
@media print {
    .chat-header,
    .quick-actions,
    .input-area {
        display: none;
    }
    
    .messages-container {
        overflow: visible;
    }
    
    .chat-container {
        max-width: 100%;
        box-shadow: none;
    }
}

