.emalm-insights {
  --insights-border: var(--emalm-ui-border);
  --insights-muted: var(--emalm-ui-text-muted);
  --insights-panel: var(--emalm-ui-surface-1);
  --insights-bg: var(--emalm-ui-surface-2);
  --insights-accent: var(--emalm-ui-accent-strong);
  --insights-cell-gap: 1px;
  --insights-level-0: #ebedf0;
  --insights-level-1: #9be9a8;
  --insights-level-2: #40c463;
  --insights-level-3: #30a14e;
  --insights-level-4: #216e39;
  background: var(--insights-bg);
  border: 1px solid var(--insights-border);
  border-radius: 8px;
  margin: 16px 0;
  max-width: 1100px;
  padding: 14px;
}

.emalm-insights-header {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.emalm-insights-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.emalm-insights-header p {
  color: var(--insights-muted);
  font-size: 12px;
  margin: 0;
}

.emalm-insights-summary-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin-bottom: 14px;
}

.emalm-insights-summary-card {
  background: var(--insights-panel);
  border: 1px solid var(--insights-border);
  border-radius: 6px;
  color: inherit;
  display: grid;
  gap: 2px;
  min-height: 58px;
  padding: 9px 10px;
  text-decoration: none;
}

.emalm-insights-summary-card:hover {
  border-color: var(--emalm-ui-accent);
  text-decoration: none;
}

.emalm-insights-summary-card.tag-type-0,
.emalm-post-analytics-query.tag-type-0 { color: var(--emalm-tag-general-color, #006ffa); }
.emalm-insights-summary-card.tag-type-1,
.emalm-post-analytics-query.tag-type-1 { color: var(--emalm-tag-artist-color, #ff0000); }
.emalm-insights-summary-card.tag-type-3,
.emalm-post-analytics-query.tag-type-3 { color: var(--emalm-tag-copyright-color, #b000b0); }
.emalm-insights-summary-card.tag-type-4,
.emalm-post-analytics-query.tag-type-4 { color: var(--emalm-tag-character-color, #00a000); }
.emalm-insights-summary-card.tag-type-5,
.emalm-post-analytics-query.tag-type-5 { color: var(--emalm-tag-meta-color, #ff4a00); }

.emalm-insights-summary-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.emalm-insights-summary-label {
  color: var(--insights-muted);
  font-size: 12px;
}

.emalm-insights-heatmap {
  display: grid;
  flex: 1 1 auto;
  gap: var(--insights-cell-gap);
  grid-auto-flow: column;
  grid-template-columns: repeat(var(--emalm-insights-heatmap-weeks, 53), minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  min-height: 0;
  padding: 2px 0;
  width: 100%;
}

.emalm-insights-day {
  background: var(--insights-level-0);
  border-radius: 2px;
  display: block;
  min-height: 0;
  min-width: 0;
}

.emalm-insights-level-1 {
  background: var(--insights-level-1);
}

.emalm-insights-level-2 {
  background: var(--insights-level-2);
}

.emalm-insights-level-3 {
  background: var(--insights-level-3);
}

.emalm-insights-level-4 {
  background: var(--insights-level-4);
}

.emalm-insights-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.emalm-insights-panel {
  background: var(--insights-panel);
  border: 1px solid var(--insights-border);
  border-radius: 6px;
  min-width: 0;
  padding: 10px;
}

.emalm-insights-lower-row {
  align-items: stretch;
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

.emalm-insights-activity {
  align-self: stretch;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.emalm-insights-activity .emalm-insights-heatmap {
  height: 100%;
}

.emalm-insights-panel h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 8px;
}

.emalm-insights-muted {
  color: var(--insights-muted);
  margin: 0;
}

.emalm-insights-ranked-list {
  display: grid;
  gap: 5px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.emalm-insights-ranked-list li {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
}

.emalm-insights-ranked-list a,
.emalm-insights-ranked-list span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.emalm-insights-ranked-list span:last-child {
  color: var(--insights-muted);
  flex: 0 0 auto;
}

.emalm-insights-bars {
  display: grid;
  gap: 6px;
}

.emalm-insights-bar-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 62px minmax(80px, 1fr) 36px;
}

.emalm-insights-bar-row span,
.emalm-insights-bar-row strong {
  color: var(--insights-muted);
  font-size: 12px;
}

.emalm-insights-bar-row b {
  background: var(--emalm-ui-accent);
  border-radius: 999px;
  display: block;
  height: 8px;
}

.emalm-insights-thumbs {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.emalm-insights-thumb {
  color: inherit;
  display: grid;
  gap: 4px;
  text-decoration: none;
}

.emalm-insights-thumb img,
.emalm-insights-thumb-fallback {
  aspect-ratio: 1;
  background: var(--emalm-ui-surface-2);
  border: 1px solid var(--insights-border);
  border-radius: 4px;
  object-fit: cover;
  width: 100%;
}

.emalm-insights-thumb span {
  color: var(--insights-muted);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 760px) {
  .emalm-insights {
    border-radius: 6px;
    margin: 12px 0;
    padding: 10px;
  }

  .emalm-insights-summary-grid,
  .emalm-insights-grid,
  .emalm-insights-lower-row {
    grid-template-columns: 1fr;
  }

  .emalm-insights-thumbs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .emalm-insights-activity {
    min-height: 160px;
  }
}
