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

:root {
    --primary-color: #0066FF;
    --secondary-color: #5856D6;
    --background: #F2F2F7;
    --surface: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --border-color: #E5E5EA;
    --danger-color: #FF3B30;
    --success-color: #34C759;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--background);
    display: flex;
    flex-direction: column;
}

/* Заголовок */
.app-header {
    background: var(--surface);
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.header-text {
    min-width: 0;
}

.app-header h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 2px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 12px;
}

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

.chat-counter {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-color);
    color: white;
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 102, 255, 0.3);
}

.chat-counter svg {
    opacity: 0.9;
}

.chat-counter span {
    min-width: 12px;
    text-align: center;
}

.refresh-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.refresh-button:active {
    opacity: 0.7;
}

.refresh-icon {
    display: block;
}

/* Лоадер */
.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

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

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

.loader p {
    margin-top: 16px;
    color: var(--text-secondary);
}

/* Статус поиска (внизу списка чатов) */
.search-status {
    padding: 8px 16px;
    margin: 0 16px 12px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.search-status-inner {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.search-status-done .search-status-spinner {
    display: none;
}

#searchStatusText {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Список чатов */
.chats-list {
    padding: 16px;
    flex: 1;
}

.empty-state, .error-state {
    flex: 1;
}

.chat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text-primary);
}

.chat-card:active {
    transform: scale(0.98);
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-details {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
}

/* Бейджи типа бота (OldBOT / NewBOT) */
.bot-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    vertical-align: middle;
    margin-left: 6px;
    line-height: 1;
}

.bot-badge.oldbot {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.bot-badge.newbot {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.bot-badge .bot-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    display: inline-block;
}

.bot-badge.oldbot .bot-dot {
    background: #3b82f6;
}

.bot-badge.newbot .bot-dot {
    background: #10b981;
}

/* Бейдж бота в шапке страницы чата */
.chat-header-bot-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.chat-header-bot-badge.oldbot {
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
}

.chat-header-bot-badge.newbot {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
}

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

/* Пустое состояние */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon, .error-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.empty-state h2, .error-state h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.empty-state p, .error-state p {
    color: var(--text-secondary);
    max-width: 280px;
}

/* Кнопки */
.retry-button, .primary-button, .secondary-button, .danger-button {
    padding: 12px 24px;
    border-radius: var(--radius);
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    width: 100%;
}

.retry-button, .primary-button {
    background: var(--primary-color);
    color: white;
    margin-top: 20px;
}

.secondary-button {
    background: var(--border-color);
    color: var(--text-primary);
}

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

.retry-button:active, .primary-button:active, .secondary-button:active, .danger-button:active {
    opacity: 0.7;
}

/* Страница чата */
.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.back-button {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--primary-color);
    cursor: pointer;
    padding: 8px;
    margin: -8px;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-avatar-large {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

.chat-content {
    padding: 16px;
}

.stats-card, .settings-card, .members-card, .danger-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.stats-card h2, .settings-card h2, .members-card h2, .danger-card h2 {
    font-size: 18px;
    margin-bottom: 16px;
}

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

.stat-item {
    text-align: center;
    padding: 16px;
    background: var(--background);
    border-radius: 8px;
}

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

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

/* Формы */
.form-group {
    margin-bottom: 16px;
}

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

.input-field {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.2s;
}

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

.textarea {
    resize: vertical;
    min-height: 80px;
}

/* Список участников */
.members-list {
    max-height: 300px;
    overflow-y: auto;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.member-item:last-child {
    border-bottom: none;
}

.member-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.member-info {
    flex: 1;
}

.member-name {
    font-weight: 600;
    font-size: 15px;
}

.member-role {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Опасная зона */
.danger-card {
    border: 1px solid var(--danger-color);
}

.danger-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 400px;
    width: 100%;
}

.modal-content h2 {
    font-size: 20px;
    margin-bottom: 12px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius);
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
    max-width: 90%;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Футер */
.app-footer {
    margin-top: auto;
    padding: 10px 12px;
    background: white;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.footer-content {
    max-width: 520px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
    white-space: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.footer-item,
.footer-separator {
    font-size: 11px;
    color: #666;
    letter-spacing: 0.2px;
    font-weight: 400;
}

.footer-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s;
}

.footer-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Адаптив */
@media (max-width: 375px) {
    .app-header h1 {
        font-size: 20px;
    }

    .chat-card {
        padding: 12px;
    }

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

    .footer-item,
    .footer-separator {
        font-size: 10px;
    }
}

/* ==================== РЕКЛАМНЫЕ БАННЕРЫ ==================== */

.ad-banner {
    display: block;
    width: 100%;
    max-width: 568px;
    height: 120px;
    margin: 12px auto;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    position: relative;
}

.ad-banner:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.ad-banner:active {
    transform: scale(0.98);
}

.ad-banner img,
.ad-banner video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Баннер в списке чатов */
.chat-list .ad-banner {
    margin: 6px 0;
}

/* Баннер в секциях настроек */
.section-content .ad-banner {
    margin: 16px 0;
}

/* Баннер внизу страницы */
.ad-banner-bottom {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    max-width: calc(100% - 32px);
}

.ad-banner-bottom:hover {
    transform: translateX(-50%) translateY(-2px);
}

/* Лейбл "Реклама" */
.ad-banner::after {
    content: 'Реклама';
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 9px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

/* Кнопка закрытия баннера (опционально) */
.ad-banner-close {
    position: absolute;
    top: 4px;
    left: 6px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.ad-banner:hover .ad-banner-close {
    opacity: 1;
}

/* Скрытие баннеров при отключённой рекламе */
.ads-hidden .ad-banner {
    display: none !important;
}

/* Кнопка "Наши проекты" */
.projects-button-container {
    padding: 16px;
    margin-top: auto;
}

.projects-button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
}

.projects-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.projects-button:active {
    transform: scale(0.98);
}

.projects-button svg {
    flex-shrink: 0;
}

/* Кнопка поддержки */
.support-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100;
    text-decoration: none;
}

.support-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.support-btn:active {
    transform: scale(0.95);
}

.support-btn svg {
    width: 24px;
    height: 24px;
}

/* Адаптив */
@media (max-width: 600px) {
    .ad-banner {
        height: 90px;
        border-radius: 10px;
    }
    
    .ad-banner-bottom {
        bottom: 12px;
        max-width: calc(100% - 24px);
    }
    
    .support-btn {
        bottom: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
    }
    
    .support-btn svg {
        width: 20px;
        height: 20px;
    }
}
