/* JDリーグダッシュボード（動的版） 独自CSS */

:root {
  --brand-900: #0f172a;
  --brand-700: #1e293b;
  --brand-500: #3b82f6;
  --brand-accent: #10b981;
  --brand-accent-light: #34d399;
}

html {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  scroll-behavior: smooth;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* カードベース */
.card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

@media (min-width: 640px) {
  .card {
    padding: 1.5rem;
  }
}

/* KPIカード */
.kpi-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--brand-accent);
}

.kpi-card.kpi-pv::before { background: var(--brand-500); }
.kpi-card.kpi-uu::before { background: var(--brand-accent); }
.kpi-card.kpi-sessions::before { background: #f59e0b; }
.kpi-card.kpi-engagement::before { background: #8b5cf6; }

.kpi-label {
  font-size: 0.75rem;
  color: #64748b;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-900);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 0.5rem;
}

@media (min-width: 640px) {
  .kpi-value {
    font-size: 2rem;
  }
}

.kpi-unit {
  font-size: 0.75rem;
  color: #64748b;
  font-weight: 500;
  margin-left: 0.25rem;
}

.kpi-compare {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.kpi-compare.up {
  color: #047857;
}

.kpi-compare.down {
  color: #b91c1c;
}

.kpi-compare.flat {
  color: #64748b;
}

/* プリセット期間ボタン */
.preset-btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.preset-btn:hover {
  background: #e2e8f0;
}

.preset-btn.is-active {
  background: var(--brand-900);
  color: #ffffff;
  border-color: var(--brand-900);
}

/* カスタム期間表示切替 */
#customRange.is-open {
  display: flex;
}

/* タブ */
.metric-tab {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #64748b;
  border-radius: 0.375rem;
  transition: all 0.15s ease;
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
  border: none;
}

.metric-tab:hover {
  color: var(--brand-900);
  background: rgba(15, 23, 42, 0.04);
}

.metric-tab.is-active {
  background: #ffffff;
  color: var(--brand-900);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* チャートボックス */
.chart-box {
  position: relative;
  width: 100%;
  height: 280px;
}

@media (min-width: 640px) {
  .chart-box {
    height: 360px;
  }
}

.chart-box-tall {
  position: relative;
  width: 100%;
  height: 400px;
}

@media (min-width: 640px) {
  .chart-box-tall {
    height: 480px;
  }
}

.chart-box-pie {
  position: relative;
  width: 100%;
  height: 240px;
}

@media (min-width: 640px) {
  .chart-box-pie {
    height: 280px;
  }
}

/* テーブル */
table {
  border-collapse: collapse;
  width: 100%;
}

tbody tr {
  border-bottom: 1px solid #f1f5f9;
}

tbody tr:hover {
  background-color: #f8fafc;
}

tbody td {
  padding: 0.5rem 0.75rem;
  vertical-align: top;
}

@media (min-width: 640px) {
  tbody td {
    padding: 0.625rem 0.75rem;
  }
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.page-title-cell {
  max-width: 360px;
  word-break: break-word;
}

@media (max-width: 640px) {
  .page-title-cell {
    max-width: 200px;
    font-size: 0.75rem;
  }
}

/* ソート可能ヘッダー */
.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.sortable:hover {
  background-color: #e2e8f0;
}

.sortable::after {
  content: " ⇅";
  color: #cbd5e1;
  font-size: 0.75em;
}

.sortable.sort-asc::after {
  content: " ↑";
  color: var(--brand-accent);
}

.sortable.sort-desc::after {
  content: " ↓";
  color: var(--brand-accent);
}

/* スクロールバー */
.overflow-x-auto::-webkit-scrollbar {
  height: 8px;
}

.overflow-x-auto::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.overflow-x-auto::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* details/summary */
details summary {
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::before {
  content: "▶ ";
  display: inline-block;
  transition: transform 0.15s ease;
  margin-right: 0.25rem;
}

details[open] summary::before {
  transform: rotate(90deg);
}

/* ローダー */
.loader {
  width: 28px;
  height: 28px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--brand-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ダッシュボード読み込み中の半透明 */
#dashboard.is-loading {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* 印刷 */
@media print {
  header,
  footer {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .preset-btn,
  .metric-tab,
  #pagesCsvBtn,
  #pagesSearch,
  #customRange,
  #loading {
    display: none !important;
  }
}
