/* Mobile-first responsive design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Authentication Screen */
.auth-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b9d 50%, #667eea 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.auth-screen.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.auth-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 90%;
    animation: slideIn 0.6s ease-out;
}

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

.auth-header h1 {
    color: #4a5568;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.auth-header p {
    color: #718096;
    font-size: 1rem;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.auth-form {
    margin: 2rem 0;
}

.pin-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.pin-input {
    width: 60px;
    height: 60px;
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    color: #2d3748;
    background: #fff;
    transition: all 0.2s ease;
    outline: none;
}

.pin-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.pin-input.filled {
    border-color: #48bb78;
    background: #f0fff4;
}

.pin-input.error {
    border-color: #e53e3e;
    background: #fff5f5;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.auth-error {
    color: #e53e3e;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    min-height: 1.2rem;
    font-weight: 500;
}

.auth-submit {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 56px;
}

.auth-submit:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}

.auth-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.auth-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.auth-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e2e8f0;
}

.auth-footer p {
    color: #718096;
    font-size: 0.9rem;
    font-style: italic;
}

.app-container {
    max-width: 100vw;
    min-height: 100vh;
    display: none;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Header */
.app-header {
    background: #fff;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    height: 72px;
}

.app-header h1 {
    font-size: 1.2rem;
    color: #4a5568;
    font-weight: 600;
}

.settings-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background-color 0.2s;
    min-width: 44px;
    min-height: 44px;
}

.settings-btn:hover {
    background: #f7fafc;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 75px;
    right: 1rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 1.5rem;
    min-width: 280px;
    max-width: calc(100vw - 2rem);
    z-index: 1000;
    transform: translateY(-10px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.settings-panel.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.settings-content h3 {
    margin-bottom: 1rem;
    color: #2d3748;
    font-size: 1.1rem;
}

.setting-group {
    margin-bottom: 1rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #4a5568;
}

.provider-select,
.model-select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    transition: border-color 0.2s;
}

.provider-select:focus,
.model-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.save-btn {
    width: 100%;
    background: #667eea;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    min-height: 44px;
}

.save-btn:hover {
    background: #5a67d8;
}

.logout-btn {
    width: 100%;
    background: #e53e3e;
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    min-height: 44px;
    margin-top: 0.5rem;
}

.logout-btn:hover {
    background: #c53030;
}

/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    max-height: calc(100vh - 80px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(5px);
}

.message {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

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

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

.message-content {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow: visible;
}

.user-message .message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 6px;
}

.assistant-message .message-content {
    background: #f7fafc;
    color: #2d3748;
    border-bottom-left-radius: 6px;
    border: 1px solid #e2e8f0;
}

/* Loading Indicators */
.loading-indicator {
    padding: 1rem;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.indicator-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-spinner,
.loading-dots,
.loading-bars,
.error-icon {
    display: inline-block;
}

.hidden {
    display: none !important;
}

/* Spinner Animation */
.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Dots Animation */
.loading-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    margin: 0 2px;
    animation: dots 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

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

/* Bars Animation */
.loading-bars span {
    display: inline-block;
    width: 3px;
    height: 16px;
    background: #667eea;
    margin: 0 1px;
    animation: bars 1.2s ease-in-out infinite;
}

.loading-bars span:nth-child(1) { animation-delay: -1.1s; }
.loading-bars span:nth-child(2) { animation-delay: -1.0s; }
.loading-bars span:nth-child(3) { animation-delay: -0.9s; }
.loading-bars span:nth-child(4) { animation-delay: -0.8s; }

@keyframes bars {
    0%, 40%, 100% {
        transform: scaleY(0.4);
        opacity: 0.5;
    }
    20% {
        transform: scaleY(1);
        opacity: 1;
    }
}

.status-text {
    font-size: 0.9rem;
    color: #4a5568;
    font-weight: 500;
}

.error-icon {
    font-size: 1.2rem;
}

/* Chat Input */
.chat-input-container {
    background: #fff;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: border-color 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.voice-btn,
.send-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-btn {
    font-size: 1.2rem;
    width: 44px;
}

.send-btn {
    padding: 0 1rem;
    font-size: 0.9rem;
}

.voice-btn:hover,
.send-btn:hover:not(:disabled) {
    background: #5a67d8;
    transform: translateY(-1px);
}

.send-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
}

/* Voice Recording State */
.voice-btn.recording {
    background: #e53e3e;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.voice-status {
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    color: #667eea;
    font-weight: 500;
}

.voice-status.error {
    color: #e53e3e;
}

/* Mobile responsive authentication */
@media (max-width: 480px) {
    .auth-container {
        padding: 2rem 1.5rem;
        margin: 1rem;
    }
    
    .auth-header h1 {
        font-size: 1.5rem;
    }
    
    .pin-input {
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
    
    .pin-container {
        gap: 0.75rem;
    }
}

/* Mobile specific settings panel positioning */
@media (max-width: 767px) {
    .settings-panel {
        top: 75px;
        right: 0.5rem;
        left: 0.5rem;
        min-width: auto;
        max-width: none;
    }
}

/* Tablet and Desktop */
@media (min-width: 768px) {
    .app-container {
        max-width: 800px;
        margin: 0 auto;
        border-radius: 0;
    }
    
    .app-header h1 {
        font-size: 1.5rem;
    }
    
    .chat-container {
        padding: 2rem;
    }
    
    .message-content {
        max-width: 70%;
    }
    
    .settings-panel {
        top: 75px;
        right: 1rem;
        left: auto;
        min-width: 350px;
        max-width: 400px;
    }
}

@media (min-width: 1024px) {
    .settings-panel {
        min-width: 320px;
        max-width: 380px;
    }
}

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

/* Focus indicators */
.voice-btn:focus,
.send-btn:focus,
.settings-btn:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

/* Markdown styling within messages */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 0.5rem 0;
    font-weight: 600;
}

.message-content h1 {
    font-size: 1.3rem;
    color: #2d3748;
}

.message-content h2 {
    font-size: 1.2rem;
    color: #2d3748;
}

.message-content h3 {
    font-size: 1.1rem;
    color: #4a5568;
}

.message-content strong {
    font-weight: 600;
    color: #2d3748;
}

.message-content em {
    font-style: italic;
    color: #4a5568;
}

.message-content code {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    color: #d53f8c;
}

.message-content pre {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    margin: 0.5rem 0;
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: #2d3748;
    display: block;
    white-space: pre;
}

.message-content ul,
.message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin: 0.25rem 0;
    line-height: 1.4;
}

.message-content ul {
    list-style-type: disc;
}

.message-content ol {
    list-style-type: decimal;
}

.message-content a {
    color: #667eea;
    text-decoration: underline;
    font-weight: 500;
}

.message-content a:hover {
    color: #5a67d8;
    text-decoration: none;
}

.message-content p {
    margin: 0.5rem 0;
    line-height: 1.5;
}

.message-content p:first-child {
    margin-top: 0;
}

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

.message-content table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.95rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    table-layout: auto;
}

