/* ======================================================
   style.css — "Учим вместе" Web App
   Aesthetic: Perplexity-inspired refined minimalism
   Warm, precise, generous whitespace, delicate borders
   ====================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&display=swap');

/* --- RESET & BASE --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #82c1fa;
    --primary-action: #5AAEF5;
    --primary-hover: #4A9FE8;
    --primary-light: #f0f7ff;
    --primary-subtle: #e8f4fd;
    --success: #48BB78;
    --success-light: #f0faf4;
    --warning: #ED8936;
    --danger: #E53E3E;
    --danger-light: #fef2f2;

    --text: #1a1a2e;
    --text-secondary: #64648b;
    --text-muted: #9e9eb8;
    --bg: #FFFFFF;
    --bg-secondary: #fafafc;
    --bg-chat: #f5f5f8;
    --bg-warm: #fefefe;
    --border: #ebebf0;
    --border-subtle: #f0f0f5;
    --shadow: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.06);
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --max-width: 720px;
    --header-height: 56px;

    --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition: 150ms var(--ease);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    letter-spacing: -0.01em;
}

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

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

/* --- HEADER --- */
.header {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    overflow: hidden;
}

.header-logo {
    font-size: 19px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}

.header-logo:hover { text-decoration: none; color: var(--text); }

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- BURGER MENU (mobile) --- */
.burger-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px;
    border-radius: var(--radius);
    transition: background var(--transition);
    flex-shrink: 0;
}

.burger-toggle:hover {
    background: var(--bg-secondary);
}

.burger-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.3s var(--ease);
}

.burger-toggle.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.burger-toggle.active span:nth-child(2) {
    opacity: 0;
}
.burger-toggle.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.25s var(--ease);
}
.mobile-menu-overlay.show {
    display: block;
    opacity: 1;
}

/* Mobile menu (outside header, no overflow issues) */
.mobile-menu {
    display: none;
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: 220px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 0 var(--radius-lg);
    box-shadow: var(--shadow-lg);
    flex-direction: column;
    padding: 8px 0;
    z-index: 200;
}
.mobile-menu.open {
    display: flex;
}
.mobile-menu a {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    display: block;
}
.mobile-menu a:hover {
    background: var(--bg-secondary);
    color: var(--text);
    text-decoration: none;
}
.mobile-menu a:not(:last-child) {
    border-bottom: 1px solid var(--border-subtle);
}
.mobile-menu a.btn {
    background: none;
    border: none;
    border-radius: 0;
    color: var(--text-secondary);
    padding: 12px 20px;
    font-size: 15px;
    width: 100%;
    text-align: left;
    box-shadow: none;
}
.mobile-menu a.btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

@media (max-width: 600px) {
    .burger-toggle {
        display: flex;
    }
    .header-nav {
        display: none;
    }
}

.header-nav a {
    font-size: 14px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: var(--radius);
    transition: all var(--transition);
    letter-spacing: -0.01em;
}

.header-nav a:not(.btn) {
    color: var(--text-secondary);
}

.header-nav a:not(.btn):hover {
    background: var(--bg-secondary);
    color: var(--text);
    text-decoration: none;
}

.header-status {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0;
}

.header-status.premium {
    color: var(--success);
    background: var(--success-light);
}

/* --- MAIN CONTENT --- */
.main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 32px 24px;
}

.main--wide {
    max-width: 960px;
}

.main--full {
    max-width: 100%;
    padding: 0;
}

/* --- LANDING PAGE --- */
.hero {
    text-align: center;
    padding: 72px 24px 48px;
}

.hero h1 {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 16px;
    color: var(--text);
    letter-spacing: -0.03em;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.hero p {
    font-size: 17px;
    color: var(--text-secondary);
    max-width: 460px;
    margin: 0 auto 32px;
    line-height: 1.6;
    font-weight: 400;
}

.hero-cta {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 48px 0 32px;
}

.feature-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    text-align: left;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.feature-card:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.feature-card .icon {
    font-size: 28px;
    margin-bottom: 14px;
    display: block;
}

.feature-card h3 {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
    color: var(--text);
}

.feature-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.55;
}

