:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-button-color: #3390ec;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #3390ec;
    --tg-theme-secondary-bg-color: #f1f1f1;
    
    --primary-color: #3390ec;
    --border-radius: 16px;
    --spacing: 16px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
    
    --success-color: #4caf50;
    --error-color: #f44336;
    --warning-color: #ff9800;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

body.dark-theme {
    --tg-theme-bg-color: #212121;
    --tg-theme-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #2d2d2d;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.hidden {
    display: none !important;
}

.error-404 {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--spacing);
    background-color: var(--tg-theme-bg-color);
}

.error-404-content {
    text-align: center;
    max-width: 400px;
}

.error-404-content h1 {
    font-size: 72px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    margin-bottom: 16px;
}

.error-404-content p {
    font-size: 18px;
    color: var(--tg-theme-text-color);
    margin-bottom: 8px;
}

.error-404-message {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 48px 24px;
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--tg-theme-secondary-bg-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading p {
    color: var(--tg-theme-hint-color);
    font-size: 16px;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 80px;
}

.page {
    display: none;
    flex: 1;
    padding-bottom: 20px;
}

.page.active {
    display: block;
}

.page-content {
    padding: var(--spacing);
    max-width: 600px;
    margin: 0 auto;
}

.user-header {
    margin-bottom: 24px;
}

.user-name-section {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.user-avatar-container {
    position: relative;
    flex-shrink: 0;
    width: 64px;
    height: 64px;
}

.user-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--tg-theme-button-color, #3390ec);
}

.user-avatar-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--tg-theme-button-color, #3390ec) 0%, var(--tg-theme-link-color, #3390ec) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--tg-theme-button-color, #3390ec);
}

.avatar-initials {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.user-info-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.user-name-label {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.user-name-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
}

.user-id {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    font-weight: 500;
}

.status-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-label {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--error-color);
    flex-shrink: 0;
    transition: background-color 0.3s ease;
}

.status-dot.connected {
    background-color: var(--success-color);
    animation: pulse 2s infinite;
}

.status-dot.connecting {
    background-color: var(--warning-color);
    animation: pulse 1s infinite;
}

.status-dot.disconnected {
    background-color: var(--error-color);
}

.status-dot.connected {
    background-color: var(--success-color);
}

.status-dot.connecting {
    background-color: var(--warning-color);
}

.status-dot.error {
    background-color: var(--error-color);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.status-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--tg-theme-text-color);
}

.section-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    margin-bottom: 16px;
}

.instruction-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--tg-theme-bg-color);
    border-radius: 12px;
}

.instruction-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.instruction-text {
    font-size: 15px;
    color: var(--tg-theme-text-color);
    font-weight: 500;
}

.functions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.function-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: var(--tg-theme-bg-color);
    border-radius: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.function-item:active {
    transform: scale(0.98);
}

.function-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.function-content {
    flex: 1;
}

.function-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
    margin-bottom: 4px;
}

.function-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    line-height: 1.4;
}

.chats-header {
    margin-bottom: 20px;
}

.chats-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
}

.chats-list {
    min-height: 200px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 16px;
    color: var(--tg-theme-hint-color);
}

.empty-hint {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-top: 8px;
    opacity: 0.7;
}

.chat-item {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    cursor: pointer;
}

.chat-item:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.chat-item:active {
    transform: translateY(0);
}

.chat-item-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.chat-item-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    flex: 1;
    min-width: 0;
}

.chat-item-messages-count {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    font-weight: 500;
    white-space: nowrap;
}

.chat-item-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-item-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.chat-item-label {
    color: var(--tg-theme-hint-color);
    font-weight: 500;
}

.chat-item-value {
    color: var(--tg-theme-text-color);
    font-weight: 600;
}
.chat-messages-list {
    padding: 16px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    height: calc(100vh - 200px);
    border-radius: var(--border-radius);
}

.message-item {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    max-width: 75%;
    align-self: flex-start;
}

.message-item-own {
    align-self: flex-end;
    background: #3390ec;
    color: #ffffff;
    margin-left: auto;
}

.message-item-own .message-text {
    color: #ffffff;
}