.message-content table thead {
    background: #f7fafc;
}

/* Only add horizontal scroll if table is too wide */
@media (max-width: 768px) {
    .message-content table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .message-content table thead,
    .message-content table tbody {
        display: table;
        width: 100%;
    }
    
    .message-content table tr {
        display: table-row;
    }
    
    .message-content table th,
    .message-content table td {
        display: table-cell;
        white-space: normal;
    }
}

.message-content table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: #2d3748;
    border-bottom: 2px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    min-width: 100px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-content table th:last-child {
    border-right: none;
}

.message-content table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    color: #4a5568;
    line-height: 1.4;
    min-width: 100px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-content table td:last-child {
    border-right: none;
}

.message-content table tbody tr:last-child td {
    border-bottom: none;
}

.message-content table tbody tr:hover {
    background: #f7fafc;
}

/* Responsive table styling */
@media (max-width: 640px) {
    .message-content table {
        font-size: 0.875rem;
    }
    
    .message-content table th,
    .message-content table td {
        padding: 0.5rem 0.75rem;
        min-width: 80px;
    }
}

/* Alternating row colors for better readability */
.message-content table tbody tr:nth-child(even) {
    background: rgba(247, 250, 252, 0.5);
}

.message-content table tbody tr:nth-child(even):hover {
    background: #f7fafc;
}

/* Styling for user messages - keep plain text appearance */
.user-message .message-content {
    font-family: inherit;
}

.user-message .message-content * {
    color: inherit;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .message-content {
        border: 2px solid currentColor;
    }
    
    .chat-input,
    .provider-select,
    .model-select {
        border-width: 2px;
    }
    
    .message-content code,
    .message-content pre,
    .message-content table,
    .message-content table th,
    .message-content table td {
        border-width: 2px;
    }
}