/* ===== Enhancements ===== */

.inline-bar-cell {
  --bar-pct: 0%;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.inline-bar-cell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(26, 115, 232, 0.15) 0,
    rgba(26, 115, 232, 0.15) var(--bar-pct),
    transparent var(--bar-pct),
    transparent 100%
  );
  z-index: 0;
}

.inline-bar-cell > * {
  position: relative;
  z-index: 1;
}

.comment-box {
  position: relative;
  margin-top: 24px;
  padding: 28px 16px 16px;
  min-height: 60px;
  border: 1px dashed #DADCE0;
  border-radius: 8px;
  background: #FAFBFC;
  color: #202124;
}

.comment-box::before {
  content: "コメント記入欄";
  position: absolute;
  top: 10px;
  left: 16px;
  font-size: 11px;
  font-weight: 600;
  color: #5F6368;
  letter-spacing: 0.02em;
}

.heatmap-table {
  border-collapse: collapse;
}

.heatmap-table th,
.heatmap-table td {
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.heatmap-table th {
  padding: 6px 10px;
  background: #E8F0FE;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: #202124;
}

.heatmap-table td {
  --heat-intensity: 0;
  --heat-fg-switch: clamp(0, (var(--heat-intensity) - 0.6) * 100, 1);
  min-width: 55px;
  padding: 6px 10px;
  font-size: 12px;
  text-align: center;
  background: rgba(26, 115, 232, var(--heat-intensity));
  color: rgb(
    calc(var(--heat-fg-switch) * 255),
    calc(var(--heat-fg-switch) * 255),
    calc(var(--heat-fg-switch) * 255)
  );
}

.chart-grid-3x3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.chart-grid-card {
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  background: #FFFFFF;
  overflow: hidden;
}

.chart-grid-title {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #202124;
}

.chart-grid-kpi {
  padding: 0 12px 12px;
  font-size: 20px;
  font-weight: 700;
  color: #202124;
}

.scatter-quadrant-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scatter-quadrant-overlay .quadrant-label {
  position: absolute;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  color: #5F6368;
  backdrop-filter: blur(4px);
}

.scatter-quadrant-overlay .quadrant-top-left {
  top: 8px;
  left: 8px;
}

.scatter-quadrant-overlay .quadrant-top-right {
  top: 8px;
  right: 8px;
}

.scatter-quadrant-overlay .quadrant-bottom-left {
  bottom: 8px;
  left: 8px;
}

.scatter-quadrant-overlay .quadrant-bottom-right {
  right: 8px;
  bottom: 8px;
}

.change-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.change-badge.up {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.1);
}

.change-badge.down {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
}

.change-badge.flat {
  color: #6b7280;
  background: rgba(107, 114, 128, 0.1);
}

.pivot-table {
  overflow-x: auto;
  max-width: 100%;
  font-size: 11px;
  white-space: nowrap;
}

.pivot-table table {
  border-collapse: collapse;
  min-width: 100%;
}

.pivot-table th,
.pivot-table td {
  padding: 6px 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #FFFFFF;
}

.pivot-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #E8F0FE;
  font-weight: 600;
}

.pivot-table th:first-child,
.pivot-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #FFFFFF;
}

.pivot-table th:first-child {
  z-index: 3;
  background: #E8F0FE;
}

.filter-dropdown-bar {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.filter-dropdown {
  border: 1px solid #DADCE0;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  background: #FFFFFF;
  color: #202124;
}

[data-theme="dark"] .inline-bar-cell::before {
  background: linear-gradient(
    90deg,
    rgba(147, 197, 253, 0.2) 0,
    rgba(147, 197, 253, 0.2) var(--bar-pct),
    transparent var(--bar-pct),
    transparent 100%
  );
}

[data-theme="dark"] .comment-box {
  border-color: #334155;
  background: #111827;
  color: #E2E8F0;
}

[data-theme="dark"] .comment-box::before {
  color: #94A3B8;
}

[data-theme="dark"] .heatmap-table th,
[data-theme="dark"] .heatmap-table td {
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .heatmap-table th {
  background: #1A2332;
  color: #BFDBFE;
}

[data-theme="dark"] .heatmap-table td {
  background: rgba(96, 165, 250, var(--heat-intensity));
}

[data-theme="dark"] .chart-grid-card {
  border-color: rgba(255, 255, 255, 0.08);
  background: #1E293B;
}

[data-theme="dark"] .chart-grid-title,
[data-theme="dark"] .chart-grid-kpi {
  color: #E2E8F0;
}

[data-theme="dark"] .scatter-quadrant-overlay .quadrant-label {
  background: rgba(15, 23, 42, 0.72);
  color: #CBD5E1;
}

[data-theme="dark"] .change-badge.up {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.14);
}

[data-theme="dark"] .change-badge.down {
  color: #f87171;
  background: rgba(248, 113, 113, 0.14);
}

[data-theme="dark"] .change-badge.flat {
  color: #94A3B8;
  background: rgba(148, 163, 184, 0.14);
}

[data-theme="dark"] .pivot-table th,
[data-theme="dark"] .pivot-table td {
  border-color: rgba(255, 255, 255, 0.08);
  background: #0F172A;
  color: #E2E8F0;
}

[data-theme="dark"] .pivot-table th {
  background: #1A2332;
  color: #BFDBFE;
}

[data-theme="dark"] .pivot-table th:first-child {
  background: #1A2332;
}

[data-theme="dark"] .pivot-table td:first-child {
  background: #0F172A;
}

[data-theme="dark"] .filter-dropdown {
  border-color: #334155;
  background: #1E293B;
  color: #E2E8F0;
}

@media (max-width: 1024px) {
  .chart-grid-3x3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .chart-grid-3x3 {
    grid-template-columns: minmax(0, 1fr);
  }
}