.steps {
    padding: 24px 0;
}

.steps h2 {
    text-align: center;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    color: var(--text);
}

.step-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 460px;
    margin: 0 auto;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.step-num {
    width: 32px;
    height: 32px;
    background: var(--primary-subtle);
    color: var(--primary-action);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.step-text h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--text);
}

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

.pricing {
    text-align: center;
    padding: 48px 0;
}

.pricing h2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}

.price-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 36px 32px;
    max-width: 360px;
    margin: 0 auto;
    transition: border-color var(--transition);
}

.price-card:hover {
    border-color: var(--primary);
}

.price-amount {
    font-family: var(--font-display);
    font-size: 40px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
}

.price-period {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 2px;
}

.price-features {
    list-style: none;
    margin: 24px 0;
    text-align: left;
}

.price-features li {
    padding: 8px 0;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 10px;
}

.price-features li:last-child {
    border-bottom: none;
}

.price-features li::before {
    content: "✓";
    font-weight: 600;
    color: var(--success);
    font-size: 15px;
    flex-shrink: 0;
}

/* --- FAQ --- */
.faq {
    padding: 48px 0;
}
.faq h2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: -0.02em;
    color: var(--text);
}
.faq-list {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.faq-item {
    border-bottom: 1px solid var(--border);
}
.faq-item:first-child {
    border-top: 1px solid var(--border);
}
.faq-question {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 16px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-family: var(--font);
    transition: color var(--transition);
}
.faq-question:hover {
    color: var(--primary-action);
}
.faq-question::after {
    content: '+';
    font-size: 20px;
    font-weight: 400;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.25s var(--ease);
}
.faq-item.open .faq-question::after {
    content: '−';
}
.faq-answer {
    display: none;
    padding: 0 0 16px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}
.faq-item.open .faq-answer {
    display: block;
}

/* --- LIVE QUERIES (hero bubbles) --- */
.hero-live {
    margin-top: 40px;
    position: relative;
    min-height: 100px;
}
.hero-live-counter {
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.hero-live-counter strong {
    color: var(--primary-action);
    font-weight: 700;
}
.hero-bubbles {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 520px;
    margin: 0 auto;
    height: 76px;
    overflow: hidden;
    align-content: flex-start;
}
.hero-bubble {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 8px 18px;
    font-size: 13px;
    color: var(--text-secondary);
    opacity: 0;
    transform: translateY(6px);
    animation: bubbleIn 0.5s var(--ease) forwards;
    white-space: nowrap;
}
@keyframes bubbleIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.hero-bubble.fade-out {
    animation: bubbleFade 0.4s var(--ease) forwards;
}
@keyframes bubbleFade {
    to {
        opacity: 0;
        transform: translateY(-6px);
    }
}

/* --- TARIFF DISCOUNT --- */
.tariff-old-price {
    font-size: 16px;
    color: var(--text-muted);
    text-decoration: line-through;
    font-weight: 400;
    margin-bottom: 2px;
}
.tariff-discount-badge {
    display: inline-block;
    background: #ff5252;
    color: white;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 100px;
    margin-left: 8px;
    vertical-align: middle;
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.btn:hover { text-decoration: none; }

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

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
    box-shadow: 0 1px 3px rgba(90, 174, 245, 0.25);
}

a.btn-primary,
a.btn-primary:hover {
    color: white;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: #d8d8e0;
}

.btn-danger {
    background: var(--bg);
    color: var(--danger);
    border: 1px solid var(--danger);
}

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

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-lg {
    padding: 13px 28px;
    font-size: 15px;
    border-radius: var(--radius-lg);
}

.btn-block {
    display: flex;
    width: 100%;
}

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

/* --- FORMS --- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
    letter-spacing: 0;
}

.form-input {
    width: 100%;
    padding: 11px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: var(--font);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-action);
    box-shadow: 0 0 0 3px rgba(90, 174, 245, 0.12);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-error {
    font-size: 13px;
    color: var(--danger);
    margin-top: 6px;
}

.form-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 6px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.5;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--primary-action);
}

/* --- AUTH PAGES --- */
.auth-container {
    max-width: 400px;
    margin: 60px auto;
    padding: 0 24px;
}

.auth-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 36px 32px;
}

.auth-card h1 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 28px;
    text-align: center;
    letter-spacing: -0.02em;
    color: var(--text);
}

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

