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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    position: relative;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 20px;
}

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

.btn-settings, .btn-history {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-settings:hover, .btn-history:hover {
    background: white;
    color: #667eea;
}

.step-container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
}

.step-container:hover {
    transform: translateY(-5px);
}

.step-header {
    display: flex;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 3px solid #f0f0f0;
}

.step-number {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    margin-right: 20px;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.4);
}

.step-title {
    flex: 1;
}

.step-title h2 {
    color: #333;
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.step-title p {
    color: #666;
    font-size: 0.95rem;
}

.step-status {
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
}

.status-pending {
    background: #ffeaa7;
    color: #d63031;
}

.status-processing {
    background: #74b9ff;
    color: #0984e3;
    animation: pulse 2s infinite;
}

.status-completed {
    background: #55efc4;
    color: #00b894;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.form-row {
    display: flex;
    gap: 15px;
}

.form-row .input-group {
    flex: 1;
}

.form-row-4 {
    align-items: flex-end;
}

.form-row-4 .btn {
    height: 46px;
    padding: 0 20px;
    margin-bottom: 15px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 600;
}

.input-group input,
.input-group select,
.input-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
    box-sizing: border-box;
}

.input-group input,
.input-group select {
    height: 46px;
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.input-group textarea {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

.input-group a {
    display: inline-block;
    margin-top: 5px;
    color: #667eea;
    text-decoration: none;
    font-size: 0.9rem;
}

.input-group a:hover {
    text-decoration: underline;
}

/* Кастомный dropdown для регионов */
.region-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 250px;
    overflow-y: auto;
    background: #fff;
    border: 2px solid #667eea;
    border-top: none;
    border-radius: 0 0 8px 8px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.region-dropdown.active {
    display: block;
}

.region-dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.95em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
}

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

.region-dropdown-item:hover,
.region-dropdown-item.highlighted {
    background: #f0f3ff;
}

.region-dropdown-item .region-engines {
    font-size: 0.75em;
    color: #999;
    margin-left: 8px;
    white-space: nowrap;
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 35px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.btn:active {
    transform: translateY(0);
}

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

.progress-bar {
    width: 100%;
    height: 30px;
    background: #e0e0e0;
    border-radius: 15px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.info-box {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
}

.info-box p {
    color: #1976d2;
    margin: 0;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.results-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: left;
    font-weight: 600;
}

.results-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
}

.results-table tr:hover {
    background: #f8f9fa;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.growth-indicator {
    display: inline-block;
    font-weight: 600;
}

.growth-up {
    color: #00b894;
}

.growth-up::before {
    content: "↑ ";
}

.growth-down {
    color: #d63031;
}

.growth-down::before {
    content: "↓ ";
}

.ai-analysis {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 10px;
    margin-top: 20px;
    border-left: 5px solid #667eea;
    line-height: 1.8;
}

.ai-analysis h1,
.ai-analysis h2,
.ai-analysis h3,
.ai-analysis h4 {
    color: #333;
    margin-top: 1em;
    margin-bottom: 0.5em;
}

.ai-analysis h1 { font-size: 1.6rem; }
.ai-analysis h2 { font-size: 1.3rem; }
.ai-analysis h3 { font-size: 1.1rem; }

.ai-analysis ul,
.ai-analysis ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.ai-analysis li {
    margin-bottom: 0.3em;
}

.ai-analysis table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.ai-analysis th,
.ai-analysis td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.ai-analysis th {
    background: #667eea;
    color: white;
    font-weight: 600;
}

.ai-analysis tr:nth-child(even) {
    background: #f0f0f0;
}

.ai-analysis code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.ai-analysis pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
}

.ai-analysis pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.ai-analysis blockquote {
    border-left: 4px solid #667eea;
    margin: 1em 0;
    padding: 0.5em 1em;
    background: #e8eaf6;
    border-radius: 0 8px 8px 0;
}

.ai-analysis p {
    margin-bottom: 0.8em;
}

.ai-analysis strong {
    color: #333;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid #f0f0f0;
}

.modal-header h2 {
    color: #333;
    font-size: 1.5rem;
}

.modal-header > button,
.modal-header-actions > button:not(.btn-clear-history) {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    transition: color 0.3s;
}

.modal-header > button:hover,
.modal-header-actions > button:not(.btn-clear-history):hover {
    color: #d63031;
}

.modal-body {
    padding: 30px;
}

.modal-footer {
    padding: 20px 30px;
    border-top: 2px solid #f0f0f0;
    text-align: right;
}

.api-key-section {
    margin-bottom: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.api-key-section h3 {
    color: #333;
    margin-bottom: 15px;
}

.active-analyses-banner {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(255, 193, 7, 0.2);
}

.active-analyses-banner h4 {
    color: #856404;
    margin-bottom: 15px;
}

.active-analyses-banner ul {
    list-style: none;
    padding: 0;
}

.active-analyses-banner li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    margin-bottom: 10px;
    border-radius: 5px;
}

.active-analyses-banner button {
    margin-left: 10px;
    padding: 5px 15px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-weight: 600;
}

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

.btn-clear-history {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-clear-history:hover {
    background: #c82333;
}

.history-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    background: #e9ecef;
}

.history-item-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-delete-history {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-delete-history:hover {
    background: #f8d7da;
}

.toggle-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-bottom: 10px;
    font-size: 0.95rem;
    color: #555;
    user-select: none;
}

.toggle-filter input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #667eea;
}

