* {
    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);
}

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

.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

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

/* Лоадер */
.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);
}

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

.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;
}

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

/* Пустое состояние */
.empty-state, .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;
}

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

    .chat-card {
        padding: 12px;
    }

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