/* ======================================================
   style.css — "Учим вместе" Web App
   Brand: warm, supportive, practical (BRAND_UCHIM_VMESTE_v2)
   Mobile-first, clean, no-nonsense
   ====================================================== */

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

:root {
    --primary: #82c1fa;
    --primary-action: #5AAEF5;
    --primary-hover: #6aaef5;
    --primary-light: #eaf6ff;
    --success: #48BB78;
    --success-light: #F0FFF4;
    --warning: #ED8936;
    --danger: #E53E3E;
    --danger-light: #FFF5F5;

    --text: #2D3748;
    --text-secondary: #4A5568;
    --text-muted: #A0AEC0;
    --bg: #FFFFFF;
    --bg-secondary: #F7FAFC;
    --bg-chat: #EDF2F7;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --radius: 8px;
    --radius-lg: 12px;

    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --max-width: 720px;
    --header-height: 44px;
}

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

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

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

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

/* --- HEADER --- */
.header {
    height: var(--header-height);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    overflow: hidden;
}

.header-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-logo:hover { text-decoration: none; }

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

.header-nav a {
    font-size: 14px;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
}

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

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

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

.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: 24px 16px;
}

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

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

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

.hero h1 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 16px;
    color: var(--text);
}

.hero p {
    font-size: 17px;
    color: var(--text-secondary);
    max-width: 480px;
    margin: 0 auto 24px;
}

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

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    padding: 32px 0;
}

.feature-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
}

.feature-card .icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.feature-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

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

.steps {
    padding: 32px 0;
}

.steps h2 {
    text-align: center;
    font-size: 22px;
    margin-bottom: 24px;
}

.step-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

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

.step-text h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

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

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

.price-card {
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 360px;
    margin: 0 auto;
}

.price-amount {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
}

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

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

.price-features li {
    padding: 6px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.price-features li::before {
    content: "✅ ";
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

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

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

.btn-primary:hover {
    filter: brightness(0.92);
}

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

.btn-secondary:hover {
    background: var(--border);
}

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

.btn-danger:hover {
    background: #C53030;
}

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

.btn-lg {
    padding: 14px 28px;
    font-size: 17px;
}

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

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

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

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

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

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}

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

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

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

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

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
}

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

.auth-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}

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

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

.alert.show { display: block; }

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

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

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

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

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

.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    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: 4px;
    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);
}

/* Feedback buttons under assistant messages */
.chat-feedback {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

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

/* Thinking indicator */
.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 */
.chat-input-area {
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    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;
}

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

.chat-btn-photo {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-muted);
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-btn-photo:hover {
    background: var(--border);
    color: var(--text);
}

.chat-btn-send {
    width: 44px;
    height: 44px;
    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 0.2s;
    flex-shrink: 0;
}

.chat-btn-send:hover {
    filter: brightness(0.92);
}

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

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

/* Image preview */
.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: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat info bar */
.chat-info {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 4px 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 0.15s;
    flex-shrink: 0;
    font-family: var(--font);
    line-height: 1;
}
.help-btn-inline:hover,
.help-btn-inline.active {
    border-color: var(--primary);
    color: var(--primary);
}

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

.profile-section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

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

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

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

.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: 8px 16px;
    border: 2px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    user-select: none;
}

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

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

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

.sub-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.sub-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

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

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

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

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

.sub-info dt {
    font-weight: 500;
    color: var(--text);
}

.sub-info dd {
    margin-bottom: 8px;
}

/* --- 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);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

/* --- FOOTER --- */
.footer {
    text-align: center;
    padding: 16px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

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

/* --- RESPONSIVE --- */
@media (max-width: 480px) {
    .hero h1 { font-size: 22px; }
    .hero p { font-size: 15px; }
    .auth-card { padding: 24px 16px; }
    .features { grid-template-columns: 1fr; }
    .chat-msg { max-width: 92%; }
    .header-logo-text { display: none; }
    .header-nav a { font-size: 12px; padding: 4px 6px; }
    .theme-toggle { width: 26px; height: 26px; font-size: 14px; }
}

@media (min-width: 768px) {
    .hero { padding: 64px 16px 48px; }
    .hero h1 { font-size: 34px; }
    .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-md);
    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: 12px 14px 10px;
    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;
}
.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: 11px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.1s;
    font-family: var(--font);
}
.help-acc-btn:hover { background: var(--bg-secondary); }
.help-acc-btn.active { color: var(--primary); 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 14px 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 0.2s;
    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;

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

    --text: #E2E8F0;
    --text-secondary: #A0AEC0;
    --text-muted: #718096;
    --bg: #1A202C;
    --bg-secondary: #2D3748;
    --bg-chat: #171923;
    --border: #3D4A5C;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

[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.2);
}

[data-theme="dark"] .btn-primary {
    border: 1px solid rgba(130, 193, 250, 0.5);
}
