/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --card2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --blue: #3b82f6;
  --green: #10b981;
  --orange: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --sidebar-w: 220px;
  --header-h: 70px;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 16px 14px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}
.sidebar-logo-img {
  width: 148px;
  height: auto;
  display: block;
  object-fit: contain;
  filter: none;
}
.sidebar-nav {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.sidebar-nav li { margin: 2px 8px; }
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}
.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
  background: rgba(59,130,246,0.15);
  color: var(--blue);
}
.sidebar-nav .nav-link i { width: 18px; text-align: center; font-size: 0.9rem; }
.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
}
.update-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}
.update-badge i { color: var(--green); }

/* ===== HAMBURGER ===== */
.hamburger {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 200;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 40px; height: 40px;
  cursor: pointer;
  font-size: 1rem;
}

/* ===== MAIN ===== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 24px 28px;
  min-width: 0;
}

/* ===== HEADER ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0;
}
.header-logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}
.page-title-sub {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.page-title i { color: var(--blue); }
.page-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.header-badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-blue { background: rgba(59,130,246,0.2); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.badge-green { background: rgba(16,185,129,0.2); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }

/* ── 手動更新ボタン ── */
.btn-manual-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-manual-refresh:hover {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn-manual-refresh:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ===== SECTION ===== */
.dashboard-section {
  margin-bottom: 52px;
  scroll-margin-top: 20px;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.section-title i { color: var(--blue); font-size: 1rem; }

/* ===== KPI GRID ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.kpi-card.small { padding: 14px 12px; }

.kpi-card[data-color="blue"]  { border-top: 3px solid var(--blue); }
.kpi-card[data-color="green"] { border-top: 3px solid var(--green); }
.kpi-card[data-color="orange"]{ border-top: 3px solid var(--orange); }
.kpi-card[data-color="red"]   { border-top: 3px solid var(--red); }
.kpi-card[data-color="purple"]{ border-top: 3px solid var(--purple); }

.kpi-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.kpi-card.small .kpi-icon { width: 32px; height: 32px; font-size: 0.85rem; }
.kpi-card[data-color="blue"]   .kpi-icon { background: rgba(59,130,246,0.15); color: var(--blue); }
.kpi-card[data-color="green"]  .kpi-icon { background: rgba(16,185,129,0.15); color: var(--green); }
.kpi-card[data-color="orange"] .kpi-icon { background: rgba(245,158,11,0.15); color: var(--orange); }
.kpi-card[data-color="red"]    .kpi-icon { background: rgba(239,68,68,0.15); color: var(--red); }
.kpi-card[data-color="purple"] .kpi-icon { background: rgba(139,92,246,0.15); color: var(--purple); }

.kpi-body { flex: 1; min-width: 0; }
.kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 4px;
}
.kpi-card.small .kpi-value { font-size: 1.3rem; }
.kpi-change {
  font-size: 0.75rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-change.positive { color: var(--green); }
.kpi-change.negative { color: var(--red); }
.kpi-spark {
  position: absolute;
  bottom: 6px; right: 6px;
  width: 80px; height: 36px;
  opacity: 0.6;
}

/* ===== CHARTS ===== */
.charts-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex: 1;
  min-width: 260px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.chart-card.chart-wide { flex: 2; }
.chart-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.chart-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.chart-body {
  padding: 12px 12px;
  position: relative;
  flex: 1;
}
.chart-body canvas { max-height: 100%; }

/* ===== INFO BOX ===== */
.info-box {
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.25);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.6;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.info-box i { color: var(--blue); margin-top: 2px; flex-shrink: 0; }

/* ===== TABS ===== */
.tab-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn.active,
.tab-btn:hover {
  background: rgba(59,130,246,0.15);
  color: var(--blue);
  border-color: rgba(59,130,246,0.3);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== TABLE ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.data-table th {
  background: var(--card2);
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(51,65,85,0.5);
  color: var(--text);
  white-space: nowrap;
}
.data-table tr:hover td { background: rgba(59,130,246,0.05); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .tag-month {
  background: rgba(59,130,246,0.12);
  color: var(--blue);
  border-radius: 4px;
  padding: 2px 6px;
  font-weight: 600;
  font-size: 0.75rem;
}
.data-table .bar-cell { display: flex; align-items: center; gap: 6px; }
.data-table .inline-bar {
  height: 6px; border-radius: 3px;
  background: var(--blue);
  min-width: 2px;
}
.td-pos { color: var(--green); font-weight: 600; }
.td-neg { color: var(--red); font-weight: 600; }

/* ===== 推奨アクション SECTION ===== */
.actions-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.actions-info { display: flex; align-items: center; gap: 6px; }
.actions-update { display: flex; align-items: center; gap: 6px; }
.actions-update i { color: var(--green); }
.btn-refresh {
  margin-left: auto;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
}
.btn-refresh:hover { background: #2563eb; }
.btn-refresh:active { background: #1d4ed8; }

.actions-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 10px 0;
}
.filter-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}
.action-filter-btn {
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.action-filter-btn:hover { border-color: var(--blue); color: var(--blue); }
.action-filter-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

.actions-category-group { margin-bottom: 28px; }
.actions-category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.actions-category-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.actions-category-count {
  background: #e2e8f0;
  color: var(--text-muted);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 14px;
}
.action-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}
.action-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); border-color: #cbd5e1; }
.action-card.priority-3 { border-left: 4px solid var(--red); }
.action-card.priority-2 { border-left: 4px solid var(--orange); }
.action-card.priority-1 { border-left: 4px solid var(--blue); }

.action-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.action-metric-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}
.action-priority-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
}
.priority-badge-3 { background: rgba(239,68,68,0.1); color: var(--red); }
.priority-badge-2 { background: rgba(245,158,11,0.1); color: #d97706; }
.priority-badge-1 { background: rgba(59,130,246,0.1); color: var(--blue); }

.action-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.action-latest-value {
  font-size: 0.8rem;
  color: #475569;
  font-weight: 500;
}
.action-trend {
  font-size: 0.8rem;
  font-weight: 600;
}
.action-eval {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: #f1f5f9;
}

.action-analysis {
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 10px;
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.action-recommendations {
  background: #f0f9ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 10px 12px;
}
.action-recommendations-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.action-rec-list {
  font-size: 0.78rem;
  color: #1e3a5f;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.action-card-footer {
  margin-top: 10px;
  font-size: 0.7rem;
  color: #94a3b8;
  text-align: right;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== CHURN SECTION ===== */
.churn-def-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.churn-def-box {
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.churn-def-box.monthly {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.3);
  border-left: 4px solid var(--red);
}
.churn-def-box.paid {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.3);
  border-left: 4px solid var(--orange);
}
.churn-def-icon {
  font-size: 1.4rem;
  margin-top: 2px;
  flex-shrink: 0;
}
.churn-def-box.monthly .churn-def-icon { color: var(--red); }
.churn-def-box.paid    .churn-def-icon { color: var(--orange); }
.churn-def-title {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text);
}
.churn-def-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 4px;
}
.churn-def-formula {
  font-size: 0.72rem;
  color: #64748b;
  font-family: monospace;
  background: rgba(0,0,0,0.2);
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
}

.churn-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 6px;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  letter-spacing: 0.02em;
}
.churn-section-label.monthly-label {
  background: rgba(239,68,68,0.12);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.25);
}
.churn-section-label.paid-label {
  background: rgba(245,158,11,0.12);
  color: var(--orange);
  border: 1px solid rgba(245,158,11,0.25);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chart-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.chart-badge.monthly-badge {
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}
.chart-badge.paid-badge {
  background: rgba(245,158,11,0.15);
  color: var(--orange);
  border: 1px solid rgba(245,158,11,0.3);
}

/* ===== CHURN RATE CARDS (3種比較) ===== */
.kpi-grid-3rate {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 20px;
}
@media (max-width: 960px) { .kpi-grid-3rate { grid-template-columns: 1fr; } }

.rate-card {
  /* kpi-cardのflex横並びを縦並びに上書き */
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 0 !important;
  position: relative;
  overflow: hidden;
  padding: 16px 18px 44px !important; /* 下部スパークラインのスペース確保 */
}
.rate-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.rate-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.trial-icon   { background: rgba(245,158,11,0.15); color: #d97706; }
.paid-icon    { background: rgba(16,185,129,0.15); color: #059669; }
.overall-icon { background: rgba(239,68,68,0.15);  color: #dc2626; }

.rate-type-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}
.rate-big {
  font-size: 2.2rem !important;
  font-weight: 800 !important;
  margin: 4px 0 !important;
  line-height: 1.1 !important;
}
.rate-good { color: #059669 !important; }
.rate-bad  { color: #dc2626 !important; }

.rate-trend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.rate-prev {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.rate-arrow {
  font-size: 0.72rem;
  font-weight: 600;
}
.rate-arrow.positive { color: #059669; }
.rate-arrow.negative { color: #dc2626; }
.rate-arrow.neutral  { color: #64748b; }

.rate-history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}
.rh-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 2px;
}
.rh-val {
  font-size: 0.68rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  color: #475569;
}
.rh-val.warn  { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.4); color: #b45309; }
.rh-val.alert { background: rgba(239,68,68,0.12);  border-color: rgba(239,68,68,0.35); color: #b91c1c; }
.rh-val.curr  { background: #1e293b; color: #f8fafc; border-color: #1e293b; font-weight: 700; }

.rate-benchmark {
  font-size: 0.7rem;
  color: #64748b;
  padding: 4px 8px;
  background: #f8fafc;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin-top: 4px;
}
/* rate-card内のkpi-iconは非表示（rate-card-headerを使うため） */
.rate-card > .kpi-icon { display: none !important; }
/* rate-card内のkpi-bodyはflex不要 */
.rate-card > .kpi-body { flex: none; }

.rate-sparkline {
  position: absolute;
  bottom: 10px;
  right: 14px;
  width: 80px !important;
  height: 30px !important;
  opacity: 0.5;
}

.trial-rate-card  { border-top: 3px solid #f59e0b; }
.paid-rate-card   { border-top: 3px solid #10b981; }
.overall-rate-card{ border-top: 3px solid #ef4444; }

/* ===== MAGIC NUMBER SECTION ===== */
.magic-hero {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #1e3a5f 100%);
  border-radius: 16px;
  padding: 28px 32px;
  margin-bottom: 24px;
  color: #f8fafc;
  position: relative;
  overflow: hidden;
}
.magic-hero::before {
  content: '✨';
  position: absolute;
  right: 24px;
  top: 16px;
  font-size: 2.5rem;
  opacity: 0.25;
}
.magic-hero-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #7dd3fc;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.magic-hero-desc {
  font-size: 0.88rem;
  color: #94a3b8;
  line-height: 1.7;
  max-width: 700px;
}
.magic-hero-highlight {
  color: #fbbf24;
  font-weight: 600;
}

/* マジックナンバー スコアカードグリッド */
.magic-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 1200px) { .magic-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .magic-grid { grid-template-columns: 1fr; } }

.magic-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px 42px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  cursor: pointer;
}
.magic-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }

.magic-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.magic-card-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.magic-card-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1.3;
}
.magic-card-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  margin: 2px 0 6px;
}
.magic-card-value.good  { color: #059669; }
.magic-card-value.warn  { color: #d97706; }
.magic-card-value.bad   { color: #dc2626; }

.magic-card-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.magic-card-benchmark {
  font-size: 0.68rem;
  color: #64748b;
  background: #f1f5f9;
  border-radius: 4px;
  padding: 2px 6px;
  display: inline-block;
}
.magic-sparkline {
  position: absolute;
  bottom: 10px;
  right: 12px;
  width: 80px !important;
  height: 28px !important;
  opacity: 0.5;
}

/* マジックナンバー ステータスバー */
.magic-status-bar {
  height: 4px;
  border-radius: 2px;
  margin-bottom: 8px;
  background: #e2e8f0;
  overflow: hidden;
}
.magic-status-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 1s ease;
}
.magic-status-fill.good  { background: #10b981; }
.magic-status-fill.warn  { background: #f59e0b; }
.magic-status-fill.bad   { background: #ef4444; }

/* マジックナンバー 分析インサイトボックス */
.magic-insight-box {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid #7dd3fc;
  border-left: 4px solid #0ea5e9;
  border-radius: 10px;
  padding: 18px 22px;
  margin-bottom: 20px;
}
.magic-insight-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #0369a1;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.magic-insight-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 700px) { .magic-insight-list { grid-template-columns: 1fr; } }
.magic-insight-item {
  font-size: 0.78rem;
  color: #334155;
  padding: 8px 12px;
  background: rgba(255,255,255,0.7);
  border-radius: 6px;
  border: 1px solid rgba(125,211,252,0.4);
  line-height: 1.5;
}
.magic-insight-item strong { color: #0369a1; }

/* フェーズ別コンバージョンフロー */
.magic-funnel-flow {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.magic-funnel-step {
  flex: 1;
  min-width: 100px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  position: relative;
}
.magic-funnel-step + .magic-funnel-step {
  margin-left: 28px;
}
.magic-funnel-step::before {
  content: '→';
  position: absolute;
  left: -22px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: #94a3b8;
}
.magic-funnel-step:first-child::before { display: none; }
.magic-funnel-step-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}
.magic-funnel-step-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
}
.magic-funnel-step-rate {
  font-size: 0.7rem;
  margin-top: 3px;
  font-weight: 600;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
  .churn-def-row { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .main-content { margin-left: 0; padding: 16px; padding-top: 60px; }
  .chart-card.chart-wide { flex-basis: 100%; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-grid-5 { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 1.3rem; }
  .charts-row { flex-direction: column; }
  .chart-card { min-width: unset; }
}

/* ===================================================
   KPI MODAL
   =================================================== */

/* ── オーバーレイ ── */
#kpi-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#kpi-modal-overlay.active {
  display: flex;
  animation: overlayIn 0.2s ease;
}
@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── モーダル本体 ── */
.kpi-modal {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px 28px 20px;
  position: relative;
  animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

/* ── 閉じるボタン ── */
.kpi-modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  z-index: 1;
}
.kpi-modal-close:hover { background: #ef4444; color: #fff; border-color: #ef4444; }

/* ── ヘッダー ── */
.kpi-modal-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
  padding-right: 36px;
}
.kpi-modal-icon-wrap {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.kpi-modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.3;
}
.kpi-modal-note {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 3px;
  line-height: 1.5;
}

/* ── Stats row ── */
.kpi-modal-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}
.kpi-ms-item {
  flex: 1;
  min-width: 90px;
  text-align: center;
}
.kpi-ms-label {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.kpi-ms-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}
.kpi-ms-item.pos .kpi-ms-val { color: #059669; }
.kpi-ms-item.neg .kpi-ms-val { color: #dc2626; }

/* ── チャートエリア ── */
.kpi-modal-chart-wrap {
  position: relative;
  height: 280px;
  margin-bottom: 20px;
  background: #fafafa;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #e2e8f0;
}

/* ── データテーブル ── */
.kpi-modal-table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  margin-bottom: 16px;
}
.kpi-modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.kpi-modal-table thead tr {
  background: #f1f5f9;
}
.kpi-modal-table th {
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid #e2e8f0;
}
.kpi-modal-table td {
  padding: 8px 12px;
  color: #334155;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}
.kpi-modal-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.kpi-modal-table tbody tr:hover { background: #f8fafc; }
.kpi-modal-table tbody tr.latest-row {
  background: rgba(59,130,246,0.06);
}
.kpi-modal-table tbody tr.latest-row td {
  border-bottom: none;
}

.modal-month-tag {
  display: inline-block;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #475569;
}
.modal-mom {
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.modal-mom.pos { color: #059669; }
.modal-mom.neg { color: #dc2626; }

/* ── フッター ── */
.kpi-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: #94a3b8;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
}

/* ── クリック可能カード ── */
.kpi-clickable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s !important;
  position: relative;
}
.kpi-clickable:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12) !important;
}
.kpi-clickable::after {
  content: '\f201';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.65rem;
  color: #cbd5e1;
  transition: color 0.15s;
}
.kpi-clickable:hover::after { color: #3b82f6; }

/* ── モーダル スクロールバー ── */
.kpi-modal::-webkit-scrollbar { width: 5px; }
.kpi-modal::-webkit-scrollbar-track { background: transparent; }
.kpi-modal::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── レスポンシブ ── */
@media (max-width: 600px) {
  .kpi-modal { padding: 20px 16px 16px; border-radius: 12px; }
  .kpi-modal-stats { gap: 6px; }
  .kpi-ms-item { min-width: 70px; }
  .kpi-modal-chart-wrap { height: 220px; }
}

/* ===================================================
   KPI CARD DRAG & DROP
   =================================================== */

/* ── ドラッグハンドルヒント ── */
.drag-hint-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.7rem;
  color: #cbd5e1;
  opacity: 0;
  transition: opacity 0.2s;
  cursor: grab;
  pointer-events: none;
  z-index: 2;
}
[data-card-id]:hover .drag-hint-icon {
  opacity: 1;
}
[data-card-id]:active .drag-hint-icon {
  cursor: grabbing;
}

/* ── ドラッグ中のゴースト（ドラッグ元の穴） ── */
.kpi-card-ghost {
  opacity: 0.35;
  background: #f1f5f9 !important;
  border: 2px dashed #94a3b8 !important;
  border-top: 2px dashed #94a3b8 !important;
  box-shadow: none !important;
  transform: none !important;
}
.kpi-card-ghost * { visibility: hidden; }

/* ── 選択中（持ち上がったカード） ── */
.kpi-card-chosen {
  box-shadow: 0 16px 48px rgba(0,0,0,0.18) !important;
  transform: scale(1.03) rotate(0.5deg) !important;
  z-index: 9999;
  cursor: grabbing !important;
}
.kpi-card-chosen .drag-hint-icon {
  opacity: 1;
  color: #3b82f6;
}

/* ── ドラッグ中はカード全体のホバー効果を抑制 ── */
.sorting-active .kpi-card:not(.kpi-card-chosen) {
  transition: none !important;
}
.sorting-active .kpi-card:not(.kpi-card-chosen):hover {
  transform: none !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06) !important;
}

/* ── コントロールバー（並び替えラベル + リセットボタン） ── */
.sort-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 2px;
}
.sort-label {
  font-size: 0.72rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.02em;
}
.sort-label i { font-size: 0.68rem; }

.sort-reset-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  background: transparent;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.sort-reset-btn:hover {
  background: #f1f5f9;
  color: #3b82f6;
  border-color: #bfdbfe;
}
.sort-reset-btn i { font-size: 0.65rem; }

/* ── リセット時のフラッシュアニメーション ── */
@keyframes sortResetFlash {
  0%   { box-shadow: 0 0 0 2px #3b82f6, 0 1px 4px rgba(0,0,0,0.06); }
  60%  { box-shadow: 0 0 0 4px rgba(59,130,246,0.25), 0 4px 12px rgba(59,130,246,0.15); }
  100% { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
}
.sort-reset-flash {
  animation: sortResetFlash 0.6s ease-out forwards;
}

/* ── トースト通知 ── */
.sort-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 9px 20px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 99999;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}
.sort-toast i { color: #34d399; }
.sort-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── グリッドが並び替え中に縮まないよう ── */
#kpi-grid-row1[data-sortable-group],
#kpi-grid-row2[data-sortable-group] {
  /* SortableJSが高さを管理するため min-height を確保 */
  min-height: 80px;
}

/* ===================================================
   SALES セクション
   =================================================== */

/* チャートバッジ（Sales用） */
.chart-badge.sales-badge {
  background: rgba(16,185,129,0.15);
  color: #059669;
  border: 1px solid rgba(16,185,129,0.3);
}
.chart-badge.sales-badge-red {
  background: rgba(239,68,68,0.12);
  color: #dc2626;
  border: 1px solid rgba(239,68,68,0.3);
}

/* インサイトグリッド（強み / 課題 / 打ち手） */
.sales-insight-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.sales-insight-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.sales-insight-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.sales-insight-card.green::before { background: #10b981; }
.sales-insight-card.red::before   { background: #ef4444; }
.sales-insight-card.orange::before { background: #f59e0b; }

.sales-insight-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: 0.01em;
}
.sales-insight-card.green .sales-insight-header { color: #059669; }
.sales-insight-card.red   .sales-insight-header { color: #dc2626; }
.sales-insight-card.orange .sales-insight-header { color: #d97706; }

.sales-insight-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sales-insight-list li {
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.5;
  padding-left: 14px;
  position: relative;
}
.sales-insight-list li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: #94a3b8;
  font-weight: 700;
}
.sales-insight-list li strong {
  color: #0f172a;
  font-weight: 700;
}

/* レスポンシブ */
@media (max-width: 1000px) {
  .sales-insight-grid { grid-template-columns: 1fr 1fr; }
  .sales-insight-card.orange { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .sales-insight-grid { grid-template-columns: 1fr; }
  .sales-insight-card.orange { grid-column: auto; }
}

/* ===== OUTBOUND CALL SECTION ===== */
.outbound-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 24px;
  position: relative;
}
.outbound-section::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: linear-gradient(180deg, #3b82f6 0%, #8b5cf6 100%);
  border-radius: 14px 0 0 14px;
}
.outbound-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.outbound-section-title i {
  color: #3b82f6;
}
.outbound-section-desc {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 18px;
  line-height: 1.6;
}

/* アウトバウンド インサイトボックス */
.outbound-insight-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 20px;
}
.outbound-insight-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.outbound-insight-item::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
}
.outbound-green::before  { background: #10b981; }
.outbound-orange::before { background: #f59e0b; }
.outbound-blue::before   { background: #3b82f6; }

.outbound-insight-label {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.outbound-green  .outbound-insight-label { color: #059669; }
.outbound-orange .outbound-insight-label { color: #d97706; }
.outbound-blue   .outbound-insight-label { color: #2563eb; }

.outbound-insight-item ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.outbound-insight-item ul li {
  font-size: 0.77rem;
  color: #475569;
  line-height: 1.55;
  padding-left: 14px;
  position: relative;
}
.outbound-insight-item ul li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: #94a3b8;
  font-weight: 700;
}
.outbound-insight-item ul li strong {
  color: #0f172a;
  font-weight: 700;
}

@media (max-width: 1000px) {
  .outbound-insight-box { grid-template-columns: 1fr 1fr; }
  .outbound-blue { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .outbound-insight-box { grid-template-columns: 1fr; }
  .outbound-blue { grid-column: auto; }
  .outbound-section { padding: 16px; }
}