.auth-footer a {
    font-weight: 500;
}

/* --- ALERTS --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
    display: none;
    line-height: 1.5;
}

.alert.show { display: block; }

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--success-light);
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-info {
    background: var(--primary-light);
    color: #1e5fa6;
    border: 1px solid #bae0fd;
}

/* --- CHAT --- */
/* --- CHAT LAYOUT (мульти-чат) --- */
.chat-layout {
    display: flex;
    max-width: 900px;
    margin: 8px auto;
    width: calc(100% - 16px);
    height: calc(100vh - var(--header-height) - 16px);
    height: calc(100dvh - var(--header-height) - 16px);
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
}

.chat-layout .chat-container {
    flex: 1;
    max-width: none;
    margin: 0;
    width: 100%;
    border-radius: 0;
    border: none;
    height: 100%;
}

/* --- CHAT SIDEBAR --- */
.chat-sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.chat-sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-select-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
.chat-select-btn:hover {
    color: var(--primary-action);
    background: var(--bg-tertiary);
}
.chat-select-btn.active {
    color: var(--primary-action);
}

.chat-sidebar-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: none;
}

.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 10px 12px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font);
    color: var(--primary-action);
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

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

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.chat-list-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin: 2px 12px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background var(--transition);
    position: relative;
}

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

.chat-list-item.active {
    background: var(--primary-light);
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text);
}

.chat-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition);
    flex-shrink: 0;
}

.chat-list-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition);
}

.chat-item-btn:hover {
    color: var(--primary-action);
}

.chat-item-btn-delete:hover {
    color: var(--danger);
}

.chat-select-cb {
    flex-shrink: 0;
    cursor: pointer;
}

.chat-rename-input {
    flex: 1;
    font-size: 13px;
    font-family: var(--font);
    padding: 2px 6px;
    border: 1px solid var(--primary-action);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.chat-list-actions {
    display: none;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
}

.chat-bulk-delete-btn {
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}

/* --- SIDEBAR TOGGLE (mobile) --- */
.chat-sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-sidebar-toggle:hover {
    color: var(--text);
}

/* --- SIDEBAR OVERLAY (mobile) --- */
.chat-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0,0,0,0.3);
    z-index: 149;
}

.chat-sidebar-overlay.show {
    display: block;
}

/* --- CLEAR CHAT BUTTON --- */
.chat-clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color var(--transition);
}

.chat-clear-btn:hover {
    color: var(--danger);
}

/* Desktop: sidebar always visible */
@media (min-width: 601px) {
    .chat-sidebar-toggle { display: none; }
    .chat-sidebar-close { display: none; }
}

/* Mobile: sidebar as overlay */
@media (max-width: 600px) {
    .chat-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    }
    .chat-sidebar.open {
        transform: translateX(0);
    }
    .chat-sidebar-toggle {
        display: flex;
    }
    .chat-sidebar-close {
        display: block;
    }
    .chat-layout {
        margin: 0;
        width: 100%;
        border-radius: 0;
        border: none;
        height: calc(100vh - var(--header-height));
        height: calc(100dvh - var(--header-height));
    }
    .chat-layout .chat-container {
        border-left: none;
    }
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 16px);
    height: calc(100dvh - var(--header-height) - 16px);
    max-width: var(--max-width);
    margin: 8px auto;
    width: calc(100% - 16px);
    overflow: hidden;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg--user {
    align-self: flex-end;
    background: var(--primary-action);
    color: white;
}

