/* ═══════════════════════════════════════════════════════════════════════
   @anonim_cod Web — Две темы: Океанская (тёмная) / Рассветная (светлая)
   ═══════════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties (по умолчанию — тёмная «Океанская» тема) ──── */

:root {
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --max-width: 480px;

    /* Океанская тема — deep navy + teal */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-input: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #14b8a6;
    --accent-hover: #0d9488;
    --accent-soft: rgba(20,184,166,0.12);
    --accent-glow: rgba(20,184,166,0.25);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: #334155;
    --chat-user: #14b8a6;
    --chat-assistant: #1e293b;
}

/* ── Светлая «Рассветная» тема ───────────────────────────────────── */

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #0d9488;
    --accent-hover: #0f766e;
    --accent-soft: rgba(13,148,136,0.08);
    --accent-glow: rgba(13,148,136,0.15);
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --border: #e2e8f0;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --chat-user: #0d9488;
    --chat-assistant: #ffffff;
}

/* ── Автоматический выбор через prefers-color-scheme ──────────────── */

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        --bg-primary: #f8fafc;
        --bg-secondary: #ffffff;
        --bg-card: #ffffff;
        --bg-input: #f1f5f9;
        --text-primary: #0f172a;
        --text-secondary: #475569;
        --text-muted: #94a3b8;
        --accent: #0d9488;
        --accent-hover: #0f766e;
        --accent-soft: rgba(13,148,136,0.08);
        --accent-glow: rgba(13,148,136,0.15);
        --success: #059669;
        --danger: #dc2626;
        --warning: #d97706;
        --border: #e2e8f0;
        --shadow: 0 2px 12px rgba(0,0,0,0.08);
        --chat-user: #0d9488;
        --chat-assistant: #ffffff;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   Base
   ═══════════════════════════════════════════════════════════════════════ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ═══════════════════════════════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════════════════════════════ */

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: var(--max-width);
    margin: 0 auto;
    background: var(--bg-primary);
    transition: background 0.3s ease;
    overflow-y: auto;
}

.header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background 0.3s ease;
}

.logo {
    font-size: 17px;
    font-weight: 700;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

.nav {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    margin-left: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.nav::-webkit-scrollbar { display: none; }

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    white-space: nowrap;
    transition: all 0.2s;
}

.nav-link:hover:not(.active) {
    background: var(--accent-soft);
}

.nav-link.active {
    background: var(--accent);
    color: white;
}

.menu-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: all 0.2s;
    background: var(--bg-card);
}

.menu-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
}

/* ── Theme toggle ─────────────────────────────────────────────────── */

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: all 0.2s;
    background: var(--bg-card);
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Main content ─────────────────────────────────────────────────── */

.main {
    flex: 1;
    padding: 16px;
}

.footer {
    padding: 10px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════
   Welcome page
   ═══════════════════════════════════════════════════════════════════════ */

.welcome {
    text-align: center;
    padding: 32px 16px;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.welcome h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--accent);
}

.welcome p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.welcome-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 32px;
}

.features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 360px;
    margin: 0 auto;
}

.feature {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.feature-icon {
    font-size: 28px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Auth
   ═══════════════════════════════════════════════════════════════════════ */

.auth-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 16px 0;
}

.auth-container h2 {
    text-align: center;
    font-size: 22px;
    margin-bottom: 4px;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.auth-section {
    margin-bottom: 20px;
}

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

.auth-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    color: var(--text-muted);
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

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

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

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

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

.btn-link {
    background: none;
    color: var(--accent);
    padding: 8px;
    font-size: 14px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    width: auto;
}

.btn-telegram {
    background: #0088cc;
    color: white;
}

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

.telegram-waiting {
    text-align: center;
    padding: 20px;
}

.tg-spinner {
    font-size: 40px;
    animation: tgPulse 1.5s ease-in-out infinite;
}

@keyframes tgPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.1); opacity: 1; }
}

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

/* ═══════════════════════════════════════════════════════════════════════
   Forms
   ═══════════════════════════════════════════════════════════════════════ */

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-input-sm {
    padding: 6px 10px;
    font-size: 14px;
}

.form-hint {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.add-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.add-form .form-input {
    flex: 1;
}

/* ═══════════════════════════════════════════════════════════════════════
   Cards
   ═══════════════════════════════════════════════════════════════════════ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    transition: background 0.3s ease;
}

.card h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════════════════
   Chat
   ═══════════════════════════════════════════════════════════════════════ */

.chat-main {
    padding: 8px 12px;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 8px;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

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

.user-msg {
    align-self: flex-end;
    background: var(--chat-user);
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-msg {
    align-self: flex-start;
    background: var(--chat-assistant);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.system-msg {
    align-self: center;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    max-width: 90%;
    border: 1px solid var(--border);
}

.msg-role {
    font-size: 11px;
    opacity: 0.7;
    margin-bottom: 4px;
    font-weight: 600;
}

.msg-meta {
    font-size: 11px;
    opacity: 0.5;
    margin-top: 4px;
}

.chat-input-area {
    position: sticky;
    bottom: 0;
    z-index: 100;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 8px 12px;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    resize: none;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.4;
    max-height: 150px;
    font-family: inherit;
}

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

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

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

.quota-info {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    padding: 4px 0;
}

.status-badge {
    font-size: 20px;
    color: var(--text-muted);
    margin-left: auto;
}

.status-badge.connected {
    color: var(--success);
}

/* ═══════════════════════════════════════════════════════════════════════
   Profile
   ═══════════════════════════════════════════════════════════════════════ */

.profile-card {
    text-align: center;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    margin: 0 auto 12px;
    color: white;
}

.profile-card h3 {
    font-size: 20px;
    margin-bottom: 4px;
}

.profile-date {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 8px;
}

.quota-stats {
    display: grid;
    gap: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 4px 0;
}

.stat-row span:first-child {
    color: var(--text-secondary);
}

.progress-bar {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    margin: 8px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.admin-section {
    margin: 16px 0;
}

/* ═══════════════════════════════════════════════════════════════════════
   Tasks
   ═══════════════════════════════════════════════════════════════════════ */

.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
}

.task-item.priority-important {
    border-left-color: var(--warning);
}

.task-item.priority-critical {
    border-left-color: var(--danger);
}

.task-info {
    flex: 1;
}

.task-info strong {
    display: block;
    margin-bottom: 2px;
}

.task-due {
    font-size: 12px;
    color: var(--text-muted);
}

.task-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.task-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════
   Subscriptions / Memory
   ═══════════════════════════════════════════════════════════════════════ */

.subs-list, .memory-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sub-item, .mem-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Admin
   ═══════════════════════════════════════════════════════════════════════ */

.user-admin-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.user-admin-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.user-email, .user-tg {
    font-size: 13px;
    color: var(--text-muted);
}

.badge-admin {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

.user-admin-quota {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.user-admin-quota label {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Utilities
   ═══════════════════════════════════════════════════════════════════════ */

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 16px;
    font-size: 14px;
}

.alert {
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 14px;
}

.alert-error {
    background: rgba(239,68,68,0.1);
    color: var(--danger);
    border: 1px solid rgba(239,68,68,0.2);
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 32px;
}

.error {
    color: var(--danger);
    text-align: center;
    padding: 16px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Mobile menu
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .nav {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        flex-direction: column;
        padding: 8px;
        border-bottom: 1px solid var(--border);
        z-index: 99;
    }

    .nav.open {
        display: flex;
    }

    .menu-btn {
        display: block;
    }

    .features {
        grid-template-columns: 1fr;
    }
}
