/* English Learning PWA - Main Stylesheet */

/* ========================================
   CSS Variables & Theme
   ======================================== */
:root {
    /* Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --secondary-dark: #059669;
    --accent: #f59e0b;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --info: #3b82f6;
    
    /* Neutrals */
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;
    
    /* Font */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--gray-800);
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 50%, #f0f4ff 100%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ========================================
   Layout
   ======================================== */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-content {
    flex: 1;
    padding: var(--space-lg) 0;
}

/* ========================================
   Components - Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

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

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-200);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover:not(:disabled) {
    background: var(--secondary-dark);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--primary);
    color: var(--white);
}

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    font-size: 1.125rem;
}

.btn-sm {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.875rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
}

.btn-icon.btn-lg {
    width: 56px;
    height: 56px;
}

/* ========================================
   Components - Forms
   ======================================== */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 500;
    color: var(--gray-700);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
}

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

.form-input::placeholder {
    color: var(--gray-400);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: var(--space-xs);
}

.form-error {
    font-size: 0.875rem;
    color: var(--danger);
    margin-top: var(--space-xs);
}

/* ========================================
   Components - Cards
   ======================================== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--gray-100);
}

.card-body {
    padding: var(--space-lg);
}

.card-footer {
    padding: var(--space-md) var(--space-lg);
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
}

/* ========================================
   Components - Alerts
   ======================================== */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ========================================
   Auth Pages (Login/Register)
   ======================================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.auth-header {
    padding: var(--space-xl);
    text-align: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
}

.auth-logo {
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-md);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.auth-subtitle {
    opacity: 0.9;
    margin-top: var(--space-xs);
}

.auth-body {
    padding: var(--space-xl);
}

.auth-footer {
    text-align: center;
    padding: var(--space-lg);
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
}

/* ========================================
   Modules Grid
   ======================================== */
.modules-header {
    margin-bottom: var(--space-xl);
}

.modules-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-800);
}

.modules-subtitle {
    color: var(--gray-500);
    margin-top: var(--space-xs);
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.module-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all var(--transition);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.module-card.locked {
    opacity: 0.6;
    cursor: not-allowed;
}

.module-card.locked:hover {
    transform: none;
}

.module-icon {
    font-size: 3rem;
    padding: var(--space-lg);
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--gray-100) 100%);
    text-align: center;
}

.module-content {
    padding: var(--space-lg);
}

.module-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-xs);
}

.module-description {
    font-size: 0.875rem;
    color: var(--gray-500);
    line-height: 1.5;
}

.module-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--gray-100);
}

.module-difficulty {
    font-size: 0.75rem;
    font-weight: 500;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
}

.module-difficulty.beginner {
    background: #d1fae5;
    color: #065f46;
}

.module-difficulty.intermediate {
    background: #fef3c7;
    color: #92400e;
}

.module-difficulty.advanced {
    background: #fee2e2;
    color: #991b1b;
}

.module-difficulty.all {
    background: #dbeafe;
    color: #1e40af;
}

.module-progress {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ========================================
   Chat Interface
   ======================================== */
.chat-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--gray-50);
}

.chat-header {
    background: var(--white);
    padding: var(--space-md) var(--space-lg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    z-index: 10;
}

.chat-back {
    color: var(--gray-600);
}

.chat-back:hover {
    color: var(--primary);
}

.chat-module-info {
    flex: 1;
}

.chat-module-name {
    font-weight: 600;
    color: var(--gray-800);
}

.chat-module-icon {
    font-size: 1.25rem;
}

.chat-actions {
    display: flex;
    gap: var(--space-sm);
}

.chat-container {
    flex: 1;
    display: flex;
    gap: var(--space-lg);
    padding: var(--space-lg);
    overflow: hidden;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.message {
    max-width: 80%;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    background: var(--primary);
    color: var(--white);
    align-self: flex-end;
    border-bottom-right-radius: var(--radius-sm);
}

.message.assistant {
    background: var(--white);
    box-shadow: var(--shadow);
    align-self: flex-start;
    border-bottom-left-radius: var(--radius-sm);
}

.message-content {
    line-height: 1.6;
}

.message-corrections {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--gray-200);
    font-size: 0.875rem;
}

.correction-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
}

.correction-type {
    font-weight: 600;
    color: var(--primary);
    min-width: 80px;
}

.message-audio {
    margin-top: var(--space-sm);
}

.message-audio-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    border: none;
    cursor: pointer;
}

.message-audio-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

.chat-input-area {
    background: var(--white);
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

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

.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-lg);
    resize: none;
    overflow-y: auto;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.chat-voice-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.chat-voice-btn.recording {
    background: var(--danger);
    animation: pulse 1s infinite;
}

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

/* Avatar Panel */
.avatar-panel {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
}

.avatar-container {
    width: 180px;
    height: 180px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-emoji {
    font-size: 6rem;
}

.avatar-status {
    font-size: 0.875rem;
    color: var(--gray-500);
    text-align: center;
}

.avatar-status.speaking {
    color: var(--primary);
}

/* Stop Speech Button */
.stop-speech-btn {
    margin-top: var(--space-sm);
}

/* ========================================
   Payment Page
   ======================================== */
.payment-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.payment-card {
    width: 100%;
    max-width: 480px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.payment-header {
    padding: var(--space-xl);
    text-align: center;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
    color: var(--white);
}

.payment-price {
    font-size: 3rem;
    font-weight: 700;
}

.payment-price-period {
    font-size: 1rem;
    opacity: 0.9;
}

.payment-trial {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    display: inline-block;
}

.payment-body {
    padding: var(--space-xl);
}

.payment-features {
    list-style: none;
    margin-bottom: var(--space-xl);
}

.payment-feature {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
}

.payment-feature-icon {
    color: var(--success);
    font-size: 1.25rem;
}

.payment-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.payment-skip {
    text-align: center;
    color: var(--gray-500);
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
    .avatar-panel {
        display: none;
    }
    
    .modules-grid {
        grid-template-columns: 1fr;
    }
    
    .message {
        max-width: 90%;
    }
    
    .chat-header {
        padding: var(--space-sm) var(--space-md);
    }
    
    .chat-container {
        padding: var(--space-sm);
    }
}

@media (max-width: 480px) {
    .auth-card, .payment-card {
        border-radius: 0;
        min-height: 100vh;
    }
    
    .auth-page, .payment-page {
        padding: 0;
    }
}

/* ========================================
   Utilities
   ======================================== */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }

.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Loading Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    padding: var(--space-md) var(--space-lg);
    background: var(--gray-800);
    color: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