.toggle-filter span {
    transition: color 0.2s;
}

.toggle-filter:hover span {
    color: #333;
}

.results-table td a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
}

.results-table td a:hover {
    text-decoration: underline;
    color: #764ba2;
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.success {
    border-left: 5px solid #00b894;
}

.notification.error {
    border-left: 5px solid #d63031;
}

.notification.warning {
    border-left: 5px solid #ffc107;
}

.key-status {
    margin-left: 10px;
    font-size: 0.9rem;
    font-weight: 600;
}

.key-status.configured {
    color: #00b894;
}

.key-status.configured::before {
    content: "✅ ";
}

.key-status.missing {
    color: #d63031;
}

.key-status.missing::before {
    content: "❌ ";
}

.btn-test {
    background: #6c757d;
    color: white;
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-test:hover {
    background: #5a6268;
}

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

.test-result {
    margin-top: 10px;
    padding: 10px;
    border-radius: 5px;
    font-size: 0.9rem;
}

.test-result.success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid #28a745;
}

.test-result.error {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #dc3545;
}

.download-section {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 30px;
}

.download-section select {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.3s;
}

.download-section select:focus {
    outline: none;
    border-color: #667eea;
}

.preflight-errors {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

.preflight-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #ffc107;
    color: #856404;
    font-size: 1rem;
}

.preflight-header button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #856404;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}

.preflight-header button:hover {
    background: rgba(0, 0, 0, 0.1);
}

.preflight-body {
    padding: 15px 20px;
}

.preflight-error {
    padding: 10px 15px;
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #dc3545;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.preflight-error:last-child {
    margin-bottom: 0;
}

/* ==================== ЛОГИ ==================== */

.modal-content-wide {
    max-width: 1000px;
}

.logs-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e8e9eb;
}

.logs-filters .toggle-filter {
    margin-bottom: 0;
}

