/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Yu Gothic UI", Meiryo, sans-serif;
  background: #f5f7fa;
  color: #1f2937;
  font-size: 14px;
  line-height: 1.6;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 200px;
  height: 100vh;
  background: linear-gradient(180deg, #4f46e5, #6366f1);
  color: white;
  z-index: 100;
  overflow-y: auto;
  transition: width 0.3s;
}

.sidebar-logo {
  padding: 20px;
  font-size: 1.3em;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar-section {
  padding: 8px 0;
}

.sidebar-group-label {
  padding: 8px 16px;
  font-size: 0.75em;
  text-transform: uppercase;
  opacity: 0.6;
  letter-spacing: 0.05em;
}

.sidebar-link {
  display: block;
  padding: 8px 16px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.85em;
  transition: background 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-link.active {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: #fff;
  color: #fff;
  font-weight: 600;
}

.sidebar-toggle {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 500;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

/* Main Area */
.main-area {
  margin-left: 200px;
  transition: margin-left 0.3s;
}

.main-area.expanded {
  margin-left: 0;
}

/* Header */
.header {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  padding: 24px 30px;
}

.header h1 {
  font-size: 1.5em;
  margin: 0;
}

.header .sub,
.header .meta {
  font-size: 0.85em;
  opacity: 0.8;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  padding: 14px 20px;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.controls select,
.controls input {
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85em;
}

.controls .spacer {
  flex: 1;
}

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

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85em;
  cursor: pointer;
  border: none;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-pri {
  background: #6366f1;
  color: white;
}

.btn-pri:hover {
  background: #4f46e5;
}

.btn-outline {
  background: white;
  border: 1px solid #d1d5db;
  color: #374151;
}

.btn-outline:hover {
  background: #f3f4f6;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8em;
}

/* Page Sections */
.page-section {
  margin-bottom: 8px;
}

/* Section */
.section {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
}

.section h2 {
  font-size: 1.15em;
  color: #1f2937;
  margin: 0 0 14px 0;
  padding-bottom: 8px;
  border-bottom: 2px solid #e5e7eb;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: white;
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.kpi-label {
  font-size: 0.75em;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 1.8em;
  font-weight: 700;
  color: #1f2937;
  margin: 4px 0;
}

.kpi-sub {
  font-size: 0.8em;
  color: #6b7280;
}

.kpi-change {
  font-size: 0.8em;
  font-weight: 500;
}

.kpi-change.up {
  color: #22c55e;
}

.kpi-change.down {
  color: #ef4444;
}

/* Charts */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-height: 320px;
  overflow: hidden;
}

.chart-container {
  position: relative;
  height: 280px;
  max-height: 280px;
}

.chart-container canvas {
  max-height: 280px !important;
}

.demo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.demo-chart {
  background: white;
  border-radius: 8px;
  padding: 12px;
}

/* Tables */
.post-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}

.post-table th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  cursor: pointer;
}

.post-table th.sorted {
  color: #6366f1;
  border-bottom-color: #6366f1;
}

.post-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

.post-row {
  cursor: pointer;
  transition: background 0.15s;
}

.post-row:hover {
  background: #f8fafc;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82em;
}

.mini-table th {
  background: #f8fafc;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
}

.mini-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
}

/* Summary Table */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}

.summary-table th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
}

.summary-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.summary-section-header td {
  background: #eef2ff;
  font-weight: 700;
  color: #4338ca;
  padding: 10px 12px;
}

.change-up {
  color: #22c55e;
  font-weight: 600;
}

.change-down {
  color: #ef4444;
  font-weight: 600;
}

