{{- /* 1. Host & Production Environment Guard */ -}}
{{- $host := "status.nemo.zone" -}}
{{- if and .Req .Req.Host -}}
  {{- $host = lower .Req.Host -}}
{{- else if .Host -}}
  {{- $host = lower .Host -}}
{{- end -}}
{{- $isProdHost := or (eq $host "status.nemo.zone") (and (hasSuffix ".nemo.zone" $host) (not (hasPrefix "dev." $host)) (not (contains ".dev." $host))) -}}

{{- /* 2. Path & Query Parsing */ -}}
{{- $reqPath := "/" -}}
{{- $rawQuery := "" -}}
{{- if and .Req .Req.URL -}}
  {{- $reqPath = .Req.URL.Path -}}
  {{- $rawQuery = lower .Req.URL.RawQuery -}}
{{- end -}}

{{- /* 3. Language Resolution: explicit ?hl= first, then Accept-Language, default ko for bots */ -}}
{{- $hlParam := "" -}}
{{- if or (contains "hl=ko" $rawQuery) (contains "lang=ko" $rawQuery) -}}
  {{- $hlParam = "ko" -}}
{{- else if or (contains "hl=ja" $rawQuery) (contains "lang=ja" $rawQuery) -}}
  {{- $hlParam = "ja" -}}
{{- else if or (contains "hl=en" $rawQuery) (contains "lang=en" $rawQuery) -}}
  {{- $hlParam = "en" -}}
{{- end -}}
{{- $acceptLang := "" -}}
{{- if and .Req .Req.Header -}}
  {{- $acceptLang = lower (.Req.Header.Get "Accept-Language") -}}
{{- end -}}
{{- $isJa := or (eq $hlParam "ja") (and (eq $hlParam "") (hasPrefix "ja" $acceptLang)) -}}
{{- $isEn := or (eq $hlParam "en") (and (eq $hlParam "") (not $isJa) (not (contains "ko" $acceptLang)) (ne $acceptLang "")) -}}
{{- $isKo := and (not $isJa) (not $isEn) -}}