.message-item-own .message-date {
    color: rgba(255, 255, 255, 0.7);
}

.message-item-own .message-forwarded {
    color: rgba(255, 255, 255, 0.8);
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.message-item-own .message-media {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-text {
    font-size: 15px;
    color: var(--tg-theme-text-color);
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
}

.message-date {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    align-self: flex-end;
    margin-top: 4px;
}

.message-forwarded {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

body.dark-theme .message-forwarded {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.forwarded-icon {
    font-size: 14px;
}

.forwarded-from {
    font-style: italic;
}

.message-media {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    margin-top: 8px;
    font-size: 14px;
    color: var(--tg-theme-text-color);
}

.media-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s;
}

.media-link:hover {
    opacity: 0.8;
}

.media-icon {
    font-size: 16px;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--tg-theme-secondary-bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding: 8px 0;
    z-index: 1000;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
}

body.dark-theme .bottom-nav {
    border-top-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px;
    background: none;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
    color: var(--tg-theme-hint-color);
}

.nav-item:active {
    opacity: 0.7;
}

.nav-item.active {
    color: var(--tg-theme-button-color);
}

.nav-icon {
    font-size: 24px;
    line-height: 1;
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
}

@media (max-width: 480px) {
    .page-content {
        padding: 12px;
    }
    
    .user-name-value {
        font-size: 20px;
    }
    
    .section-title {
        font-size: 16px;
    }
    
    .function-item {
        padding: 12px;
    }
    
    .function-icon {
        font-size: 28px;
    }
}

.action-card {
    width: 100%;
    background: var(--tg-theme-secondary-bg-color);
    border: none;
    border-radius: var(--border-radius);
    padding: 0;
    margin-bottom: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow);
    text-align: left;
}

.action-card:active {
    transform: scale(0.98);
}

.action-card-content {
    display: flex;
    align-items: center;
    padding: 20px;
    gap: 16px;
}

.action-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.action-text {
    flex: 1;
}

.action-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    margin-bottom: 4px;
}

.action-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.action-arrow {
    font-size: 24px;
    color: var(--tg-theme-hint-color);
    flex-shrink: 0;
}

.referral-card {
    margin-bottom: 20px;
}

.referral-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.referral-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.referral-content {
    flex: 1;
}

.referral-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    margin-top: 4px;
}

.referral-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--tg-theme-bg-color);
    border-radius: 12px;
}

.referral-stat-item {
    flex: 1;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--tg-theme-button-color);
    margin-bottom: 4px;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.referral-link-section {
    margin-top: 16px;
}

.referral-link-container {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.referral-link-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--tg-theme-bg-color);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: 14px;
    color: var(--tg-theme-text-color);
    font-family: monospace;
}

body.dark-theme .referral-link-input {
    border-color: rgba(255, 255, 255, 0.1);
}

.copy-button {
    padding: 12px 16px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.copy-button:active {
    opacity: 0.8;
}

.referral-hint {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    text-align: center;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 16px var(--spacing);
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    background: var(--tg-theme-bg-color);
    z-index: 100;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#chatViewPage .page-content {
    padding: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
}

#chatViewPage .page-header {
    margin-bottom: 0;
    padding: 12px 16px;
    border-bottom: 1px solid var(--tg-theme-hint-color, #ccc);
}

#chatViewPage .chat-messages-list {
    flex: 1;
    height: auto;
    overflow-y: auto;
    padding: 16px;
}

body.dark-theme .page-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    flex: 1;
}

.back-button {
    padding: 8px 16px;
    background: var(--tg-theme-secondary-bg-color);
    border: none;
    border-radius: 12px;
    color: var(--tg-theme-text-color);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.back-button:active {
    opacity: 0.7;
}

.setup-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setup-step {
    display: flex;
    gap: 16px;
    padding: 20px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
    margin-bottom: 8px;
}

.step-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    line-height: 1.5;
}

.functions-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.function-card {
    padding: 24px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.function-icon-large {
    font-size: 48px;
    margin-bottom: 16px;
}

.function-card-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--tg-theme-text-color);
    margin-bottom: 12px;
}

.function-card-description {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
    line-height: 1.6;
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-nav {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    
    .app {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

