/* Основные стили и переменные */
:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --nav-width: 280px;
    --content-padding: 20px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

/* Контейнер */
.container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: calc(100% - 40px);
    margin: 0 auto;
    gap: 20px;
    padding: 20px 0;
}

/* Навигация */
.main-nav {
    width: var(--nav-width);
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
    position: sticky;
    top: 20px;
    height: fit-content;
    flex-shrink: 0;
}

.nav-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.nav-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.version {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-color);
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.nav-list {
    list-style: none;
}

.nav-list li {
    margin-bottom: 4px;
}

.nav-separator {
    margin-top: 16px !important;
    margin-bottom: 8px !important;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.nav-link {
    display: block;
    padding: 8px 12px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 14px;
}

.nav-link:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

.nav-link.active {
    background: var(--primary-color);
    color: white;
    font-weight: 500;
}

.sub-link {
    padding-left: 24px;
    font-size: 13px;
}

.current-profile {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}

.current-profile strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.current-profile span {
    color: var(--primary-color);
    font-weight: 500;
}

/* Основной контент */
.main-content {
    flex: 1;
    background: var(--card-bg);
    border-radius: 12px;
    padding: var(--content-padding);
    border: 1px solid var(--border-color);
    min-height: calc(100vh - 40px);
}

/* Страницы */
.page {
    display: none;
    animation: fadeIn 0.3s;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.hint {
    font-size: 13px;
    color: var(--text-secondary);
    background: #fef3c7;
    border: 1px solid #fde68a;
    padding: 8px 12px;
    border-radius: 6px;
    display: inline-block;
}

/* Таблица */
.table-wrapper {
    overflow-x: auto;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--bg-color);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.profile-name {
    font-weight: 600;
    color: var(--primary-color);
}

.url-cell a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 12px;
}

.url-cell a:hover {
    text-decoration: underline;
}

code {
    background: var(--bg-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    color: #dc2626;
}

.actions-row {
    background: var(--bg-color);
    padding: 12px !important;
}

.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Кнопки */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

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

.btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: white;
}

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

.btn-success:hover {
    background: #059669;
    border-color: #059669;
    color: white;
}

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

.btn-warning:hover {
    background: #d97706;
    border-color: #d97706;
    color: white;
}

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

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
}

/* Формы */
.form-group {
    margin-bottom: 20px;
}

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

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.5;
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

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

.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button .form-control {
    flex: 1;
}

.copy-field {
    display: flex;
    gap: 8px;
}

.copy-field .form-control {
    flex: 1;
    background: var(--bg-color);
}

/* Фильтры и правила */
.filters-list,
.bulk-rules {
    margin-bottom: 32px;
}

.filter-item,
.rule-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-desc {
    flex: 1;
    font-size: 13px;
}

.filter-desc strong {
    color: var(--primary-color);
    font-weight: 600;
}

.rule-item {
    display: block;
}

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

.rule-header h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.rule-content {
    font-size: 13px;
    color: var(--text-secondary);
}

.add-filter-form,
.add-rule-form {
    background: var(--bg-color);
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.add-filter-form h3,
.add-rule-form h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Checkbox и Radio группы */
.checkbox-group,
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-group label,
.radio-group label {
    display: flex;
    align-items: center;
    font-weight: normal;
    cursor: pointer;
    padding: 6px 0;
}

.checkbox-group input,
.radio-group input {
    margin-right: 8px;
}

.sub-options {
    margin-top: 12px;
    padding: 12px;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

/* Sortable список */
.sortable-list {
    margin-bottom: 12px;
}

.sortable-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 8px;
}

.drag-handle {
    cursor: move;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
}

.sortable-item .form-control {
    flex: 1;
}

/* Формы правил */
.rule-form {
    margin-top: 16px;
}

/* Page Actions */
.page-actions {
    display: flex;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* Settings Form */
.settings-form {
    max-width: 800px;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: slideUp 0.3s;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close {
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

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

.modal-body {
    padding: 20px;
}

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

/* Адаптивность */
@media (max-width: 1024px) {
    .container {
        flex-direction: column;
        max-width: 100%;
        padding: 10px;
    }
    
    .main-nav {
        width: 100%;
        position: static;
    }
    
    .nav-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .nav-list li {
        margin: 0;
    }
    
    .nav-separator {
        width: 100%;
        margin: 12px 0 8px !important;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
    
    .table-wrapper {
        overflow-x: scroll;
    }
    
    .data-table {
        min-width: 1200px;
    }
}