/* Material UI-Inspired Design with Pure CSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette */
    --primary-main: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary-main: #ec4899;
    --secondary-light: #f472b6;
    --secondary-dark: #db2777;
    --success-main: #10b981;
    --warning-main: #f59e0b;
    --error-main: #ef4444;
    
    /* Background Colors */
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-paper: rgba(26, 26, 46, 0.9);
    --bg-surface: rgba(255, 255, 255, 0.05);
    
    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-disabled: #64748b;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 50%;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(99, 102, 241, 0.3);
    --shadow-xl: 0 16px 64px rgba(0, 0, 0, 0.4);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

body {
    font-family: 'Inter', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Enhanced Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity var(--transition-slow);
}

.loading-content {
    text-align: center;
}

.loading-logo-container {
    position: relative;
    display: inline-block;
    margin-bottom: var(--spacing-xl);
}

.loading-logo {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    animation: float 3s ease-in-out infinite;
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.5));
}

.loading-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-full);
    animation: ripple 2s ease-out infinite;
}

.loading-ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: 160px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-full);
    animation: ripple 2s ease-out infinite 0.5s;
}

.loading-text h2 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-main);
    margin-bottom: var(--spacing-sm);
    animation: glow 2s ease-in-out infinite alternate;
}

.loading-text p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 400;
    opacity: 0;
    animation: fadeInUp 1s ease-out 0.5s forwards;
}

/* Main App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: all var(--transition-slow);
}

/* Header */
.app-header {
    background: var(--bg-paper);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: var(--spacing-md) var(--spacing-lg);
    position: sticky;
    top: 0;
    z-index: 100;
    animation: slideDown 0.6s ease-out;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.logo-container {
    position: relative;
    animation: scaleIn 0.6s ease-out 0.2s both;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-light);
    animation: slideInRight 0.6s ease-out 0.3s both;
}

/* Status Chip */
.status-chip {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-xl);
    font-weight: 500;
    font-size: 0.875rem;
    transition: all var(--transition-normal);
    animation: slideInLeft 0.6s ease-out 0.4s both;
    box-shadow: var(--shadow-md);
}

.status-chip.connecting {
    background: linear-gradient(135deg, var(--primary-main), var(--primary-dark));
    color: white;
}

.status-chip.waiting {
    background: linear-gradient(135deg, var(--secondary-main), var(--secondary-dark));
    color: white;
    animation: pulse 2s infinite, gradientShift 3s ease-in-out infinite;
}

.status-chip.connected {
    background: linear-gradient(135deg, var(--success-main), #059669);
    color: white;
}

.status-chip.disconnected {
    background: linear-gradient(135deg, var(--error-main), #dc2626);
    color: white;
}

.status-icon {
    font-size: 1rem;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    padding: var(--spacing-lg);
    animation: fadeInUp 0.8s ease-out 0.5s both;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-paper);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    overflow: hidden;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.1);
}

/* Messages Container */
.messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.5);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.7);
}

/* Message Bubbles */
.message {
    display: flex;
    margin-bottom: var(--spacing-md);
    align-items: flex-end;
    animation: messageSlideIn 0.4s ease-out;
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast);
}

.message-bubble:hover {
    transform: translateY(-1px);
}

.message.sent .message-bubble {
    background: linear-gradient(135deg, var(--primary-main), var(--primary-dark));
    color: white;
    border-bottom-right-radius: var(--spacing-xs);
    margin-left: var(--spacing-md);
}

.message.received .message-bubble {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom-left-radius: var(--spacing-xs);
    margin-right: var(--spacing-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0 var(--spacing-sm);
}

.message.sent .message-avatar {
    background: var(--primary-main);
    color: white;
    order: 2;
}

.message.received .message-avatar {
    background: var(--secondary-main);
    color: white;
    order: 1;
}

/* Welcome Message */
.welcome-message {
    padding: var(--spacing-xl);
    text-align: center;
    color: var(--text-secondary);
    animation: fadeIn 0.6s ease-out;
}

.welcome-content h3 {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
}

.welcome-content p {
    font-size: 0.875rem;
}

/* Input Container */
.input-container {
    padding: var(--spacing-lg);
    background: rgba(26, 26, 46, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-surface);
    border: 2px solid transparent;
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 0.875rem;
    resize: none;
    outline: none;
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
}

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

.message-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Action Buttons */
.action-button {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-size: 1rem;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.action-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
    transform: translate(-50%, -50%);
}

.action-button:hover::before {
    width: 100%;
    height: 100%;
}

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

.action-button.primary {
    background: linear-gradient(135deg, var(--primary-main), var(--primary-dark));
    color: white;
}

.action-button.secondary {
    background: linear-gradient(135deg, var(--secondary-main), var(--secondary-dark));
    color: white;
}

.action-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.action-button:disabled::before {
    display: none;
}

/* Material Icons */
.material-icons {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
}

/* Animations */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

@keyframes ripple {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0;
    }
}

@keyframes glow {
    from { text-shadow: 0 0 10px rgba(99, 102, 241, 0.5); }
    to { text-shadow: 0 0 20px rgba(99, 102, 241, 0.8), 0 0 30px rgba(99, 102, 241, 0.4); }
}

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

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

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

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes gradientShift {
    0% { background: linear-gradient(135deg, var(--secondary-main), var(--secondary-dark)); }
    50% { background: linear-gradient(135deg, var(--secondary-dark), var(--primary-main)); }
    100% { background: linear-gradient(135deg, var(--secondary-main), var(--secondary-dark)); }
}

