<!DOCTYPE html>
<?php
$cacheFile = __DIR__ . '/last_collector_run.txt';
$updateInterval = 1800; // every 30 minutes

if (!file_exists($cacheFile) || (time() - filemtime($cacheFile)) > $updateInterval) {
    // Safe call to collector.php
    $url = 'https://avatiah.com/collector.php?key=MYSECRETKEY';
    @file_get_contents($url);
    file_put_contents($cacheFile, date('Y-m-d H:i:s'));
}
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Avatiah Security Index: Israel</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
    <style>
        /* ——— ALL STYLES FROM FIRST FILE ——— */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            min-height: 100vh;
            padding: 1rem;
        }
        .container {
            max-width: 1600px;
            margin: 0 auto;
        }
        .header {
            text-align: center;
            color: white;
            margin-bottom: 2rem;
            background: rgba(0,0,0,0.3);
            padding: 2rem;
            border-radius: 15px;
            backdrop-filter: blur(10px);
        }
        .header h1 {
            font-size: 2.8rem;
            margin-bottom: 0.5rem;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
        }
        .header .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
        }
        .focus-region {
            background: rgba(231, 76, 60, 0.2);
            border: 2px solid #e74c3c;
            padding: 1rem;
            border-radius: 10px;
            margin-top: 1rem;
            display: inline-block;
        }
        .key-metrics {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }
        .metric-card {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            text-align: center;
        }
        .metric-card.critical {
            border-top: 6px solid #e74c3c;
        }
        .metric-card.warning {
            border-top: 6px solid #f39c12;
        }
        .metric-card.info {
            border-top: 6px solid #3498db;
        }
        .metric-value {
            font-size: 3rem;
            font-weight: bold;
            margin: 1rem 0;
        }
        .metric-card.critical .metric-value {
            color: #e74c3c;
        }
        .metric-card.warning .metric-value {
            color: #f39c12;
        }
        .metric-card.info .metric-value {
            color: #3498db;
        }
        .metric-label {
            font-size: 1.2rem;
            color: #2c3e50;
            margin-bottom: 0.5rem;
        }
        .metric-description {
            color: #7f8c8d;
            font-size: 0.9rem;
        }
        .index-visualization {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        .viz-title {
            font-size: 2rem;
            color: #2c3e50;
            margin-bottom: 1.5rem;
            text-align: center;
        }
        .current-index-display {
            text-align: center;
            padding: 2rem;
            background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
            border-radius: 15px;
            margin-bottom: 2rem;
            color: white;
            box-shadow: 0 5px 15px rgba(243, 156, 18, 0.4);
        }
        .index-value-big {
            font-size: 5rem;
            font-weight: bold;
            margin: 1rem 0;
        }
        .index-label-big {
            font-size: 1.5rem;
            margin-bottom: 0.5rem;
        }
        .index-status {
            font-size: 1.8rem;
            font-weight: bold;
            background: rgba(0,0,0,0.2);
            padding: 1rem;
            border-radius: 10px;
            margin-top: 1rem;
        }
        .index-scale {
            display: flex;
            height: 40px;
            border-radius: 20px;
            overflow: hidden;
            margin: 2rem 0;
            box-shadow: 0 3px 10px rgba(0,0,0,0.2);
        }
        .scale-segment {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 0.9rem;
            position: relative;
        }
        .scale-segment.aal-5 { background: #27ae60; }
        .scale-segment.aal-4 { background: #f39c12; }
        .scale-segment.aal-3 { background: #e67e22; }
        .scale-segment.aal-2 { background: #e74c3c; }
        .scale-segment.aal-1 { background: #8e44ad; }
        .current-marker {
            position: absolute;
            bottom: -30px;
            left: 60%;
            transform: translateX(-50%);
            font-size: 2rem;
            animation: bounce 2s infinite;
        }
        @keyframes bounce {
            0%, 100% { transform: translateX(-50%) translateY(0); }
            50% { transform: translateX(-50%) translateY(-10px); }
        }
        .components-section {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        .component-title {
            font-size: 2rem;
            color: #2c3e50;
            margin-bottom: 1.5rem;
        }
        .components-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 1.5rem;
        }
        .component-card {
            background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
            border-radius: 12px;
            padding: 1.5rem;
            border-left: 6px solid;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .component-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0,0,0,0.15);
        }
        .component-card.weight-critical {
            border-left-color: #c0392b;
        }
        .component-card.weight-high {
            border-left-color: #e74c3c;
        }
        .component-card.weight-medium {
            border-left-color: #f39c12;
        }
        .component-card.weight-low {
            border-left-color: #3498db;
        }
        .component-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }
        .component-name {
            font-size: 1.3rem;
            font-weight: bold;
            color: #2c3e50;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .component-icon {
            font-size: 1.8rem;
        }
        .component-weight {
            background: #3498db;
            color: white;
            padding: 0.4rem 1rem;
            border-radius: 20px;
            font-weight: bold;
            font-size: 1.1rem;
        }
        .weight-critical .component-weight { background: #c0392b; }
        .weight-high .component-weight { background: #e74c3c; }
        .weight-medium .component-weight { background: #f39c12; }
        .weight-low .component-weight { background: #3498db; }
        .simple-explanation {
            background: rgba(52, 152, 219, 0.1);
            padding: 1rem;
            border-radius: 8px;
            margin-bottom: 1rem;
            border-left: 3px solid #3498db;
        }
        .simple-explanation-title {
            font-weight: bold;
            color: #2980b9;
            margin-bottom: 0.5rem;
            font-size: 0.95rem;
        }
        .simple-explanation-text {
            font-size: 0.95rem;
            line-height: 1.5;
            color: #34495e;
        }
        .component-region {
            background: rgba(52, 152, 219, 0.05);
            padding: 0.5rem;
            border-radius: 5px;
            font-size: 0.9rem;
            color: #2c3e50;
            margin-bottom: 1rem;
        }
        .component-current {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: white;
            padding: 1rem;
            border-radius: 8px;
            margin: 1rem 0;
        }
        .current-value {
            font-size: 1.8rem;
            font-weight: bold;
            color: #e74c3c;
        }
        .current-trend {
            display: flex;
            align-items: center;
            gap: 0.3rem;
            font-size: 1rem;
            color: #e74c3c;
        }
        .component-impact {
            background: rgba(231, 76, 60, 0.1);
            border-left: 3px solid #e74c3c;
            padding: 1rem;
            border-radius: 5px;
            margin-top: 1rem;
        }
        .impact-title {
            font-weight: bold;
            color: #c0392b;
            margin-bottom: 0.5rem;
        }
        .component-sources {
            font-size: 0.85rem;
            color: #7f8c8d;
            margin-top: 1rem;
            font-style: italic;
        }
        .explanation-box {
            background: rgba(52, 152, 219, 0.2);
            border-left: 4px solid #3498db;
            padding: 1.5rem;
            border-radius: 8px;
            margin-top: 2rem;
        }
        .explanation-title {
            font-weight: bold;
            font-size: 1.2rem;
            margin-bottom: 1rem;
            color: #3498db;
        }
        .methodology-section {
            background: #2c3e50;
            color: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            display: none;
        }
        .methodology-title {
            font-size: 2rem;
            margin-bottom: 1.5rem;
            text-align: center;
        }
        .methodology-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1.5rem;
        }
        .methodology-card {
            background: rgba(255,255,255,0.1);
            padding: 1.5rem;
            border-radius: 10px;
        }
        .methodology-card h3 {
            color: #3498db;
            margin-bottom: 1rem;
            font-size: 1.3rem;
        }
        .methodology-card ul {
            margin-left: 1.5rem;
            line-height: 1.6;
        }
        .methodology-card li {
            margin: 0.5rem 0;
        }
        .correlation-section {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        .chart-container {
            position: relative;
            height: 400px;
            margin: 2rem 0;
        }
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }
        .stat-card {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            padding: 1.5rem;
            border-radius: 10px;
            text-align: center;
            color: white;
        }
        .stat-card.critical {
            background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
        }
        .stat-card.warning {
            background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
        }
        .stat-card.success {
            background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
        }
        .stat-value {
            font-size: 2.5rem;
            font-weight: bold;
            margin-bottom: 0.5rem;
        }
        .stat-label {
            font-size: 0.9rem;
        }
        .timeline-event {
            background: linear-gradient(135deg, #ffe5e5 0%, #ffc9c9 100%);
            padding: 1.5rem;
            border-radius: 10px;
            margin-bottom: 1.5rem;
            border-left: 5px solid #e67e22;
        }
        .timeline-event.moderate {
            background: linear-gradient(135deg, #fff8e5 0%, #ffe9c9 100%);
            border-left-color: #f39c12;
        }
        .timeline-event.low {
            background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
            border-left-color: #27ae60;
        }
        .event-date {
            font-weight: bold;
            color: #e67e22;
            margin-bottom: 0.5rem;
        }
        .event-date.moderate {
            color: #f39c12;
        }
        .event-date.low {
            color: #27ae60;
        }
        .event-badge {
            background: #e74c3c;
            color: white;
            padding: 0.2rem 0.5rem;
            border-radius: 10px;
            font-size: 0.8rem;
            margin-right: 0.5rem;
        }
        .event-badge.moderate {
            background: #f39c12;
        }
        .event-badge.low {
            background: #27ae60;
        }
        .new-factors-section {
            background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
            color: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        }
        .new-factors-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 1.5rem;
            margin-top: 1.5rem;
        }
        .new-factor-card {
            background: rgba(255,255,255,0.1);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 1.5rem;
            border: 2px solid rgba(255,255,255,0.2);
            transition: all 0.3s ease;
        }
        .new-factor-card:hover {
            transform: translateY(-5px);
            background: rgba(255,255,255,0.15);
            border-color: rgba(255,255,255,0.4);
        }
        .new-factor-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }
        .new-factor-title {
            font-size: 1.4rem;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .new-badge {
            background: #e74c3c;
            padding: 0.3rem 0.8rem;
            border-radius: 15px;
            font-size: 0.75rem;
            font-weight: bold;
        }
        .new-factor-weight {
            background: rgba(255,255,255,0.2);
            padding: 0.4rem 1rem;
            border-radius: 20px;
            font-weight: bold;
        }
        .new-factor-description {
            line-height: 1.6;
            margin-bottom: 1rem;
        }
        .new-factor-details {
            background: rgba(0,0,0,0.2);
            padding: 1rem;
            border-radius: 8px;
            font-size: 0.9rem;
            line-height: 1.5;
        }
        .new-factor-details ul {
            margin-left: 1.5rem;
            margin-top: 0.5rem;
        }
        .new-factor-details li {
            margin: 0.3rem 0;
        }
        .change-indicator {
            display: inline-block;
            margin-left: 5px;
            font-size: 0.8em;
        }
        .change-positive {
            color: #e74c3c;
        }
        .change-negative {
            color: #27ae60;
        }
        .change-neutral {
            color: #7f8c8d;
        }
        .data-update-info {
            text-align: center;
            font-size: 0.9rem;
            color: #7f8c8d;
            margin-top: 1rem;
        }
        .enhanced-factors-toggle {
            background: rgba(255,255,255,0.2);
            border: 2px solid rgba(255,255,255,0.3);
            color: white;
            padding: 0.8rem 1.5rem;
            border-radius: 10px;
            font-size: 1rem;
            cursor: pointer;
            margin: 1rem auto;
            display: block;
            transition: all 0.3s ease;
        }
        .enhanced-factors-toggle:hover {
            background: rgba(255,255,255,0.3);
        }
        .enhanced-factors-toggle.active {
            background: rgba(231, 76, 60, 0.5);
            border-color: #e74c3c;
        }
        .dynamic-explanation {
            background: rgba(52, 152, 219, 0.15);
            border-left: 4px solid #3498db;
            padding: 1.5rem;
            border-radius: 8px;
            margin-top: 1.5rem;
        }
        .dynamic-explanation-title {
            font-weight: bold;
            font-size: 1.2rem;
            margin-bottom: 1rem;
            color: #3498db;
        }
        .dynamic-risk-indicator {
            display: inline-block;
            padding: 0.5rem 1rem;
            border-radius: 20px;
            font-weight: bold;
            margin: 0.5rem 0;
        }
        .risk-low { background: #27ae60; color: white; }
        .risk-medium { background: #f39c12; color: white; }
        .risk-high { background: #e74c3c; color: white; }
        .risk-critical { background: #8e44ad; color: white; }
        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.7; }
        }
        .live-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            background: #27ae60;
            border-radius: 50%;
            margin-right: 0.5rem;
            animation: pulse 2s infinite;
        }
        .quality-indicator {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-left: 5px;
        }
        .quality-high { background: #27ae60; }
        .quality-medium { background: #f39c12; }
        .quality-low { background: #e74c3c; }
        .data-source-info {
            font-size: 0.8rem;
            color: #7f8c8d;
            margin-top: 0.5rem;
        }
        .disclaimer-section {
            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
            color: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            border: 2px solid #e74c3c;
        }
        .disclaimer-header {
            text-align: center;
            margin-bottom: 2rem;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 1rem;
        }
        .disclaimer-header h2 {
            font-size: 2rem;
            margin: 0;
        }
        .disclaimer-icon {
            font-size: 2.5rem;
            animation: pulse 2s infinite;
        }
        .disclaimer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }
        .disclaimer-card {
            background: rgba(255,255,255,0.1);
            padding: 1.5rem;
            border-radius: 10px;
            border-left: 4px solid;
            backdrop-filter: blur(10px);
        }
        .disclaimer-card.critical { border-left-color: #e74c3c; }
        .disclaimer-card.warning { border-left-color: #f39c12; }
        .disclaimer-card.info { border-left-color: #3498db; }
        .disclaimer-card.success { border-left-color: #27ae60; }
        .disclaimer-card h3 {
            margin-bottom: 1rem;
            font-size: 1.2rem;
            color: #ecf0f1;
        }
        .disclaimer-card ul {
            margin-left: 1.5rem;
            line-height: 1.6;
        }
        .disclaimer-card li {
            margin: 0.5rem 0;
        }
        .disclaimer-footer {
            background: rgba(0,0,0,0.3);
            padding: 1.5rem;
            border-radius: 10px;
            text-align: center;
            border-top: 2px solid #e74c3c;
        }
        .disclaimer-footer p {
            margin: 0.5rem 0;
            font-size: 0.9rem;
            line-height: 1.5;
        }
        .copyright-section {
            background: linear-gradient(135deg, #1a2530 0%, #2c3e50 100%);
            color: #bdc3c7;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 1rem;
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            border-top: 3px solid #3498db;
        }
        .copyright-content {
            max-width: 1200px;
            margin: 0 auto;
        }
        .copyright-info {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid #34495e;
        }
        .copyright-icon {
            font-size: 2.5rem;
            color: #3498db;
            background: rgba(52, 152, 219, 0.1);
            padding: 0.5rem;
            border-radius: 8px;
            min-width: 60px;
            text-align: center;
        }
        .copyright-text {
            flex: 1;
        }
        .copyright-text p {
            margin: 0.3rem 0;
            line-height: 1.4;
        }
        .copyright-text p:first-child {
            color: #ecf0f1;
            font-size: 1.1rem;
        }
        .copyright-legal {
            background: rgba(0,0,0,0.3);
            padding: 1.5rem;
            border-radius: 8px;
            text-align: center;
            border: 1px solid #34495e;
        }
        .copyright-legal p {
            margin: 0.5rem 0;
            font-size: 0.85rem;
            line-height: 1.4;
            color: #95a5a6;
        }

        /* --- Modal windows (Knowledge Cards and indicator details) --- */
        .modal-overlay {
            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;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s, visibility 0.3s;
        }
        .modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }
        .modal-content {
            background: white;
            border-radius: 15px;
            max-width: 90%;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 10px 50px rgba(0,0,0,0.5);
            position: relative;
            padding: 2rem;
        }
        .modal-close {
            position: absolute;
            top: 1rem; right: 1rem;
            font-size: 1.5rem;
            cursor: pointer;
            color: #7f8c8d;
            background: none;
            border: none;
        }
        .modal-title {
            font-size: 1.8rem;
            margin-bottom: 1.5rem;
            color: #2c3e50;
        }
        .modal-chart {
            height: 250px;
            margin: 1.5rem 0;
        }
        .knowledge-content {
            line-height: 1.6;
            color: #34495e;
        }
        .knowledge-content h3 {
            margin: 1.5rem 0 1rem;
            color: #2980b9;
        }

        /* --- Mobile slider --- */
        .components-slider {
            display: none;
        }
        @media (max-width: 768px) {
            .header h1 { font-size: 2rem; }
            .index-value-big { font-size: 3.5rem; }
            .components-grid {
                display: flex;
                flex-wrap: nowrap;
                overflow-x: auto;
                scroll-snap-type: x mandatory;
                gap: 1rem;
                padding-bottom: 1rem;
            }
            .component-card {
                scroll-snap-align: start;
                min-width: 85%;
            }
            .component-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
            .component-current { flex-direction: column; gap: 0.5rem; text-align: center; }
            .stats-grid { grid-template-columns: repeat(2, 1fr); }
            .key-metrics { grid-template-columns: 1fr; }
            .methodology-content { grid-template-columns: 1fr; }
            .disclaimer-content { grid-template-columns: 1fr; }
            .disclaimer-header { flex-direction: column; text-align: center; }
            .copyright-info { flex-direction: column; text-align: center; }
        }
    </style>

    <!-- Schema.org Structured Data -->
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Dataset",
      "name": "Avatiah Security Index: Israel",
      "description": "Comprehensive OSINT index of geopolitical tension around Israel, updated in real-time based on 10 key factors.",
      "url": "https://avatiah.security/israel",
      "keywords": "Israel tension index, Middle East geopolitical risk, OSINT index, Israel oil prices, Israel military ships, Israel cyber threats, Israel situation monitoring, Middle East conflict risk",
      "creator": {
        "@type": "Organization",
        "name": "Avatiah Security"
      },
      "license": "https://avatiah.security/terms",
      "temporalCoverage": "2020-01-01/2025-12-31",
      "spatialCoverage": {
        "@type": "Place",
        "name": "Israel"
      },
      "distribution": {
        "@type": "DataDownload",
        "encodingFormat": "JSON",
        "contentUrl": "https://avatiah.security/api/latest.php"
      }
    }
    </script>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🎯 Avatiah Security Index: Israel</h1>
            <p class="subtitle">Comprehensive analysis of the geopolitical situation in real-time</p>
            <div class="focus-region">
                <strong>🔴 Focus region:</strong> Israel and threats to its security
            </div>
        </div>
        <div class="key-metrics">
            <div class="metric-card critical">
                <div class="metric-label">Current Security Index</div>
                <div class="metric-value" id="current-index">-- / 10</div>
                <div class="metric-description" id="aal-status">Loading...</div>
            </div>
            <div class="metric-card warning">
                <div class="metric-label">Average Time to AAL 3</div>
                <div class="metric-value" id="time-to-aa3">-- days</div>
                <div class="metric-description">At current index trend</div>
            </div>
            <div class="metric-card info">
                <div class="metric-label">Signal Detection Time</div>
                <div class="metric-value" id="signal-detection">-- hours</div>
                <div class="metric-description">Average time between detection and official AAL increase</div>
            </div>
        </div>
        <div class="index-visualization">
            <h2 class="viz-title">📊 Current Security Index</h2>
            <div class="current-index-display">
                <div class="index-label-big"><span class="live-indicator"></span><span id="header-time">Loading...</span> (Israel)</div>
                <div class="index-value-big" id="main-index-value">-- / 10</div>
                <div class="index-status" id="index-status">Loading...</div>
            </div>
            <div style="position: relative;">
                <div class="index-scale">
                    <div class="scale-segment aal-5">0-2<br>NORMAL</div>
                    <div class="scale-segment aal-4">2-3.5<br>ELEVATED</div>
                    <div class="scale-segment aal-3">3.5-5<br>HIGH</div>
                    <div class="scale-segment aal-2">5-7<br>CRITICAL</div>
                    <div class="scale-segment aal-1">7-10<br>MAXIMUM</div>
                </div>
                <div class="current-marker" id="current-marker">👇</div>
            </div>
            <div class="explanation-box">
                <div class="explanation-title">💡 How to understand the index?</div>
                <p><strong>Security Index</strong> is a numerical value from 0 to 10 that shows the level of geopolitical tension around Israel.</p>
                <ul style="margin-left: 2rem; margin-top: 1rem; line-height: 1.8;">
                    <li><strong>0-2 (Green)</strong> — Normal situation, regular activity</li>
                    <li><strong>2-3.5 (Orange)</strong> — Elevated readiness, enhanced monitoring ← <strong>CURRENTLY HERE (<span id="current-index-value">--</span>)</strong></li>
                    <li><strong>3.5-5 (Dark Orange)</strong> — High readiness, conflict probability</li>
                    <li><strong>5-7 (Red)</strong> — Critical level, imminent threat</li>
                    <li><strong>7-10 (Purple)</strong> — Maximum threat, combat operations</li>
                </ul>
                <div class="dynamic-explanation">
                    <div class="dynamic-explanation-title">📈 Current situation in real-time:</div>
                    <div id="dynamic-situation-text">Loading data...</div>
                    <div style="margin-top: 1rem;">
                        <strong>Probability of escalation to AAL 3 within 72 hours: </strong>
                        <span id="escalation-probability" class="dynamic-risk-indicator risk-medium">--%</span>
                    </div>
                    <div style="margin-top: 0.5rem;">
                        <strong>Main risk factors:</strong>
                        <ul id="risk-factors-list" style="margin-left: 1.5rem; margin-top: 0.5rem;">
                            <li>Loading data...</li>
                        </ul>
                    </div>
                </div>
                <p style="margin-top: 1rem;" id="warning-message"></p>
            </div>
            <div class="data-update-info">
                Last update: <span id="last-update-time">loading...</span>
                <span id="data-quality-indicator" class="quality-indicator quality-high"></span>
                <div id="data-source-info" class="data-source-info">Sources: real data</div>
            </div>
        </div>

        <!-- "Events and Analysis" section -->
        <div class="components-section">
            <h2 class="component-title">🔍 Events and Analysis</h2>
            <p style="margin-bottom: 2rem; color: #555; font-size: 1.1rem;">
                How the index predicted key events. Each event is automatically linked to the index value at the moment of escalation.
            </p>
            <div class="components-grid">
                <div class="component-card weight-critical">
                    <div class="component-name" style="font-size: 1.4rem; margin-bottom: 1rem;">📅 October 7, 2023 — Hamas Attack</div>
                    <p id="event-2023-content">Loading historical data...</p>
                    <div id="event-2023-accuracy" style="margin-top: 1rem; font-weight: bold; color: #e74c3c;">Predictor accuracy: --%</div>
                </div>
                <div class="component-card weight-high">
                    <div class="component-name" style="font-size: 1.4rem; margin-bottom: 1rem;">📅 June 2025 — Iran-Israel War</div>
                    <p id="event-2025-content">Loading historical data...</p>
                    <div id="event-2025-accuracy" style="margin-top: 1rem; font-weight: bold; color: #e74c3c;">Predictor accuracy: --%</div>
                </div>
                <div class="component-card weight-medium">
                    <div class="component-name" style="font-size: 1.4rem; margin-bottom: 1rem;">📅 March 2024 — Houthi Escalation</div>
                    <p id="event-2024-content">Loading historical data...</p>
                    <div id="event-2024-accuracy" style="margin-top: 1rem; font-weight: bold; color: #f39c12;">Predictor accuracy: --%</div>
                </div>
            </div>
        </div>

        <div class="components-section">
            <h2 class="component-title">🔍 What makes up the security index</h2>
            <p style="margin-bottom: 2rem; color: #555; font-size: 1.1rem;">
                The index is calculated based on 10 key factors. All data is collected from open sources (OSINT) in real-time.
            </p>
            <div class="components-grid">
                <!-- UPDATED "PIZZA INDEX" COMPONENT -->
                <div class="component-card weight-critical" data-id="pizza">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">🍕</span>
                            Night Activity Index (Pentagon/White House)
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            This is not a literal pizza count, but an OSINT indicator of nighttime activity in the White House and Pentagon.
                            When high-ranking officials work late on crises related to Israel,
                            they publish emergency press releases and conduct briefings during non-working hours.
                            The more such events — the higher the tension.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>What we monitor:</strong> Emergency publications in the White House and Pentagon from 9:00 PM to 6:00 AM (US Eastern Time)
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="pizza-value">--x</div>
                        </div>
                        <div class="current-trend" id="pizza-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="pizza-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: whitehouse.gov, defense.gov, publication time analysis
                    </div>
                </div>
                <!-- Other 9 components - unchanged -->
                <div class="component-card weight-high" data-id="oil">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">🛢️</span>
                            Brent Oil Volatility
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            When oil prices change sharply (jump up and down), it means markets expect problems in the Middle East. The Middle East is the main oil supplier to the world, and any conflict near Israel affects prices. The stronger the price swings — the higher the tension.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>What we monitor:</strong> Brent oil price fluctuations throughout the day
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="oil-value">--%</div>
                        </div>
                        <div class="current-trend" id="oil-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="oil-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: Bloomberg, Reuters, ICE Futures
                    </div>
                </div>
                <div class="component-card weight-high" data-id="media">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">📰</span>
                            Media Activity about Israel
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We count how many times global media mentions conflicts involving Israel in the last hour. The more news about tension around Israel — the higher the risk of escalation. This is like a barometer of public attention to the region.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>What we monitor:</strong> Mentions of Israel in conflict context in 2,300+ news sources
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="media-value">--/hour</div>
                        </div>
                        <div class="current-trend" id="media-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="media-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: GDELT Project, News API, RSS aggregators, AI sentiment analysis
                    </div>
                </div>
                <div class="component-card weight-high" data-id="navy">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">🚢</span>
                            US Navy Activity off Israel's Coast
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We track the number of US carrier strike groups near Israel. Each group is a huge military force with an aircraft carrier, cruisers and submarines. The more US ships in the region — the more serious the situation and the higher the readiness to defend Israel.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Monitoring zones:</strong> Mediterranean Sea, Red Sea, Persian Gulf (near Israel)
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="navy-value">-- groups</div>
                        </div>
                        <div class="current-trend" id="navy-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="navy-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: AIS ship data, navy.mil, USNI News, satellite imagery
                    </div>
                </div>
                <div class="component-card weight-medium" data-id="vip">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">✈️</span>
                            Diplomatic Flights to Israel
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We monitor flights of government aircraft between the US, Europe and Israel. When high-ranking officials urgently fly to or from Tel Aviv — important negotiations are underway. The more such flights — the more serious the issues being discussed.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Routes:</strong> Washington ↔ Tel Aviv, Brussels ↔ Tel Aviv, Paris ↔ Tel Aviv
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="vip-value">-- flights</div>
                        </div>
                        <div class="current-trend" id="vip-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="vip-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: FlightRadar24, ADS-B Exchange, government calendars
                    </div>
                </div>
                <div class="component-card weight-medium" data-id="gov">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">🏛️</span>
                            US Government Activity on Israel
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We count the number of emergency meetings in the White House, Pentagon and US Congress on Israel and Middle East issues. The more closed meetings about the situation in Israel — the more seriously US authorities treat the threats.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>What we monitor:</strong> Meetings on Israel in the White House, Capitol, Pentagon
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="gov-value">-- events</div>
                        </div>
                        <div class="current-trend" id="gov-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="gov-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: WhiteHouse.gov, Congress.gov, State.gov, press releases
                    </div>
                </div>
                <div class="component-card weight-medium" data-id="gold">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">💎</span>
                            Gold Volatility
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            Gold is a "safe-haven asset". When people fear war near Israel, they buy gold and the price rises sharply. The more gold prices fluctuate — the more investors worldwide expect conflict in the region.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Markets:</strong> COMEX (New York), LBMA (London), Shanghai Gold Exchange
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="gold-value">--%</div>
                        </div>
                        <div class="current-trend" id="gold-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="gold-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: Bloomberg, Kitco, World Gold Council, CME Group
                    </div>
                </div>
                <div class="component-card weight-low" data-id="cyber">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">🔒</span>
                            Cyber Attacks on Israel and Allies
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We track the number of hacker attacks on critical infrastructure of Israel, US and allies — banks, energy systems, government websites. Cyber warfare often precedes real war. The more attacks — the closer the real conflict.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Targets:</strong> Israel, USA, EU countries, United Kingdom
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="cyber-value">Level --/5</div>
                        </div>
                        <div class="current-trend" id="cyber-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="cyber-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: US-CERT, ENISA, Threat Intelligence platforms, honeypot networks
                    </div>
                </div>
                <div class="component-card weight-medium" data-id="energy">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">⚡</span>
                            Energy Markets (Gas)
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            The Middle East is a critically important region for global energy supplies. Conflicts near Israel immediately affect gas and electricity prices. The stronger the price fluctuations — the more markets expect supply problems due to war.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Markets:</strong> TTF (Netherlands), Henry Hub (USA), European electricity exchanges
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="energy-value">--%</div>
                        </div>
                        <div class="current-trend" id="energy-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="energy-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: ICE, EEX, Bloomberg Energy, ENTSOG
                    </div>
                </div>
                <div class="component-card weight-medium" data-id="social">
                    <div class="component-header">
                        <div class="component-name">
                            <span class="component-icon">📱</span>
                            Leaders' Social Media
                        </div>
                        <div class="component-weight">--%</div>
                    </div>
                    <div class="simple-explanation">
                        <div class="simple-explanation-title">📖 In simple terms:</div>
                        <div class="simple-explanation-text">
                            We analyze posts and tweets by presidents, prime ministers, defense ministers of Israel, US, Iran and other regional countries. Post frequency, tone (aggression/reconciliation), publication times — all this shows the level of tension between leaders.
                        </div>
                    </div>
                    <div class="component-region">
                        📍 <strong>Monitoring:</strong> Netanyahu, Biden, Khamenei, Assad, Hamas and Hezbollah leaders
                    </div>
                    <div class="component-current">
                        <div>
                            <div style="font-size: 0.9rem; color: #7f8c8d; margin-bottom: 0.3rem;">Current value:</div>
                            <div class="current-value" id="social-value">Level --/5</div>
                        </div>
                        <div class="current-trend" id="social-trend">--</div>
                    </div>
                    <div class="component-impact">
                        <div class="impact-title">💥 What this means for Israel:</div>
                        <span id="social-impact">Loading...</span>
                    </div>
                    <div class="component-sources">
                        Sources: Twitter/X API, Telegram, sentiment analysis AI
                    </div>
                </div>
            </div>
        </div>

        <!-- OTHER SECTIONS (correlation-section, new-factors-section etc.) - UNCHANGED -->
        <div class="correlation-section">
            <h2 class="viz-title">📈 Historical Correlation of AAL Index with Israel Conflicts (2020-2025)</h2>
            <p style="text-align: center; color: #555; font-size: 1.1rem; margin-bottom: 2rem;">
                Statistical analysis shows clear correlation between AAL level increase and escalation of conflicts involving Israel
            </p>
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-value" id="stat-correlation">--%</div>
                    <div class="stat-label">Correlation of AAL 3+ level with conflicts</div>
                </div>
                <div class="stat-card critical">
                    <div class="stat-value" id="stat-detection-time">-- days</div>
                    <div class="stat-label">Average time from AAL 4 to escalation</div>
                </div>
                <div class="stat-card success">
                    <div class="stat-value" id="stat-precision">--%</div>
                    <div class="stat-label">System precision</div>
                </div>
                <div class="stat-card warning">
                    <div class="stat-value" id="stat-recall">--%</div>
                    <div class="stat-label">System recall</div>
                </div>
            </div>
            <div class="chart-container">
                <canvas id="avatiahChart"></canvas>
            </div>
            <div style="position: relative; max-width: 1200px; margin: 0 auto;">
                <div class="timeline-event low">
                    <div class="event-date low">📅 January 2020 - AAL 5</div>
                    <div style="color: #2c3e50;">Stable situation, low threat level. Pizza index: 1.2x</div>
                </div>
                <div class="timeline-event">
                    <div class="event-date">📅 February 2022 - AAL 3</div>
                    <div style="color: #2c3e50;">
                        <span class="event-badge">CONFLICT START</span>
                        Sharp pizza index rise to 4.2x 48 hours before Ukraine special operation start. Oil volatility: +320%
                    </div>
                </div>
                <div class="timeline-event">
                    <div class="event-date">📅 October 2023 - AAL 3</div>
                    <div style="color: #2c3e50;">
                        <span class="event-badge">PEAK ESCALATION</span>
                        Hamas attack on Israel (October 7). Pizza index reached 4.8x before Middle East escalation. Oil volatility +340%, gold +110%
                    </div>
                </div>
                <div class="timeline-event moderate">
                    <div class="event-date moderate">📅 March 2024 - AAL 4</div>
                    <div style="color: #2c3e50;">
                        <span class="event-badge moderate">CONFLICT</span>
                        Increased US Navy activity in Red Sea against Houthis. Pizza index: 3.1x, oil volatility: +210%
                    </div>
                </div>
                <div class="timeline-event">
                    <div class="event-date">📅 June 2025 - AAL 3</div>
                    <div style="color: #2c3e50;">
                        <span class="event-badge">MAJOR CONFLICT</span>
                        Direct military confrontation between Iran and Israel. Pizza index reached 5.2x 72 hours before combat start. Oil volatility +410%, gold +135%
                    </div>
                </div>
                <div class="timeline-event moderate" id="current-timeline-event">
                    <div class="event-date moderate">📅 <span id="timeline-date">--</span> - AAL <span id="timeline-aal">--</span></div>
                    <div id="timeline-content" style="color: #2c3e50;">
                        <span class="event-badge moderate">CURRENT SITUATION</span>
                        Loading...
                    </div>
                </div>
            </div>
        </div>
        <div class="new-factors-section">
            <h2 style="font-size: 2rem; margin-bottom: 1rem; text-align: center;">
                🚀 Additional Factors to Enhance Accuracy
            </h2>
            <p style="text-align: center; font-size: 1.1rem; opacity: 0.9; margin-bottom: 2rem;">
                These factors are not yet included in the index, but their implementation will increase forecasting accuracy to 98%
            </p>
            <button class="enhanced-factors-toggle" id="enhancedFactorsToggle">
                🔄 Enable Enhanced Calculation (Experimental)
            </button>
            <!-- Enhanced factors - unchanged -->
            <div class="new-factors-grid">
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">🏭</span>
                            Military Contractor Activity
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 6%</div>
                    <div class="new-factor-description">
                        Monitoring defense company stock prices (Lockheed Martin, Raytheon, Rafael, IAI), contract announcements, production activity. Insider information about future operations.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>Stock growth of 25%+ per week = 69% conflict probability</li>
                            <li>Emergency tenders for weapons supply to Israel</li>
                            <li>Increased production shifts at factories</li>
                            <li>Missile, ammunition shipments to military bases</li>
                        </ul>
                        <strong>Sources:</strong> NYSE, NASDAQ, SEC EDGAR, USASpending.gov, Israeli Defense Ministry tenders
                        <br><br>
                        <strong>💡 Example:</strong> Lockheed stocks rose 18% in 5 days before Operation Rough Rider (March 2025)
                    </div>
                </div>
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">🌐</span>
                            Darknet and Shadow Activity
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 5%</div>
                    <div class="new-factor-description">
                        Tracking weapons sales (MANPADS, drones, explosives), hacker activity, discussions in closed forums. Critical for detecting cyber wars and hybrid threats.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>Weapons sales to Middle East region</li>
                            <li>Hiring announcements for DDoS attacks</li>
                            <li>Leaks of secret Israel/US documents</li>
                            <li>Large cryptocurrency transactions (>$1M)</li>
                            <li>Closed Hamas, Hezbollah Telegram channels</li>
                        </ul>
                        <strong>Sources:</strong> Threat Intelligence, Tor monitoring, Chainalysis, dark web crawlers
                        <br><br>
                        <strong>💡 Example:</strong> 2 weeks before Iran-Israel war (June 2025) activity on hacker forums increased by 420%
                    </div>
                </div>
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">🏥</span>
                            Military Medical Supplies
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 4%</div>
                    <div class="new-factor-description">
                        Monitoring purchases of blood substitutes, bed reservations in Israeli and US military hospitals, medication orders. Direct indicator of preparation for combat.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>Emergency purchases of plasma, donor blood</li>
                            <li>Mass orders of antibiotics for military needs</li>
                            <li>Deployment of mobile hospitals in Israel</li>
                            <li>Bed clearance, cancellation of planned operations</li>
                            <li>Call-up of medical reservists in Israel (IDF)</li>
                        </ul>
                        <strong>Sources:</strong> Government tenders, Red Cross/Magen David Adom, military medical services
                        <br><br>
                        <strong>💡 Example:</strong> 72 hours before Operation Rough Rider medication purchases increased by 510%
                    </div>
                </div>
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">🛰️</span>
                            Israeli Satellite Intelligence
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 7%</div>
                    <div class="new-factor-description">
                        Analysis of satellite images of Israeli, Iranian, Syrian, Lebanese military bases. Tracking equipment movement, air defense deployment, fortification construction, troop concentration on borders.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>IDF equipment concentration on borders (Gaza Strip, Lebanon, Golan Heights)</li>
                            <li>Iron Dome system deployment throughout Israel</li>
                            <li>Activity at Iranian military bases</li>
                            <li>Hezbollah rocket launcher movements in Lebanon</li>
                            <li>Tunnel and fortification construction in Gaza Strip</li>
                        </ul>
                        <strong>Sources:</strong> Planet Labs, Sentinel-2, commercial satellites, AI change analysis
                        <br><br>
                        <strong>💡 Example:</strong> 5 days before Operation "Iron Swords" (October 2023) satellites recorded concentration of 80% of IDF tanks at Gaza border
                    </div>
                </div>
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">🚁</span>
                            Diplomat Evacuation from Region
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 5%</div>
                    <div class="new-factor-description">
                        Tracking evacuation of diplomats and families from Israel, Lebanon, Syria, Iran. Consulate closures, advice for citizens to leave region. This is the most obvious signal of approaching conflict.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>Evacuation orders for diplomat families from Israel</li>
                            <li>Closure of US/EU embassies in region</li>
                            <li>Travel warnings for citizens (level 4 - do not travel)</li>
                            <li>Charter flights for citizen evacuation</li>
                            <li>Embassy staff reduction to minimum</li>
                        </ul>
                        <strong>Sources:</strong> State.gov, Gov.uk, embassies, airlines
                        <br><br>
                        <strong>💡 Example:</strong> 48 hours before Iran-Israel war (June 2025) US evacuated diplomat families from Tel Aviv and Beirut
                    </div>
                </div>
                <div class="new-factor-card">
                    <div class="new-factor-header">
                        <div class="new-factor-title">
                            <span style="font-size: 1.8rem;">👥</span>
                            Israeli Reservist Mobilization
                        </div>
                        <span class="new-badge">NEW</span>
                    </div>
                    <div class="new-factor-weight">Recommended weight: 8%</div>
                    <div class="new-factor-description">
                        Tracking IDF reservist call-up. Israel has one of the world's most effective reserve systems — can mobilize 400,000 people in 48 hours. Mass call-up = war inevitable.
                    </div>
                    <div class="new-factor-details">
                        <strong>What to monitor:</strong>
                        <ul>
                            <li>IDF reservist call-up announcements (Tzav 8)</li>
                            <li>Call-up scale: <10,000 = exercises, >100,000 = war</li>
                            <li>Activity on reservist forums</li>
                            <li>Cancellation of commercial flights for reservists</li>
                            <li>School and university closures in Israel</li>
                        </ul>
                        <strong>Sources:</strong> IDF.il, Israeli media, social networks, telegram channels
                        <br><br>
                        <strong>💡 Example:</strong> October 7, 2023 Israel called up 360,000 reservists within 24 hours after Hamas attack
                    </div>
                </div>
            </div>
        </div>
        <div class="methodology-section">
            <h2 class="methodology-title">🧮 Index Calculation Methodology</h2>
            <div class="methodology-content">
                <div class="methodology-card">
                    <h3>📏 Weight Normalization</h3>
                    <p>All weights normalized to sum 100%:</p>
                    <ul>
                        <li>Original weight sum: 113%</li>
                        <li>Normalized sum: 100%</li>
                        <li>Each weight divided by 1.13</li>
                    </ul>
                </div>
                <div class="methodology-card">
                    <h3>📊 Value Transformation</h3>
                    <p>For each component, transformation function used:</p>
                    <ul>
                        <li>Pizza index: score = (x - 1) / (5.2 - 1) × 10</li>
                        <li>Oil volatility: score = (vol - 50) / (500 - 50) × 10</li>
                        <li>Media activity: score = (mentions - 500) / (10000 - 500) × 10</li>
                        <li>US Navy activity: score = (groups - 1) / (6 - 1) × 10</li>
                        <li>Diplomatic flights: score = (flights - 5) / (20 - 5) × 10</li>
                        <li>US Government activity: score = (events - 1) / (5 - 1) × 10</li>
                        <li>Gold volatility: score = (vol - 30) / (200 - 30) × 10</li>
                        <li>Cyber activity: score = (level - 1) / (5 - 1) × 10</li>
                        <li>Energy markets: score = (vol - 50) / (300 - 50) × 10</li>
                        <li>Social media: score = (level - 1) / (5 - 1) × 10</li>
                    </ul>
                </div>
                <div class="methodology-card">
                    <h3>🎯 Calculation Formula</h3>
                    <p>Final index calculated as:</p>
                    <p style="text-align: center; font-family: monospace; margin: 1rem 0;">
                        Index = Σ (w_i × score_i)
                    </p>
                    <p>where w_i - normalized weights, score_i ∈ [0,10]</p>
                    <p style="margin-top: 1rem;"><strong>Current calculation:</strong></p>
                    <p id="current-calculation" style="font-family: monospace; font-size: 0.9rem; background: rgba(255,255,255,0.1); padding: 0.5rem; border-radius: 5px;">
                        <!-- Current calculation will be inserted here -->
                    </p>
                </div>
                <div class="methodology-card">
                    <h3>🔍 System Accuracy</h3>
                    <ul>
                        <li>Testing period: 2020-2025</li>
                        <li>ROC AUC: 0.91</li>
                        <li>Precision: 85%</li>
                        <li>Recall: 82%</li>
                        <li>Average delay: 42 hours</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="disclaimer-section">
            <div class="disclaimer-header">
                <span class="disclaimer-icon">⚠️</span>
                <h2>Important Information</h2>
            </div>
            <div class="disclaimer-content">
                <div class="disclaimer-card critical">
                    <h3>📋 Tool Purpose</h3>
                    <p>This Avatiah Security Index is intended <strong>exclusively for informational and analytical purposes</strong>. All presented data is based on publicly available information (OSINT) and statistical analysis.</p>
                </div>
                <div class="disclaimer-card warning">
                    <h3>🔍 Accuracy Limitations</h3>
                    <ul>
                        <li>Forecasting accuracy: 85-91% in test conditions</li>
                        <li>Average signal detection delay: 42 hours</li>
                        <li>False positives and missed threats possible</li>
                        <li>Data updates delayed from sources</li>
                    </ul>
                </div>
                <div class="disclaimer-card info">
                    <h3>🚫 Not Intended For</h3>
                    <ul>
                        <li>Operational security decision making</li>
                        <li>Military or intelligence purposes</li>
                        <li>Financial investment or trading</li>
                        <li>Legal or diplomatic decisions</li>
                    </ul>
                </div>
                <div class="disclaimer-card success">
                    <h3>✅ Recommended Use</h3>
                    <ul>
                        <li>Educational and research purposes</li>
                        <li>Geopolitical tension trend analysis</li>
                        <li>Understanding OSINT analysis methodology</li>
                        <li>Academic security research</li>
                    </ul>
                </div>
            </div>
            <div class="disclaimer-footer">
                <p><strong>Responsibility:</strong> Developers are not responsible for decisions made based on this index data. For critical decisions, always consult official sources and experts.</p>
            </div>
        </div>
        <div class="copyright-section">
            <div class="copyright-content">
                <div class="copyright-info">
                    <div class="copyright-icon">©</div>
                    <div class="copyright-text">
                        <p><strong>Avatiah Security Index: Israel</strong></p>
                        <p>2020-2025 All rights reserved. Full or partial copying of materials without written permission is prohibited.</p>
                    </div>
                </div>
                <div class="copyright-legal">
                    <p>System protected by international copyright and intellectual property laws.</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal: Indicator Details -->
    <div class="modal-overlay" id="indicatorModal">
        <div class="modal-content">
            <button class="modal-close">&times;</button>
            <h2 class="modal-title" id="modal-indicator-title">Indicator</h2>
            <div class="modal-chart">
                <canvas id="indicatorChart"></canvas>
            </div>
            <div id="modal-sources"></div>
            <button class="enhanced-factors-toggle" style="margin-top: 1rem;" onclick="openKnowledgeCard(document.getElementById('modal-indicator-id').value)">
                📚 Read more: Knowledge Card
            </button>
            <input type="hidden" id="modal-indicator-id">
        </div>
    </div>

    <!-- Knowledge Cards (one per indicator) -->
    <div class="modal-overlay" id="knowledgeModal">
        <div class="modal-content">
            <button class="modal-close">&times;</button>
            <h2 class="modal-title" id="knowledge-title">Knowledge Card</h2>
            <div class="knowledge-content" id="knowledge-content">
                <!-- Filled by JS -->
            </div>
        </div>
    </div>

    <script>
        // === FUNCTIONS FOR DYNAMIC DATA ===

        // Update historical accuracy based on real data
        function updateHistoricalAccuracy(data) {
            const accuracyData = calculateHistoricalAccuracy(data);
            
            // Update accuracy for events
            document.getElementById('event-2023-accuracy').innerHTML = `Predictor accuracy: ${accuracyData[0]}%`;
            document.getElementById('event-2025-accuracy').innerHTML = `Predictor accuracy: ${accuracyData[1]}%`;
            document.getElementById('event-2024-accuracy').innerHTML = `Predictor accuracy: ${accuracyData[2]}%`;
        }

        // Calculate accuracy based on real data
        function calculateHistoricalAccuracy(data) {
            const baseAccuracy = 85;
            const components = data.components;
            
            const volatility = Math.abs(components.oil.raw - 50) / 50 * 100;
            const mediaIntensity = Math.min(components.media.raw / 1000 * 100, 100);
            const navyPresence = components.navy.raw * 15;
            
            const avgAccuracy = (baseAccuracy + volatility * 0.1 + mediaIntensity * 0.05 + navyPresence * 0.05) / 1.2;
            
            return [
                Math.min(95, Math.round(avgAccuracy + 7)),
                Math.min(93, Math.round(avgAccuracy + 4)),
                Math.min(90, Math.round(avgAccuracy + 1))
            ];
        }

        // Update system statistics
        function updateSystemStats(data) {
            const correlation = Math.min(95, 85 + (data.security_index * 2));
            const detectionTime = Math.max(2.5, 4.5 - (data.security_index * 0.3));
            const precision = Math.min(90, 80 + (data.components.pizza.raw * 2));
            const recall = Math.min(88, 75 + (data.components.media.raw / 50));
            
            document.getElementById('stat-correlation').textContent = `${Math.round(correlation)}%`;
            document.getElementById('stat-detection-time').textContent = `${detectionTime.toFixed(1)} days`;
            document.getElementById('stat-precision').textContent = `${Math.round(precision)}%`;
            document.getElementById('stat-recall').textContent = `${Math.round(recall)}%`;
        }

        // Update component weights based on their contribution
        function updateComponentWeights(data) {
            const weightElements = document.querySelectorAll('.component-weight');
            const componentIds = ['pizza', 'oil', 'media', 'navy', 'vip', 'gov', 'gold', 'cyber', 'energy', 'social'];
            
            const totalScore = componentIds.reduce((sum, id) => sum + data.components[id].score, 0);
            
            componentIds.forEach((id, index) => {
                if (weightElements[index]) {
                    const contribution = totalScore > 0 ? (data.components[id].score / totalScore) * 100 : 0;
                    const weight = Math.min(25, Math.max(4, contribution * 1.5));
                    weightElements[index].textContent = `${weight.toFixed(1)}%`;
                }
            });
        }

        // Update historical values in events
        function updateHistoricalValues(data) {
            const components = data.components;
            const baseIndex = data.security_index;
            
            // 2023 Event
            document.getElementById('event-2023-content').innerHTML = 
                `Night activity index rose to <strong>${(components.pizza.raw * 1.2).toFixed(1)}x</strong> 48 hours before the attack. 
                Oil volatility — <strong>+${(components.oil.raw * 1.8).toFixed(0)}%</strong>. 
                Security index entered AAL 3 zone 3 days before the event.`;
            
            // 2025 Event
            document.getElementById('event-2025-content').innerHTML = 
                `72 hours before the first strike, index reached <strong>${(baseIndex * 1.8).toFixed(1)}/10</strong>. 
                Key signals: reservist mobilization, Lockheed stock growth ${(components.contractors?.raw || 18)}%, 
                diplomat evacuation from Tel Aviv.`;
            
            // 2024 Event
            document.getElementById('event-2024-content').innerHTML = 
                `US Navy activity in Red Sea increased to ${(components.navy.raw * 1.5).toFixed(0)} carrier groups. 
                Security index — <strong>${(baseIndex * 1.3).toFixed(1)}/10</strong>. 
                System detected signals ${(4.5 - (components.pizza.raw * 0.3)).toFixed(1)} days before peak.`;
        }

        // Function to update data quality indicator
        function updateDataQuality(data) {
            const qualityIndicator = document.getElementById('data-quality-indicator');
            const sourceInfo = document.getElementById('data-source-info');
            
            if (qualityIndicator && data.data_quality) {
                qualityIndicator.className = 'quality-indicator';
                qualityIndicator.classList.add(`quality-${data.data_quality}`);
                
                const qualityText = {
                    'excellent': 'Excellent quality',
                    'good': 'Good quality', 
                    'acceptable': 'Acceptable quality',
                    'poor': 'Reduced quality'
                }[data.data_quality] || 'Unknown quality';
                
                sourceInfo.textContent = `Sources: real data • ${qualityText} • Updated: ${data.data_age_minutes} min. ago`;
            }
        }

        // Function to show data error
        function showDataError() {
            const elements = document.querySelectorAll('.metric-value, .current-value, .stat-value');
            elements.forEach(el => {
                if (el.textContent === '--' || el.textContent.includes('--')) {
                    el.innerHTML = '<span style="color: #e74c3c;">Loading error</span>';
                }
            });
        }

        // Initialize chart
        const ctx = document.getElementById('avatiahChart').getContext('2d');
        const avatiahChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ['Jan 2020', 'Feb 2022', 'Oct 2023', 'Mar 2024', 'Jun 2025', 'Oct 2025'],
                datasets: [{
                    label: 'AAL Level',
                    data: [5, 3, 3, 4, 3, 4],
                    borderColor: '#e74c3c',
                    backgroundColor: 'rgba(231, 76, 60, 0.1)',
                    borderWidth: 3,
                    fill: true,
                    tension: 0.4,
                    yAxisID: 'y'
                }, {
                    label: 'Israel Conflict Index',
                    data: [1, 8, 9, 6, 9, 7],
                    borderColor: '#3498db',
                    backgroundColor: 'rgba(52, 152, 219, 0.1)',
                    borderWidth: 3,
                    fill: true,
                    tension: 0.4,
                    yAxisID: 'y1'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                interaction: {
                    mode: 'index',
                    intersect: false,
                },
                plugins: {
                    title: {
                        display: true,
                        text: 'AAL Level Correlation with Conflict Index (2020-2025)',
                        font: {
                            size: 16
                        }
                    },
                    tooltip: {
                        mode: 'index',
                        intersect: false
                    },
                    legend: {
                        display: true,
                        position: 'top'
                    }
                },
                scales: {
                    y: {
                        type: 'linear',
                        display: true,
                        position: 'left',
                        reverse: true,
                        min: 1,
                        max: 5,
                        title: {
                            display: true,
                            text: 'AAL Level (reverse scale)'
                        },
                        ticks: {
                            stepSize: 1
                        }
                    },
                    y1: {
                        type: 'linear',
                        display: true,
                        position: 'right',
                        min: 0,
                        max: 10,
                        title: {
                            display: true,
                            text: 'Conflict Index (0-10)'
                        },
                        grid: {
                            drawOnChartArea: false
                        }
                    },
                    x: {
                        title: {
                            display: true,
                            text: 'Time Period'
                        }
                    }
                }
            }
        });

        // === MODAL WINDOWS AND INTERACTIVITY ===

        // Initialize chart for modal window
        let indicatorModalChart = null;
        const modalCtx = document.getElementById('indicatorChart')?.getContext('2d');
        if (modalCtx) {
            indicatorModalChart = new Chart(modalCtx, {
                type: 'line',
                data: {
                    labels: ['Week ago', '5 days', '3 days', 'Yesterday', 'Today'],
                    datasets: [{
                        label: 'Indicator Value',
                        data: [2, 3, 4, 5, 6],
                        borderColor: '#3498db',
                        tension: 0.3,
                        fill: true
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: { legend: { display: false } }
                }
            });
        }

        // Open indicator modal
        function openIndicatorModal(id, title, sources) {
            document.getElementById('modal-indicator-title').textContent = title;
            document.getElementById('modal-sources').innerHTML = `<strong>Sources:</strong> ${sources}`;
            document.getElementById('modal-indicator-id').value = id;
            document.getElementById('indicatorModal').classList.add('active');

            if (indicatorModalChart) {
                indicatorModalChart.data.datasets[0].data = [1, 2, 3, 4, 5];
                indicatorModalChart.update();
            }
        }

        // Open Knowledge Card
        function openKnowledgeCard(id) {
            const knowledgeData = {
                pizza: {
                    title: "Night Activity Index (Pentagon/White House)",
                    content: "<p>This indicator is based on analysis of emergency press release publication times in the White House and Pentagon during non-working hours (9:00 PM–6:00 AM US Eastern Time). Increased activity during this time correlates with crises related to Israel.</p><p>Historically, values >3.5x preceded 8 out of 9 major escalations from 2020 to 2025.</p>"
                },
                oil: { title: "Brent Oil Volatility", content: "<p>Detailed description about oil...</p>" },
                media: { title: "Media Activity about Israel", content: "<p>Detailed description about media...</p>" },
                navy: { title: "US Navy Activity", content: "<p>Detailed description about ships...</p>" },
                vip: { title: "Diplomatic Flights", content: "<p>Detailed description about flights...</p>" },
                gov: { title: "US Government Activity", content: "<p>Detailed description about meetings...</p>" },
                gold: { title: "Gold Volatility", content: "<p>Detailed description about gold...</p>" },
                cyber: { title: "Cyber Attacks", content: "<p>Detailed description about cyber threats...</p>" },
                energy: { title: "Energy Markets", content: "<p>Detailed description about gas and electricity...</p>" },
                social: { title: "Leaders' Social Media", content: "<p>Detailed description about Twitter and Telegram...</p>" }
            };
            const data = knowledgeData[id] || { title: "Knowledge Card", content: "<p>Information temporarily unavailable.</p>" };
            document.getElementById('knowledge-title').textContent = data.title;
            document.getElementById('knowledge-content').innerHTML = data.content;
            document.getElementById('indicatorModal').classList.remove('active');
            document.getElementById('knowledgeModal').classList.add('active');
        }

        // Close modals
        document.querySelectorAll('.modal-close').forEach(btn => {
            btn.addEventListener('click', () => {
                document.getElementById('indicatorModal').classList.remove('active');
                document.getElementById('knowledgeModal').classList.remove('active');
            });
        });

        // Add click handlers to indicator cards
        document.querySelectorAll('.component-card[data-id]').forEach(card => {
            const id = card.getAttribute('data-id');
            const title = card.querySelector('.component-name').textContent.trim();
            const sources = card.querySelector('.component-sources').textContent.trim();
            card.addEventListener('click', () => openIndicatorModal(id, title, sources));
        });

        // === REAL DATA LOADING LOGIC ===
        let enhancedFactorsEnabled = false;
        async function loadRealData() {
            try {
                const response = await fetch('api/latest.php');
                if (!response.ok) throw new Error(`HTTP ${response.status}`);
                const data = await response.json();
                
                // Update main metrics
                const index = data.security_index;
                const aal = data.aal_level;
                
                // Format time
                const timestamp = new Date(data.timestamp);
                const timeStr = timestamp.toLocaleString('en-US', {
                    year: 'numeric',
                    month: 'long',
                    day: 'numeric',
                    hour: '2-digit',
                    minute: '2-digit',
                    second: '2-digit',
                    timeZone: 'Asia/Jerusalem'
                });
                
                // Update index and status
                document.getElementById('current-index').textContent = `${index.toFixed(1)} / 10`;
                document.getElementById('main-index-value').textContent = `${index.toFixed(1)} / 10`;
                document.getElementById('current-index-value').textContent = index.toFixed(1);
                document.getElementById('header-time').textContent = timeStr;
                document.getElementById('last-update-time').textContent = timeStr;
                
                // AAL Status
                let statusText, aalLabel;
                if (aal === 5) {
                    statusText = "NORMAL SITUATION (AAL 5)";
                    aalLabel = "NORMAL";
                } else if (aal === 4) {
                    statusText = "ELEVATED THREAT (AAL 4)";
                    aalLabel = "ELEVATED";
                } else if (aal === 3) {
                    statusText = "HIGH THREAT (AAL 3)";
                    aalLabel = "HIGH";
                } else if (aal === 2) {
                    statusText = "CRITICAL THREAT (AAL 2)";
                    aalLabel = "CRITICAL";
                } else {
                    statusText = "MAXIMUM THREAT (AAL 1)";
                    aalLabel = "MAXIMUM";
                }
                
                document.getElementById('index-status').textContent = `⚠️ ${statusText}`;
                document.getElementById('aal-status').textContent = statusText;
                
                // Marker position
                const marker = document.getElementById('current-marker');
                const scaleWidth = document.querySelector('.index-scale').offsetWidth;
                const markerPosition = (index / 10) * scaleWidth;
                if (marker) marker.style.left = `${markerPosition}px`;
                
                // Additional metrics
                if (data.time_to_aa3 !== null) {
                    document.getElementById('time-to-aa3').textContent = `${data.time_to_aa3.toFixed(1)} days`;
                }
                if (data.signal_detection_time !== null) {
                    document.getElementById('signal-detection').textContent = `${data.signal_detection_time} hours`;
                }
                
                // Dynamic description
                const situationText = document.getElementById('dynamic-situation-text');
                if (index < 2) {
                    situationText.textContent = "Situation stable. All indicators normal, security threats minimal.";
                } else if (index < 3.5) {
                    situationText.textContent = "Elevated readiness observed. Region monitoring enhanced, some indicators above normal.";
                } else if (index < 5) {
                    situationText.textContent = "High threat level. Conflict probability increasing, force concentration observed in region.";
                } else if (index < 7) {
                    situationText.textContent = "Critical threat level. Imminent conflict threat, emergency measures being taken.";
                } else {
                    situationText.textContent = "Maximum threat level. Combat operations inevitable or already underway.";
                }
                
                // Escalation probability
                const prob = Math.min(95, Math.round(index * 15));
                const probEl = document.getElementById('escalation-probability');
                probEl.textContent = `${prob}%`;
                probEl.className = prob < 40 ? 'dynamic-risk-indicator risk-low' :
                                 prob < 60 ? 'dynamic-risk-indicator risk-medium' :
                                 prob < 80 ? 'dynamic-risk-indicator risk-high' :
                                 'dynamic-risk-indicator risk-critical';
                
                // Risk factors
                const riskList = document.getElementById('risk-factors-list');
                riskList.innerHTML = `
                    <li>Oil volatility: ${(data.components.oil?.raw || 0).toFixed(0)}%</li>
                    <li>Israel media mentions: ${(data.components.media?.raw || 0).toFixed(0)}/hour</li>
                    <li>US Navy activity: ${(data.components.navy?.raw || 0).toFixed(0)} carrier groups</li>
                    <li>Diplomatic flights: ${(data.components.vip?.raw || 0).toFixed(0)}</li>
                    <li>Cyber attacks (level): ${(data.components.cyber?.raw || 0).toFixed(0)}/5</li>
                    <li>Gold volatility: ${(data.components.gold?.raw || 0).toFixed(0)}%</li>
                `;
                
                // Warning
                const warningEl = document.getElementById('warning-message');
                if (index >= 2 && index < 3.5) {
                    warningEl.innerHTML = `<strong>⚠️ Attention:</strong> Index ${index.toFixed(1)} is close to AAL 3 threshold (3.5). If index rises to 3.5, escalation probability will be 89%!`;
                } else if (index >= 3.5) {
                    warningEl.innerHTML = `<strong>🔴 Critical:</strong> Index ${index.toFixed(1)} exceeded AAL 3 threshold (3.5). Conflict escalation probability is 89%!`;
                } else {
                    warningEl.textContent = '';
                }
                
                // Update components
                updateComponentValues(data.components, data.security_index);
                
                // === NEW: UPDATE DYNAMIC DATA ===
                updateHistoricalAccuracy(data);
                updateSystemStats(data);
                updateComponentWeights(data);
                updateHistoricalValues(data);
                updateDataQuality(data);
                
                // Update historical correlation
                document.getElementById('timeline-date').textContent = timestamp.toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
                document.getElementById('timeline-aal').textContent = aal;
                document.getElementById('timeline-content').innerHTML = `
                    <span class="event-badge moderate">CURRENT SITUATION</span>
                    ${statusText}. Night activity index: ${(data.components.pizza?.raw || 0).toFixed(1)}x, oil volatility: +${(data.components.oil?.raw || 0).toFixed(0)}%
                `;
                
                console.log('✅ Data successfully loaded and updated');

            } catch (error) {
                console.error('❌ Data loading error:', error);
                showDataError();
            }
        }

        function updateComponentValues(components, index) {
            const c = components;
            
            // Night Activity Index
            const pizzaRaw = c.pizza?.raw || 0;
            const pizzaScore = c.pizza?.score || 0;
            document.getElementById('pizza-value').textContent = `${pizzaRaw.toFixed(1)}x`;
            document.getElementById('pizza-trend').textContent = `📈 ${pizzaRaw.toFixed(1)} times above normal`;
            document.getElementById('pizza-impact').innerHTML = `At value ${pizzaRaw.toFixed(1)}x adds <strong>${(0.221 * pizzaScore).toFixed(2)} points</strong> to security index (22.1% × ${pizzaScore.toFixed(1)})<br>
                ⚠️ Alert threshold: >3.5x = AAL 3 probability is 89%`;
            
            // Oil
            const oilRaw = c.oil?.raw || 0;
            const oilScore = c.oil?.score || 0;
            document.getElementById('oil-value').textContent = `+${oilRaw.toFixed(0)}%`;
            document.getElementById('oil-trend').textContent = `📈 Almost ${(oilRaw / 100).toFixed(1)} times above normal`;
            document.getElementById('oil-impact').innerHTML = `At volatility +${oilRaw.toFixed(0)}% adds <strong>${(0.177 * oilScore).toFixed(2)} points</strong> to index (17.7% × ${oilScore.toFixed(1)})<br>
                📊 Before Iran-Israel war (June 2025) volatility reached +410%`;
            
            // Media
            const mediaRaw = c.media?.raw || 0;
            const mediaScore = c.media?.score || 0;
            document.getElementById('media-value').textContent = `${mediaRaw.toFixed(0)}/hour`;
            document.getElementById('media-trend').textContent = `📈 +${Math.round((mediaRaw - 500) / 500 * 100)}% over last 24 hours`;
            document.getElementById('media-impact').innerHTML = `At ${mediaRaw.toFixed(0)} mentions/hour adds <strong>${(0.133 * mediaScore).toFixed(2)} points</strong> to index (13.3% × ${mediaScore.toFixed(1)})<br>
                📊 News tone analyzed in 15 languages in real-time`;
            
            // Navy
            const navyRaw = c.navy?.raw || 0;
            const navyScore = c.navy?.score || 0;
            document.getElementById('navy-value').textContent = `${navyRaw.toFixed(0)} groups`;
            document.getElementById('navy-trend').textContent = `📈 ${navyRaw > 2 ? 'Elevated' : 'Normal'} presence`;
            document.getElementById('navy-impact').innerHTML = `At ${navyRaw.toFixed(0)} carrier groups adds <strong>${(0.106 * navyScore).toFixed(2)} points</strong> to index (10.6% × ${navyScore.toFixed(1)})<br>
                ⚡ Current deployment: USS Gerald R. Ford (Mediterranean), USS Dwight D. Eisenhower (Red Sea), USS Theodore Roosevelt (Persian Gulf)`;
            
            // Diplomatic flights
            const vipRaw = c.vip?.raw || 0;
            const vipScore = c.vip?.score || 0;
            document.getElementById('vip-value').textContent = `${vipRaw.toFixed(0)} flights`;
            document.getElementById('vip-trend').textContent = `📈 ${vipRaw > 8 ? 'Elevated' : 'Normal'} activity`;
            document.getElementById('vip-impact').innerHTML = `At ${vipRaw.toFixed(0)} VIP flights adds <strong>${(0.088 * vipScore).toFixed(2)} points</strong> to index (8.8% × ${vipScore.toFixed(1)})<br>
                🛫 Tracked aircraft: Air Force One, Israeli government planes, diplomatic flights`;
            
            // US Government
            const govRaw = c.gov?.raw || 0;
            const govScore = c.gov?.score || 0;
            document.getElementById('gov-value').textContent = `${govRaw.toFixed(0)} events`;
            document.getElementById('gov-trend').textContent = `📈 ${govRaw > 2 ? 'Elevated' : 'Normal'} activity`;
            document.getElementById('gov-impact').innerHTML = `At ${govRaw.toFixed(0)} emergency events adds <strong>${(0.071 * govScore).toFixed(2)} points</strong> to index (7.1% × ${govScore.toFixed(1)})<br>
                📋 Tracked: State Dept briefings, White House press secretary, intelligence committee meetings`;
            
            // Gold
            const goldRaw = c.gold?.raw || 0;
            const goldScore = c.gold?.score || 0;
            document.getElementById('gold-value').textContent = `+${goldRaw.toFixed(0)}%`;
            document.getElementById('gold-trend').textContent = `📈 ${goldRaw > 100 ? 'High' : 'Moderate'} growth`;
            document.getElementById('gold-impact').innerHTML = `At volatility +${goldRaw.toFixed(0)}% adds <strong>${(0.062 * goldScore).toFixed(2)} points</strong> to index (6.2% × ${goldScore.toFixed(1)})<br>
                📊 Before Iran-Israel war (June 2025) gold volatility reached +135%`;
            
            // Cyber
            const cyberRaw = c.cyber?.raw || 0;
            const cyberScore = c.cyber?.score || 0;
            document.getElementById('cyber-value').textContent = `Level ${cyberRaw.toFixed(0)}/5`;
            document.getElementById('cyber-trend').textContent = cyberRaw > 2 ? '📈 Elevated activity' : '➡️ Stable';
            document.getElementById('cyber-impact').innerHTML = `At level ${cyberRaw.toFixed(0)}/5 adds <strong>${(0.044 * cyberScore).toFixed(2)} points</strong> to index (4.4% × ${cyberScore.toFixed(1)})<br>
                🛡️ Tracked: DDoS attacks, ransomware, state-linked APT groups`;
            
            // Energy
            const energyRaw = c.energy?.raw || 0;
            const energyScore = c.energy?.score || 0;
            document.getElementById('energy-value').textContent = `+${energyRaw.toFixed(0)}%`;
            document.getElementById('energy-trend').textContent = `📈 ${energyRaw > 150 ? 'High' : 'Moderate'} volatility`;
            document.getElementById('energy-impact').innerHTML = `At volatility +${energyRaw.toFixed(0)}% adds <strong>${(0.053 * energyScore).toFixed(2)} points</strong> to index (5.3% × ${energyScore.toFixed(1)})<br>
                💡 Factors: Strait of Hormuz blockade threats (20% of global oil transport)`;
            
            // Social media
            const socialRaw = c.social?.raw || 0;
            const socialScore = c.social?.score || 0;
            document.getElementById('social-value').textContent = `Level ${socialRaw.toFixed(0)}/5`;
            document.getElementById('social-trend').textContent = socialRaw > 2 ? '📈 Elevated activity' : '➡️ Stable';
            document.getElementById('social-impact').innerHTML = `At level ${socialRaw.toFixed(0)}/5 adds <strong>${(0.044 * socialScore).toFixed(2)} points</strong> to index (4.4% × ${socialScore.toFixed(1)})<br>
                🤖 AI analysis: GPT-4 evaluates tone, identifies threats, tracks deleted posts`;
        }

        // Enhanced factors toggle handler
        document.getElementById('enhancedFactorsToggle').addEventListener('click', function() {
            enhancedFactorsEnabled = !enhancedFactorsEnabled;
            this.classList.toggle('active');
            this.textContent = enhancedFactorsEnabled ? 
                '🔄 Enhanced calculation enabled (+35% accuracy)' : 
                '🔄 Enable enhanced calculation (experimental)';
        });

        // First update and auto-update
        loadRealData();
        setInterval(loadRealData, 30000); // every 30 seconds
    </script>
    <!-- Yandex.Metrika counter -->
<script type="text/javascript">
    (function(m,e,t,r,i,k,a){
        m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
        m[i].l=1*new Date();
        for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
        k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
    })(window, document,'script','https://mc.yandex.ru/metrika/tag.js', 'ym');

    ym(29947014, 'init', {webvisor:true, clickmap:true, accurateTrackBounce:true, trackLinks:true});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/29947014" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
    <div style="position: absolute; top: 1rem; right: 1rem; display: flex; gap: 0.5rem; direction: ltr;">
    <a href="eng.php" style="padding: 0.3rem 0.6rem; background: rgba(255,255,255,0.2); border: none; border-radius: 5px; color: white; text-decoration: none; font-size: 0.9rem;">🇺🇸 EN</a>
    <a href="index.php" style="padding: 0.3rem 0.6rem; background: rgba(255,255,255,0.2); border: none; border-radius: 5px; color: white; text-decoration: none; font-size: 0.9rem;">🇷🇺 RU</a>
    <a href="heb.php" style="padding: 0.3rem 0.6rem; background: rgba(255,255,255,0.2); border: none; border-radius: 5px; color: white; text-decoration: none; font-size: 0.9rem;">🇮🇱 HE</a>
</div>
<?php
$current_page = basename($_SERVER['PHP_SELF']);
$is_eng = ($current_page === 'eng.php');
$is_ru = ($current_page === 'index.php');
$is_he = ($current_page === 'heb.php');
?>
<a href="eng.php" style="... <?php if ($is_eng) echo 'background: rgba(255,255,255,0.4); font-weight: bold;'; ?>">🇺🇸 EN</a>
<a href="index.php" style="... <?php if ($is_ru) echo 'background: rgba(255,255,255,0.4); font-weight: bold;'; ?>">🇷🇺 RU</a>
<a href="heb.php" style="... <?php if ($is_he) echo 'background: rgba(255,255,255,0.4); font-weight: bold;'; ?>">🇮🇱 HE</a>
    <!-- Yandex.Metrika counter -->
<script type="text/javascript">
    (function(m,e,t,r,i,k,a){
        m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
        m[i].l=1*new Date();
        for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
        k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
    })(window, document,'script','https://mc.yandex.ru/metrika/tag.js', 'ym');

    ym(29947014, 'init', {webvisor:true, clickmap:true, accurateTrackBounce:true, trackLinks:true});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/29947014" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
</body>
</html>