/* style.css - Адаптивные стили с поддержкой тем Telegram */

:root {
    /* Telegram theme variables fallback */
    --tg-theme-bg-color: #fff;
    --tg-theme-text-color: #000;
    --tg-theme-hint-color: #999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #fff;
    --tg-theme-secondary-bg-color: #f1f1f1;

    /* App specific */
    --header-height: 56px;
    --nav-height: 56px;
    --border-radius: 12px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Dark theme support via Telegram */
[data-theme="dark"] {
    --tg-theme-bg-color: #17212b;
    --tg-theme-text-color: #f5f5f5;
    --tg-theme-hint-color: #777;
    --tg-theme-secondary-bg-color: #232e3c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: var(--header-height);
    background: var(--tg-theme-secondary-bg-color);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.level-badge {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 80px;
    scroll-behavior: smooth;
}

.welcome-message {
    text-align: center;
    padding: 24px 16px;
    color: var(--tg-theme-hint-color);
}

.welcome-message .hint {
    margin-top: 12px;
    font-style: italic;
    background: var(--tg-theme-secondary-bg-color);
    padding: 8px 12px;
    border-radius: 8px;
    display: inline-block;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background: var(--tg-theme-secondary-bg-color);
    border-bottom-left-radius: 4px;
}

.message .corrected {
    font-weight: 500;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.message .error-item {
    background: rgba(255, 0, 0, 0.1);
    border-left: 3px solid #ff4444;
    padding: 8px 12px;
    margin: 6px 0;
    border-radius: 0 6px 6px 0;
    font-size: 14px;
}

.message .error-item .wrong {
    text-decoration: line-through;
    opacity: 0.7;
    display: block;
}

.message .error-item .correct {
    color: #2ecc71;
    font-weight: 500;
}

.message .feedback {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed rgba(0, 0, 0, 0.2);
    font-style: italic;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    color: var(--tg-theme-hint-color);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--tg-theme-secondary-bg-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Input Area */
.input-area {
    position: absolute;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: var(--tg-theme-bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 8px;
    z-index: 5;
}

.input-area textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 24px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 15px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

.input-area textarea:focus {
    border-color: var(--tg-theme-button-color);
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 48px;
    height: 48px;
    padding: 0 16px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 24px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Bottom Navigation */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    height: var(--nav-height);
    background: var(--tg-theme-bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--tg-theme-hint-color);
    font-size: 13px;
    padding: 8px 4px;
    cursor: pointer;
    transition: color 0.2s;
}

.nav-btn.active {
    color: var(--tg-theme-button-color);
    font-weight: 500;
}

/* Tabs */
.tab-content {
    position: absolute;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    top: var(--header-height);
    background: var(--tg-theme-bg-color);
    overflow-y: auto;
    display: none;
    padding: 16px;
}

.tab-content .tab.active {
    display: block;
}

/* Mistakes List */
.mistake-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    margin-bottom: 12px;
}

.mistake-card .category {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-radius: 10px;
    margin-bottom: 8px;
}

.mistake-card .original {
    text-decoration: line-through;
    opacity: 0.7;
    margin: 4px 0;
}

.mistake-card .correct {
    color: #2ecc71;
    font-weight: 500;
    margin: 4px 0;
}

.mistake-card .explanation {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(0, 0, 0, 0.2);
}

.filter-bar {
    margin-bottom: 16px;
}

.filter-bar select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

.load-more {
    width: 100%;
    padding: 12px;
    background: none;
    border: 1px dashed var(--tg-theme-button-color);
    color: var(--tg-theme-button-color);
    border-radius: 8px;
    cursor: pointer;
    margin-top: 8px;
}

/* Stats */
.stats-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 16px;
}

.stats-card h3 {
    margin-bottom: 12px;
    font-size: 16px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--tg-theme-button-color);
}

.stat-label {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

.trend {
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(46, 204, 113, 0.1);
    border-radius: 8px;
    color: #27ae60;
    font-weight: 500;
    text-align: center;
}

.trend.warning {
    background: rgba(255, 68, 68, 0.1);
    color: #ff4444;
}

.category-chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chart-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chart-bar .label {
    min-width: 100px;
    font-size: 14px;
}

.chart-bar .bar {
    flex: 1;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.chart-bar .fill {
    height: 100%;
    background: var(--tg-theme-button-color);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.chart-bar .value {
    min-width: 30px;
    text-align: right;
    font-size: 14px;
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 100;
    animation: slideUp 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.toast.error {
    background: #ff4444;
}

.toast.success {
    background: #2ecc71;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Utilities */
.hidden {
    display: none !important;
}

[hidden] {
    display: none !important;
}

/* Responsive */
@media (max-height: 700px) {
    .input-area textarea {
        rows: 2;
    }

    .chat-container {
        padding-bottom: 70px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}