/* Responsive Design */
/* Enhanced Mobile Responsiveness */
@media (max-width: 768px) {
    :root {
        --spacing-xs: 2px;
        --spacing-sm: 6px;
        --spacing-md: 12px;
        --spacing-lg: 16px;
        --spacing-xl: 24px;
    }
    
    body {
        /* Prevent zoom on input focus */
        -webkit-text-size-adjust: 100%;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    .app-header {
        padding: var(--spacing-sm) var(--spacing-md);
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(20px);
        background: rgba(15, 15, 35, 0.95);
    }
    
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: var(--spacing-sm);
    }
    
    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
        min-width: 0;
    }
    
    .app-title {
        font-size: 1.1rem;
        font-weight: 600;
        white-space: nowrap;
    }
    
    .status-chip {
        font-size: 0.75rem;
        padding: var(--spacing-xs) var(--spacing-sm);
        border-radius: var(--radius-md);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }
    
    .chat-main {
        padding: var(--spacing-sm);
        /* Account for mobile keyboard */
        padding-bottom: calc(var(--spacing-sm) + env(keyboard-inset-height, 0px));
    }
    
    .chat-container {
        border-radius: var(--radius-md);
        min-height: calc(100vh - 120px);
        /* Optimize for mobile viewport */
        height: calc(100vh - 120px);
        max-height: calc(100vh - 120px);
    }
    
    .messages {
        padding: var(--spacing-md);
        /* Better scrolling on mobile */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .messages::-webkit-scrollbar {
        width: 4px;
    }
    
    .message {
        margin-bottom: var(--spacing-sm);
    }
    
    .message-bubble {
        max-width: 85%;
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.9rem;
        line-height: 1.4;
        /* Better text rendering on mobile */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
        margin: 0 var(--spacing-xs);
    }
    
    .input-container {
        padding: var(--spacing-md);
        /* Stick to bottom on mobile */
        position: sticky;
        bottom: 0;
        background: rgba(26, 26, 46, 0.95);
        backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .input-wrapper {
        gap: var(--spacing-sm);
        align-items: center;
    }
    
    .message-input {
        padding: var(--spacing-md);
        font-size: 16px; /* Prevent zoom on iOS */
        border-radius: var(--radius-lg);
        min-height: 44px; /* Touch target size */
        /* Better mobile input handling */
        -webkit-appearance: none;
        appearance: none;
        -webkit-border-radius: var(--radius-lg);
        border-radius: var(--radius-lg);
    }
    
    .action-button {
        width: 44px;
        height: 44px;
        /* Ensure proper touch targets */
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
        /* Better touch response */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .loading-text h2 {
        font-size: 1.5rem;
    }
    
    .loading-logo {
        width: 60px;
        height: 60px;
    }
    
    .welcome-message {
        padding: var(--spacing-md);
    }
    
    .welcome-content h3 {
        font-size: 1.1rem;
    }
    
    .welcome-content p {
        font-size: 0.8rem;
    }
}

/* Extra Small Mobile Devices */
@media (max-width: 480px) {
    .header-content {
        flex-direction: column;
        gap: var(--spacing-sm);
        text-align: center;
    }
    
    .header-left {
        align-items: center;
        width: 100%;
    }
    
    .app-title {
        font-size: 1rem;
    }
    
    .status-chip {
        font-size: 0.7rem;
        padding: 2px var(--spacing-sm);
        max-width: 180px;
    }
    
    .chat-container {
        min-height: calc(100vh - 140px);
        height: calc(100vh - 140px);
        border-radius: var(--spacing-sm);
    }
    
    .message-bubble {
        max-width: 90%;
        font-size: 0.85rem;
        padding: var(--spacing-sm) 12px;
    }
    
    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.65rem;
    }
    
    .input-wrapper {
        flex-direction: row;
        gap: var(--spacing-sm);
        align-items: stretch;
    }
    
    .message-input {
        font-size: 16px; /* Prevent zoom */
        padding: 12px var(--spacing-md);
        border-radius: var(--radius-md);
    }
    
    .action-button {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .action-button .material-icons {
        font-size: 20px;
    }
    
    .loading-logo {
        width: 50px;
        height: 50px;
    }
    
    .loading-text h2 {
        font-size: 1.25rem;
    }
    
    .loading-text p {
        font-size: 0.8rem;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        min-height: calc(100vh - 80px);
        height: calc(100vh - 80px);
    }
    
    .app-header {
        padding: var(--spacing-xs) var(--spacing-md);
    }
    
    .header-content {
        flex-direction: row;
    }
    
    .messages {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .input-container {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* Touch and hover optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Mobile devices without hover capability */
    .action-button:hover::before {
        width: 0;
        height: 0;
    }
    
    .action-button:active::before {
        width: 100%;
        height: 100%;
    }
    
    .message-bubble:hover {
        transform: none;
    }
    
    .action-button:active {
        transform: scale(0.95);
        background-color: rgba(255, 255, 255, 0.1);
    }
}

/* iOS Safari specific optimizations */
@supports (-webkit-touch-callout: none) {
    .input-container {
        /* Account for iOS safe area */
        padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
    }
    
    .message-input {
        /* Prevent iOS zoom */
        font-size: max(16px, 1em);
        /* Fix iOS input styling */
        -webkit-appearance: none;
        appearance: none;
        -webkit-border-radius: var(--radius-lg);
        border-radius: var(--radius-lg);
    }
    
    .chat-container {
        /* Better iOS viewport handling */
        height: calc(100vh - 120px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
}

/* High DPI displays optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .action-button {
        /* Sharper icons on retina displays */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .message-bubble {
        /* Better text rendering on high DPI */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}
