/* ===================================
   InstantBase Dashboard - Main Styles
   =================================== */

:root {
    --primary: #2A6DF4;
    --primary-light: #e8f0fe;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --dark: #343a40;
    --light: #f8f9fa;
    --border: #dee2e6;
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #999;
    --sidebar-width: 250px;
    --header-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f5f7fa;
    color: var(--text-primary);
    line-height: 1.6;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: all 0.3s;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.sidebar-header .logo-text {
    font-size: 20px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-nav {
    padding: 20px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li {
    margin: 5px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
}

.sidebar-nav a i {
    width: 20px;
    font-size: 18px;
}

.sidebar-nav .nav-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px 30px;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
}

.page-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.page-title .breadcrumb {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 5px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-info {
    text-align: right;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
}

.user-email {
    font-size: 12px;
    color: var(--text-muted);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Period Selector */
.period-selector {
    display: flex;
    gap: 10px;
    align-items: center;
    background: white;
    padding: 5px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.period-btn {
    padding: 8px 16px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.3s;
}

.period-btn:hover {
    background: var(--light);
}

.period-btn.active {
    background: var(--primary);
    color: white;
}

.custom-date {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-left: 1px solid var(--border);
}

.custom-date input {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 13px;
    width: 120px;
}

/* Cards */
.card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-header .card-actions {
    display: flex;
    gap: 10px;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.metric-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    transition: transform 0.3s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
}

.metric-title {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.metric-change {
    font-size: 12px;
}

.metric-change.positive {
    color: var(--success);
}

.metric-change.negative {
    color: var(--danger);
}

/* Charts */
.chart-container {
    height: 300px;
    margin: 20px 0;
    position: relative;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    text-align: left;
    padding: 12px;
    background: var(--light);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
}

table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

table tbody tr:hover {
    background: var(--primary-light);
}

/* Pagination */
.pagination {
    display: flex;
    gap: 5px;
    justify-content: center;
    margin-top: 20px;
}

.page-item {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.page-item:hover,
.page-item.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Loading States */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    border: 3px solid var(--light);
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Notifications */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    animation: slideIn 0.3s;
    max-width: 400px;
}

.notification.success {
    border-left: 4px solid var(--success);
}

.notification.error {
    border-left: 4px solid var(--danger);
}

.notification.warning {
    border-left: 4px solid var(--warning);
}

.notification.info {
    border-left: 4px solid var(--primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 10px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 14px;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42,109,244,0.1);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102,126,234,0.4);
}

.btn-secondary {
    background: var(--light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #e9ecef;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

/* Utilities */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }

.text-center { text-align: center; }
.text-right { text-align: right; }

.mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 15px; }
.mt-4 { margin-top: 20px; }
.mt-5 { margin-top: 30px; }

.mb-2 { margin-bottom: 10px; }
.mb-3 { margin-bottom: 15px; }
.mb-4 { margin-bottom: 20px; }
.mb-5 { margin-bottom: 30px; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .main-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .period-selector {
        flex-wrap: wrap;
    }
}

/* User menu with avatar dropdown */
.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

.avatar-wrapper {
    cursor: pointer;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    transition: transform 0.3s;
}

.avatar:hover {
    transform: scale(1.05);
}

/* Notification button */
.notification-btn {
    position: relative;
    font-size: 20px;
    padding: 8px;
}

.notification-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: #dc3545;
    color: white;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Profile dropdown menu */
.profile-menu {
    position: absolute;
    top: 60px;
    right: 0;
    width: 280px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    z-index: 1000;
    display: none;
}

.profile-menu.active {
    display: block;
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.profile-menu-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.profile-menu-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
}

.profile-menu-name {
    font-weight: 600;
    color: var(--text-primary);
}

.profile-menu-email {
    font-size: 12px;
    color: var(--text-muted);
}

.profile-menu-items {
    padding: 10px 0;
}

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.3s;
}

.profile-menu-item:hover {
    background: var(--primary-light);
}

.menu-icon {
    font-size: 18px;
    width: 24px;
}

.profile-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* Funnel selector styles */
.funnel-events-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--light);
}

.funnel-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.event-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
    border: 1px solid var(--border);
}

.event-checkbox:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.event-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.event-checkbox .event-name {
    flex: 1;
    font-weight: 500;
}

.event-checkbox .event-count {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

/* Pagination styles */
.pagination-container {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

.pagination-controls .btn {
    min-width: 40px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    font-size: 13px;
}

.pagination-controls .btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination-controls .btn-primary:hover {
    background: var(--primary-dark, #1a5ac9);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(42, 109, 244, 0.3);
}

.pagination-controls .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Специфичные стили для пагинации на разных страницах */
.orders-pagination,
.events-pagination {
    composes: pagination-container;
}

/* Адаптивность */
@media (max-width: 768px) {
    .pagination-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .pagination-info {
        text-align: center;
    }
    
    .pagination-controls {
        justify-content: center;
    }
    
    .pagination-controls .btn {
        min-width: 36px;
        padding: 0 8px;
        font-size: 12px;
    }
}

/* Для очень маленьких экранов */
@media (max-width: 480px) {
    .pagination-controls {
        gap: 3px;
    }
    
    .pagination-controls .btn {
        min-width: 32px;
        height: 32px;
        padding: 0 6px;
    }
}

/* Информационная иконка */
.widget-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e0e0e0;
    color: #666;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
    margin-left: 8px;
    position: relative;
    transition: all 0.3s;
}

.widget-info:hover {
    background: var(--primary);
    color: white;
}

/* Всплывающая подсказка */
.widget-tooltip {
    visibility: hidden;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: normal; /* изменено с nowrap на normal */
    width: max-content;
    max-width: 300px; /* максимальная ширина */
    min-width: 150px; /* минимальная ширина */
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    margin-bottom: 8px;
    text-align: center;
    word-wrap: break-word; /* перенос слов */
}

.widget-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.widget-info:hover .widget-tooltip {
    visibility: visible;
    opacity: 1;
}

/* Для мобильных устройств */
@media (max-width: 768px) {
    .widget-tooltip {
        max-width: 250px;
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* Корректировка позиции для карточек в правой части */
.metric-card:last-child .widget-tooltip,
.card-actions .widget-tooltip {
    left: auto;
    right: 0;
    transform: none;
}

.metric-card:last-child .widget-tooltip::after,
.card-actions .widget-tooltip::after {
    left: auto;
    right: 10px;
}

/* Информационная иконка для заголовков карточек */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-header .widget-info {
    width: 20px;
    height: 20px;
    font-size: 13px;
}

/* Для графиков */
.chart-container {
    position: relative;
}