.log-badge {
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.log-badge.log-error {
    background: #fce4ec;
    color: #c62828;
}

.log-badge.log-warn {
    background: #fff3e0;
    color: #e65100;
}

.log-badge.log-info {
    background: #e3f2fd;
    color: #1565c0;
}

.log-badge.log-debug {
    background: #f3e5f5;
    color: #6a1b9a;
}

.logs-container {
    max-height: 60vh;
    overflow-y: auto;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.82rem;
    background: #1e1e2e;
    border-radius: 10px;
    padding: 12px;
    color: #cdd6f4;
}

.logs-empty {
    color: #6c7086;
    text-align: center;
    padding: 40px 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
}

.log-entry {
    padding: 4px 8px;
    border-left: 3px solid transparent;
    margin-bottom: 2px;
    border-radius: 0 4px 4px 0;
    line-height: 1.5;
    word-break: break-word;
}

.log-entry.log-level-error {
    border-left-color: #f38ba8;
    background: rgba(243, 139, 168, 0.08);
}

.log-entry.log-level-warn {
    border-left-color: #fab387;
    background: rgba(250, 179, 135, 0.08);
}

.log-entry.log-level-info {
    border-left-color: #89b4fa;
    background: rgba(137, 180, 250, 0.08);
}

.log-entry.log-level-debug {
    border-left-color: #6c7086;
}

.log-time {
    color: #6c7086;
    margin-right: 8px;
    font-size: 0.78rem;
}

.log-level-badge {
    display: inline-block;
    width: 32px;
    text-align: center;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-right: 8px;
    padding: 1px 0;
}

.log-level-error .log-level-badge {
    background: #f38ba8;
    color: #1e1e2e;
}

.log-level-warn .log-level-badge {
    background: #fab387;
    color: #1e1e2e;
}

.log-level-info .log-level-badge {
    background: #89b4fa;
    color: #1e1e2e;
}

.log-level-debug .log-level-badge {
    background: #585b70;
    color: #cdd6f4;
}

.log-message {
    color: #cdd6f4;
}

.log-detail {
    color: #a6adc8;
    font-size: 0.78rem;
    padding-left: 90px;
    margin-top: 1px;
}

/* ==================== РЕЖИМЫ АНАЛИЗА ДИНАМИКИ ==================== */

.badge-stable {
    background: #e2e3e5;
    color: #383d41;
}

.badge-volatile {
    background: #fff3cd;
    color: #856404;
}

.badge-reversal-up {
    background: #d1ecf1;
    color: #0c5460;
}

.badge-reversal-down {
    background: #f5c6cb;
    color: #721c24;
}

.growth-stable {
    color: #6c757d;
}

.growth-stable::before {
    content: "→ ";
}

.mode-description {
    font-size: 0.88rem;
    color: #666;
    margin: 6px 0 12px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-left: 3px solid #667eea;
    border-radius: 0 6px 6px 0;
    line-height: 1.5;
}

/* ==================== ГРАФИК ДИНАМИКИ ==================== */

.chart-container {
    display: none;
    margin-top: 16px;
    padding: 16px;
    background: #fff;
    border: 1px solid #e8e9eb;
    border-radius: 8px;
    position: relative;
}

.chart-container.visible {
    display: block;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 320px;
}

.chart-empty-hint {
    text-align: center;
    color: #999;
    padding: 40px 20px;
    font-size: 0.95rem;
}

.chart-checkbox-cell {
    width: 36px;
    text-align: center;
}

.chart-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #667eea;
}

/* ==================== ЗАМОРОЗКА ШАГА 2 ==================== */

.frozen-label {
    font-weight: 600;
    color: #555;
    padding: 6px 10px;
    background: #f0f2f5;
    border-radius: 6px;
    display: inline-block;
}

tr.approved-for-ai {
    background: rgba(102, 126, 234, 0.06) !important;
    border-left: 3px solid #667eea;
}

tr.approved-for-ai:hover {
    background: rgba(102, 126, 234, 0.1) !important;
}

.ai-marker-cell {
    text-align: center;
    font-weight: 600;
    color: #667eea;
}

/* ==================== КНОПКА ОТМЕНЫ АНАЛИЗА ==================== */

.btn-cancel-analysis {
    background: #dc3545 !important;
    margin-left: 12px;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

.btn-cancel-analysis:hover {
    background: #c82333 !important;
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
}