{{- /* 4. Canonical & Alternate URLs */ -}}
{{- $canonicalPath := "/" -}}
{{- $baseCanonicalUrl := printf "https://status.nemo.zone%s" $canonicalPath -}}
{{- $enAlternateUrl := printf "%s?hl=en" $baseCanonicalUrl -}}
{{- $jaAlternateUrl := printf "%s?hl=ja" $baseCanonicalUrl -}}
{{- $canonicalUrl := $baseCanonicalUrl -}}
{{- if eq $hlParam "en" -}}
  {{- $canonicalUrl = $enAlternateUrl -}}
{{- else if eq $hlParam "ja" -}}
  {{- $canonicalUrl = $jaAlternateUrl -}}
{{- end -}}
{{- $isPublicPage := and $isProdHost (or (eq $reqPath "/") (eq $reqPath "/index.html")) -}}
<!DOCTYPE html>
<html lang="{{ if $isJa }}ja{{ else if $isKo }}ko{{ else }}en{{ end }}">
<head>
  <base href="/">
  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">

  {{- $pageTitle := "시스템 상태 | Nemo 실시간 서비스 가동 현황" -}}
  {{- $pageDesc := "Nemo 플랫폼 및 모든 마이크로서비스·콘솔의 실시간 가동 상태, 응답 지연 시간, 점검 일정 및 장애 히스토리를 확인하세요." -}}
  {{- $pageKeywords := "시스템 상태, Nemo 상태, 가동률, 서비스 장애, 점검 현황, System Status, Nemo" -}}
  {{- if $isKo -}}
    {{- $pageTitle = "시스템 상태 | Nemo 실시간 서비스 가동 현황" -}}
    {{- $pageDesc = "Nemo 플랫폼 및 모든 마이크로서비스·콘솔의 실시간 가동 상태, 응답 지연 시간, 점검 일정 및 장애 히스토리를 확인하세요." -}}
    {{- $pageKeywords = "시스템 상태, Nemo 상태, 가동률, 서비스 장애, 점검 현황, System Status, Nemo" -}}
  {{- else if $isJa -}}
    {{- $pageTitle = "システムステータス | Nemo リアルタイム稼働状況" -}}
    {{- $pageDesc = "Nemoプラットフォームおよび全マイクロサービス・コンソールのリアルタイム稼働状況、応答レイテンシ、メンテナンス予定、障害履歴を確認できます。" -}}
    {{- $pageKeywords = "システムステータス, Nemo, 稼働状況, サービス状態, メンテナンス, System Status" -}}
  {{- else -}}
    {{- $pageTitle = "System Status | Nemo Live Service Health" -}}
    {{- $pageDesc = "Monitor live service health, latency, scheduled maintenance, and incident history across the Nemo platform and all microservices." -}}
    {{- $pageKeywords = "System Status, Nemo Status, Service Health, Uptime, Incident History, Nemo" -}}
  {{- end -}}

  <title>{{$pageTitle}}</title>
  <meta name="description" content="{{$pageDesc}}">
  <meta name="keywords" content="{{$pageKeywords}}">
  <meta property="og:title" content="{{$pageTitle}}">
  <meta property="og:description" content="{{$pageDesc}}">
  <meta property="og:locale" content="{{ if $isJa }}ja_JP{{ else if $isKo }}ko_KR{{ else }}en_US{{ end }}">
  <meta property="og:type" content="website">
  <meta property="og:site_name" content="Nemo">
  <meta property="og:url" content="{{$canonicalUrl}}">
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="{{$pageTitle}}">
  <meta name="twitter:description" content="{{$pageDesc}}">

  {{- if $isPublicPage -}}
    <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1">
  {{- else -}}
    <meta name="robots" content="noindex, nofollow, noarchive">
  {{- end -}}
  <link rel="canonical" href="{{$canonicalUrl}}">
  <link rel="alternate" hreflang="ko" href="{{$baseCanonicalUrl}}">
  <link rel="alternate" hreflang="en" href="{{$enAlternateUrl}}">
  <link rel="alternate" hreflang="ja" href="{{$jaAlternateUrl}}">
  <link rel="alternate" hreflang="x-default" href="{{$baseCanonicalUrl}}">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="apple-mobile-web-app-title" content="Status">
  <meta name="theme-color" media="(prefers-color-scheme: dark)" content="#0C0C0E">
  <meta name="theme-color" media="(prefers-color-scheme: light)" content="#F8FAFC">
  <link rel="manifest" href="manifest.json">
  <link rel="icon" type="image/svg+xml" href="favicon.svg">
  <link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
  <link rel="shortcut icon" href="favicon.ico">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard-dynamic-subset.css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Noto+Sans+KR:wght@400;500;600;700;800;900&display=swap">
  <script>
    window.setDocumentTitle = function(title) {
      try {
        document.title = title;
      } catch (e) {}
    };

    window.isBrowserOnline = function() {
      return navigator.onLine !== false;
    };
  </script>
  <style>
    body {
      inset: 0;
      overflow: hidden;
      margin: 0;
      padding: 0;
      position: fixed;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
      background-color: #0C0C0E;
      font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    }
  </style>
</head>
<body>
  <div id="nemo-app-loading" style="position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#0C0C0E;z-index:9999;transition:opacity 0.25s ease-out;font-family:'Pretendard',sans-serif;pointer-events:none;">
    <style>
      @media (prefers-color-scheme: light) {
        #nemo-app-loading { background: #FFFFFF !important; }
      }
      .status-pulse {
        width: 48px;
        height: 48px;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .status-pulse-core {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: #10B981;
      }
      .status-pulse-ring {
        position: absolute;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        border: 2px solid #10B981;
        opacity: 0.75;
        animation: pulseRing 1.8s cubic-bezier(0.24, 0, 0.38, 1) infinite;
      }
      @keyframes pulseRing {
        0% { transform: scale(0.4); opacity: 0.9; }
        100% { transform: scale(1.2); opacity: 0; }
      }
    </style>
    <div class="status-pulse">
      <div class="status-pulse-ring"></div>
      <div class="status-pulse-core"></div>
    </div>
  </div>
  <script>
    (function() {
      function dismissLoader() {
        var el = document.getElementById('nemo-app-loading');
        if (el) {
          el.style.opacity = '0';
          el.style.pointerEvents = 'none';
          el.style.display = 'none';
          if (el.parentNode) {
            el.parentNode.removeChild(el);
          }
        }
      }
      window.addEventListener('flutter-first-frame', dismissLoader);
      setTimeout(dismissLoader, 20000);
    })();
  </script>
  <script src="flutter_bootstrap.js" async></script>
</body>
</html>
