:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --secondary: #6b7280;
    --background: #f3f4f6;
    --surface: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-md: rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
}

/* ============ АВТОРИЗАЦИЯ ============ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow-md);
}

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

.auth-header h1 {
    color: var(--primary);
    font-size: 2rem;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
}

.auth-tab {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
}

.auth-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

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

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

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.error-message {
    padding: 12px;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 8px;
    margin-bottom: 20px;
}

.success-message {
    padding: 12px;
    background: #d1fae5;
    color: #065f46;
    border-radius: 8px;
    margin-bottom: 20px;
}

/* ============ ОСНОВНОЕ ПРИЛОЖЕНИЕ ============ */
.app-container {
    display: flex;
    height: 100vh;
}

/* ============ БОКОВАЯ ПАНЕЛЬ ============ */
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    color: var(--primary);
    margin-bottom: 8px;
}

.user-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.sidebar-nav {
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.nav-item:hover {
    background: var(--background);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-item .icon {
    font-size: 1.2rem;
}

.btn-logout {
    margin-top: 20px;
}

/* ============ ОСНОВНОЙ КОНТЕНТ ============ */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.page-section {
    display: none;
}

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

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 2rem;
}

/* ============ КНОПКИ ============ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

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

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

.btn-block {
    width: 100%;
}

/* ============ ДАШБОРД ============ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    border-left: 4px solid var(--primary);
}

.stat-card.primary { border-left-color: var(--primary); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.info { border-left-color: var(--info); }
.stat-card.tax { border-left-color: #8b5cf6; }

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--text);
    margin-bottom: 8px;
}

.stat-details {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--background);
    border-radius: 4px;
    margin: 8px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}

.dashboard-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.section-card {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
}

.section-card h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text);
}

/* ============ КЛИЕНТЫ ============ */
.filters {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.filter-select, .search-input {
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}

.search-input {
    flex: 1;
    min-width: 250px;
}

.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.client-card {
    background: var(--surface);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border-left: 4px solid var(--primary);
}

.client-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px var(--shadow-md);
}

.client-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.client-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
}

.client-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-lead { background: #e0e7ff; color: #4338ca; }
.status-in_progress { background: #dbeafe; color: #1e40af; }
.status-paid_partial { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-archived { background: #f3f4f6; color: #4b5563; }

.client-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.client-finances {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.finance-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

/* ============ KANBAN ДОСКА ============ */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.kanban-column {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    min-height: 500px;
}

.column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.column-header h3 {
    font-size: 1.1rem;
}

.task-count {
    background: var(--background);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.task-list {
    min-height: 400px;
}

.task-card {
    background: var(--background);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: move;
    border-left: 3px solid var(--primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

.task-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.task-card.dragging {
    opacity: 0.5;
}

.task-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

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

.priority-high { border-left-color: var(--danger); }
.priority-urgent { border-left-color: #dc2626; }
.priority-medium { border-left-color: var(--warning); }
.priority-low { border-left-color: var(--info); }

/* ============ ФИНАНСЫ ============ */
.finance-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
}

.finance-tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.finance-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.finance-content {
    display: none;
}

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

.payments-table, .expenses-table {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
}

.table-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
    gap: 15px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.table-row:hover {
    background: var(--background);
}

.table-header {
    font-weight: 600;
    background: var(--background);
}

.expense-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 30px;
}

.overview-card {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
}

/* ============ КАЛЕНДАРЬ ============ */
.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--surface);
    border-radius: 12px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
    margin-bottom: 30px;
}

.calendar-day {
    aspect-ratio: 1;
    background: var(--surface);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.calendar-day:hover {
    background: var(--background);
    transform: scale(1.05);
}

.calendar-day.has-events {
    border: 2px solid var(--primary);
}

.calendar-day.selected {
    background: var(--primary);
    color: white;
}

.day-number {
    font-size: 1.2rem;
    font-weight: 600;
}

.event-indicator {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

.events-list {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
}

.chart-container {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    margin-top: 30px;
}

/* ============ МОДАЛЬНЫЕ ОКНА ============ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

/* ============ MINI КАРТОЧКИ ============ */
.mini-card {
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 3px solid var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.mini-card:hover {
    transform: translateX(4px);
    background: #e5e7eb;
}

.clients-list-mini,
.tasks-list-mini,
.events-list-mini {
    max-height: 300px;
    overflow-y: auto;
}

/* ============ МОДАЛЬНЫЕ ОКНА ============ */
.modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.active {
    opacity: 1;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: translateY(-20px);
    transition: transform 0.3s;
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--background);
    color: var(--text);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
    margin-top: 20px;
    border-top: 1px solid var(--border);
}

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

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

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

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

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

/* ============ АДАПТИВНОСТЬ ============ */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-nav {
        display: flex;
        overflow-x: auto;
    }

    .nav-item {
        min-width: fit-content;
    }

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

    .kanban-board {
        grid-template-columns: 1fr;
    }

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

    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .modal-body {
        padding: 16px;
    }
}
