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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f9fafb;
    color: #111827;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.header {
    margin-bottom: 32px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h1 {
    font-size: 30px;
    font-weight: 700;
    margin-bottom: 8px;
}

.header p {
    color: #6b7280;
    font-size: 16px;
}

.filters-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 24px;
    margin-bottom: 24px;
}

.filters-title {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

.filters-title svg {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    color: #4b5563;
}

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

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

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
}

.input-range {
    display: flex;
    gap: 8px;
}
.input-range input[type="number"] {
    flex: 1 1 0;
    min-width: 0;
}

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

.buttons-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background-color: #2563eb;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #1d4ed8;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-export {
    background-color: #16a34a;
    color: white;
}

.btn-export:hover:not(:disabled) {
    background-color: #15803d;
}

.btn-export:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 16px;
}

.summary-card-label {
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}

.summary-card-value {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
}

.table-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    white-space: nowrap;
}

th:hover {
    background-color: #e5e7eb;
}

th.sorted {
    background-color: #e5e7eb;
}

th::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 6px;
    vertical-align: middle;
}

th.sorted-asc::after {
    content: '▲';
    font-size: 10px;
}

th.sorted-desc::after {
    content: '▼';
    font-size: 10px;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}

.subject-cell {
    max-width: 200px;
    word-wrap: break-word;
    white-space: normal;
    line-height: 1.4;
}

.screenshot-link {
    color: #2563eb;
    text-decoration: none;
    font-size: 16px;
    transition: color 0.2s;
}

.screenshot-link:hover {
    color: #1d4ed8;
}

tbody tr:hover {
    background-color: #f9fafb;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.badge-blue {
    background-color: #dbeafe;
    color: #1e40af;
    cursor: pointer;
}

.badge-green {
    background-color: #dcfce7;
    color: #15803d;
}

.badge-purple {
    background-color: #f3e8ff;
    color: #7e22ce;
}

.badge-red {
    background-color: #fee2e2;
    color: #991b1b;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.empty-state-icon { display: none; }

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #6b7280;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
}

.pagination-info {
    color: #6b7280;
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-pagination {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    color: #374151;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-pagination:hover:not(:disabled) {
    background-color: #f3f4f6;
    border-color: #9ca3af;
}

.btn-pagination:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-pages {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.page-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    color: #374151;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover {
    background-color: #f3f4f6;
    border-color: #9ca3af;
}

.page-btn.active {
    background-color: #2563eb;
    border-color: #2563eb;
    color: white;
}

.page-ellipsis {
    padding: 0 6px;
    color: #6b7280;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 8px;
    padding: 32px;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 25px rgba(0, 0, 0, 0.15);
}

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 600;
}

.modal-content p {
    color: #6b7280;
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

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

    .header h1 {
        font-size: 24px;
    }

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

    table {
        font-size: 12px;
    }

    td, th {
        padding: 8px 12px;
    }

    .buttons-group {
        flex-direction: column;
    }

    button {
        width: 100%;
    }
}

.cards-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 16px;
}

.filter-recipients-from {
    text-align: center;
}
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.sort-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

/* Блок 1: Поиск и фильтрация по датам */
.sort-controls-search-filter {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    flex: 1 1 280px;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
}
.search-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.date-filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.date-filter-label {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
}

.date-filter-input {
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: #374151;
}
.date-filter-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.date-filter-separator {
    color: #9ca3af;
    font-size: 14px;
}

/* Блок 2: Кнопки сортировки */
.sort-controls-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.sort-controls-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
}

/* Блок 3: Количество карточек на странице */
.sort-controls-pagesize {
    display: flex;
    gap: 8px;
    align-items: center;
}

.page-size-label {
    font-size: 13px;
    color: #6b7280;
}

.page-size-select {
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font-size: 14px;
}
.page-size-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-secondary {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
}
.btn-secondary:hover { background: #f9fafb; }

/* Стили для кнопок сортировки - фиксированная ширина и стрелочки */
.sort-controls-buttons .btn-secondary {
    min-width: 110px;
    justify-content: center;
}
.sort-controls-buttons .btn-secondary.active { 
    border-color: #2563eb; 
    color: #2563eb; 
}
.sort-controls-buttons .btn-secondary::after { 
    content: ''; 
    display: inline-block; 
    width: 12px; 
    margin-left: 6px; 
}
.sort-controls-buttons .btn-secondary.active.asc::after { 
    content: '↑'; 
}
.sort-controls-buttons .btn-secondary.active.desc::after { 
    content: '↓'; 
}

.card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    /* transform: translateY(-2px); */
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

.card-preview {
    position: relative;
    height: 220px;
    overflow: hidden;
    background: #f3f4f6;
}

.card-preview-inner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    will-change: transform;
    transition: transform 1000ms linear;
}

.card-preview:hover .card-preview-inner {
    transition: none;
}

.card-preview a {
    display: block;
}

.card-preview img {
    display: block;
    width: 100%;
    height: auto;
}

.card-body {
    padding: 12px 14px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto; 
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    color: #111827;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    line-clamp: 4;
    overflow: hidden;
}

.card-subtitle {
    font-size: 13px;
    color: #6b7280;
}

.card-date {
    font-size: 12px;
    color: #6b7280;
}

.card-meta {
    display: flex;
    /* justify-content: space-between; */
    align-items: center;
    gap: 8px;
    margin-top: auto;
}

.meta-left {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
}

.card-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 12px;
    margin-top: 8px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 11px;
    color: #6b7280;
}

.stat-value {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

@media (max-width: 768px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
}

/* Charts section */
.charts-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
    overflow: hidden;
}

.charts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.charts-header:hover {
    background-color: #f9fafb;
}

.charts-header:focus {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

.charts-title {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.charts-toggle {
    font-size: 14px;
    color: #6b7280;
    transition: transform 0.3s ease;
}

.charts-header[aria-expanded="true"] .charts-toggle {
    transform: rotate(-180deg);
}

.charts-content {
    padding: 0 24px 24px 24px;
}

/* Chart Builder */
.chart-builder {
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.builder-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0 0 16px 0;
}

.builder-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.builder-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.metrics-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    padding: 12px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.checkbox-label:hover {
    background-color: #f3f4f6;
}

.metric-checkbox {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.builder-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 20px;
}

.empty-charts-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: #9ca3af;
    font-size: 14px;
}

.chart-card {
    position: relative;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    min-height: 350px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0;
}

.chart-remove-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
    transition: color 0.2s;
}

.chart-remove-btn:hover {
    color: #ef4444;
}

.chart-card canvas {
    max-height: 300px;
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .charts-header {
        padding: 16px;
    }
    
    .charts-content {
        padding: 0 16px 16px 16px;
    }
    
    .builder-row {
        grid-template-columns: 1fr;
    }
    
    .metrics-checkboxes {
        grid-template-columns: 1fr;
    }
}