/* Profile KPI */
.profile-kpi {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

/* Stories KPI */
.stories-kpi {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.stories-kpi-card {
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 140px;
}

.stories-kpi-value {
  font-size: 1.4em;
  font-weight: 700;
  color: #1f2937;
}

/* Hashtag Section */
.hashtag-tops {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.hashtag-top-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 16px;
}

.hashtag-top-card h4 {
  font-size: 0.95em;
  color: #374151;
  margin-bottom: 10px;
  margin-top: 0;
}

/* Comment Layout */
.comment-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  min-height: 300px;
}

.comment-posts,
.comment-detail {
  background: #f8fafc;
  border-radius: 8px;
  padding: 16px;
  overflow-y: auto;
  max-height: 500px;
}

.comment-card {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  transition: border-color 0.2s;
}

.comment-card:hover,
.comment-card.active {
  border-color: #6366f1;
}

.comment-badge {
  display: inline-block;
  background: #eef2ff;
  color: #4338ca;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 500;
}

/* Competitor Table */
.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}

.comp-table th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
}

.comp-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.comp-row {
  cursor: pointer;
  transition: background 0.15s;
}

.comp-row:hover {
  background: #f8fafc;
}

.comp-row.active {
  background: #eef2ff;
}

/* Trend Cards */
.trend-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.trend-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 20px;
  border-left: 4px solid #6366f1;
}

.trend-card h4 {
  font-size: 0.95em;
  color: #6366f1;
  margin: 0 0 8px 0;
}

.trend-card p {
  font-size: 0.88em;
  color: #374151;
  line-height: 1.5;
  margin: 0;
}

/* AI Report */
.ai-report .ai-text {
  font-size: 0.9em;
  line-height: 1.7;
  color: #374151;
}

.ai-report h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #4f46e5;
  margin: 0 0 12px 0;
}

.ai-report h3::before {
  content: "🤖";
  font-size: 1.2em;
}

/* Trend Info */
.trend-info {
  background: #eef2ff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  font-size: 0.9em;
  color: #4338ca;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
}

.modal.active {
  display: block;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: #fff;
  margin: 5% auto;
  max-width: 700px;
  border-radius: 12px;
  padding: 30px;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 201;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5em;
  cursor: pointer;
  color: #6b7280;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #1f2937;
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.detail-metric {
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.detail-metric .value {
  font-size: 1.3em;
  font-weight: 700;
  color: #1f2937;
}

.detail-metric .label {
  font-size: 0.75em;
  color: #6b7280;
}

/* Loading */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e5e7eb;
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 0;
    overflow: hidden;
  }

  .main-area {
    margin-left: 0;
  }

  .chart-row,
  .demo-grid,
  .hashtag-tops,
  .comment-layout,
  .trend-cards {
    grid-template-columns: 1fr;
  }

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

/* Empty state message */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #94a3b8;
  font-size: 14px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px dashed #cbd5e1;
  margin: 12px 0;
}
.section-desc {
  color: #64748b;
  font-size: 14px;
  margin-bottom: 16px;
}

/* Post Snapshot Cards */
.snapshot-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.snapshot-header {
  margin-bottom: 8px;
  font-size: 14px;
}
.snapshot-type {
  display: inline-block;
  background: #6366f1;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.snapshot-date {
  color: #6b7280;
  font-size: 13px;
  margin-left: 4px;
}
.snapshot-caption {
  color: #374151;
  font-size: 13px;
  margin-left: 8px;
}
.snapshot-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 14px;
  color: #4b5563;
  flex-wrap: wrap;
}
.snapshot-stats strong {
  color: #111827;
}
.snapshot-note {
  color: #9ca3af;
  font-size: 13px;
  font-style: italic;
  margin: 8px 0 0;
}
.section-desc {
  color: #6b7280;
  font-size: 13px;
  margin: 0 0 16px;
}

/* ===== 拡張 (2026-06-11): サムネ/インパクト/ヒートマップ/検索/バッジ ===== */
.post-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
.thumb-na { color: #cbd5e1; }
.post-search { width: 100%; max-width: 320px; padding: 8px 12px; margin-bottom: 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 0.9rem; }
.post-search:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }

.impact-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; }
.impact-card { display: flex; gap: 12px; align-items: flex-start; background: linear-gradient(135deg, #f8faff, #eef2ff); border: 1px solid #e0e7ff; border-radius: 12px; padding: 14px; position: relative; }
.impact-rank { position: absolute; top: -10px; left: -6px; background: #6366f1; color: #fff; font-weight: 700; font-size: 0.8rem; border-radius: 999px; padding: 2px 9px; }
.impact-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.impact-card-body { min-width: 0; }
.impact-caption { font-size: 0.85rem; font-weight: 600; line-height: 1.35; max-height: 3.6em; overflow: hidden; white-space: pre-line; }
.impact-date { font-size: 0.75rem; color: #64748b; margin: 4px 0; }
.impact-metrics { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.8rem; font-weight: 700; }
.impact-warn { color: #d97706; font-weight: 600; }
.imp-pos { color: #16a34a; }
.imp-neg { color: #dc2626; }
.impact-table .impact-cap { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.impact-note { font-size: 0.78rem; color: #64748b; margin-top: 10px; line-height: 1.6; }

.heatmap-grid { display: grid; grid-template-columns: 42px repeat(8, 1fr); gap: 3px; max-width: 720px; }
.hm-corner { }
.hm-head { font-size: 0.72rem; color: #64748b; text-align: center; align-self: center; }
.hm-cell { aspect-ratio: 2.2 / 1; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; color: #1e293b; cursor: default; }

.growth-badge { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge-fast { background: #fee2e2; color: #dc2626; }
.badge-slow { background: #dcfce7; color: #16a34a; }
.badge-mid { background: #e0e7ff; color: #4f46e5; }
.badge-collecting { background: #f1f5f9; color: #64748b; }

/* ===== デイリー詳細モーダル (2026-06-11) ===== */
.day-detail-title { margin: 0 0 12px; font-size: 1.05rem; }
.day-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.day-kpi { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.day-kpi .label { font-size: 0.72rem; color: #64748b; }
.day-kpi .value { font-size: 1.15rem; font-weight: 700; }
.day-diff { font-size: 0.75rem; font-weight: 700; }
.day-posts-title { margin: 16px 0 8px; font-size: 0.95rem; }
.day-posts { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.day-post-row { display: flex; align-items: center; gap: 12px; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px; }
.day-post-row .post-thumb { width: 52px; height: 52px; }
.day-post-info { flex: 1; min-width: 0; }
.day-post-cap { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-post-meta { font-size: 0.72rem; color: #64748b; margin: 2px 0; }
.day-post-stats { display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.78rem; }
.day-post-row button { flex-shrink: 0; padding: 6px 12px; border: 1px solid #6366f1; color: #6366f1; background: #fff; border-radius: 8px; cursor: pointer; }
.day-post-row button:hover { background: #6366f1; color: #fff; }

/* ===== HTML外部ツールチップ（サムネ対応） ===== */
#chartjs-tooltip { position: absolute; background: rgba(15,23,42,0.94); color: #fff; border-radius: 10px; padding: 10px 12px; font-size: 12px; z-index: 9999; pointer-events: none; transition: opacity .12s; max-width: 300px; box-shadow: 0 8px 24px rgba(0,0,0,.3); opacity: 0; }
#chartjs-tooltip .ctt-title { font-weight: 700; margin-bottom: 6px; font-size: 12.5px; }
#chartjs-tooltip .ctt-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#chartjs-tooltip .ctt-box { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex-shrink: 0; }
#chartjs-tooltip .ctt-sep { margin: 8px 0 4px; color: #cbd5e1; font-size: 11px; }
#chartjs-tooltip .ctt-post { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
#chartjs-tooltip .ctt-thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
#chartjs-tooltip .ctt-post-info { min-width: 0; }
#chartjs-tooltip .ctt-cap { font-weight: 600; line-height: 1.35; }
#chartjs-tooltip .ctt-meta { color: #cbd5e1; font-size: 11px; margin-top: 2px; }
#chartjs-tooltip .ctt-hint { color: #94a3b8; font-size: 10px; margin-top: 6px; }
