/* ========================================
   Service Dashboard — CSS Design System
   ======================================== */

/* --- リセット & ベース --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* カラーパレット */
  --bg-primary: #0b0f1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.04);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-color: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  /* アクセントカラー */
  --accent: #6366f1;
  --accent-light: #818cf8;
  --cyan: #06b6d4;
  --gradient-primary: linear-gradient(135deg, #6366f1, #06b6d4);

  /* ステータスカラー */
  --status-online: #22c55e;
  --status-online-bg: rgba(34, 197, 94, 0.12);
  --status-online-glow: rgba(34, 197, 94, 0.3);

  --status-degraded: #f59e0b;
  --status-degraded-bg: rgba(245, 158, 11, 0.12);
  --status-degraded-glow: rgba(245, 158, 11, 0.3);

  --status-offline: #ef4444;
  --status-offline-bg: rgba(239, 68, 68, 0.12);
  --status-offline-glow: rgba(239, 68, 68, 0.3);

  --status-unknown: #64748b;
  --status-unknown-bg: rgba(100, 116, 139, 0.12);

  /* タイポグラフィ */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;

  /* スペーシング */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* ボーダー半径 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* トランジション */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* シャドウ */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* 背景グラデーション */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(6, 182, 212, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- ヘッダー --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 15, 26, 0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border-color);
}

.header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header__logo {
  display: flex;
  align-items: center;
}

.header__title {
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header__status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-glass);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-unknown);
  transition: background var(--transition-base);
}

.header__status--connected .header__status-dot {
  background: var(--status-online);
  box-shadow: 0 0 8px var(--status-online-glow);
  animation: pulse 2s ease-in-out infinite;
}

.header__status--error .header__status-dot {
  background: var(--status-offline);
}

/* --- ボタン --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  font-family: var(--font-family);
  transition: all var(--transition-fast);
}

.btn--icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn--icon:active {
  transform: scale(0.95);
}

.btn--icon.spinning svg {
  animation: spin 0.8s linear infinite;
}

/* --- サマリーバー --- */
.summary {
  max-width: 1400px;
  margin: var(--space-lg) auto 0;
  padding: 0 var(--space-lg);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

.summary__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition: all var(--transition-base);
}

.summary__card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}

.summary__value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.summary__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: var(--space-xs);
}

.summary__card--online .summary__value { color: var(--status-online); }
.summary__card--degraded .summary__value { color: var(--status-degraded); }
.summary__card--offline .summary__value { color: var(--status-offline); }

/* --- メインコンテンツ --- */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg);
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-md);
}

/* --- サービスカード --- */
.service-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: var(--space-lg);
  transition: all var(--transition-base);
  animation: fadeInUp 0.4s ease backwards;
  position: relative;
  overflow: hidden;
}

.service-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-primary);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.service-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.service-card:hover::before {
  opacity: 1;
}

.service-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.service-card__info {
  flex: 1;
  min-width: 0;
}

.service-card__name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.service-card__type {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ステータスバッジ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.status-badge--online {
  background: var(--status-online-bg);
  color: var(--status-online);
}

.status-badge--degraded {
  background: var(--status-degraded-bg);
  color: var(--status-degraded);
}

.status-badge--offline {
  background: var(--status-offline-bg);
  color: var(--status-offline);
}

.status-badge--unknown {
  background: var(--status-unknown-bg);
  color: var(--status-unknown);
}

.status-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge--online .status-badge__dot {
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 6px currentColor;
}

/* メトリクス */
.service-card__metrics {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.metric-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.metric-tag__label {
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-tag__value {
  color: var(--accent-light);
  font-weight: 500;
}

/* 最終確認 */
.service-card__footer {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.service-card__last-seen {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.service-card__last-seen--stale {
  color: var(--status-degraded);
}

/* --- 空状態 --- */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  animation: fadeInUp 0.5s ease;
}

.empty-state__icon {
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
  opacity: 0.5;
}

.empty-state__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.empty-state__desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: var(--space-lg);
}

.empty-state__code {
  display: inline-block;
  text-align: left;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cyan);
  overflow-x: auto;
  max-width: 100%;
}

/* --- フッター --- */
.footer {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  width: 100%;
}

/* --- アニメーション --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

/* カードのスタッガードアニメーション */
.service-card:nth-child(1) { animation-delay: 0ms; }
.service-card:nth-child(2) { animation-delay: 50ms; }
.service-card:nth-child(3) { animation-delay: 100ms; }
.service-card:nth-child(4) { animation-delay: 150ms; }
.service-card:nth-child(5) { animation-delay: 200ms; }
.service-card:nth-child(6) { animation-delay: 250ms; }
.service-card:nth-child(7) { animation-delay: 300ms; }
.service-card:nth-child(8) { animation-delay: 350ms; }

/* --- レスポンシブ --- */
@media (max-width: 768px) {
  .summary {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .header__inner {
    padding: var(--space-sm) var(--space-md);
  }

  .main {
    padding: var(--space-md);
  }

  .summary {
    padding: 0 var(--space-md);
  }

  .summary__value {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .header__title {
    font-size: 1rem;
  }

  .service-card {
    padding: var(--space-md);
  }
}
