/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* Страницы аутентификации */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-box {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    font-size: 24px;
    margin-bottom: 5px;
    color: #333;
}

.auth-header p {
    color: #666;
    font-size: 14px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-weight: 500;
    font-size: 14px;
    color: #333;
}

.form-group .required {
    color: #e74c3c;
}

.form-group input,
.form-group select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2196f3;
}

.form-group small {
    font-size: 12px;
    color: #666;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
}

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-primary:hover {
    background: #1976d2;
}

.btn-secondary {
    background: #757575;
    color: white;
}

.btn-secondary:hover {
    background: #616161;
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 10px;
    border-radius: 4px;
    font-size: 14px;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
}

.auth-footer a {
    color: #2196f3;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* Личный кабинет */
.cabinet-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.cabinet-header {
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px 0;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 20px;
    color: #333;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.cabinet-main {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    gap: 20px;
}

.cabinet-nav {
    width: 200px;
    background: white;
    border-radius: 8px;
    padding: 20px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    height: fit-content;
}

.nav-item {
    display: block;
    padding: 12px 20px;
    color: #666;
    text-decoration: none;
    transition: background-color 0.3s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: #f5f5f5;
}

.nav-item.active {
    background: #e3f2fd;
    color: #2196f3;
    border-left-color: #2196f3;
    font-weight: 500;
}

.cabinet-content {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
}

.content-section h2 {
    margin-bottom: 20px;
    color: #333;
}

/* Статистика */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
}

.stat-card h3 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: #333;
}

/* Карточки интеграций в списке */
.integration-list-card {
    display: flex;
    align-items: stretch;
}

.integration-list-card-inner {
    flex: 1;
    min-width: 0;
}

/* Полоска статуса справа (вертикальный текст, как бордер) */
.integration-list-card-status {
    width: 1.75rem;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.integration-list-card-status-text {
    display: inline-block;
    white-space: nowrap;
}

.integration-list-card-status-active {
    background: #dcfce7;
    color: #166534;
}

.dark .integration-list-card-status-active {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.integration-list-card-status-pending_link {
    background: #fef3c7;
    color: #b45309;
}

.dark .integration-list-card-status-pending_link {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.integration-list-card-status-banned,
.integration-list-card-status:not(.integration-list-card-status-active):not(.integration-list-card-status-pending_link) {
    background: #fee2e2;
    color: #b91c1c;
}

.dark .integration-list-card-status-banned,
.dark .integration-list-card-status:not(.integration-list-card-status-active):not(.integration-list-card-status-pending_link) {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.integration-list-card-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.integration-list-card-logo img {
    width: 1.5rem;
    height: 1.5rem;
    object-fit: contain;
}

.integration-list-card-body {
    flex: 1;
    min-width: 0;
}

.integration-list-card-domain {
    font-weight: 500;
    font-size: 0.9375rem;
}

.integration-list-card-meta {
    font-size: 0.75rem;
    margin-top: 0.125rem;
}

/* Интеграции (legacy) */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.integrations-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.integration-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.integration-info h4 {
    margin-bottom: 5px;
}

.integration-info p {
    color: #666;
    font-size: 14px;
}

.integration-status {
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.integration-status.active {
    background: #c8e6c9;
    color: #2e7d32;
}

.integration-status.pending_link {
    background: #fff3e0;
    color: #e65100;
}

.integration-status.banned {
    background: #ffebee;
    color: #c62828;
}

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

/* Единая ширина контента модалок в кабинете */
.cabinet-modal-dialog {
    width: 100%;
    max-width: 32rem;
}

@media (max-width: 640px) {
    .cabinet-modal {
        padding: 0;
        align-items: flex-end;
    }
    .cabinet-modal .flex.min-h-full {
        min-height: 100%;
        align-items: flex-end;
        padding: 0;
    }
    .cabinet-modal-dialog {
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 1rem 1rem 0 0;
        margin-top: auto;
    }
}

.modal-content {
    background: white;
    border-radius: 8px;
    padding: 30px;
    width: 90%;
    max-width: 32rem;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.modal-close:hover {
    color: #333;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Биллинг */
.billing-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.info-card {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
}

.info-card h3 {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
}

.balance-amount {
    font-size: 24px;
    font-weight: 600;
    color: #333;
}

.billing-actions {
    margin-bottom: 30px;
}

.payment-history {
    margin-top: 30px;
}

.payment-history h3 {
    margin-bottom: 15px;
}

.payment-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.payment-amount {
    font-weight: 600;
}

.payment-amount.positive {
    color: #2e7d32;
}

.payment-amount.negative {
    color: #c62828;
}

/* Профиль */
.profile-form {
    max-width: 500px;
    margin-bottom: 40px;
}

.profile-section {
    margin-top: 40px;
    padding-top: 40px;
    border-top: 1px solid #eee;
}

.profile-section h3 {
    margin-bottom: 20px;
}

/* Адаптивность */
@media (max-width: 768px) {
    .cabinet-main {
        flex-direction: column;
    }
    
    .cabinet-nav {
        width: 100%;
        display: flex;
        overflow-x: auto;
    }
    
    .nav-item {
        white-space: nowrap;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Навигация кабинета: равная ширина кнопок только на мобильных (десктоп не меняем) */
@media (max-width: 767px) {
    .nav-cabinet {
        display: flex;
        flex-direction: row;
    }
    .nav-cabinet-link {
        min-width: 0;
        flex: 1 1 0;
    }
}

/* Сетка карточек CRM: 1 — на всю ширину, 2 — 50/50, 3 — в ряд (макс. 3 в ряд). */
.crm-cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .crm-cards-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .crm-cards-grid .integration-crm-card {
        grid-column: span 2;
    }
    .crm-cards-grid .integration-crm-card:only-child {
        grid-column: span 6;
    }
    .crm-cards-grid:has(.integration-crm-card:nth-last-child(2):first-child) .integration-crm-card {
        grid-column: span 3;
    }
}
