/* ======================================
   shadcn/ui 風デザインシステム
   HSLベースのカラートークン
   ====================================== */

:root {
  /* shadcn neutral (zinc ベース) */
  --background: 0 0% 3.9%;
  --foreground: 0 0% 98%;
  --card: 0 0% 5.5%;
  --card-foreground: 0 0% 98%;
  --popover: 0 0% 5.5%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 0 0% 9%;
  --secondary: 0 0% 14.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 0 0% 14.9%;
  --muted-foreground: 0 0% 63.9%;
  --accent: 0 0% 14.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 0% 98%;
  --border: 0 0% 14.9%;
  --input: 0 0% 14.9%;
  --ring: 0 0% 83.1%;

  /* セマンティックカラー */
  --green: 142 71% 45%;
  --blue: 217 91% 60%;
  --orange: 38 92% 50%;
  --red: 0 84% 60%;

  /* 共通 */
  --radius: 0.5rem;
  --font-sans: 'Inter', 'Noto Sans JP', ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

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

body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
}

a {
  color: hsl(var(--muted-foreground));
  text-decoration: none;
  transition: color 0.15s;
}
a:hover {
  color: hsl(var(--foreground));
}

/* ======================================
   レイアウト
   ====================================== */
.layout {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ======================================
   トップバー
   ====================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 32px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: hsl(var(--foreground));
  letter-spacing: -0.01em;
}

.topbar-logo svg {
  color: hsl(var(--muted-foreground));
}

/* ステータスインジケーター */
.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  padding: 3px 10px;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: hsl(var(--muted-foreground));
}

.topbar-status.online .status-indicator {
  background: hsl(var(--green));
  box-shadow: 0 0 0 2px hsl(var(--green) / 0.2);
}
.topbar-status.online {
  color: hsl(var(--green));
  border-color: hsl(var(--green) / 0.2);
}

.topbar-status.fetching .status-indicator {
  background: hsl(var(--orange));
  animation: blink 1s ease-in-out infinite;
}
.topbar-status.fetching {
  color: hsl(var(--orange));
  border-color: hsl(var(--orange) / 0.2);
}

.topbar-status.error .status-indicator {
  background: hsl(var(--red));
}
.topbar-status.error {
  color: hsl(var(--red));
  border-color: hsl(var(--red) / 0.2);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ナビリンク */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  background: transparent;
  transition: all 0.15s;
}
.nav-link:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

/* ======================================
   ページヘッダー
   ====================================== */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.page-description {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  margin-top: 4px;
}

/* ======================================
   グリッド
   ====================================== */
.grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

/* ======================================
   カード
   ====================================== */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 9999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
}

/* ======================================
   メトリクスカード
   ====================================== */
.card-metric {
  margin-bottom: 0;
}

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

.metric-label {
  font-size: 12px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.metric-icon {
  color: hsl(var(--muted-foreground));
  opacity: 0.5;
}

.metric-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: 'tnum';
}

.metric-value-sm {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.4;
}

.metric-sub {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* タグ */
.tag {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  font-feature-settings: 'tnum';
}

.tag-blue {
  background: hsl(var(--blue) / 0.12);
  color: hsl(var(--blue));
}

.tag-green {
  background: hsl(var(--green) / 0.12);
  color: hsl(var(--green));
}

/* ======================================
   URLボックス
   ====================================== */
.url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
}

.url-box code {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  word-break: break-all;
}

.hint {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  margin-top: 8px;
}

/* ======================================
   ボタン
   ====================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-default {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-default:hover {
  opacity: 0.9;
}

.btn-outline {
  background: transparent;
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}
.btn-outline:hover {
  background: hsl(var(--accent));
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--muted-foreground));
  border: none;
  padding: 0;
  height: auto;
  width: 28px;
  min-width: 28px;
}
.btn-ghost:hover {
  color: hsl(var(--foreground));
}
.btn-ghost.copied {
  color: hsl(var(--green));
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ======================================
   アラート（フェッチ結果）
   ====================================== */
.alert {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 13px;
  border: 1px solid transparent;
}

.alert.hidden { display: none; }

.alert-info {
  background: hsl(var(--blue) / 0.08);
  color: hsl(var(--blue));
  border-color: hsl(var(--blue) / 0.15);
}

.alert-success {
  background: hsl(var(--green) / 0.08);
  color: hsl(var(--green));
  border-color: hsl(var(--green) / 0.15);
}

.alert-error {
  background: hsl(var(--red) / 0.08);
  color: hsl(var(--red));
  border-color: hsl(var(--red) / 0.15);
}

/* ======================================
   チャート
   ====================================== */
.chart-container {
  position: relative;
  height: 220px;
}

/* ======================================
   獣種統計（水平バーチャート）
   ====================================== */
.species-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.species-row {
  display: grid;
  grid-template-columns: 100px 1fr 60px;
  align-items: center;
  gap: 12px;
}

.species-name {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  font-weight: 500;
}

.species-bar-track {
  height: 8px;
  background: hsl(var(--muted));
  border-radius: 9999px;
  overflow: hidden;
}

.species-bar-fill {
  height: 100%;
  background: hsl(var(--foreground));
  border-radius: 9999px;
  transition: width 0.5s ease;
  opacity: 0.6;
}

.species-value {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  font-feature-settings: 'tnum';
}

/* ======================================
   テーブル
   ====================================== */
.table-container {
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
}

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

.table th {
  background: hsl(var(--muted) / 0.5);
  color: hsl(var(--muted-foreground));
  font-weight: 500;
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}

.table td {
  padding: 8px 12px;
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
}

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

.table tbody tr:hover td {
  background: hsl(var(--muted) / 0.3);
}

.text-right { text-align: right; }
.text-muted { color: hsl(var(--muted-foreground)); }
.tabular { font-feature-settings: 'tnum'; }

/* バッジ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid transparent;
}

.badge-ckan {
  background: hsl(var(--blue) / 0.1);
  color: hsl(var(--blue));
  border-color: hsl(var(--blue) / 0.15);
}

.badge-kumadas {
  background: hsl(var(--green) / 0.1);
  color: hsl(var(--green));
  border-color: hsl(var(--green) / 0.15);
}

.badge-ok {
  background: hsl(var(--green) / 0.1);
  color: hsl(var(--green));
}

.badge-err {
  background: hsl(var(--red) / 0.1);
  color: hsl(var(--red));
}

/* ======================================
   プレースホルダー
   ====================================== */
.placeholder {
  color: hsl(var(--muted-foreground));
  text-align: center;
  padding: 16px;
  font-size: 13px;
}

/* ======================================
   フッター
   ====================================== */
.footer {
  padding: 20px 0;
  margin-top: 8px;
  border-top: 1px solid hsl(var(--border));
  text-align: center;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

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

@media (max-width: 480px) {
  .layout {
    padding: 0 16px;
  }
  .grid-4 {
    grid-template-columns: 1fr 1fr;
  }
  .topbar {
    height: auto;
    padding: 12px 0;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-left {
    flex-wrap: wrap;
  }
  .btn-group {
    flex-direction: column;
  }
  .btn-group .btn {
    width: 100%;
  }
  .species-row {
    grid-template-columns: 80px 1fr 50px;
  }
}