.chat-msg--assistant {
    align-self: flex-start;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.chat-msg--assistant b,
.chat-msg--assistant strong {
    color: var(--text);
}

.chat-msg--assistant code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 14px;
}

.chat-msg--assistant pre {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
    font-size: 14px;
}

.chat-msg--assistant .spoiler {
    background: var(--text);
    color: var(--text);
    border-radius: 4px;
    padding: 0 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.chat-msg--assistant .spoiler.revealed {
    background: transparent;
    color: var(--success);
}

.chat-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.chat-feedback .btn {
    font-size: 12px;
    padding: 4px 10px;
}

.chat-thinking {
    align-self: flex-start;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 18px;
    color: var(--text-muted);
    font-size: 14px;
    display: none;
}

.chat-thinking.show { display: block; }

.chat-thinking .dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.chat-input-area {
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.chat-input {
    width: 100%;
    padding: 11px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text);
    resize: none;
    height: 44px;
    min-height: 44px;
    max-height: 120px;
    font-family: var(--font);
    line-height: 1.4;
    transition: border-color var(--transition);
}

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

.chat-btn-photo {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-muted);
    transition: all var(--transition);
    flex-shrink: 0;
}

.chat-btn-photo:hover {
    border-color: var(--primary);
    color: var(--primary-action);
}

.chat-btn-send {
    width: 42px;
    height: 42px;
    border: none;
    background: var(--primary-action);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.chat-btn-send:hover {
    background: var(--primary-hover);
}

.chat-btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 3px 16px 7px;
    background: var(--bg);
    letter-spacing: 0.01em;
}

.image-preview {
    display: none;
    position: relative;
    margin-bottom: 8px;
}

.image-preview.show { display: block; }

.image-preview img {
    max-height: 120px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: 2px solid var(--bg);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-info {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 6px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
}

.chat-info-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-btn-inline {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid var(--text-muted);
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    font-family: var(--font);
    line-height: 1;
}

.help-btn-inline:hover,
.help-btn-inline.active {
    border-color: var(--primary-action);
    color: var(--primary-action);
}

/* --- CLARIFY BUTTON --- */
.chat-messages {
    position: relative;
}
.clarify-btn {
    position: absolute;
    display: none;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    color: white;
    background: var(--primary-action);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    z-index: 50;
    transform: translateX(-50%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    white-space: nowrap;
    transition: background var(--transition);
}
.clarify-btn:hover {
    background: var(--primary-hover);
}
.clarify-btn::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--primary-action);
}

/* --- QUOTE PREVIEW --- */
.quote-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    border-left: 3px solid var(--primary-action);
    font-size: 13px;
    color: var(--text-secondary);
}
.quote-preview-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-style: italic;
}
.quote-preview-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}
.quote-preview-close:hover {
    color: var(--text);
}

/* --- PROFILE --- */
.profile-section {
    margin-bottom: 36px;
}

.profile-section h2 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    color: var(--text);
}

.grade-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.grade-btn {
    width: 46px;
    height: 46px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
}

.grade-btn:hover {
    border-color: var(--primary-action);
    color: var(--primary-action);
}

.grade-btn.selected {
    background: var(--primary-action);
    border-color: var(--primary-action);
    color: white;
}

.subject-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.subject-chip {
    padding: 9px 18px;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: var(--bg);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font);
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
    user-select: none;
}

.subject-chip:hover {
    border-color: var(--primary-action);
    color: var(--primary-action);
}

.subject-chip.selected {
    background: var(--primary-light);
    border-color: var(--primary-action);
    color: var(--primary-action);
}

/* --- STUDENT MEMORY --- */
.memory-category {
    margin-bottom: 20px;
}

.memory-category-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.memory-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    background: var(--bg);
    transition: background var(--transition);
}

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

.memory-item-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.memory-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.4;
}

