/* Cleverly PWA - Mobile-First Styles */

:root {
    --primary-color: #6366F1;
    --primary-dark: #4F46E5;
    --primary-light: #818CF8;
    --secondary-color: #F59E0B;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --error-color: #EF4444;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F3F4F6;
    --text-primary: #1F2937;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --header-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: contain;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.menu-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-title {
    flex: 1;
    margin-left: 12px;
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
}

.header-stats {
    display: flex;
    gap: 8px;
    align-items: center;
}

.xp-badge, .streak-badge {
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.xp-badge {
    color: var(--primary-color);
}

.streak-badge {
    color: var(--secondary-color);
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    transform: translateX(280px);
}

.menu-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.menu-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
}

.close-menu {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.menu-items {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}

.menu-item:hover {
    background: var(--bg-secondary);
}

.menu-item.active {
    background: var(--primary-color);
    color: white;
}

.menu-icon {
    font-size: 20px;
}

.menu-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

.install-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

/* Main Content */
.app-content {
    margin-top: var(--header-height);
    flex: 1;
    position: relative;
}

.view {
    display: none;
    min-height: calc(100vh - var(--header-height));
}

.view.active {
    display: block;
}

/* Chat View */
#chatView {
    display: flex;
    flex-direction: column;
}

.chat-modes {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
    -webkit-overflow-scrolling: touch;
}

.mode-btn {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

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

.chat-container {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg-secondary);
}

.welcome-message {
    text-align: center;
    padding: 48px 24px;
}

.welcome-avatar {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: messageSlide 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    background: var(--bg-primary);
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
}

.input-container {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 12px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px;
    margin-bottom: 8px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

.message-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 120px;
    font-family: inherit;
}

.message-input:focus {
    border-color: var(--primary-color);
}

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

.send-btn:active {
    background: var(--primary-dark);
}

.input-info {
    display: flex;
    justify-content: space-between;
    padding: 4px 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Profile View */
.profile-container {
    padding: 24px 16px;
    background: var(--bg-primary);
}

.profile-header {
    text-align: center;
    margin-bottom: 24px;
}

.avatar-placeholder {
    width: 80px;
    height: 80px;
    margin: 0 auto 12px;
    background: var(--bg-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
}

.username {
    font-size: 20px;
    margin-bottom: 4px;
}

.user-level {
    color: var(--text-secondary);
}

.xp-progress {
    margin: 24px 0;
}

.xp-bar {
    height: 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-light));
    transition: width 0.5s ease;
}

.xp-text {
    text-align: center;
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 600;
    color: var(--primary-color);
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Achievements */
.achievements-container {
    padding: 16px;
    background: var(--bg-primary);
    min-height: 100vh;
}

.achievement-tabs {
    display: flex;
    gap: 8px;
    margin: 16px 0;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-secondary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

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

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

/* Challenges */
.challenges-container {
    padding: 16px;
    background: var(--bg-primary);
}

.challenges-date {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.challenge-item {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.challenge-item.completed {
    opacity: 0.7;
}

.challenge-info h3 {
    font-size: 16px;
    margin-bottom: 4px;
}

.challenge-info p {
    font-size: 14px;
    color: var(--text-secondary);
}

.challenge-xp {
    color: var(--primary-color);
    font-weight: 500;
    font-size: 12px;
}

.checkmark {
    color: var(--success-color);
    font-size: 24px;
}

/* Mood Tracker */
.mood-container {
    padding: 16px;
    background: var(--bg-primary);
}

.mood-selector {
    display: flex;
    justify-content: space-around;
    margin: 24px 0;
}

.mood-btn {
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.2s;
}

.mood-btn.selected {
    border-color: var(--primary-color);
    transform: scale(1.1);
}

.mood-note {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    resize: none;
    font-family: inherit;
}

.save-mood-btn {
    width: 100%;
    padding: 14px;
    margin-top: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

.mood-history {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.mood-chart {
    display: flex;
    align-items: flex-end;
    height: 100px;
    gap: 8px;
    margin-top: 16px;
}

.mood-bar {
    flex: 1;
    background: var(--primary-color);
    border-radius: 4px 4px 0 0;
    min-height: 20%;
}

/* Settings */
.settings-container {
    padding: 16px;
    background: var(--bg-primary);
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.setting-select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 16px;
    background: var(--bg-secondary);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.theme-option {
    padding: 16px;
    border: 2px solid transparent;
    border-radius: var(--radius);
    color: white;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
}

.theme-option.active {
    border-color: var(--text-primary);
}

.toggle-setting {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle-setting input {
    width: 20px;
    height: 20px;
}

.setting-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 16px;
}

.save-btn {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
}

.clear-data-btn {
    width: 100%;
    padding: 12px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
}

/* Loading & Toast */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-primary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.toast-container {
    position: fixed;
    bottom: 80px;
    left: 16px;
    right: 16px;
    z-index: 500;
    pointer-events: none;
}

.toast {
    background: var(--text-primary);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

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

.toast.error {
    background: var(--error-color);
}

.toast.warning {
    background: var(--warning-color);
}

.toast.achievement {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

/* Responsive Design */
@media (min-width: 768px) {
    .app-content {
        max-width: 768px;
        margin: var(--header-height) auto 0;
    }
    
    .message-content {
        max-width: 50%;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1F2937;
        --bg-secondary: #111827;
        --text-primary: #F9FAFB;
        --text-secondary: #9CA3AF;
        --border-color: #374151;
    }
    
    .message-content {
        background: var(--bg-secondary);
    }
    
    .message.user .message-content {
        background: var(--primary-color);
    }
}