.memory-subject {
    font-size: 12px;
    color: var(--primary-action);
    background: var(--primary-light);
    padding: 1px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.memory-times {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.memory-delete {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.5;
    transition: all var(--transition);
}

.memory-delete:hover {
    opacity: 1;
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

/* --- SUBSCRIPTION --- */
.sub-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    margin-bottom: 16px;
}

.sub-card h3 {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.sub-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
}

.sub-status.active {
    background: var(--success-light);
    color: var(--success);
}

.sub-status.trial {
    background: var(--primary-light);
    color: var(--primary-action);
}

.sub-status.expired {
    background: var(--danger-light);
    color: var(--danger);
}

.sub-info {
    margin: 16px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.sub-info dt {
    font-weight: 500;
    color: var(--text);
    font-size: 13px;
    margin-top: 12px;
}

.sub-info dt:first-child {
    margin-top: 0;
}

.sub-info dd {
    margin-bottom: 0;
    margin-top: 2px;
}

/* --- SUBSCRIPTION STATUS BAR --- */
.sub-status-bar {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.sub-status-left {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.sub-status-label {
    font-size: 14px;
    color: var(--text-secondary);
}
.sub-status-value {
    font-size: 14px;
}

@media (max-width: 480px) {
    .sub-status-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .sub-status-bar > .sub-status {
        align-self: flex-start;
    }
}

/* --- TARIFF CARDS --- */
.tariff-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.tariff-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition), box-shadow var(--transition);
    position: relative;
    cursor: pointer;
}

.tariff-card:hover {
    border-color: var(--primary);
}

.tariff-card.recommended,
.tariff-card.selected {
    border-color: var(--primary-action);
    box-shadow: 0 0 0 1px var(--primary-action);
}

.tariff-badge {
    position: absolute;
    top: -11px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-action);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 14px;
    border-radius: 100px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.tariff-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.tariff-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.tariff-price {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.tariff-price-period {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.tariff-features {
    list-style: none;
    margin: 0 0 24px;
    padding: 0;
    flex: 1;
}

.tariff-features li {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tariff-features li::before {
    content: "✓";
    font-weight: 600;
    color: var(--success);
    font-size: 14px;
    flex-shrink: 0;
}

.tariff-features li strong {
    font-weight: 600;
    color: var(--text);
}

.tariff-card .btn {
    margin-top: auto;
}

.tariff-card.current {
    background: var(--bg-secondary);
}

.tariff-card.current .btn {
    opacity: 0.5;
    pointer-events: none;
}

@media (max-width: 768px) {
    .tariff-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* --- UTILITIES --- */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 14px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* --- LOADING SPINNER --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-action);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

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

/* --- FOOTER --- */
.footer {
    text-align: center;
    padding: 24px;
    font-size: 13px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    letter-spacing: -0.01em;
}

.footer a {
    color: var(--text-muted);
    transition: color var(--transition);
}

.footer a:hover {
    color: var(--text-secondary);
}

/* --- RESPONSIVE --- */
@media (max-width: 480px) {
    .header { padding: 0 16px; }
    .main { padding: 24px 16px; }
    .hero { padding: 48px 16px 32px; }
    .hero h1 { font-size: 24px; }
    .hero p { font-size: 15px; }
    .auth-container { padding: 0 16px; margin: 32px auto; }
    .auth-card { padding: 28px 20px; }
    .features { grid-template-columns: 1fr; gap: 12px; }
    .feature-card { padding: 20px; }
    .chat-msg { max-width: 92%; }
    .header-logo-text { display: none; }
    .header-nav a { font-size: 12px; padding: 5px 8px; }
    .theme-toggle { width: 28px; height: 28px; font-size: 15px; }
    .price-card { padding: 28px 24px; }
}

@media (min-width: 768px) {
    .hero { padding: 96px 24px 64px; }
    .hero h1 { font-size: 40px; }
    .hero p { font-size: 18px; }
    .step-list {
        flex-direction: row;
        gap: 24px;
    }
    .step {
        flex-direction: column;
        align-items: center;
        text-align: center;
        flex: 1;
    }
}

/* ===== HELP PANEL ===== */
.help-panel {
    display: none;
    position: fixed;
    z-index: 200;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 280px;
    max-height: 70vh;
    overflow-y: auto;
}
.help-panel.show { display: block; }

.help-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.help-panel-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0;
    transition: color var(--transition);
}
.help-panel-close:hover { color: var(--text); }

.help-acc-btn {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background var(--transition);
    font-family: var(--font);
}
.help-acc-btn:hover { background: var(--bg-secondary); }
.help-acc-btn.active { color: var(--primary-action); background: var(--primary-light); }
.help-acc-btn::after {
    content: '›';
    margin-left: auto;
    font-size: 16px;
    color: var(--text-muted);
    transition: transform 0.2s;
}
.help-acc-btn.active::after { transform: rotate(90deg); }

.help-acc-body {
    display: none;
    padding: 10px 16px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.help-acc-body.show { display: block; }
.help-acc-body ul {
    margin: 0;
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.help-acc-body li {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}
.help-acc-body em {
    color: var(--text);
    font-style: normal;
    font-weight: 500;
}
.help-acc-item:last-child .help-acc-btn { border-bottom: none; }
.help-acc-item:last-child .help-acc-body { border-bottom: none; }

@media (max-width: 480px) {
    .help-panel { width: calc(100vw - 24px); }
}

/* --- THEME TOGGLE --- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.theme-toggle {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 17px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
}

/* ===== DARK THEME ===== */
[data-theme="dark"] {
    --primary: #82c1fa;
    --primary-action: #5AAEF5;
    --primary-hover: #6aaef5;
    --primary-light: #1a2d3d;
    --primary-subtle: #152535;

    --success: #68D391;
    --success-light: #1a2e23;
    --warning: #F6AD55;
    --danger: #FC8181;
    --danger-light: #2d1a1a;

    --text: #E2E8F0;
    --text-secondary: #A0AEC0;
    --text-muted: #718096;
    --bg: #1A202C;
    --bg-secondary: #242d3d;
    --bg-chat: #151a25;
    --bg-warm: #1e2533;
    --border: #2d3748;
    --border-subtle: #2a3345;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

[data-theme="dark"] .header {
    background: rgba(26, 32, 44, 0.92);
}

[data-theme="dark"] .alert-error {
    border-color: #742A2A;
}

[data-theme="dark"] .alert-success {
    color: #9AE6B4;
    border-color: #276749;
}

[data-theme="dark"] .alert-info {
    color: #90CDF4;
    border-color: #2C5282;
}

[data-theme="dark"] .form-input:focus {
    box-shadow: 0 0 0 3px rgba(130, 193, 250, 0.15);
}

[data-theme="dark"] .btn-primary {
    border-color: rgba(130, 193, 250, 0.3);
}

[data-theme="dark"] .btn-danger {
    background: transparent;
    border-color: var(--danger);
}

[data-theme="dark"] .btn-danger:hover {
    background: var(--danger);
    color: white;
}

[data-theme="dark"] .chat-sidebar {
    background: var(--bg-secondary);
}

[data-theme="dark"] .chat-sidebar-overlay.show {
    background: rgba(0,0,0,0.5);
}

[data-theme="dark"] .chat-new-btn {
    background: var(--primary-subtle);
    border-color: var(--primary);
}

[data-theme="dark"] .chat-list-item.active {
    background: var(--primary-light);
}

/* --- PAGE ENTRY ANIMATION --- */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.main,
.auth-container {
    animation: fadeUp 0.3s var(--ease) both;
}

.hero {
    animation: fadeUp 0.4s var(--ease) both;
}

.feature-card {
    animation: fadeUp 0.35s var(--ease) both;
}

.feature-card:nth-child(1) { animation-delay: 0.05s; }
.feature-card:nth-child(2) { animation-delay: 0.1s; }
.feature-card:nth-child(3) { animation-delay: 0.15s; }
